summaryrefslogtreecommitdiff
path: root/retrace/daemon/gldispatch/glframe_glhelper.cpp
blob: 9f90b707e5cd9f62c9819786c2733a8e86993273 (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
// Copyright (C) Intel Corp.  2015.  All Rights Reserved.

// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:

// The above copyright notice and this permission notice (including the
// next paragraph) shall be included in all copies or substantial
// portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

//  **********************************************************************/
//  * Authors:
//  *   Mark Janes <mark.a.janes@intel.com>
//  **********************************************************************/

#include "glframe_glhelper.hpp"

#include <assert.h>
#ifdef WIN32
#include "retrace.hpp"
#include "glretrace.hpp"
#include "glws.hpp"
#else
#include <dlfcn.h>
#endif

using glretrace::GlFunctions;

bool GlFunctions::m_is_initialized = false;

namespace {
static void *pCreateProgram = NULL;
static void *pCreateShader = NULL;
static void *pShaderSource = NULL;
static void *pCompileShader = NULL;
static void *pAttachShader = NULL;
static void *pLinkProgram = NULL;
static void *pUseProgram = NULL;
static void *pGetError = NULL;
static void *pGetShaderiv = NULL;
static void *pGetShaderInfoLog = NULL;
static void *pGenBuffers = NULL;
static void *pBindBuffer = NULL;
static void *pGetAttribLocation = NULL;
static void *pGetUniformLocation = NULL;
static void *pClearColor = NULL;
static void *pClear = NULL;
static void *pUniform1f = NULL;
static void *pUniform4f = NULL;
static void *pBufferData = NULL;
static void *pEnableVertexAttribArray = NULL;
static void *pVertexAttribPointer = NULL;
static void *pDrawArrays = NULL;
static void *pDisableVertexAttribArray = NULL;
static void *pEnable = NULL;
static void *pReadPixels = NULL;
static void *pDrawElements = NULL;
static void *pBlendFunc = NULL;
static void *pGetFirstPerfQueryIdINTEL = NULL;
static void *pGetNextPerfQueryIdINTEL = NULL;
static void *pGetIntegerv = NULL;
static void *pGetStringi = NULL;
static void *pGetPerfQueryInfoINTEL = NULL;
static void *pGetPerfCounterInfoINTEL = NULL;
static void *pCreatePerfQueryINTEL = NULL;
static void *pDeletePerfQueryINTEL = NULL;
static void *pBeginPerfQueryINTEL = NULL;
static void *pEndPerfQueryINTEL = NULL;
static void *pGetPerfQueryDataINTEL = NULL;
static void *pGetProgramiv = NULL;
static void *pGetProgramInfoLog = NULL;
static void *pGetProgramResourceName = NULL;
static void *pGetBooleanv = NULL;
static void *pGetFloatv = NULL;
static void *pBlendColor = NULL;
static void *pBlendFuncSeparate = NULL;
static void *pDisable = NULL;
static void *pBlendEquation = NULL;
static void *pBlendEquationSeparate = NULL;
static void *pBindAttribLocation = NULL;
static void *pValidateProgram = NULL;
static void *pIsEnabled = NULL;
static void *pGetUniformBlockIndex = NULL;
static void *pUniformBlockBinding = NULL;
static void *pBindFragDataLocation = NULL;
static void *pGetActiveUniform = NULL;
static void *pGetUniformfv = NULL;
static void *pGetUniformiv = NULL;
static void *pUniform1fv = NULL;
static void *pUniform1iv = NULL;
static void *pUniform1uiv = NULL;
static void *pUniform2fv = NULL;
static void *pUniform2iv = NULL;
static void *pUniform2uiv = NULL;
static void *pUniform3fv = NULL;
static void *pUniform3iv = NULL;
static void *pUniform3uiv = NULL;
static void *pUniform4fv = NULL;
static void *pUniform4iv = NULL;
static void *pUniform4uiv = NULL;
static void *pUniformMatrix2fv = NULL;
static void *pUniformMatrix2x3fv = NULL;
static void *pUniformMatrix2x4fv = NULL;
static void *pUniformMatrix3fv = NULL;
static void *pUniformMatrix3x2fv = NULL;
static void *pUniformMatrix3x4fv = NULL;
static void *pUniformMatrix4fv = NULL;
static void *pUniformMatrix4x2fv = NULL;
static void *pUniformMatrix4x3fv = NULL;
static void *pFinish = NULL;
static void *pCullFace = NULL;
static void *pLineWidth = NULL;
static void *pColorMask = NULL;
static void *pClearDepthf = NULL;
static void *pDepthFunc = NULL;
static void *pDepthRangef = NULL;
static void *pDepthMask = NULL;

}  // namespace

static void * _GetProcAddress(const char *name) {
  typedef void* (* GETPROCADDRESS) (const char *procName);
  static GETPROCADDRESS lookup_fn = NULL;
#ifdef WIN32
  static HMODULE lib_handle = NULL;
  if (!lib_handle) {
    char szDll[MAX_PATH] = {0};
    if (!GetSystemDirectoryA(szDll, MAX_PATH)) {
      return NULL;
    }
    strncat(szDll, "\\opengl32.dll", MAX_PATH - 1);
    lib_handle = LoadLibraryA(szDll);
  }
  if (!lookup_fn) {
    lookup_fn = (GETPROCADDRESS) GetProcAddress(lib_handle,
                                                "wglGetProcAddress");
  }
#else
  static void *lib_handle = NULL;
  lib_handle = dlopen("libGL.so", RTLD_LAZY | RTLD_GLOBAL);
  lookup_fn = reinterpret_cast<GETPROCADDRESS>(dlsym(lib_handle,
                                                     "glXGetProcAddress"));
#endif
  assert(lookup_fn);
  void* ret = lookup_fn(name);
#ifdef WIN32
  if (ret == NULL)
    ret = GetProcAddress(lib_handle, name);
  if (ret == NULL)
    ret = wglGetProcAddress(name);
#endif
  assert(ret);
  return ret;
}
void
GlFunctions::Init(void *lookup_fn) {
  if (m_is_initialized)
    return;

#ifdef WIN32
  // GetProcAddress will return null on windows unless there is an
  // active GL context.
  retrace::setUp();
  glws::Drawable *d = glretrace::createDrawable();
  glretrace::Context *c = glretrace::createContext();
  glws::makeCurrent(d, c->wsContext);
#endif

  pCreateProgram = _GetProcAddress("glCreateProgram");
  assert(pCreateProgram);

  pCreateShader = _GetProcAddress("glCreateShader");
  assert(pCreateShader);
  pShaderSource = _GetProcAddress("glShaderSource");
  assert(pShaderSource);
  pCompileShader = _GetProcAddress("glCompileShader");
  assert(pCompileShader);
  pAttachShader = _GetProcAddress("glAttachShader");
  assert(pAttachShader);
  pLinkProgram = _GetProcAddress("glLinkProgram");
  assert(pLinkProgram);
  pUseProgram = _GetProcAddress("glUseProgram");
  assert(pUseProgram);
  pGetError = _GetProcAddress("glGetError");
  assert(pGetError);
  pGetShaderiv = _GetProcAddress("glGetShaderiv");
  assert(pGetShaderiv);
  pGetShaderInfoLog = _GetProcAddress("glGetShaderInfoLog");
  assert(pGetShaderInfoLog);
  pGenBuffers = _GetProcAddress("glGenBuffers");
  assert(pGenBuffers);
  pBindBuffer = _GetProcAddress("glBindBuffer");
  assert(pBindBuffer);
  pGetAttribLocation = _GetProcAddress("glGetAttribLocation");
  assert(pGetAttribLocation);
  pGetUniformLocation = _GetProcAddress("glGetUniformLocation");
  assert(pGetUniformLocation);
  pClearColor = _GetProcAddress("glClearColor");
  assert(pClearColor);
  pClear = _GetProcAddress("glClear");
  assert(pClear);
  pUniform1f = _GetProcAddress("glUniform1f");
  assert(pUniform1f);
  pUniform4f = _GetProcAddress("glUniform4f");
  assert(pUniform4f);
  pBufferData = _GetProcAddress("glBufferData");
  assert(pBufferData);
  pEnableVertexAttribArray = _GetProcAddress("glEnableVertexAttribArray");
  assert(pEnableVertexAttribArray);
  pVertexAttribPointer = _GetProcAddress("glVertexAttribPointer");
  assert(pVertexAttribPointer);
  pDrawArrays = _GetProcAddress("glDrawArrays");
  assert(pDrawArrays);
  pDisableVertexAttribArray = _GetProcAddress("glDisableVertexAttribArray");
  assert(pDisableVertexAttribArray);
  pEnable = _GetProcAddress("glEnable");
  assert(pEnable);
  pReadPixels = _GetProcAddress("glReadPixels");
  assert(pReadPixels);
  pDrawElements = _GetProcAddress("glDrawElements");
  assert(pDrawElements);
  pBlendFunc = _GetProcAddress("glBlendFunc");
  assert(pBlendFunc);
  pGetFirstPerfQueryIdINTEL = _GetProcAddress("glGetFirstPerfQueryIdINTEL");
  assert(pGetFirstPerfQueryIdINTEL);
  pGetNextPerfQueryIdINTEL = _GetProcAddress("glGetNextPerfQueryIdINTEL");
  assert(pGetNextPerfQueryIdINTEL);
  pGetIntegerv = _GetProcAddress("glGetIntegerv");
  assert(pGetIntegerv);
  pGetStringi = _GetProcAddress("glGetStringi");
  assert(pGetStringi);
  pGetPerfQueryInfoINTEL = _GetProcAddress("glGetPerfQueryInfoINTEL");
  assert(pGetPerfQueryInfoINTEL);
  pGetPerfCounterInfoINTEL = _GetProcAddress("glGetPerfCounterInfoINTEL");
  assert(pGetPerfCounterInfoINTEL);
  pCreatePerfQueryINTEL = _GetProcAddress("glCreatePerfQueryINTEL");
  assert(pCreatePerfQueryINTEL);
  pDeletePerfQueryINTEL = _GetProcAddress("glDeletePerfQueryINTEL");
  assert(pDeletePerfQueryINTEL);
  pBeginPerfQueryINTEL = _GetProcAddress("glBeginPerfQueryINTEL");
  assert(pBeginPerfQueryINTEL);
  pEndPerfQueryINTEL = _GetProcAddress("glEndPerfQueryINTEL");
  assert(pEndPerfQueryINTEL);
  pGetPerfQueryDataINTEL = _GetProcAddress("glGetPerfQueryDataINTEL");
  assert(pGetPerfQueryDataINTEL);
  pGetProgramiv = _GetProcAddress("glGetProgramiv");
  assert(pGetProgramiv);
  pGetProgramInfoLog = _GetProcAddress("glGetProgramInfoLog");
  assert(pGetProgramInfoLog);
  pGetProgramResourceName = _GetProcAddress("glGetProgramResourceName");
  assert(pGetProgramResourceName);
  pGetBooleanv = _GetProcAddress("glGetBooleanv");
  assert(pGetBooleanv);
  pGetFloatv = _GetProcAddress("glGetFloatv");
  assert(pGetFloatv);
  pBlendColor = _GetProcAddress("glBlendColor");
  assert(pBlendColor);
  pBlendFuncSeparate = _GetProcAddress("glBlendFuncSeparate");
  assert(pBlendFuncSeparate);
  pDisable = _GetProcAddress("glDisable");
  assert(pDisable);
  pBlendEquation = _GetProcAddress("glBlendEquation");
  assert(pBlendEquation);
  pBlendEquationSeparate = _GetProcAddress("glBlendEquationSeparate");
  assert(pBlendEquationSeparate);
  pBindAttribLocation = _GetProcAddress("glBindAttribLocation");
  assert(pBindAttribLocation);
  pValidateProgram = _GetProcAddress("glValidateProgram");
  assert(pValidateProgram);
  pIsEnabled = _GetProcAddress("glIsEnabled");
  assert(pIsEnabled);
  pGetUniformBlockIndex = _GetProcAddress("glGetUniformBlockIndex");
  assert(pGetUniformBlockIndex);
  pUniformBlockBinding = _GetProcAddress("glUniformBlockBinding");
  assert(pUniformBlockBinding);
  pBindFragDataLocation = _GetProcAddress("glBindFragDataLocation");
  assert(pBindFragDataLocation);
  pGetActiveUniform = _GetProcAddress("glGetActiveUniform");
  assert(pGetActiveUniform);
  pGetUniformiv = _GetProcAddress("glGetUniformiv");
  assert(pGetUniformiv);
  pGetUniformfv = _GetProcAddress("glGetUniformfv");
  assert(pGetUniformfv);
  pUniform1fv = _GetProcAddress("glUniform1fv");
  assert(pUniform1fv);
  pUniform1iv = _GetProcAddress("glUniform1iv");
  assert(pUniform1iv);
  pUniform1uiv = _GetProcAddress("glUniform1uiv");
  assert(pUniform1uiv);
  pUniform2fv = _GetProcAddress("glUniform2fv");
  assert(pUniform2fv);
  pUniform2iv = _GetProcAddress("glUniform2iv");
  assert(pUniform2iv);
  pUniform2uiv = _GetProcAddress("glUniform2uiv");
  assert(pUniform2uiv);
  pUniform3fv = _GetProcAddress("glUniform3fv");
  assert(pUniform3fv);
  pUniform3iv = _GetProcAddress("glUniform3iv");
  assert(pUniform3iv);
  pUniform3uiv = _GetProcAddress("glUniform3uiv");
  assert(pUniform3uiv);
  pUniform4fv = _GetProcAddress("glUniform4fv");
  assert(pUniform4fv);
  pUniform4iv = _GetProcAddress("glUniform4iv");
  assert(pUniform4iv);
  pUniform4uiv = _GetProcAddress("glUniform4uiv");
  assert(pUniform4uiv);
  pUniformMatrix2fv = _GetProcAddress("glUniformMatrix2fv");
  assert(pUniformMatrix2fv);
  pUniformMatrix2x3fv = _GetProcAddress("glUniformMatrix2x3fv");
  assert(pUniformMatrix2x3fv);
  pUniformMatrix2x4fv = _GetProcAddress("glUniformMatrix2x4fv");
  assert(pUniformMatrix2x4fv);
  pUniformMatrix3fv = _GetProcAddress("glUniformMatrix3fv");
  assert(pUniformMatrix3fv);
  pUniformMatrix3x2fv = _GetProcAddress("glUniformMatrix3x2fv");
  assert(pUniformMatrix3x2fv);
  pUniformMatrix3x4fv = _GetProcAddress("glUniformMatrix3x4fv");
  assert(pUniformMatrix3x4fv);
  pUniformMatrix4fv = _GetProcAddress("glUniformMatrix4fv");
  assert(pUniformMatrix4fv);
  pUniformMatrix4x2fv = _GetProcAddress("glUniformMatrix4x2fv");
  assert(pUniformMatrix4x2fv);
  pUniformMatrix4x3fv = _GetProcAddress("glUniformMatrix4x3fv");
  assert(pUniformMatrix4x3fv);
  pFinish = _GetProcAddress("glFinish");
  assert(pFinish);
  pCullFace = _GetProcAddress("glCullFace");
  assert(pCullFace);
  pLineWidth = _GetProcAddress("glLineWidth");
  assert(pLineWidth);
  pColorMask = _GetProcAddress("glColorMask");
  assert(pColorMask);;
  pClearDepthf = _GetProcAddress("glClearDepthf");
  assert(pClearDepthf);
  pDepthFunc = _GetProcAddress("glDepthFunc");
  assert(pDepthFunc);
  pDepthRangef = _GetProcAddress("glDepthRangef");
  assert(pDepthRangef);
  pDepthMask = _GetProcAddress("glDepthMask");
  assert(pDepthMask);
}

GLuint
GlFunctions::CreateProgram(void) {
  typedef GLuint(*CREATEPROGRAM)();
  return ((CREATEPROGRAM)pCreateProgram)();
}

GLuint
GlFunctions::CreateShader(GLenum type) {
  typedef GLuint (*CREATESHADER)(GLenum type);
  return ((CREATESHADER)pCreateShader)(type);
}

void
GlFunctions::ShaderSource(GLuint shader, GLsizei count,
                          const GLchar *const*str,
                          const GLint *length) {
  typedef void (*SHADERSOURCE)(GLuint shader, GLsizei count,
                               const GLchar *const*str,
                               const GLint *length);
  ((SHADERSOURCE)pShaderSource)(shader, count, str, length);
}

void
GlFunctions::CompileShader(GLuint shader) {
  typedef void (*COMPILESHADER)(GLuint shader);
  ((COMPILESHADER)pCompileShader)(shader);
}

void
GlFunctions::AttachShader(GLuint program, GLuint shader) {
  typedef void (*ATTACHSHADER)(GLuint program, GLuint shader);
  ((ATTACHSHADER)pAttachShader)(program, shader);
}

void
GlFunctions::LinkProgram(GLuint program) {
  typedef void (*LINKPROGRAM)(GLuint program);
  ((LINKPROGRAM)pLinkProgram)(program);
}

void
GlFunctions::UseProgram(GLuint program) {
  typedef void (*USEPROGRAM)(GLuint program);
  ((USEPROGRAM)pUseProgram)(program);
}

GLenum
GlFunctions::GetError() {
  typedef GLenum (*GETERROR)();
  return ((GETERROR)pGetError)();
}

void
GlFunctions::GetShaderiv(GLuint shader, GLenum pname, GLint *params) {
  typedef void (*GETSHADERIV)(GLuint shader, GLenum pname, GLint *params);
  ((GETSHADERIV)pGetShaderiv)(shader, pname, params);
}

void
GlFunctions::GetShaderInfoLog(GLuint shader, GLsizei bufSize, GLsizei *length,
                              GLchar *infoLog) {
  typedef void (*GETSHADERINFOLOG)(GLuint shader, GLsizei bufSize,
                                   GLsizei *length, GLchar *infoLog);
  ((GETSHADERINFOLOG)pGetShaderInfoLog)(shader, bufSize,
                                        length, infoLog);
}

void
GlFunctions::GenBuffers(GLsizei n, GLuint *buffers) {
  typedef void (*GENBUFFERS)(GLsizei n, GLuint *buffers);
  ((GENBUFFERS) pGenBuffers)(n, buffers);
}

void
GlFunctions::BindBuffer(GLenum target, GLuint buffer) {
  typedef void (*BINDBUFFER)(GLenum target, GLuint buffer);
  ((BINDBUFFER)pBindBuffer)(target, buffer);
}

GLint
GlFunctions::GetAttribLocation(GLuint program, const GLchar *name) {
  typedef GLint (*GETATTRIBLOCATION)(GLuint program, const GLchar *name);
  return ((GETATTRIBLOCATION)pGetAttribLocation)(program, name);
}

GLint
GlFunctions::GetUniformLocation(GLuint program, const GLchar *name) {
  typedef GLint (*GETUNIFORMLOCATION)(GLuint program, const GLchar *name);
  return ((GETUNIFORMLOCATION)pGetUniformLocation)(program, name);
}

void
GlFunctions::ClearColor(GLclampf red, GLclampf green, GLclampf blue,
                        GLclampf alpha) {
  typedef void (*CLEARCOLOR)(GLclampf red, GLclampf green, GLclampf blue,
                             GLclampf alpha);
  ((CLEARCOLOR)pClearColor)(red, green, blue, alpha);
}

void
GlFunctions::Clear(GLbitfield mask) {
  typedef void(*CLEAR)(GLbitfield mask);
  ((CLEAR)pClear)(mask);
}


void
GlFunctions::Uniform1f(GLint location, GLfloat v0) {
  typedef void (*UNIFORM1F)(GLint location, GLfloat v0);
  ((UNIFORM1F)pUniform1f)(location, v0);
}

void
GlFunctions::Uniform4f(GLint location, GLfloat v0, GLfloat v1, GLfloat v2,
                       GLfloat v3) {
  typedef void (*UNIFORM4F)(GLint location, GLfloat v0, GLfloat v1, GLfloat v2,
                            GLfloat v3);
  ((UNIFORM4F)pUniform4f)(location, v0, v1, v2, v3);
}

void
GlFunctions::BufferData(GLenum target, GLsizeiptr size, const void *data,
                        GLenum usage) {
  typedef void (*BUFFERDATA) (GLenum target, GLsizeiptr size, const void *data,
                              GLenum usage);
  ((BUFFERDATA)pBufferData) (target, size, data, usage);
}

void
GlFunctions::EnableVertexAttribArray(GLuint index) {
  typedef void (*ENABLEVERTEXATTRIBARRAY)(GLuint index);
  ((ENABLEVERTEXATTRIBARRAY)pEnableVertexAttribArray)(index);
}

void
GlFunctions::VertexAttribPointer(GLuint index, GLint size, GLenum type,
                                 GLboolean normalized, GLsizei stride,
                                 const void *pointer) {
  typedef void (*VERTEXATTRIBPOINTER)(GLuint index, GLint size, GLenum type,
                                      GLboolean normalized, GLsizei stride,
                                      const void *pointer);
  ((VERTEXATTRIBPOINTER)pVertexAttribPointer)(index, size,
                                              type, normalized,
                                              stride, pointer);
}

void
GlFunctions::DrawArrays(GLenum mode, GLint first, GLsizei count) {
  typedef void (*DRAWARRAYS)(GLenum mode, GLint first, GLsizei count);
  ((DRAWARRAYS)pDrawArrays)(mode, first, count);
}

void
GlFunctions::DisableVertexAttribArray(GLuint index) {
  typedef void (*DISABLEVERTEXATTRIBARRAY)(GLuint index);
  ((DISABLEVERTEXATTRIBARRAY)pDisableVertexAttribArray)(index);
}

void
GlFunctions::Enable(GLenum cap) {
  typedef void (*ENABLE)(GLenum cap);
  ((ENABLE)pEnable)(cap);
}


void
GlFunctions::ReadPixels(GLint x, GLint y,
                        GLsizei width, GLsizei height,
                        GLenum format, GLenum type,
                        GLvoid *pixels) {
  typedef void (*READPIXELS)(GLint x, GLint y,
                             GLsizei width, GLsizei height,
                             GLenum format, GLenum type,
                             GLvoid *pixels);
  ((READPIXELS)pReadPixels)(x, y, width, height, format, type, pixels);
}

void
GlFunctions::DrawElements(GLenum mode, GLsizei count,
                          GLenum type, const GLvoid *indices) {
  typedef void (*DRAWELEMENTS)(GLenum mode, GLsizei count,
                               GLenum type, const GLvoid *indices);
  ((DRAWELEMENTS) pDrawElements)(mode, count, type, indices);
}

void
GlFunctions::BlendFunc(GLenum sfactor, GLenum dfactor) {
  typedef void (*BLENDFUNC)(GLenum sfactor, GLenum dfactor);
  ((BLENDFUNC) pBlendFunc)(sfactor, dfactor);
}

void
GlFunctions::GetFirstPerfQueryIdINTEL(GLuint *queryId) {
  if (!pGetFirstPerfQueryIdINTEL) {
    *queryId = -1;
    return;
  }
  typedef void (*GETFIRSTPERFQUERYIDINTEL)(GLuint *queryId);
  ((GETFIRSTPERFQUERYIDINTEL) pGetFirstPerfQueryIdINTEL)(queryId);
}

void
GlFunctions::GetNextPerfQueryIdINTEL(GLuint queryId, GLuint *nextQueryId) {
  typedef void (*GETNEXTPERFQUERYIDINTEL)(GLuint queryId, GLuint *nextQueryId);
  ((GETNEXTPERFQUERYIDINTEL) pGetNextPerfQueryIdINTEL)(queryId, nextQueryId);
}

void
GlFunctions::GetIntegerv(GLenum pname, GLint *params) {
  typedef void (*GETINTEGERV)(GLenum pname, GLint *params);
  ((GETINTEGERV)pGetIntegerv)(pname, params);
}

const GLubyte *
GlFunctions::GetStringi(GLenum pname, GLuint index) {
  typedef const GLubyte * (*GETSTRINGI)(GLenum pname, GLuint index);
  return ((GETSTRINGI)pGetStringi)(pname, index);
}

void GlFunctions::GetPerfQueryInfoINTEL(GLuint queryId, GLuint queryNameLength,
                                        GLchar *queryName, GLuint *dataSize,
                                        GLuint *noCounters, GLuint *noInstances,
                                        GLuint *capsMask) {
  typedef void (*GETPERFQUERYINFOINTEL)(GLuint queryId, GLuint queryNameLength,
                                        GLchar *queryName, GLuint *dataSize,
                                        GLuint *noCounters, GLuint *noInstances,
                                        GLuint *capsMask);
  ((GETPERFQUERYINFOINTEL)pGetPerfQueryInfoINTEL)(queryId, queryNameLength,
                                                  queryName, dataSize,
                                                  noCounters, noInstances,
                                                  capsMask);
}

void
GlFunctions::GetPerfCounterInfoINTEL(GLuint queryId, GLuint counterId,
                                     GLuint counterNameLength,
                                     GLchar *counterName,
                                     GLuint counterDescLength,
                                     GLchar *counterDesc,
                                     GLuint *counterOffset,
                                     GLuint *counterDataSize,
                                     GLuint *counterTypeEnum,
                                     GLuint *counterDataTypeEnum,
                                     GLuint64 *rawCounterMaxValue) {
  typedef void (*GETPERFCOUNTERINFOINTEL)(GLuint queryId, GLuint counterId,
                                          GLuint counterNameLength,
                                          GLchar *counterName,
                                          GLuint counterDescLength,
                                          GLchar *counterDesc,
                                          GLuint *counterOffset,
                                          GLuint *counterDataSize,
                                          GLuint *counterTypeEnum,
                                          GLuint *counterDataTypeEnum,
                                          GLuint64 *rawCounterMaxValue);
  ((GETPERFCOUNTERINFOINTEL)pGetPerfCounterInfoINTEL)(queryId,
                                                      counterId,
                                                      counterNameLength,
                                                      counterName,
                                                      counterDescLength,
                                                      counterDesc,
                                                      counterOffset,
                                                      counterDataSize,
                                                      counterTypeEnum,
                                                      counterDataTypeEnum,
                                                      rawCounterMaxValue);
}

void GlFunctions::CreatePerfQueryINTEL(GLuint queryId, GLuint *queryHandle) {
  typedef void (*CREATEPERFQUERYINTEL)(GLuint queryId, GLuint *queryHandle);
  ((CREATEPERFQUERYINTEL)pCreatePerfQueryINTEL)(queryId, queryHandle);
}

void GlFunctions::DeletePerfQueryINTEL(GLuint queryHandle) {
  typedef void (*DELETEPERFQUERYINTEL)(GLuint queryHandle);
  ((DELETEPERFQUERYINTEL)pDeletePerfQueryINTEL)(queryHandle);
}

void
GlFunctions::BeginPerfQueryINTEL(GLuint queryHandle) {
  typedef void (*BEGINPERFQUERYINTEL)(GLuint queryHandle);
  ((BEGINPERFQUERYINTEL) pBeginPerfQueryINTEL)(queryHandle);
}

void
GlFunctions::EndPerfQueryINTEL(GLuint queryHandle) {
  typedef void (*ENDPERFQUERYINTEL)(GLuint queryHandle);
  ((ENDPERFQUERYINTEL) pEndPerfQueryINTEL)(queryHandle);
}

void
GlFunctions::GetPerfQueryDataINTEL(GLuint queryHandle, GLuint flags,
                                   GLsizei dataSize, GLvoid *data,
                                   GLuint *bytesWritten) {
  typedef void (*GETPERFQUERYDATAINTEL)(GLuint queryHandle, GLuint flags,
                                        GLsizei dataSize, GLvoid *data,
                                        GLuint *bytesWritten);
  ((GETPERFQUERYDATAINTEL) pGetPerfQueryDataINTEL)(queryHandle, flags,
                                                   dataSize, data,
                                                   bytesWritten);
}

void
GlFunctions::GetProgramiv(GLuint program, GLenum pname, GLint *params) {
  typedef void (*GETPROGRAMIV)(GLuint program, GLenum pname, GLint *params);
  ((GETPROGRAMIV) pGetProgramiv)(program, pname, params);
}

void
GlFunctions::GetProgramInfoLog(GLuint program, GLsizei bufSize,
                               GLsizei *length, GLchar *infoLog) {
  typedef void (*GETPROGRAMINFOLOG)(GLuint program, GLsizei bufSize,
                                    GLsizei *length, GLchar *infoLog);
  ((GETPROGRAMINFOLOG) pGetProgramInfoLog)(program, bufSize,
                                           length, infoLog);
}

void
GlFunctions::GetProgramResourceName(GLuint program, GLenum programInterface,
                                    GLuint index, GLsizei bufSize,
                                    GLsizei *length, GLchar *name) {
  typedef void (*GETPROGRAMRESOURCENAME)(GLuint program,
                                         GLenum programInterface,
                                         GLuint index, GLsizei bufSize,
                                         GLsizei *length, GLchar *name);
  ((GETPROGRAMRESOURCENAME) pGetProgramResourceName)(program,
                                                     programInterface,
                                                     index, bufSize,
                                                     length, name);
}


void
GlFunctions::GetBooleanv(GLenum pname, GLboolean *params) {
  typedef void (*GETBOOLEANV)(GLenum pname, GLboolean *params);
  ((GETBOOLEANV) pGetBooleanv)(pname, params);
}

void
GlFunctions::GetFloatv(GLenum pname, GLfloat *params) {
  typedef void (*GETFLOATV)(GLenum pname, GLfloat *params);
  ((GETFLOATV) pGetFloatv)(pname, params);
}

void
GlFunctions::BlendColor(GLclampf red, GLclampf green,
                        GLclampf blue, GLclampf alpha) {
  typedef void (*BLENDCOLOR)(GLclampf red, GLclampf green,
                             GLclampf blue, GLclampf alpha);
  ((BLENDCOLOR) pBlendColor)(red, green, blue, alpha);
}

void
GlFunctions::BlendFuncSeparate(GLenum sfactorRGB, GLenum dfactorRGB,
                               GLenum sfactorAlpha, GLenum dfactorAlpha) {
  typedef void (*BLENDFUNCSEPARATE)(GLenum sfactorRGB, GLenum dfactorRGB,
                                    GLenum sfactorAlpha, GLenum dfactorAlpha);
  ((BLENDFUNCSEPARATE) pBlendFuncSeparate)(sfactorRGB, dfactorRGB,
                                           sfactorAlpha, dfactorAlpha);
}

void
GlFunctions::Disable(GLenum cap) {
  typedef void (*DISABLE)(GLenum cap);
  ((DISABLE) pDisable)(cap);
}

void
GlFunctions::BlendEquation(GLenum mode) {
  typedef void (*BLENDEQUATION)(GLenum mode);
  ((BLENDEQUATION) pBlendEquation)(mode);
}

void
GlFunctions::BlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha) {
  typedef void (*BLENDEQUATIONSEPARATE)(GLenum modeRGB, GLenum modeAlpha);
  ((BLENDEQUATIONSEPARATE) pBlendEquationSeparate)(modeRGB, modeAlpha);
}

