-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathshader.go
59 lines (47 loc) · 1.23 KB
/
shader.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
// Copyright 2012 The go-gl 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 glh
import (
"log"
"github.com/go-gl/gl"
)
type Shader struct {
Type gl.GLenum
Program string
}
func (s Shader) Compile() gl.Shader {
return MakeShader(s.Type, s.Program)
}
func NewProgram(shaders ...Shader) gl.Program {
program := gl.CreateProgram()
for _, shader := range shaders {
program.AttachShader(shader.Compile())
}
program.Link()
OpenGLSentinel()
linkstat := program.Get(gl.LINK_STATUS)
if linkstat != 1 {
log.Panic("Program link failed, status=", linkstat,
"Info log: ", program.GetInfoLog())
}
program.Validate()
valstat := program.Get(gl.VALIDATE_STATUS)
if valstat != 1 {
log.Panic("Program validation failed: ", valstat)
}
return program
}
func MakeShader(shader_type gl.GLenum, source string) gl.Shader {
shader := gl.CreateShader(shader_type)
shader.Source(source)
shader.Compile()
OpenGLSentinel()
compstat := shader.Get(gl.COMPILE_STATUS)
if compstat != 1 {
log.Print("vert shader compilation status: ", compstat)
log.Print("Info log: ", shader.GetInfoLog())
log.Panic("Problem creating shader?")
}
return shader
}