]> git.tdb.fi Git - gldbg.git/blob - flavors/gles2/source/glwrap_funcs.c
Use a centralized packet framework
[gldbg.git] / flavors / gles2 / source / glwrap_funcs.c
1 /* $Id$
2
3 This file is part of gldbg
4 Copyright © 2010  Mikko Rasa, Mikkosoft Productions
5 Distributed under the GPL
6 */
7
8 #include <dlfcn.h>
9 #include "arraysize.h"
10 #include "functions.h"
11 #include "glwrap.h"
12 #include "opengl.h"
13 #include "packet.h"
14
15 GLenum cur_error = GL_NO_ERROR;
16
17 static void check_error()
18 {
19         GLenum (*orig_glGetError)() = NULL;
20         GLenum code;
21
22         if(!orig_glGetError)
23                 orig_glGetError = glsym("glGetError");
24
25         code = orig_glGetError();
26         if(code!=GL_NO_ERROR)
27         {
28                 GlPacket *pkt;
29
30                 pkt = packet_begin(FUNC_GLDERROR);
31                 packet_write_int(pkt, code);
32                 packet_send(pkt, get_out_fd());
33
34                 if(cur_error==GL_NO_ERROR)
35                         cur_error = code;
36         }
37 }
38
39 GLenum APIENTRY glGetError()
40 {
41         GLenum ret = cur_error;
42         cur_error = GL_NO_ERROR;
43         GlPacket *pkt;
44
45         pkt = packet_begin(FUNC_GLGETERROR);
46         packet_write_int(pkt, ret);
47         packet_send(pkt, get_out_fd());
48
49         return ret;
50 }
51
52 void (*eglGetProcAddress(const char *procname))(void)
53 {
54         void *handle = NULL;
55         void (*ret)() = NULL;
56         GlPacket *pkt;
57
58         if(glsym((const char *)procname))
59         {
60                 handle = dlopen(NULL, RTLD_LAZY);
61                 ret = dlsym(handle, (const char *)procname);
62         }
63
64         pkt = packet_begin(FUNC_EGLGETPROCADDRESS);
65         packet_write_pointer(pkt, ret);
66         packet_write_string(pkt, (const char *)procname);
67         packet_send(pkt, get_out_fd());
68
69         return ret;
70 }
71
72 #include "gensrc/glwrap.funcs"