void
GlFunctions::BindAttribLocation(GLuint program, GLuint index,
                                const GLchar *name) {
  typedef void (*BINDATTRIBLOCATION)(GLuint program, GLuint index,
                                     const GLchar *name);
  ((BINDATTRIBLOCATION) pBindAttribLocation)(program, index, name);
}

void
GlFunctions::ValidateProgram(GLuint program) {
  typedef void (*VALIDATEPROGRAM)(GLuint program);
  ((VALIDATEPROGRAM) pValidateProgram)(program);
}

GLboolean
GlFunctions::IsEnabled(GLenum cap) {
  typedef GLboolean (*ISENABLED)(GLenum cap);
  return ((ISENABLED) pIsEnabled)(cap);
}

GLuint
GlFunctions::GetUniformBlockIndex(GLuint program,
                                  const GLchar *uniformBlockName) {
  typedef GLuint (*GETUNIFORMBLOCKINDEX)(GLuint program,
                                         const GLchar *uniformBlockName);
  return ((GETUNIFORMBLOCKINDEX) pGetUniformBlockIndex)(program,
                                                        uniformBlockName);
}

void
GlFunctions::UniformBlockBinding(GLuint program, GLuint uniformBlockIndex,
                                 GLuint uniformBlockBinding) {
  typedef void (*UNIFORMBLOCKBINDING)(GLuint program, GLuint uniformBlockIndex,
                                      GLuint uniformBlockBinding);
  return ((UNIFORMBLOCKBINDING) pUniformBlockBinding)(program,
                                                      uniformBlockIndex,
                                                      uniformBlockBinding);
}

