forked from go-gl-legacy/gl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgl.go
2527 lines (1995 loc) · 75.8 KB
/
gl.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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package gl
// #cgo darwin LDFLAGS: -framework OpenGL -lGLEW
// #cgo windows LDFLAGS: -lglew32 -lopengl32
// #cgo linux LDFLAGS: -lGLEW -lGL
//
// #include <stdlib.h>
//
// #include <GL/glew.h>
//
// #undef GLEW_GET_FUN
// #define GLEW_GET_FUN(x) (*x)
import "C"
import "unsafe"
import "reflect"
type GLenum C.GLenum
type GLbitfield C.GLbitfield
type GLclampf C.GLclampf
type GLclampd C.GLclampd
type Pointer unsafe.Pointer
// those types are left for compatibility reasons
type GLboolean C.GLboolean
type GLbyte C.GLbyte
type GLshort C.GLshort
type GLint C.GLint
type GLsizei C.GLsizei
type GLubyte C.GLubyte
type GLushort C.GLushort
type GLuint C.GLuint
type GLfloat C.GLfloat
type GLdouble C.GLdouble
// helpers
func glBool(v bool) C.GLboolean {
if v {
return 1
}
return 0
}
func goBool(v C.GLboolean) bool {
return v != 0
}
func glString(s string) *C.GLchar { return (*C.GLchar)(C.CString(s)) }
func freeString(ptr *C.GLchar) { C.free(unsafe.Pointer(ptr)) }
func GetGLenumType(v interface{}) (t GLenum, p unsafe.Pointer) {
rv := reflect.ValueOf(v)
var et reflect.Value
switch rv.Type().Kind() {
case reflect.Ptr:
if rv.IsNil() {
panic("nil pointer")
}
et = rv.Elem()
case reflect.Slice:
if rv.IsNil() {
panic("nil slice")
}
et = rv.Index(0)
case reflect.Array:
et = rv.Index(0)
default:
panic("not a pointer or a slice")
}
p = unsafe.Pointer(et.UnsafeAddr())
switch et.Type().Kind() {
case reflect.Uint8:
t = UNSIGNED_BYTE
case reflect.Int8:
t = BYTE
case reflect.Uint16:
t = UNSIGNED_SHORT
case reflect.Int16:
t = SHORT
case reflect.Uint32:
t = UNSIGNED_INT
case reflect.Int32:
t = INT
case reflect.Float32:
t = FLOAT
case reflect.Float64:
t = DOUBLE
default:
panic("unknown type: " + reflect.TypeOf(v).String())
}
return
}
// Object
type Object C.GLuint
func (object Object) IsBuffer() bool { return C.glIsBuffer(C.GLuint(object)) != 0 }
func (object Object) IsProgram() bool { return C.glIsProgram(C.GLuint(object)) != 0 }
func (object Object) IsShader() bool { return C.glIsShader(C.GLuint(object)) != 0 }
func (object Object) IsTexture() bool { return C.glIsTexture(C.GLuint(object)) != 0 }
func (object Object) IsTransformFeedback() bool { return C.glIsTransformFeedback(C.GLuint(object)) != 0 }
func (object Object) IsVertexArray() bool { return C.glIsVertexArray(C.GLuint(object)) != 0 }
// Shader
type Shader Object
func CreateShader(type_ GLenum) Shader { return Shader(C.glCreateShader(C.GLenum(type_))) }
func (shader Shader) Delete() { C.glDeleteShader(C.GLuint(shader)) }
func (shader Shader) GetInfoLog() string {
var length C.GLint
C.glGetShaderiv(C.GLuint(shader), C.GLenum(INFO_LOG_LENGTH), &length)
// length is buffer size including null character
if length > 1 {
log := C.malloc(C.size_t(length))
defer C.free(log)
C.glGetShaderInfoLog(C.GLuint(shader), C.GLsizei(length), nil, (*C.GLchar)(log))
return C.GoString((*C.char)(log))
}
return ""
}
func (shader Shader) GetSource() string {
var len C.GLint
C.glGetShaderiv(C.GLuint(shader), C.GLenum(SHADER_SOURCE_LENGTH), &len)
log := C.malloc(C.size_t(len + 1))
C.glGetShaderSource(C.GLuint(shader), C.GLsizei(len), nil, (*C.GLchar)(log))
defer C.free(log)
return C.GoString((*C.char)(log))
}
func (shader Shader) Source(source string) {
csource := glString(source)
defer freeString(csource)
var one C.GLint = C.GLint(len(source))
C.glShaderSource(C.GLuint(shader), 1, &csource, &one)
}
func (shader Shader) Compile() { C.glCompileShader(C.GLuint(shader)) }
func (shader Shader) Get(param GLenum) int {
var rv C.GLint
C.glGetShaderiv(C.GLuint(shader), C.GLenum(param), &rv)
return int(rv)
}
// Program
type Program Object
func CreateProgram() Program { return Program(C.glCreateProgram()) }
func (program Program) Delete() { C.glDeleteProgram(C.GLuint(program)) }
func (program Program) AttachShader(shader Shader) {
C.glAttachShader(C.GLuint(program), C.GLuint(shader))
}
func (program Program) GetAttachedShaders() []Object {
var len C.GLint
C.glGetProgramiv(C.GLuint(program), C.GLenum(ACTIVE_UNIFORM_MAX_LENGTH), &len)
objects := make([]Object, len)
C.glGetAttachedShaders(C.GLuint(program), C.GLsizei(len), nil, *((**C.GLuint)(unsafe.Pointer(&objects))))
return objects
}
func (program Program) DetachShader(shader Shader) {
C.glDetachShader(C.GLuint(program), C.GLuint(shader))
}
func (program Program) TransformFeedbackVaryings (names []string, buffer_mode GLenum) {
if len(names) == 0 {
C.glTransformFeedbackVaryings(C.GLuint(program), 0, (**C.GLchar)(nil), C.GLenum(buffer_mode))
} else {
gl_names := make([]*C.GLchar, len(names))
for i := range(names) {
gl_names[i] = glString(names[i])
}
C.glTransformFeedbackVaryings(C.GLuint(program), C.GLsizei(len(gl_names)), &gl_names[0], C.GLenum(buffer_mode))
for _, s := range(gl_names) {
freeString(s)
}
}
}
func (program Program) Link() { C.glLinkProgram(C.GLuint(program)) }
func (program Program) Validate() { C.glValidateProgram(C.GLuint(program)) }
func (program Program) Use() { C.glUseProgram(C.GLuint(program)) }
func ProgramUnuse() { C.glUseProgram(C.GLuint(0)) }
func (program Program) GetInfoLog() string {
var length C.GLint
C.glGetProgramiv(C.GLuint(program), C.GLenum(INFO_LOG_LENGTH), &length)
// length is buffer size including null character
if length > 1 {
log := C.malloc(C.size_t(length))
defer C.free(log)
C.glGetProgramInfoLog(C.GLuint(program), C.GLsizei(length), nil, (*C.GLchar)(log))
return C.GoString((*C.char)(log))
}
return ""
}
func (program Program) Get(param GLenum) int {
var rv C.GLint
C.glGetProgramiv(C.GLuint(program), C.GLenum(param), &rv)
return int(rv)
}
func (program Program) GetUniformiv(location UniformLocation, values []int) {
// no range check
C.glGetUniformiv(C.GLuint(program), C.GLint(location), (*C.GLint)(unsafe.Pointer(&(values[0]))))
}
func (program Program) GetUniformfv(location UniformLocation, values []float32) {
// no range check
C.glGetUniformfv(C.GLuint(program), C.GLint(location), (*C.GLfloat)(unsafe.Pointer(&(values[0]))))
}
func (program Program) GetUniformLocation(name string) UniformLocation {
cname := glString(name)
defer freeString(cname)
return UniformLocation(C.glGetUniformLocation(C.GLuint(program), cname))
}
func (program Program) GetAttribLocation(name string) AttribLocation {
cname := glString(name)
defer freeString(cname)
return AttribLocation(C.glGetAttribLocation(C.GLuint(program), cname))
}
func (program Program) BindAttribLocation(index AttribLocation, name string) {
cname := glString(name)
defer freeString(cname)
C.glBindAttribLocation(C.GLuint(program), C.GLuint(index), cname)
}
// Texture
type Texture Object
// Create single texture object
func GenTexture() Texture {
var b C.GLuint
C.glGenTextures(1, &b)
return Texture(b)
}
// Fill slice with new textures
func GenTextures(textures []Texture) {
C.glGenTextures(C.GLsizei(len(textures)), (*C.GLuint)(&textures[0]))
}
// Delete texture object
func (texture Texture) Delete() {
b := C.GLuint(texture)
C.glDeleteTextures(1, &b)
}
// Delete all textures in slice
func DeleteTextures(textures []Texture) {
C.glDeleteTextures(C.GLsizei(len(textures)), (*C.GLuint)(&textures[0]))
}
// Bind this texture as target
func (texture Texture) Bind(target GLenum) {
C.glBindTexture(C.GLenum(target), C.GLuint(texture))
}
// Unbind this texture
func (texture Texture) Unbind(target GLenum) {
C.glBindTexture(C.GLenum(target), 0)
}
//void glTexImage1D (GLenum target, int level, int internalformat, int width, int border, GLenum format, GLenum type, const GLvoid *pixels)
func TexImage1D(target GLenum, level int, internalformat int, width int, border int, format GLenum, pixels interface{}) {
t, p := GetGLenumType(pixels)
C.glTexImage1D(C.GLenum(target), C.GLint(level), C.GLint(internalformat), C.GLsizei(width), C.GLint(border), C.GLenum(format), C.GLenum(t), p)
}
//void glTexImage2D (GLenum target, int level, int internalformat, int width, int height, int border, GLenum format, GLenum type, const GLvoid *pixels)
func TexImage2D(target GLenum, level int, internalformat int, width int, height int, border int, format, typ GLenum, pixels interface{}) {
if pixels == nil {
C.glTexImage2D(C.GLenum(target), C.GLint(level), C.GLint(internalformat),
C.GLsizei(width), C.GLsizei(height), C.GLint(border), C.GLenum(format), C.GLenum(typ), nil)
return
}
_, p := GetGLenumType(pixels)
C.glTexImage2D(C.GLenum(target), C.GLint(level), C.GLint(internalformat),
C.GLsizei(width), C.GLsizei(height), C.GLint(border), C.GLenum(format), C.GLenum(typ), p)
}
//void glPixelMapfv (GLenum map, int mapsize, const float *values)
func PixelMapfv(map_ GLenum, mapsize int, values *float32) {
C.glPixelMapfv(C.GLenum(map_), C.GLsizei(mapsize), (*C.GLfloat)(values))
}
//void glPixelMapuiv (GLenum map, int mapsize, const uint *values)
func PixelMapuiv(map_ GLenum, mapsize int, values *uint32) {
C.glPixelMapuiv(C.GLenum(map_), C.GLsizei(mapsize), (*C.GLuint)(values))
}
//void glPixelMapusv (GLenum map, int mapsize, const uint16 *values)
func PixelMapusv(map_ GLenum, mapsize int, values *uint16) {
C.glPixelMapusv(C.GLenum(map_), C.GLsizei(mapsize), (*C.GLushort)(values))
}
//void glTexSubImage1D (GLenum target, int level, int xoffset, int width, GLenum format, GLenum type, const GLvoid *pixels)
func TexSubImage1D(target GLenum, level int, xoffset int, width int, format GLenum, pixels interface{}) {
t, p := GetGLenumType(pixels)
C.glTexSubImage1D(C.GLenum(target), C.GLint(level), C.GLint(xoffset), C.GLsizei(width), C.GLenum(format), C.GLenum(t), p)
}
//void glTexSubImage2D (GLenum target, int level, int xoffset, int yoffset, int width, int height, GLenum format, GLenum type, const GLvoid *pixels)
func TexSubImage2D(target GLenum, level int, xoffset int, yoffset int, width int, height int, format GLenum, pixels interface{}) {
t, p := GetGLenumType(pixels)
C.glTexSubImage2D(C.GLenum(target), C.GLint(level), C.GLint(xoffset), C.GLint(yoffset), C.GLsizei(width), C.GLsizei(height), C.GLenum(format), C.GLenum(t), p)
}
//void glCopyTexImage1D (GLenum target, int level, GLenum internalFormat, int x, int y, int width, int border)
func CopyTexImage1D(target GLenum, level int, internalFormat GLenum, x int, y int, width int, border int) {
C.glCopyTexImage1D(C.GLenum(target), C.GLint(level), C.GLenum(internalFormat), C.GLint(x), C.GLint(y), C.GLsizei(width), C.GLint(border))
}
//void glCopyTexImage2D (GLenum target, int level, GLenum internalFormat, int x, int y, int width, int height, int border)
func CopyTexImage2D(target GLenum, level int, internalFormat GLenum, x int, y int, width int, height int, border int) {
C.glCopyTexImage2D(C.GLenum(target), C.GLint(level), C.GLenum(internalFormat), C.GLint(x), C.GLint(y), C.GLsizei(width), C.GLsizei(height), C.GLint(border))
}
//void glCopyTexSubImage1D (GLenum target, int level, int xoffset, int x, int y, int width)
func CopyTexSubImage1D(target GLenum, level int, xoffset int, x int, y int, width int) {
C.glCopyTexSubImage1D(C.GLenum(target), C.GLint(level), C.GLint(xoffset), C.GLint(x), C.GLint(y), C.GLsizei(width))
}
//void glCopyTexSubImage2D (GLenum target, int level, int xoffset, int yoffset, int x, int y, int width, int height)
func CopyTexSubImage2D(target GLenum, level int, xoffset int, yoffset int, x int, y int, width int, height int) {
C.glCopyTexSubImage2D(C.GLenum(target), C.GLint(level), C.GLint(xoffset), C.GLint(yoffset), C.GLint(x), C.GLint(y), C.GLsizei(width), C.GLsizei(height))
}
// TODO 3D textures
//void glTexEnvf (GLenum target, GLenum pname, float32 param)
func TexEnvf(target GLenum, pname GLenum, param float32) {
C.glTexEnvf(C.GLenum(target), C.GLenum(pname), C.GLfloat(param))
}
//void glTexEnvfv (GLenum target, GLenum pname, const float *params)
func TexEnvfv(target GLenum, pname GLenum, params []float32) {
C.glTexEnvfv(C.GLenum(target), C.GLenum(pname), (*C.GLfloat)(¶ms[0]))
}
//void glTexEnvi (GLenum target, GLenum pname, int param)
func TexEnvi(target GLenum, pname GLenum, param int) {
C.glTexEnvi(C.GLenum(target), C.GLenum(pname), C.GLint(param))
}
//void glTexEnviv (GLenum target, GLenum pname, const int *params)
func TexEnviv(target GLenum, pname GLenum, params []int32) {
C.glTexEnviv(C.GLenum(target), C.GLenum(pname), (*C.GLint)(¶ms[0]))
}
//void glTexGend (GLenum coord, GLenum pname, float64 param)
func TexGend(coord GLenum, pname GLenum, param float64) {
C.glTexGend(C.GLenum(coord), C.GLenum(pname), C.GLdouble(param))
}
//void glTexGendv (GLenum coord, GLenum pname, const float64 *params)
func TexGendv(coord GLenum, pname GLenum, params []float64) {
C.glTexGendv(C.GLenum(coord), C.GLenum(pname), (*C.GLdouble)(¶ms[0]))
}
//void glTexGenf (GLenum coord, GLenum pname, float32 param)
func TexGenf(coord GLenum, pname GLenum, param float32) {
C.glTexGenf(C.GLenum(coord), C.GLenum(pname), C.GLfloat(param))
}
//void glTexGenfv (GLenum coord, GLenum pname, const float *params)
func TexGenfv(coord GLenum, pname GLenum, params []float32) {
C.glTexGenfv(C.GLenum(coord), C.GLenum(pname), (*C.GLfloat)(¶ms[0]))
}
//void glTexGeni (GLenum coord, GLenum pname, int param)
func TexGeni(coord GLenum, pname GLenum, param int) {
C.glTexGeni(C.GLenum(coord), C.GLenum(pname), C.GLint(param))
}
//void glTexGeniv (GLenum coord, GLenum pname, const int *params)
func TexGeniv(coord GLenum, pname GLenum, params []int32) {
C.glTexGeniv(C.GLenum(coord), C.GLenum(pname), (*C.GLint)(¶ms[0]))
}
//void glTexParameterf (GLenum target, GLenum pname, float32 param)
func TexParameterf(target GLenum, pname GLenum, param float32) {
C.glTexParameterf(C.GLenum(target), C.GLenum(pname), C.GLfloat(param))
}
//void glTexParameterfv (GLenum target, GLenum pname, const float *params)
func TexParameterfv(target GLenum, pname GLenum, params []float32) {
C.glTexParameterfv(C.GLenum(target), C.GLenum(pname), (*C.GLfloat)(¶ms[0]))
}
//void glTexParameteri (GLenum target, GLenum pname, int param)
func TexParameteri(target GLenum, pname GLenum, param int) {
C.glTexParameteri(C.GLenum(target), C.GLenum(pname), C.GLint(param))
}
//void glTexParameteriv (GLenum target, GLenum pname, const int *params)
func TexParameteriv(target GLenum, pname GLenum, params []int32) {
C.glTexParameteriv(C.GLenum(target), C.GLenum(pname), (*C.GLint)(¶ms[0]))
}
//void glPrioritizeTextures (GLsizei n, const uint *textures, const GLclampf *priorities)
func PrioritizeTextures(n int, textures *uint32, priorities *GLclampf) {
C.glPrioritizeTextures(C.GLsizei(n), (*C.GLuint)(textures), (*C.GLclampf)(priorities))
}
//void glGetTexEnvfv (GLenum target, GLenum pname, float *params)
func GetTexEnvfv(target GLenum, pname GLenum, params []float32) {
C.glGetTexEnvfv(C.GLenum(target), C.GLenum(pname), (*C.GLfloat)(¶ms[0]))
}
//void glGetTexEnviv (GLenum target, GLenum pname, int *params)
func GetTexEnviv(target GLenum, pname GLenum, params []int32) {
C.glGetTexEnviv(C.GLenum(target), C.GLenum(pname), (*C.GLint)(¶ms[0]))
}
//void glGetTexGendv (GLenum coord, GLenum pname, float64 *params)
func GetTexGendv(coord GLenum, pname GLenum, params []float64) {
C.glGetTexGendv(C.GLenum(coord), C.GLenum(pname), (*C.GLdouble)(¶ms[0]))
}
//void glGetTexGenfv (GLenum coord, GLenum pname, float *params)
func GetTexGenfv(coord GLenum, pname GLenum, params []float32) {
C.glGetTexGenfv(C.GLenum(coord), C.GLenum(pname), (*C.GLfloat)(¶ms[0]))
}
//void glGetTexGeniv (GLenum coord, GLenum pname, int *params)
func GetTexGeniv(coord GLenum, pname GLenum, params []int32) {
C.glGetTexGeniv(C.GLenum(coord), C.GLenum(pname), (*C.GLint)(¶ms[0]))
}
//void glGetTexImage (GLenum target, int level, GLenum format, GLenum type, GLvoid *pixels)
func GetTexImage(target GLenum, level int, format GLenum, pixels interface{}) {
t, p := GetGLenumType(pixels)
C.glGetTexImage(C.GLenum(target), C.GLint(level), C.GLenum(format), C.GLenum(t), p)
}
//void glGetTexLevelParameterfv (GLenum target, int level, GLenum pname, float *params)
func GetTexLevelParameterfv(target GLenum, level int, pname GLenum, params []float32) {
C.glGetTexLevelParameterfv(C.GLenum(target), C.GLint(level), C.GLenum(pname), (*C.GLfloat)(¶ms[0]))
}
//void glGetTexLevelParameteriv (GLenum target, int level, GLenum pname, int *params)
func GetTexLevelParameteriv(target GLenum, level int, pname GLenum, params []int32) {
C.glGetTexLevelParameteriv(C.GLenum(target), C.GLint(level), C.GLenum(pname), (*C.GLint)(¶ms[0]))
}
//void glGetTexParameterfv (GLenum target, GLenum pname, float *params)
func GetTexParameterfv(target GLenum, pname GLenum, params []float32) {
C.glGetTexParameterfv(C.GLenum(target), C.GLenum(pname), (*C.GLfloat)(¶ms[0]))
}
//void glGetTexParameteriv (GLenum target, GLenum pname, int *params)
func GetTexParameteriv(target GLenum, pname GLenum, params []int32) {
C.glGetTexParameteriv(C.GLenum(target), C.GLenum(pname), (*C.GLint)(¶ms[0]))
}
// Buffer Objects
type Buffer Object
// Create single buffer object
func GenBuffer() Buffer {
var b C.GLuint
C.glGenBuffers(1, &b)
return Buffer(b)
}
// Fill slice with new buffers
func GenBuffers(buffers []Buffer) {
C.glGenBuffers(C.GLsizei(len(buffers)), (*C.GLuint)(&buffers[0]))
}
// Delete buffer object
func (buffer Buffer) Delete() {
b := C.GLuint(buffer)
C.glDeleteBuffers(1, &b)
}
// Delete all textures in slice
func DeleteBuffers(buffers []Buffer) {
C.glDeleteBuffers(C.GLsizei(len(buffers)), (*C.GLuint)(&buffers[0]))
}
// Remove buffer binding
func BufferUnbind(target GLenum) {
C.glBindBuffer(C.GLenum(target), C.GLuint(0))
}
// Bind this buffer as target
func (buffer Buffer) Bind(target GLenum) {
C.glBindBuffer(C.GLenum(target), C.GLuint(buffer))
}
// Bind this buffer as index of target
func (buffer Buffer) BindBufferBase(target GLenum, index uint) {
C.glBindBufferBase(C.GLenum(target), C.GLuint(index), C.GLuint(buffer))
}
// Bind this buffer range as index of target
func (buffer Buffer) BindBufferRange(target GLenum, index uint, offset int, size uint) {
C.glBindBufferRange(C.GLenum(target), C.GLuint(index), C.GLuint(buffer), C.GLintptr(offset), C.GLsizeiptr(size))
}
// Creates and initializes a buffer object's data store
func BufferData(target GLenum, size int, data interface{}, usage GLenum) {
_, p := GetGLenumType(data)
C.glBufferData(C.GLenum(target), C.GLsizeiptr(size), p, C.GLenum(usage))
}
// Update a subset of a buffer object's data store
func BufferSubData(target GLenum, offset int, size int, data interface{}) {
_, p := GetGLenumType(data)
C.glBufferSubData(C.GLenum(target), C.GLintptr(offset), C.GLsizeiptr(size), p)
}
// Returns a subset of a buffer object's data store
func GetBufferSubData(target GLenum, offset int, size int, data interface{}) {
_, p := GetGLenumType(data)
C.glGetBufferSubData(C.GLenum(target), C.GLintptr(offset), C.GLsizeiptr(size), p)
}
// Map a buffer object's data store
func MapBuffer(target GLenum, access GLenum) {
C.glMapBuffer(C.GLenum(target), C.GLenum(access))
}
// Unmap a buffer object's data store
func UnmapBuffer(target GLenum) bool {
return goBool(C.glUnmapBuffer(C.GLenum(target)))
}
// Return buffer pointer
func glGetBufferPointerv(target GLenum, pname GLenum, params []unsafe.Pointer) {
C.glGetBufferPointerv(C.GLenum(target), C.GLenum(pname), ¶ms[0])
}
// Return parameters of a buffer object
func GetBufferParameteriv(target GLenum, pname GLenum, params []int32) {
C.glGetBufferParameteriv(C.GLenum(target), C.GLenum(pname), (*C.GLint)(¶ms[0]))
}
// Transform Feedback Objects
type TransformFeedback Object
// Create a single transform feedback object
func GenTransformFeedback() TransformFeedback {
var t C.GLuint
C.glGenTransformFeedbacks(1, &t)
return TransformFeedback(t)
}
// Fill slice with new transform feedbacks
func GenTransformFeedbacks(feedbacks []TransformFeedback) {
C.glGenBuffers(C.GLsizei(len(feedbacks)), (*C.GLuint)(&feedbacks[0]))
}
// Delete a transform feedback object
func (feedback TransformFeedback) Delete() {
C.glDeleteTransformFeedbacks(1, (*C.GLuint)(&feedback))
}
// Draw the results of the last Begin/End cycle from this transform feedback using primitive type 'mode'
func (feedback TransformFeedback) Draw(mode GLenum) {
C.glDrawTransformFeedback(C.GLenum(mode), C.GLuint(feedback))
}
// Delete all transform feedbacks in a slice
func DeleteTransformFeedbacks(feedbacks []TransformFeedback) {
C.glDeleteTransformFeedbacks(C.GLsizei(len(feedbacks)), (*C.GLuint)(&feedbacks[0]))
}
// Bind this transform feedback as target
func (feedback TransformFeedback) Bind(target GLenum) {
C.glBindTransformFeedback(C.GLenum(target), C.GLuint(feedback))
}
// Begin transform feedback with primitive type 'mode'
func BeginTransformFeedback(mode GLenum) {
C.glBeginTransformFeedback(C.GLenum(mode))
}
// Pause transform feedback
func PauseTransformFeedback() {
C.glPauseTransformFeedback()
}
// End transform feedback
func EndTransformFeedback() {
C.glEndTransformFeedback()
}
// AttribLocation
type AttribLocation int
func (indx AttribLocation) Attrib1f(x float32) {
C.glVertexAttrib1f(C.GLuint(indx), C.GLfloat(x))
}
func (indx AttribLocation) Attrib1fv(values []float32) {
//no range check
C.glVertexAttrib1fv(C.GLuint(indx), (*C.GLfloat)(unsafe.Pointer(&values[0])))
}
func (indx AttribLocation) Attrib2f(x float32, y float32) {
C.glVertexAttrib2f(C.GLuint(indx), C.GLfloat(x), C.GLfloat(y))
}
func (indx AttribLocation) Attrib2fv(values []float32) {
//no range check
C.glVertexAttrib2fv(C.GLuint(indx), (*C.GLfloat)(unsafe.Pointer(&values[0])))
}
func (indx AttribLocation) Attrib3f(x float32, y float32, z float32) {
C.glVertexAttrib3f(C.GLuint(indx), C.GLfloat(x), C.GLfloat(y), C.GLfloat(z))
}
func (indx AttribLocation) Attrib3fv(values []float32) {
//no range check
C.glVertexAttrib3fv(C.GLuint(indx), (*C.GLfloat)(unsafe.Pointer(&values[0])))
}
func (indx AttribLocation) Attrib4f(x float32, y float32, z float32, w float32) {
C.glVertexAttrib4f(C.GLuint(indx), C.GLfloat(x), C.GLfloat(y), C.GLfloat(z), C.GLfloat(w))
}
func (indx AttribLocation) Attrib4fv(values []float32) {
//no range check
C.glVertexAttrib4fv(C.GLuint(indx), (*C.GLfloat)(unsafe.Pointer(&values[0])))
}
func (indx AttribLocation) AttribPointer(size uint, normalized bool, stride int, pointer interface{}) {
t, p := GetGLenumType(pointer)
C.glVertexAttribPointer(C.GLuint(indx), C.GLint(size), C.GLenum(t), glBool(normalized), C.GLsizei(stride), p)
}
func (indx AttribLocation) EnableArray() {
C.glEnableVertexAttribArray(C.GLuint(indx))
}
func (indx AttribLocation) DisableArray() {
C.glDisableVertexAttribArray(C.GLuint(indx))
}
// Vertex Arrays
type VertexArray Object
func GenVertexArray () VertexArray {
var a C.GLuint
C.glGenVertexArrays(1, &a)
return VertexArray(a)
}
func GenVertexArrays (arrays []VertexArray) {
C.glGenVertexArrays(C.GLsizei(len(arrays)), (*C.GLuint)(&arrays[0]))
}
func (array VertexArray) Delete () {
C.glDeleteVertexArrays(1, (*C.GLuint)(&array))
}
func DeleteVertexArrays (arrays []VertexArray) {
C.glDeleteVertexArrays(C.GLsizei(len(arrays)), (*C.GLuint)(&arrays[0]))
}
func (array VertexArray) Bind () {
C.glBindVertexArray(C.GLuint(array))
}
// UniformLocation
//TODO
type UniformLocation int
func (location UniformLocation) Uniform1f(x float32) {
C.glUniform1f(C.GLint(location), C.GLfloat(x))
}
func (location UniformLocation) Uniform2f(x float32, y float32) {
C.glUniform2f(C.GLint(location), C.GLfloat(x), C.GLfloat(y))
}
func (location UniformLocation) Uniform3f(x float32, y float32, z float32) {
C.glUniform3f(C.GLint(location), C.GLfloat(x), C.GLfloat(y), C.GLfloat(z))
}
func (location UniformLocation) Uniform1fv(v []float32) {
_, p := GetGLenumType(v)
C.glUniform1fv(C.GLint(location), C.GLsizei(len(v)), (*C.GLfloat)(p));
}
func (location UniformLocation) Uniform1i(x int) {
C.glUniform1i(C.GLint(location), C.GLint(x))
}
func (location UniformLocation) Uniform1iv(v []int) {
panic("unimplemented")
// C.glUniform1iv(C.GLint(location), (*C.int)(&v[0]));
}
func (location UniformLocation) Uniform2fv(v []float32) {
panic("unimplemented")
// C.glUniform2fv(C.GLint(location), (*C.float)(&v[0]));
}
func (location UniformLocation) Uniform2i(x int, y int) {
C.glUniform2i(C.GLint(location), C.GLint(x), C.GLint(y))
}
func (location UniformLocation) Uniform2iv(v []int32) {
panic("unimplemented")
// C.glUniform2iv(C.GLint(location), (*C.int)(&v[0]));
}
func (location UniformLocation) Uniform3fv(v []float32) {
panic("unimplemented")
// C.glUniform3fv(C.GLint(location), (*C.float)(&v[0]));
}
func (location UniformLocation) Uniform3i(x int, y int, z int) {
C.glUniform3i(C.GLint(location), C.GLint(x), C.GLint(y), C.GLint(z))
}
func (location UniformLocation) Uniform3iv(v []int32) {
panic("unimplemented")
// C.glUniform3iv(C.GLint(location), (*C.int)(&v[0]));
}
func (location UniformLocation) Uniform4f(x float32, y float32, z float32, w float32) {
C.glUniform4f(C.GLint(location), C.GLfloat(x), C.GLfloat(y), C.GLfloat(z), C.GLfloat(w))
}
func (location UniformLocation) Uniform4fv(v []float32) {
panic("unimplemented")
// C.glUniform4fv(C.GLint(location), (*C.float)(&v[0]));
}
func (location UniformLocation) Uniform4i(x int, y int, z int, w int) {
C.glUniform4i(C.GLint(location), C.GLint(x), C.GLint(y), C.GLint(z), C.GLint(w))
}
func (location UniformLocation) Uniform4iv(v []int32) {
panic("unimplemented")
// C.glUniform4iv(C.GLint(location), (*C.int)(&v[0]));
}
/*
uniformMatrix2fv
uniformMatrix2fv
uniformMatrix3fv
uniformMatrix3fv
uniformMatrix4fv
uniformMatrix4fv
*/
// Main
func ActiveTexture(texture GLenum) { C.glActiveTexture(C.GLenum(texture)) }
func BlendColor(red GLclampf, green GLclampf, blue GLclampf, alpha GLclampf) {
C.glBlendColor(C.GLclampf(red), C.GLclampf(green), C.GLclampf(blue), C.GLclampf(alpha))
}
func BlendEquation(mode GLenum) { C.glBlendEquation(C.GLenum(mode)) }
func BlendEquationSeparate(modeRGB GLenum, modeAlpha GLenum) {
C.glBlendEquationSeparate(C.GLenum(modeRGB), C.GLenum(modeAlpha))
}
func BlendFuncSeparate(srcRGB GLenum, dstRGB GLenum, srcAlpha GLenum, dstAlpha GLenum) {
C.glBlendFuncSeparate(C.GLenum(srcRGB), C.GLenum(dstRGB), C.GLenum(srcAlpha), C.GLenum(dstAlpha))
}
func SampleCoverage(value GLclampf, invert bool) {
C.glSampleCoverage(C.GLclampf(value), glBool(invert))
}
func StencilFuncSeparate(face GLenum, func_ GLenum, ref int, mask uint) {
C.glStencilFuncSeparate(C.GLenum(face), C.GLenum(func_), C.GLint(ref), C.GLuint(mask))
}
func StencilMaskSeparate(face GLenum, mask uint) {
C.glStencilMaskSeparate(C.GLenum(face), C.GLuint(mask))
}
func StencilOpSeparate(face GLenum, fail GLenum, zfail GLenum, zpass GLenum) {
C.glStencilOpSeparate(C.GLenum(face), C.GLenum(fail), C.GLenum(zfail), C.GLenum(zpass))
}
//void glAccum (GLenum op, float32 value)
func Accum(op GLenum, value float32) {
C.glAccum(C.GLenum(op), C.GLfloat(value))
}
//void glAlphaFunc (GLenum func, GLclampf ref)
func AlphaFunc(func_ GLenum, ref GLclampf) {
C.glAlphaFunc(C.GLenum(func_), C.GLclampf(ref))
}
//bool glAreTexturesResident (GLsizei n, const uint *textures, bool *residences)
func AreTexturesResident(n int, textures *uint, residences *bool) bool {
//TODO
panic("unimlemented")
//return C.glAreTexturesResident(C.GLsizei(n), (*C.GLuint)(unsafe.Pointer(textures)), (*C.GLboolean)(unsafe.Pointer(residences))) != 0
}
//void glArrayElement (int i)
func ArrayElement(i int) {
C.glArrayElement(C.GLint(i))
}
//void glBegin (GLenum mode)
func Begin(mode GLenum) {
C.glBegin(C.GLenum(mode))
}
//void glBindTexture (GLenum target, uint texture)
func BindTexture(target GLenum, texture uint) {
C.glBindTexture(C.GLenum(target), C.GLuint(texture))
}
//void glBitmap (GLsizei width, int height, float32 xorig, float32 yorig, float32 xmove, float32 ymove, const uint8 *bitmap)
func Bitmap(width int, height int, xorig float32, yorig float32, xmove float32, ymove float32, bitmap *uint8) {
C.glBitmap(C.GLsizei(width), C.GLsizei(height), C.GLfloat(xorig), C.GLfloat(yorig), C.GLfloat(xmove), C.GLfloat(ymove), (*C.GLubyte)(bitmap))
}
//void glBlendFunc (GLenum sfactor, GLenum dfactor)
func BlendFunc(sfactor GLenum, dfactor GLenum) {
C.glBlendFunc(C.GLenum(sfactor), C.GLenum(dfactor))
}
//void glCallList (uint list)
func CallList(list uint) {
C.glCallList(C.GLuint(list))
}
//void glCallLists (GLsizei n, GLenum type, const GLvoid *lists)
func CallLists(n int, lists interface{}) {
t, p := GetGLenumType(lists)
C.glCallLists(C.GLsizei(n), C.GLenum(t), p)
}
//void glClear (GLbitfield mask)
func Clear(mask GLbitfield) {
C.glClear(C.GLbitfield(mask))
}
//void glClearAccum (float32 red, float32 green, float32 blue, float32 alpha)
func ClearAccum(red float32, green float32, blue float32, alpha float32) {
C.glClearAccum(C.GLfloat(red), C.GLfloat(green), C.GLfloat(blue), C.GLfloat(alpha))
}
//void glClearColor (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
func ClearColor(red GLclampf, green GLclampf, blue GLclampf, alpha GLclampf) {
C.glClearColor(C.GLclampf(red), C.GLclampf(green), C.GLclampf(blue), C.GLclampf(alpha))
}
//void glClearDepth (GLclampd depth)
func ClearDepth(depth GLclampd) {
C.glClearDepth(C.GLclampd(depth))
}
//void glClearIndex (float32 c)
func ClearIndex(c float32) {
C.glClearIndex(C.GLfloat(c))
}
//void glClearStencil (int s)
func ClearStencil(s int) {
C.glClearStencil(C.GLint(s))
}
//void glClipPlane (GLenum plane, const float64 *equation)
func ClipPlane(plane GLenum, equation *float64) {
C.glClipPlane(C.GLenum(plane), (*C.GLdouble)(equation))
}
//void glColor3b (int8 red, int8 green, int8 blue)
func Color3b(red int8, green int8, blue int8) {
C.glColor3b(C.GLbyte(red), C.GLbyte(green), C.GLbyte(blue))
}
//void glColor3bv (const int8 *v)
func Color3bv(v []int8) {
C.glColor3bv((*C.GLbyte)(&v[0]))
}
//void glColor3d (float64 red, float64 green, float64 blue)
func Color3d(red float64, green float64, blue float64) {
C.glColor3d(C.GLdouble(red), C.GLdouble(green), C.GLdouble(blue))
}
//void glColor3dv (const float64 *v)
func Color3dv(v []float64) {
C.glColor3dv((*C.GLdouble)(&v[0]))
}
//void glColor3f (float32 red, float32 green, float32 blue)
func Color3f(red float32, green float32, blue float32) {
C.glColor3f(C.GLfloat(red), C.GLfloat(green), C.GLfloat(blue))
}
//void glColor3fv (const float *v)
func Color3fv(v []float32) {
C.glColor3fv((*C.GLfloat)(&v[0]))
}
//void glColor3i (int red, int green, int blue)
func Color3i(red int, green int, blue int) {
C.glColor3i(C.GLint(red), C.GLint(green), C.GLint(blue))
}
//void glColor3iv (const int *v)
func Color3iv(v []int32) {
C.glColor3iv((*C.GLint)(&v[0]))
}
//void glColor3s (int16 red, int16 green, int16 blue)
func Color3s(red int16, green int16, blue int16) {
C.glColor3s(C.GLshort(red), C.GLshort(green), C.GLshort(blue))
}
//void glColor3sv (const int16 *v)
func Color3sv(v []int16) {
C.glColor3sv((*C.GLshort)(&v[0]))
}
//void glColor3ub (uint8 red, uint8 green, uint8 blue)
func Color3ub(red uint8, green uint8, blue uint8) {
C.glColor3ub(C.GLubyte(red), C.GLubyte(green), C.GLubyte(blue))
}
//void glColor3ubv (const uint8 *v)
func Color3ubv(v []uint8) {
C.glColor3ubv((*C.GLubyte)(&v[0]))
}
//void glColor3ui (uint red, uint green, uint blue)
func Color3ui(red uint, green uint, blue uint) {
C.glColor3ui(C.GLuint(red), C.GLuint(green), C.GLuint(blue))