]> git.tdb.fi Git - gldbg.git/blobdiff - flavors/gl/source/glwrap_funcs.c
Use a centralized packet framework
[gldbg.git] / flavors / gl / source / glwrap_funcs.c
index 7fc5adfddf815d108ca98d15565f1970e0248725..38621f3b15d42f71e1b60322ce14db75eaff1b0c 100644 (file)
@@ -10,13 +10,14 @@ Distributed under the GPL
 #include "functions.h"
 #include "glwrap.h"
 #include "opengl.h"
+#include "packet.h"
 
-int in_begin_block = 0;
-GLenum cur_error = GL_NO_ERROR;
+static int in_begin_block = 0;
+static GLenum cur_error = GL_NO_ERROR;
 
 static void check_error()
 {
-       GLenum (*orig_glGetError)() = 0;
+       static GLenum (*orig_glGetError)() = NULL;
        GLenum code;
 
        if(in_begin_block)
@@ -28,9 +29,11 @@ static void check_error()
        code = orig_glGetError();
        if(code!=GL_NO_ERROR)
        {
-               begin_packet(FUNC_GLDERROR);
-               write_int(code);
-               send_packet();
+               GlPacket *pkt;
+
+               pkt = packet_begin(FUNC_GLDERROR);
+               packet_write_int(pkt, code);
+               packet_send(pkt, get_out_fd());
 
                if(cur_error==GL_NO_ERROR)
                        cur_error = code;
@@ -39,27 +42,31 @@ static void check_error()
 
 void APIENTRY glBegin(GLenum mode)
 {
-       static void (*orig)(GLenum);
+       static void (*orig)(GLenum) = NULL;
+       GlPacket *pkt;
+
        if(!orig)
                orig = glsym("glBegin");
        orig(mode);
 
-       begin_packet(FUNC_GLBEGIN);
-       write_int(mode);
-       send_packet();
+       pkt = packet_begin(FUNC_GLBEGIN);
+       packet_write_int(pkt, mode);
+       packet_send(pkt, get_out_fd());
 
        in_begin_block = 1;
 }
 
 void APIENTRY glEnd()
 {
-       static void (*orig)();
+       static void (*orig)() = NULL;
+       GlPacket *pkt;
+
        if(!orig)
                orig = glsym("glEnd");
        orig();
 
-       begin_packet(FUNC_GLEND);
-       send_packet();
+       pkt = packet_begin(FUNC_GLEND);
+       packet_send(pkt, get_out_fd());
 
        in_begin_block = 0;
        check_error();
@@ -68,6 +75,7 @@ void APIENTRY glEnd()
 GLenum APIENTRY glGetError()
 {
        GLenum ret = GL_NO_ERROR;
+       GlPacket *pkt;
 
        if(in_begin_block)
        {
@@ -80,9 +88,9 @@ GLenum APIENTRY glGetError()
                cur_error = GL_NO_ERROR;
        }
 
-       begin_packet(FUNC_GLGETERROR);
-       write_int(ret);
-       send_packet();
+       pkt = packet_begin(FUNC_GLGETERROR);
+       packet_write_int(pkt, ret);
+       packet_send(pkt, get_out_fd());
 
        return ret;
 }
@@ -91,6 +99,7 @@ void (*glXGetProcAddress(const GLubyte *procname))(void)
 {
        void *handle = 0;
        void (*ret)() = 0;
+       GlPacket *pkt;
 
        if(glsym((const char *)procname))
        {
@@ -98,10 +107,10 @@ void (*glXGetProcAddress(const GLubyte *procname))(void)
                ret = dlsym(handle, (const char *)procname);
        }
 
-       begin_packet(FUNC_GLXGETPROCADDRESS);
-       write_string((const char *)procname);
-       write_pointer(ret);
-       send_packet();
+       pkt = packet_begin(FUNC_GLXGETPROCADDRESS);
+       packet_write_string(pkt, (const char *)procname);
+       packet_write_pointer(pkt, ret);
+       packet_send(pkt, get_out_fd());
 
        return ret;
 }