void
GlFunctions::BindFragDataLocation(GLuint program, GLuint colorNumber,
                                  const char * name) {
  typedef void (*BINDFRAGDATALOCATION)(GLuint program, GLuint colorNumber,
                                       const char * name);
  return ((BINDFRAGDATALOCATION) pBindFragDataLocation)(program,
                                                       colorNumber,
                                                       name);
}

void
GlFunctions::GetActiveUniform(GLuint program, GLuint index,
                              GLsizei bufSize, GLsizei *length,
                              GLint *size, GLenum *type,
                              GLchar *name) {
  typedef void (*GETACTIVEUNIFORM)(GLuint program, GLuint index,
                                   GLsizei bufSize, GLsizei *length,
                                   GLint *size, GLenum *type, GLchar *name);
  return ((GETACTIVEUNIFORM)pGetActiveUniform)(program, index, bufSize,
                                               length, size, type, name);
}

void
GlFunctions::GetUniformfv(GLuint program, GLint location, GLfloat *params) {
  typedef void (*GETUNIFORMFV)(GLuint program, GLint location, GLfloat *params);
  return ((GETUNIFORMFV) pGetUniformfv)(program, location, params);
}

void
GlFunctions::GetUniformiv(GLuint program, GLint location, GLint *params) {
  typedef void (*GETUNIFORMIV)(GLuint program, GLint location, GLint *params);
  return ((GETUNIFORMIV) pGetUniformiv)(program, location, params);
}

