]> git.tdb.fi Git - gldbg.git/blob - flavors/gl/source/glwrap_funcs.c
Replace per-file license notices with License.txt
[gldbg.git] / flavors / gl / source / glwrap_funcs.c
1 #include <dlfcn.h>
2 #include "arraysize.h"
3 #include "breakpoint.h"
4 #include "functions.h"
5 #include "glwrap.h"
6 #include "opengl.h"
7 #include "packet.h"
8
9 static int in_begin_block = 0;
10 static GLenum cur_error = GL_NO_ERROR;
11
12 static void check_error()
13 {
14         static GLenum (*orig_glGetError)() = NULL;
15         GLenum code;
16
17         if(in_begin_block)
18                 return;
19
20         if(!orig_glGetError)
21                 orig_glGetError = glsym("glGetError");
22
23         code = orig_glGetError();
24         if(code!=GL_NO_ERROR)
25         {
26                 GlPacket *pkt;
27
28                 pkt = packet_begin(FUNC_GLDERROR);
29                 packet_write_int(pkt, code);
30                 packet_send(pkt, get_out_fd());
31
32                 if(cur_error==GL_NO_ERROR)
33                         cur_error = code;
34         }
35 }
36
37 void APIENTRY glBegin(GLenum mode)
38 {
39         static void (*orig)(GLenum) = NULL;
40         GlPacket *pkt;
41
42         if(!orig)
43                 orig = glsym("glBegin");
44         orig(mode);
45
46         pkt = packet_begin(FUNC_GLBEGIN);
47         packet_write_int(pkt, mode);
48         packet_send(pkt, get_out_fd());
49
50         in_begin_block = 1;
51 }
52
53 void APIENTRY glEnd()
54 {
55         static void (*orig)() = NULL;
56         GlPacket *pkt;
57
58         if(!orig)
59                 orig = glsym("glEnd");
60         orig();
61
62         pkt = packet_begin(FUNC_GLEND);
63         packet_send(pkt, get_out_fd());
64
65         in_begin_block = 0;
66         check_error();
67 }
68
69 GLenum APIENTRY glGetError()
70 {
71         GLenum ret = GL_NO_ERROR;
72         GlPacket *pkt;
73
74         if(in_begin_block)
75         {
76                 if(cur_error==GL_NO_ERROR)
77                         cur_error = GL_INVALID_OPERATION;
78         }
79         else
80         {
81                 ret = cur_error;
82                 cur_error = GL_NO_ERROR;
83         }
84
85         pkt = packet_begin(FUNC_GLGETERROR);
86         packet_write_int(pkt, ret);
87         packet_send(pkt, get_out_fd());
88
89         return ret;
90 }
91
92 void (*glXGetProcAddress(const GLubyte *procname))(void)
93 {
94         void *handle = 0;
95         void (*ret)() = 0;
96         GlPacket *pkt;
97
98         if(glsym((const char *)procname))
99         {
100                 handle = dlopen(NULL, RTLD_LAZY);
101                 ret = dlsym(handle, (const char *)procname);
102         }
103
104         pkt = packet_begin(FUNC_GLXGETPROCADDRESS);
105         packet_write_string(pkt, (const char *)procname);
106         packet_write_pointer(pkt, ret);
107         packet_send(pkt, get_out_fd());
108
109         return ret;
110 }
111
112 void (*glXGetProcAddressARB(const GLubyte *))(void) __attribute__((alias("glXGetProcAddress")));
113
114 #include "gensrc/glwrap.funcs"