-
Notifications
You must be signed in to change notification settings - Fork 8
/
intercepts.c
810 lines (566 loc) · 15.7 KB
/
intercepts.c
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
#include "gluray.h"
// GL_VERSION_1_0
void glBegin(GLenum mode)
{
gr_beginPrimitive(mode);
next_glBegin(mode);
printGLError();
debugPrint("glBegin(mode= %s)\n", getEnumString(mode));
}
void glCallList(GLuint list)
{
gr_callList(list);
}
void glClear(GLbitfield mask)
{
gr_clear(mask);
}
void glClearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
{
gr_setBackgroundColor(red, green, blue, alpha);
next_glClearColor(red, green, blue, alpha);
printGLError();
debugPrint("glClearColor(red= %f, green= %f, blue= %f, alpha= %f)\n", red, green, blue, alpha);
}
void glColor3d(GLdouble red, GLdouble green, GLdouble blue)
{
gr_setColor(red,green,blue, 1.0f);
next_glColor3d(red, green, blue);
printGLError();
debugPrint("glColor3d(red= %f, green= %f, blue= %f)\n", red, green, blue);
}
void glColor3dv(const GLdouble* v)
{
gr_setColor(v[0],v[1],v[2], 1.0f);
next_glColor3dv(v);
printGLError();
debugPrint("glColor3dv(v= %x)\n", v);
}
void glColor3f(GLfloat red, GLfloat green, GLfloat blue)
{
gr_setColor(red,green,blue, 1.0f);
next_glColor3f(red, green, blue);
printGLError();
debugPrint("glColor3f(red= %f, green= %f, blue= %f)\n", red, green, blue);
}
void glColor3fv(const GLfloat* v)
{
gr_setColor(v[0],v[1],v[2], 1.0f);
next_glColor3fv(v);
printGLError();
debugPrint("glColor3fv(v= %x)\n", v);
}
void glColor3iv(const GLint* v)
{
gr_setColor(v[0],v[1],v[2], 1.0f);
next_glColor3iv(v);
printGLError();
debugPrint("glColor3iv(v= %x)\n", v);
}
void glColor3ubv(const GLubyte* v)
{
gr_setColorub(v[0], v[1], v[2], 255);
next_glColor3ubv(v);
printGLError();
debugPrint("glColor3ubv(v= %x)\n", v);
}
void glColor4d(GLdouble red, GLdouble green, GLdouble blue, GLdouble alpha)
{
gr_setColor(red,green,blue, alpha);
next_glColor4d(red, green, blue, alpha);
printGLError();
debugPrint("glColor4d(red= %f, green= %f, blue= %f, alpha= %f)\n", red, green, blue, alpha);
}
void glColor4dv(const GLdouble* v)
{
gr_setColor(v[0],v[1],v[2],v[3]);
next_glColor4dv(v);
printGLError();
debugPrint("glColor4dv(v= %x)\n", v);
}
void glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
{
gr_setColor(red,green,blue, alpha);
next_glColor4f(red, green, blue, alpha);
printGLError();
debugPrint("glColor4f(red= %f, green= %f, blue= %f, alpha= %f)\n", red, green, blue, alpha);
}
void glColor4fv(const GLfloat* v)
{
gr_setColor(v[0],v[1],v[2],v[3]);
next_glColor4fv(v);
printGLError();
debugPrint("glColor4fv(v= %x)\n", v);
}
void glColor4ubv(const GLubyte* v)
{
gr_setColorub(v[0],v[1],v[2],v[3]);
next_glColor4ubv(v);
printGLError();
debugPrint("glColor4ubv(v= %x)\n", v);
}
void glDeleteLists(GLuint list, GLsizei range)
{
gr_deleteLists(list, range);
next_glDeleteLists(list, range);
printGLError();
debugPrint("glDeleteLists(list= %u, range= %u)\n", list, range);
}
void glDisable(GLenum cap)
{
gr_disable(cap);
next_glDisable(cap);
printGLError();
debugPrint("glDisable(cap= %s)\n", getEnumString(cap));
}
void glEnable(GLenum cap)
{
gr_enable(cap);
next_glEnable(cap);
printGLError();
debugPrint("glEnable(cap= %s)\n", getEnumString(cap));
}
void glEnd()
{
gr_endPrimitive();
next_glEnd();
printGLError();
debugPrint("glEnd()\n");
}
void glEndList()
{
gr_endList();
}
void glFinish()
{
if (GLURAY_RENDER_MODE & GLURAY_RENDER_GLFINISH)
gr_render();
next_glFinish();
printGLError();
debugPrint("glFinish()\n");
}
void glFlush()
{
if (GLURAY_RENDER_MODE & GLURAY_RENDER_GLFLUSH)
gr_render();
next_glFlush();
printGLError();
debugPrint("glFlush()\n");
}
void glFrustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar)
{
gr_frustum(left,right,bottom,top,zNear,zFar);
next_glFrustum(left, right, bottom, top, zNear, zFar);
printGLError();
debugPrint("glFrustum(left= %f, right= %f, bottom= %f, top= %f, zNear= %f, zFar= %f)\n", left, right, bottom, top, zNear, zFar);
}
void glLightfv(GLenum light, GLenum pname, const GLfloat* params)
{
gr_light(light, pname, params);
next_glLightfv(light, pname, params);
printGLError();
debugPrint("glLightfv(light= %s, pname= %s, params= %x)\n", getEnumString(light), getEnumString(pname), params);
}
void glLoadIdentity()
{
gr_loadIdentity();
next_glLoadIdentity();
printGLError();
debugPrint("glLoadIdentity()\n");
}
void glLoadMatrixd(const GLdouble* m)
{
gr_loadMatrixd(m);
next_glLoadMatrixd(m);
printGLError();
debugPrint("glLoadMatrixd(m= %x)\n", m);
}
void glLoadMatrixf(const GLfloat* m)
{
gr_loadMatrixf(m);
next_glLoadMatrixf(m);
printGLError();
debugPrint("glLoadMatrixf(m= %x)\n", m);
}
void glMaterialf(GLenum face, GLenum pname, GLfloat param)
{
gr_materialf(face, pname, param);
next_glMaterialf(face, pname, param);
printGLError();
debugPrint("glMaterialf(face= %s, pname= %s, param= %f)\n", getEnumString(face), getEnumString(pname), param);
}
void glMaterialfv(GLenum face, GLenum pname, const GLfloat* params)
{
gr_materialfv(face, pname, params);
next_glMaterialfv(face, pname, params);
printGLError();
debugPrint("glMaterialfv(face= %s, pname= %s, params= %x)\n", getEnumString(face), getEnumString(pname), params);
}
void glMateriali(GLenum face, GLenum pname, GLint param)
{
gr_materiali(face, pname, param);
next_glMateriali(face, pname, param);
printGLError();
debugPrint("glMateriali(face= %s, pname= %s, param= %i)\n", getEnumString(face), getEnumString(pname), param);
}
void glMaterialiv(GLenum face, GLenum pname, const GLint* params)
{
gr_materialiv(face, pname, params);
next_glMaterialiv(face, pname, params);
printGLError();
debugPrint("glMaterialiv(face= %s, pname= %s, params= %x)\n", getEnumString(face), getEnumString(pname), params);
}
void glMatrixMode(GLenum mode)
{
gr_matrixMode(mode);
next_glMatrixMode(mode);
printGLError();
debugPrint("glMatrixMode(mode= %s)\n", getEnumString(mode));
}
void glMultMatrixd(const GLdouble* m)
{
gr_multMatrixd(m);
next_glMultMatrixd(m);
printGLError();
debugPrint("glMultMatrixd(m= %x)\n", m);
}
void glMultMatrixf(const GLfloat* m)
{
gr_multMatrixf(m);
next_glMultMatrixf(m);
printGLError();
debugPrint("glMultMatrixf(m= %x)\n", m);
}
void glNewList(GLuint list, GLenum mode)
{
gr_newList(list,mode);
}
void glNormal3d(GLdouble nx, GLdouble ny, GLdouble nz)
{
gr_normal(nx,ny,nz);
}
void glNormal3dv(const GLdouble* v)
{
gr_normal(v[0],v[1],v[2]);
}
void glNormal3f(GLfloat nx, GLfloat ny, GLfloat nz)
{
gr_normal(nx,ny,nz);
}
void glNormal3fv(const GLfloat* v)
{
gr_normal(v[0],v[1],v[2]);
}
void glNormal3i(GLint nx, GLint ny, GLint nz)
{
gr_normal(nx,ny,nz);
next_glNormal3i(nx, ny, nz);
printGLError();
debugPrint("glNormal3i(nx= %i, ny= %i, nz= %i)\n", nx, ny, nz);
}
void glNormal3iv(const GLint* v)
{
gr_normal(v[0],v[1],v[2]);
next_glNormal3iv(v);
printGLError();
debugPrint("glNormal3iv(v= %x)\n", v);
}
void glNormal3s(GLshort nx, GLshort ny, GLshort nz)
{
gr_normal(nx,ny,nz);
next_glNormal3s(nx, ny, nz);
printGLError();
debugPrint("glNormal3s(nx= %i, ny= %i, nz= %i)\n", nx, ny, nz);
}
void glNormal3sv(const GLshort* v)
{
gr_normal(v[0],v[1],v[2]);
next_glNormal3sv(v);
printGLError();
debugPrint("glNormal3sv(v= %x)\n", v);
}
void glPopMatrix()
{
gr_popMatrix();
next_glPopMatrix();
printGLError();
debugPrint("glPopMatrix()\n");
}
void glPushMatrix()
{
gr_pushMatrix();
next_glPushMatrix();
printGLError();
debugPrint("glPushMatrix()\n");
}
void glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void * pixels)
{
if (format == GL_RGBA //TODO: this assumes compositors will read in rgba first...
&& (GLURAY_RENDER_MODE & GLURAY_RENDER_GLREADPIXELS) )
gr_render();
next_glReadPixels(x, y, width, height, format, type, pixels);
printGLError();
debugPrint("glReadPixels(x= %i, y= %i, width= %u, height= %u, format= %s, type= %s, pixels= %x)\n", x, y, width, height, getEnumString(format), getEnumString(type), pixels);
}
void glRotated(GLdouble angle, GLdouble x, GLdouble y, GLdouble z)
{
gr_rotate(angle,x,y,z);
next_glRotated(angle, x, y, z);
printGLError();
debugPrint("glRotated(angle= %f, x= %f, y= %f, z= %f)\n", angle, x, y, z);
}
void glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z)
{
gr_rotate(angle,x,y,z);
next_glRotatef(angle, x, y, z);
printGLError();
debugPrint("glRotatef(angle= %f, x= %f, y= %f, z= %f)\n", angle, x, y, z);
}
void glScaled(GLdouble x, GLdouble y, GLdouble z)
{
gr_scale(x,y,z);
next_glScaled(x, y, z);
printGLError();
debugPrint("glScaled(x= %f, y= %f, z= %f)\n", x, y, z);
}
void glScalef(GLfloat x, GLfloat y, GLfloat z)
{
gr_scale(x,y,z);
next_glScalef(x, y, z);
printGLError();
debugPrint("glScalef(x= %f, y= %f, z= %f)\n", x, y, z);
}
void glTexCoord2fv(const GLfloat* v)
{
gr_texCoord(v[0], v[1], 0.0);
next_glTexCoord2fv(v);
printGLError();
debugPrint("glTexCoord2fv(v= %x)\n", v);
}
void glTexImage1D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const void * pixels)
{
gr_texImage1D(target, level, internalformat, width, border, format, type, pixels);
next_glTexImage1D(target, level, internalformat, width, border, format, type, pixels);
printGLError();
debugPrint("glTexImage1D(target= %s, level= %i, internalformat= %i, width= %u, border= %i, format= %s, type= %s, pixels= %x)\n", getEnumString(target), level, internalformat, width, border, getEnumString(format), getEnumString(type), pixels);
}
void glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void * pixels)
{
gr_texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
next_glTexImage2D(target, level, internalformat, width, height, border, format, type, pixels);
printGLError();
debugPrint("glTexImage2D(target= %s, level= %i, internalformat= %i, width= %u, height= %u, border= %i, format= %s, type= %s, pixels= %x)\n", getEnumString(target), level, internalformat, width, height, border, getEnumString(format), getEnumString(type), pixels);
}
void glTranslated(GLdouble x, GLdouble y, GLdouble z)
{
gr_translate(x,y,z);
next_glTranslated(x, y, z);
printGLError();
debugPrint("glTranslated(x= %f, y= %f, z= %f)\n", x, y, z);
}
void glTranslatef(GLfloat x, GLfloat y, GLfloat z)
{
gr_translate(x,y,z);
next_glTranslatef(x, y, z);
printGLError();
debugPrint("glTranslatef(x= %f, y= %f, z= %f)\n", x, y, z);
}
void glVertex2d(GLdouble x, GLdouble y)
{
gr_addVertex(x,y,0);
next_glVertex2d(x, y);
printGLError();
debugPrint("glVertex2d(x= %f, y= %f)\n", x, y);
}
void glVertex3d(GLdouble x, GLdouble y, GLdouble z)
{
gr_addVertex(x,y,z);
}
void glVertex3dv(const GLdouble* v)
{
gr_addVertex(v[0],v[1],v[2]);
}
void glVertex3f(GLfloat x, GLfloat y, GLfloat z)
{
gr_addVertex(x,y,z);
}
void glVertex3fv(const GLfloat* v)
{
gr_addVertex(v[0],v[1],v[2]);
}
void glVertex3iv(const GLint* v)
{
gr_addVertex(v[0],v[1],v[2]);
next_glVertex3iv(v);
printGLError();
debugPrint("glVertex3iv(v= %x)\n", v);
}
void glVertex3sv(const GLshort* v)
{
gr_addVertex(v[0],v[1],v[2]);
next_glVertex3sv(v);
printGLError();
debugPrint("glVertex3sv(v= %x)\n", v);
}
void glVertex4dv(const GLdouble* v)
{
gr_addVertex(v[0],v[1],v[2]);
next_glVertex4dv(v);
printGLError();
debugPrint("glVertex4dv(v= %x)\n", v);
}
void glVertex4fv(const GLfloat* v)
{
gr_addVertex(v[0],v[1],v[2]);
next_glVertex4fv(v);
printGLError();
debugPrint("glVertex4fv(v= %x)\n", v);
}
void glVertex4iv(const GLint* v)
{
gr_addVertex(v[0],v[1],v[2]);
next_glVertex4iv(v);
printGLError();
debugPrint("glVertex4iv(v= %x)\n", v);
}
void glVertex4sv(const GLshort* v)
{
gr_addVertex(v[0],v[1],v[2]);
next_glVertex4sv(v);
printGLError();
debugPrint("glVertex4sv(v= %x)\n", v);
}
void glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
{
gr_viewport(x,y,width,height);
next_glViewport(x, y, width, height);
printGLError();
debugPrint("glViewport(x= %i, y= %i, width= %u, height= %u)\n", x, y, width, height);
}
// GL_VERSION_1_1
void glColorPointer(GLint size, GLenum type, GLsizei stride, const void * pointer)
{
gr_colorPointer(size,type,stride, pointer);
next_glColorPointer(size, type, stride, pointer);
printGLError();
debugPrint("glColorPointer(size= %i, type= %s, stride= %u, pointer= %x)\n", size, getEnumString(type), stride, pointer);
}
void glDisableClientState(GLenum array)
{
gr_disableClientState(array);
next_glDisableClientState(array);
printGLError();
debugPrint("glDisableClientState(array= %s)\n", getEnumString(array));
}
void glDrawArrays(GLenum mode, GLint first, GLsizei count)
{
gr_drawArrays(mode, first, count);
}
void glDrawElements(GLenum mode, GLsizei count, GLenum type, const void * indices)
{
gr_drawElements(mode, count, type, indices);
}
void glEnableClientState(GLenum array)
{
gr_enableClientState(array);
next_glEnableClientState(array);
printGLError();
debugPrint("glEnableClientState(array= %s)\n", getEnumString(array));
}
void glVertexPointer(GLint size, GLenum type, GLsizei stride, const void * pointer)
{
gr_vertexPointer(size,type,stride,pointer);
next_glVertexPointer(size, type, stride, pointer);
printGLError();
debugPrint("glVertexPointer(size= %i, type= %s, stride= %u, pointer= %x)\n", size, getEnumString(type), stride, pointer);
}
// GL_VERSION_1_2
// GL_VERSION_1_3
// GL_VERSION_1_4
// GL_VERSION_1_5
// GL_VERSION_2_0
// GL_VERSION_2_1
// GL_VERSION_3_0
// GL_VERSION_3_1
// GL_VERSION_3_2
// GL_VERSION_3_3
// GL_VERSION_4_0
// GL_VERSION_4_1
// GL_VERSION_4_2
// GL_VERSION_4_3
// GL_VERSION_4_4
// GL_VERSION_4_5
//GLX
XVisualInfo * glXChooseVisual(Display * dpy, GLint screen, GLint * attriblist) {
XVisualInfo * result = NULL;
result = next_glXChooseVisual(dpy, screen, attriblist);
gr_chooseVisual(result);
return result;
}
void glXDestroyContext(Display * dpy, GLXContext ctx) {
return;
}
Bool glXMakeCurrent(Display * dpy, GLXDrawable drawable, GLXContext ctx) {
gr_makeCurrent(drawable);
Bool result;
result = next_glXMakeCurrent(dpy, drawable, ctx);
return result;
}
void glXSwapBuffers(Display * dpy, GLXDrawable drawable) {
if (GLURAY_RENDER_MODE & GLURAY_RENDER_GLXSWAPBUFFERS)
gr_render();
next_glXSwapBuffers(dpy, drawable);
}
__GLXextFuncPtr glXGetProcAddressARB(const GLubyte* procName) {
void* hdl;
void* retval = NULL;
const char* dlerr;
dlerror();
hdl = dlopen(NULL, RTLD_NOW | RTLD_LOCAL);
if((dlerr = dlerror()) != NULL) {
fprintf(stderr, "badness opening ourself: %s\n", dlerr);
}
dlerror();
*(void**) (&retval) = dlsym(hdl, procName);
if((dlerr = dlerror()) != NULL) {
fprintf(stderr, "badness loading function %s: %s\n", procName, dlerr);
}
if(dlclose(hdl) != 0) {
fprintf(stderr, "error closing self: %s\n", dlerror());
}
return retval;
}
// MPI
#include <UseMPI.h>
#if USE_MPI
#include <mpi.h>
#endif
#if USE_MPI
int MPI_Init(int *argc, char*** argv)
{
printf("GLURAY Initializing MPI\n");
int provided=-1;
int requested=MPI_THREAD_MULTIPLE;
//int argc = 1;
//char*** argv = NULL;
int initialized;
MPI_Initialized(&initialized);
if (!initialized)
{
MPI_Init_thread(argc, argv, requested, &provided);
int rank;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
if (rank == 0 && (provided != requested))
printf("Error: MPI provided does not support MPI_THREAD_MULTIPLE\n do not run with more than one thread\n");
}
int rank;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
printf("MPI_Init rank: %d\n", rank);
}
int MPI_Finalize(void)
{
GLLOCK();
next_MPI_Finalize();
GLUNLOCK();
}
#endif