void
GlFunctions::Uniform1fv(GLint location, GLsizei count, const GLfloat *value) {
  typedef void (*UNIFORM1FV)(GLint location, GLsizei count,
                             const GLfloat *value);
  return ((UNIFORM1FV)pUniform1fv)(location, count, value);
}

void
GlFunctions::Uniform1iv(GLint location, GLsizei count, const GLint *value) {
  typedef void (*UNIFORM1IV)(GLint location, GLsizei count,
                             const GLint *value);
  return ((UNIFORM1IV)pUniform1iv)(location, count, value);
}

void
GlFunctions::Uniform1uiv(GLint location, GLsizei count, const GLuint *value) {
  typedef void (*UNIFORM1UIV)(GLint location, GLsizei count,
                              const GLuint *value);
  return ((UNIFORM1UIV)pUniform1uiv)(location, count, value);
}

void
GlFunctions::Uniform2fv(GLint location, GLsizei count, const GLfloat *value) {
  typedef void (*UNIFORM2FV)(GLint location, GLsizei count,
                             const GLfloat *value);
  return ((UNIFORM2FV)pUniform2fv)(location, count, value);
}

void
GlFunctions::Uniform2iv(GLint location, GLsizei count, const GLint *value) {
  typedef void (*UNIFORM2IV)(GLint location, GLsizei count, const GLint *value);
  return ((UNIFORM2IV)pUniform2iv)(location, count, value);
}

