/
gg.go
195 lines (158 loc) · 3.87 KB
/
gg.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
package gg
type Backend interface {
Enable(Enum)
DepthFunc(f Enum)
BlendFunc(sfactor, dfactor Enum)
Clear(mask Enum)
ClearColor(r, g, b, a float32)
CreateBuffer() *Buffer
BindBuffer(typ Enum, b *Buffer)
BufferData(typ Enum, src []byte, usage Enum)
CreateShader(src []byte, typ Enum) (*Shader, error)
AttachShader(*Program, *Shader)
CreateProgram() *Program
LinkProgram(*Program) error
UseProgram(*Program)
GetUniformLocation(*Program, string) (*Uniform, error)
Uniform1f(*Uniform, float32)
Uniform1i(*Uniform, int)
Uniform4f(*Uniform, float32, float32, float32, float32)
UniformMatrix4fv(*Uniform, []float32)
GetAttribLocation(*Program, string) (*Attribute, error)
EnableVertexAttribArray(*Attribute)
VertexAttribPointer(
a *Attribute, size int, typ Enum, normalized bool,
stride, offset int,
)
CreateTexture() *Texture
ActiveTexture(tex Enum)
BindTexture(target Enum, texture *Texture)
TexImage2D(
target Enum, level int, internalFormat Enum,
width, height, border int,
format, typ Enum,
data interface{},
)
TexParameteri(target Enum, pname Enum, param Enum)
DrawArrays(mode Enum, first, count int)
}
type Buffer struct {
Value interface{}
}
type Program struct {
Value interface{}
}
type Shader struct {
Value interface{}
}
type Uniform struct {
Value interface{}
}
type Attribute struct {
Value interface{}
}
type Texture struct {
Value interface{}
}
type Enum uint32
var backend Backend
func Register(b Backend) {
if b == nil {
panic("gg: Register with nil backend")
}
if backend != nil {
panic("gg: Register called twice")
}
backend = b
}
func Enable(c Enum) {
backend.Enable(c)
}
func DepthFunc(f Enum) {
backend.DepthFunc(f)
}
func BlendFunc(sfactor, dfactor Enum) {
backend.BlendFunc(sfactor, dfactor)
}
func Clear(mask Enum) {
backend.Clear(mask)
}
func ClearColor(r, g, b, a float32) {
backend.ClearColor(r, g, b, a)
}
func CreateBuffer() *Buffer {
return backend.CreateBuffer()
}
func BindBuffer(typ Enum, b *Buffer) {
backend.BindBuffer(typ, b)
}
func BufferData(typ Enum, src []byte, usage Enum) {
backend.BufferData(typ, src, usage)
}
func CreateShader(src []byte, typ Enum) (*Shader, error) {
return backend.CreateShader(src, typ)
}
func CreateProgram() *Program {
return backend.CreateProgram()
}
func AttachShader(p *Program, s *Shader) {
backend.AttachShader(p, s)
}
func LinkProgram(p *Program) error {
return backend.LinkProgram(p)
}
func UseProgram(p *Program) {
backend.UseProgram(p)
}
func GetUniformLocation(p *Program, name string) (*Uniform, error) {
return backend.GetUniformLocation(p, name)
}
func Uniform1f(u *Uniform, v0 float32) {
backend.Uniform1f(u, v0)
}
func Uniform4f(u *Uniform, v0, v1, v2, v3 float32) {
backend.Uniform4f(u, v0, v1, v2, v3)
}
func Uniform1i(u *Uniform, v0 int) {
backend.Uniform1i(u, v0)
}
func UniformMatrix4fv(u *Uniform, value []float32) {
backend.UniformMatrix4fv(u, value)
}
func GetAttribLocation(p *Program, name string) (*Attribute, error) {
return backend.GetAttribLocation(p, name)
}
func EnableVertexAttribArray(a *Attribute) {
backend.EnableVertexAttribArray(a)
}
func VertexAttribPointer(a *Attribute, size int, typ Enum, normalized bool, stride, offset int) {
backend.VertexAttribPointer(a, size, typ, normalized, stride, offset)
}
func CreateTexture() *Texture {
return backend.CreateTexture()
}
func ActiveTexture(tex Enum) {
backend.ActiveTexture(tex)
}
func BindTexture(target Enum, texture *Texture) {
backend.BindTexture(target, texture)
}
func TexImage2D(
target Enum, level int, internalFormat Enum,
width, height, border int,
format, typ Enum,
data interface{},
) {
backend.TexImage2D(
target, level, internalFormat,
width, height, border,
format, typ,
data,
)
}
func TexParameteri(target Enum, pname Enum, param Enum) {
backend.TexParameteri(target, pname, param)
}
func DrawArrays(mode Enum, first, count int) {
backend.DrawArrays(mode, first, count)
}