]> git.tdb.fi Git - gldbg.git/blobdiff - source/glwrap.c
Add gldQueryViewport and gldReadPixels calls
[gldbg.git] / source / glwrap.c
index c121e22709c819eb3e9040245818e419023bd49e..970e61923a611754e555d2901c382e322513e21e 100644 (file)
@@ -1,7 +1,7 @@
 /* $Id$
 
 This file is part of gldbg
-Copyright © 2009-2010  Mikko Rasa, Mikkosoft Productions
+Copyright © 2009-2011  Mikko Rasa, Mikkosoft Productions
 Distributed under the GPL
 */
 
@@ -12,13 +12,18 @@ Distributed under the GPL
 #include <dlfcn.h>
 #include <fcntl.h>
 #include <signal.h>
+#include "arraysize.h"
 #include "breakpoint.h"
 #include "functions.h"
+#include "opengl.h"
 #include "packet.h"
 
+#define UNUSED __attribute__((unused))
+
 static unsigned char breakpoints[N_FUNCS] = { };
 static char break_any = 0;
 static char hold = 0;
+static char no_break = 0;
 
 static const char *get_lib_names(void)
 {
@@ -146,11 +151,41 @@ static void receive_gldBreak(GlPacket *pkt)
                break_any = flags_set;
 }
 
-static void receive_gldHold(GlPacket *pkt __attribute__((unused)))
+static void receive_gldHold(GlPacket *pkt UNUSED)
 {
        hold = 1;
 }
 
+static void receive_gldQueryViewport(GlPacket *pkt UNUSED)
+{
+       int viewport[4];
+
+       no_break = 1;
+       glGetIntegerv(GL_VIEWPORT, viewport);
+       no_break = 0;
+}
+
+static void receive_gldReadPixels(GlPacket *pkt)
+{
+       GLint x, y;
+       GLsizei width, height;
+       GLenum format, type;
+       char *data;
+
+       packet_read_int(pkt, &x);
+       packet_read_int(pkt, &y);
+       packet_read_int(pkt, &width);
+       packet_read_int(pkt, &height);
+       packet_read_int(pkt, (int *)&format);
+       packet_read_int(pkt, (int *)&type);
+
+       data = (char *)malloc(width*height*typesize(type)*formatsize(format));
+       no_break = 1;
+       glReadPixels(x, y, width, height, format, type, data);
+       no_break = 0;
+       free(data);
+}
+
 static void receive(void)
 {
        GlPacket *pkt;
@@ -164,6 +199,8 @@ static void receive(void)
                {
                case FUNC_GLDBREAK: receive_gldBreak(pkt); break;
                case FUNC_GLDHOLD: receive_gldHold(pkt); break;
+               case FUNC_GLDQUERYVIEWPORT: receive_gldQueryViewport(pkt); break;
+               case FUNC_GLDREADPIXELS: receive_gldReadPixels(pkt); break;
                default:;
                }
        }
@@ -173,6 +210,9 @@ void tracepoint(unsigned short func, int flag)
 {
        int breakpoint;
 
+       if(no_break)
+               return;
+
        receive();
 
        breakpoint = (breakpoints[func]|break_any)&flag;