void
GlFunctions::Uniform2uiv(GLint location, GLsizei count, const GLuint *value) {
  typedef void (*UNIFORM2UIV)(GLint location, GLsizei count,
                              const GLuint *value);
  return ((UNIFORM2UIV)pUniform2uiv)(location, count, value);
}

void
GlFunctions::Uniform3fv(GLint location, GLsizei count, const GLfloat *value) {
  typedef void (*UNIFORM3FV)(GLint location, GLsizei count,
                             const GLfloat *value);
  return ((UNIFORM3FV)pUniform3fv)(location, count, value);
}

void
GlFunctions::Uniform3iv(GLint location, GLsizei count, const GLint *value) {
  typedef void (*UNIFORM3IV)(GLint location, GLsizei count, const GLint *value);
  return ((UNIFORM3IV)pUniform3iv)(location, count, value);
}

void
GlFunctions::Uniform3uiv(GLint location, GLsizei count, const GLuint *value) {
  typedef void (*UNIFORM3UIV)(GLint location, GLsizei count,
                              const GLuint *value);
  return ((UNIFORM3UIV)pUniform3uiv)(location, count, value);
}

void
GlFunctions::Uniform4fv(GLint location, GLsizei count, const GLfloat *value) {
  typedef void (*UNIFORM4FV)(GLint location, GLsizei count,
                             const GLfloat *value);
  return ((UNIFORM4FV)pUniform4fv)(location, count, value);
}

void
GlFunctions::Uniform4iv(GLint location, GLsizei count, const GLint *value) {
  typedef void (*UNIFORM4IV)(GLint location, GLsizei count, const GLint *value);
  return ((UNIFORM4IV)pUniform4iv)(location, count, value);
}

void
GlFunctions::Uniform4uiv(GLint location, GLsizei count, const GLuint *value) {
  typedef void (*UNIFORM4UIV)(GLint location, GLsizei count,
                              const GLuint *value);
  return ((UNIFORM4UIV)pUniform4uiv)(location, count, value);
}

void
GlFunctions::UniformMatrix2fv(GLint location, GLsizei count,
                              GLboolean transpose, const GLfloat *value) {
  typedef void (*UNIFORMMATRIX2FV)(GLint location, GLsizei count,
                                   GLboolean transpose, const GLfloat *value);
  return ((UNIFORMMATRIX2FV)pUniformMatrix2fv)(location, count, transpose,
                                               value);
}

void
GlFunctions::UniformMatrix2x3fv(GLint location, GLsizei count,
                                GLboolean transpose, const GLfloat *value) {
  typedef void (*UNIFORMMATRIX2X3FV)(GLint location, GLsizei count,
                                     GLboolean transpose, const GLfloat *value);
  return ((UNIFORMMATRIX2X3FV)pUniformMatrix2x3fv)(location, count, transpose,
                                                   value);
}

void
GlFunctions::UniformMatrix2x4fv(GLint location, GLsizei count,
                                GLboolean transpose, const GLfloat *value) {
  typedef void (*UNIFORMMATRIX2X4FV)(GLint location, GLsizei count,
                                     GLboolean transpose, const GLfloat *value);
  return ((UNIFORMMATRIX2X4FV)pUniformMatrix2x4fv)(location, count, transpose,
                                                   value);
}

void
GlFunctions::UniformMatrix3fv(GLint location, GLsizei count,
                              GLboolean transpose, const GLfloat *value) {
  typedef void (*UNIFORMMATRIX3FV)(GLint location, GLsizei count,
                                   GLboolean transpose, const GLfloat *value);
  return ((UNIFORMMATRIX3FV)pUniformMatrix3fv)(location, count, transpose,
                                               value);
}

void
GlFunctions::UniformMatrix3x2fv(GLint location, GLsizei count,
                                GLboolean transpose, const GLfloat *value) {
  typedef void (*UNIFORMMATRIX3X2FV)(GLint location, GLsizei count,
                                     GLboolean transpose, const GLfloat *value);
  return ((UNIFORMMATRIX3X2FV)pUniformMatrix3x2fv)(location, count, transpose,
                                                   value);
}

void
GlFunctions::UniformMatrix3x4fv(GLint location, GLsizei count,
                                GLboolean transpose, const GLfloat *value) {
  typedef void (*UNIFORMMATRIX3X4FV)(GLint location, GLsizei count,
                                     GLboolean transpose, const GLfloat *value);
  return ((UNIFORMMATRIX3X4FV)pUniformMatrix3x4fv)(location, count, transpose,
                                                   value);
}

void
GlFunctions::UniformMatrix4fv(GLint location, GLsizei count,
                              GLboolean transpose, const GLfloat *value) {
  typedef void (*UNIFORMMATRIX4FV)(GLint location, GLsizei count,
                                   GLboolean transpose, const GLfloat *value);
  return ((UNIFORMMATRIX4FV)pUniformMatrix4fv)(location, count, transpose,
                                               value);
}

void
GlFunctions::UniformMatrix4x2fv(GLint location, GLsizei count,
                                GLboolean transpose, const GLfloat *value) {
  typedef void (*UNIFORMMATRIX4X2FV)(GLint location, GLsizei count,
                                     GLboolean transpose, const GLfloat *value);
  return ((UNIFORMMATRIX4X2FV)pUniformMatrix4x2fv)(location, count, transpose,
                                                   value);
}

void
GlFunctions::UniformMatrix4x3fv(GLint location, GLsizei count,
                                GLboolean transpose, const GLfloat *value) {
  typedef void (*UNIFORMMATRIX4X3FV)(GLint location, GLsizei count,
                                     GLboolean transpose, const GLfloat *value);
  return ((UNIFORMMATRIX4X3FV)pUniformMatrix4x3fv)(location, count, transpose,
                                                   value);
}

void
GlFunctions::Finish() {
  typedef void (*FINISH)();
  return ((FINISH)pFinish)();
}

void
GlFunctions::CullFace(GLenum mode) {
  typedef void (*CULLFACE)(GLenum mode);
  return ((CULLFACE)pCullFace)(mode);
}

void
GlFunctions::LineWidth(GLfloat width) {
  typedef void (*LINEWIDTH)(GLfloat width);
  return ((LINEWIDTH)pLineWidth)(width);
}


void
GlFunctions::ColorMask(GLboolean red, GLboolean green,
                       GLboolean blue, GLboolean alpha) {
  typedef void (*COLORMASK)(GLboolean red, GLboolean green,
                            GLboolean blue, GLboolean alpha);
  return ((COLORMASK)pColorMask)(red, green, blue, alpha);
}


void
GlFunctions::ClearDepthf(GLfloat d) {
  typedef void (*CLEARDEPTHF)(GLfloat d);
  return ((CLEARDEPTHF)pClearDepthf)(d);
}

void
GlFunctions::DepthFunc(GLenum func) {
  typedef void (*DEPTHFUNC)(GLenum func);
  return ((DEPTHFUNC)pDepthFunc)(func);
}

void
GlFunctions::DepthRangef(GLfloat n, GLfloat f) {
  typedef void (*DEPTHRANGEF)(GLfloat n, GLfloat f);
  return ((DEPTHRANGEF)pDepthRangef)(n, f);
}

void
GlFunctions::DepthMask(GLboolean flag) {
  typedef void (*DEPTHMASK)(GLboolean flag);
  return ((DEPTHMASK)pDepthMask)(flag);
}