summaryrefslogtreecommitdiff
path: root/progs
diff options
context:
space:
mode:
Diffstat (limited to 'progs')
-rw-r--r--progs/beos/.gitignore3
-rw-r--r--progs/demos/.gitignore2
-rw-r--r--progs/directfb/.gitignore4
-rw-r--r--progs/egl/.gitignore5
-rw-r--r--progs/fbdev/.gitignore1
-rw-r--r--progs/fp/.gitignore42
-rw-r--r--progs/glsl/.gitignore10
-rw-r--r--progs/glsl/bump.c6
-rw-r--r--progs/glsl/mandelbrot.c6
-rw-r--r--progs/glsl/noise.c2
-rw-r--r--progs/glsl/toyball.c6
-rw-r--r--progs/miniglx/.gitignore6
-rw-r--r--progs/osdemos/.gitignore8
-rw-r--r--progs/samples/.gitignore32
-rw-r--r--progs/slang/.gitignore3
-rw-r--r--progs/tests/.gitignore6
-rw-r--r--progs/tools/trace/.gitignore1
-rw-r--r--progs/trivial/.gitignore65
-rw-r--r--progs/vp/.gitignore1
-rw-r--r--progs/xdemos/.gitignore4
-rw-r--r--progs/xdemos/Makefile13
-rw-r--r--progs/xdemos/corender.c396
-rw-r--r--progs/xdemos/glxsnoop.c377
-rw-r--r--progs/xdemos/ipc.c264
-rw-r--r--progs/xdemos/ipc.h16
25 files changed, 1247 insertions, 32 deletions
diff --git a/progs/beos/.gitignore b/progs/beos/.gitignore
new file mode 100644
index 0000000000..53011ca2e6
--- /dev/null
+++ b/progs/beos/.gitignore
@@ -0,0 +1,3 @@
+demo
+GLInfo
+sample
diff --git a/progs/demos/.gitignore b/progs/demos/.gitignore
index 508b8a56f4..9c5957602c 100644
--- a/progs/demos/.gitignore
+++ b/progs/demos/.gitignore
@@ -41,8 +41,8 @@ shadowtex
showbuffer.c
showbuffer.h
singlebuffer
-spriteblast
spectex
+spriteblast
stex3d
streaming_rect
teapot
diff --git a/progs/directfb/.gitignore b/progs/directfb/.gitignore
new file mode 100644
index 0000000000..55d65fb5b0
--- /dev/null
+++ b/progs/directfb/.gitignore
@@ -0,0 +1,4 @@
+df_gears
+df_morph3d
+df_reflect
+multi_window
diff --git a/progs/egl/.gitignore b/progs/egl/.gitignore
new file mode 100644
index 0000000000..1751108235
--- /dev/null
+++ b/progs/egl/.gitignore
@@ -0,0 +1,5 @@
+demo1
+demo2
+demo3
+eglgears
+eglinfo
diff --git a/progs/fbdev/.gitignore b/progs/fbdev/.gitignore
new file mode 100644
index 0000000000..b9ddf559fd
--- /dev/null
+++ b/progs/fbdev/.gitignore
@@ -0,0 +1 @@
+glfbdevtest
diff --git a/progs/fp/.gitignore b/progs/fp/.gitignore
new file mode 100644
index 0000000000..b265f1fed7
--- /dev/null
+++ b/progs/fp/.gitignore
@@ -0,0 +1,42 @@
+point-position
+readtex.c
+readtex.h
+tri-abs
+tri-add
+tri-cmp
+tri-cos
+tri-depth
+tri-depth2
+tri-depthwrite
+tri-depthwrite2
+tri-dp3
+tri-dp4
+tri-dph
+tri-dst
+tri-ex2
+tri-flr
+tri-frc
+tri-kil
+tri-lg2
+tri-lit
+tri-lrp
+tri-mad
+tri-max
+tri-min
+tri-mov
+tri-mul
+tri-param
+tri-position
+tri-pow
+tri-rcp
+tri-rsq
+tri-scs
+tri-sge
+tri-sge2
+tri-sin
+tri-slt
+tri-sub
+tri-swz
+tri-swz2
+tri-tex
+tri-xpd
diff --git a/progs/glsl/.gitignore b/progs/glsl/.gitignore
new file mode 100644
index 0000000000..622e0417a8
--- /dev/null
+++ b/progs/glsl/.gitignore
@@ -0,0 +1,10 @@
+brick
+bump
+deriv
+extfuncs.h
+mandelbrot
+noise
+readtex.c
+readtex.h
+texdemo1
+toyball
diff --git a/progs/glsl/bump.c b/progs/glsl/bump.c
index a6846acf7e..11f87ab127 100644
--- a/progs/glsl/bump.c
+++ b/progs/glsl/bump.c
@@ -247,7 +247,7 @@ LoadAndCompileShader(GLuint shader, const char *text)
GLchar log[1000];
GLsizei len;
glGetShaderInfoLog_func(shader, 1000, &len, log);
- fprintf(stderr, "brick: problem compiling shader: %s\n", log);
+ fprintf(stderr, "bump: problem compiling shader: %s\n", log);
exit(1);
}
else {
@@ -267,12 +267,12 @@ ReadShader(GLuint shader, const char *filename)
char *buffer = (char*) malloc(max);
FILE *f = fopen(filename, "r");
if (!f) {
- fprintf(stderr, "brick: Unable to open shader file %s\n", filename);
+ fprintf(stderr, "bump: Unable to open shader file %s\n", filename);
exit(1);
}
n = fread(buffer, 1, max, f);
- printf("brick: read %d bytes from shader file %s\n", n, filename);
+ printf("bump: read %d bytes from shader file %s\n", n, filename);
if (n > 0) {
buffer[n] = 0;
LoadAndCompileShader(shader, buffer);
diff --git a/progs/glsl/mandelbrot.c b/progs/glsl/mandelbrot.c
index 7a2bad6dde..e7b2b04b0d 100644
--- a/progs/glsl/mandelbrot.c
+++ b/progs/glsl/mandelbrot.c
@@ -172,7 +172,7 @@ LoadAndCompileShader(GLuint shader, const char *text)
GLchar log[1000];
GLsizei len;
glGetShaderInfoLog_func(shader, 1000, &len, log);
- fprintf(stderr, "brick: problem compiling shader: %s\n", log);
+ fprintf(stderr, "mandelbrot: problem compiling shader: %s\n", log);
exit(1);
}
else {
@@ -192,12 +192,12 @@ ReadShader(GLuint shader, const char *filename)
char *buffer = (char*) malloc(max);
FILE *f = fopen(filename, "r");
if (!f) {
- fprintf(stderr, "brick: Unable to open shader file %s\n", filename);
+ fprintf(stderr, "mandelbrot: Unable to open shader file %s\n", filename);
exit(1);
}
n = fread(buffer, 1, max, f);
- printf("brick: read %d bytes from shader file %s\n", n, filename);
+ printf("mandelbrot: read %d bytes from shader file %s\n", n, filename);
if (n > 0) {
buffer[n] = 0;
LoadAndCompileShader(shader, buffer);
diff --git a/progs/glsl/noise.c b/progs/glsl/noise.c
index a26a805944..adccd1a7c8 100644
--- a/progs/glsl/noise.c
+++ b/progs/glsl/noise.c
@@ -188,7 +188,7 @@ LoadAndCompileShader(GLuint shader, const char *text)
GLchar log[1000];
GLsizei len;
glGetShaderInfoLog_func(shader, 1000, &len, log);
- fprintf(stderr, "brick: problem compiling shader: %s\n", log);
+ fprintf(stderr, "noise: problem compiling shader: %s\n", log);
exit(1);
}
else {
diff --git a/progs/glsl/toyball.c b/progs/glsl/toyball.c
index cef52c04a6..3aa096161a 100644
--- a/progs/glsl/toyball.c
+++ b/progs/glsl/toyball.c
@@ -185,7 +185,7 @@ LoadAndCompileShader(GLuint shader, const char *text)
GLchar log[1000];
GLsizei len;
glGetShaderInfoLog_func(shader, 1000, &len, log);
- fprintf(stderr, "brick: problem compiling shader: %s\n", log);
+ fprintf(stderr, "toyball: problem compiling shader: %s\n", log);
exit(1);
}
else {
@@ -205,12 +205,12 @@ ReadShader(GLuint shader, const char *filename)
char *buffer = (char*) malloc(max);
FILE *f = fopen(filename, "r");
if (!f) {
- fprintf(stderr, "brick: Unable to open shader file %s\n", filename);
+ fprintf(stderr, "toyball: Unable to open shader file %s\n", filename);
exit(1);
}
n = fread(buffer, 1, max, f);
- printf("brick: read %d bytes from shader file %s\n", n, filename);
+ printf("toyball: read %d bytes from shader file %s\n", n, filename);
if (n > 0) {
buffer[n] = 0;
LoadAndCompileShader(shader, buffer);
diff --git a/progs/miniglx/.gitignore b/progs/miniglx/.gitignore
new file mode 100644
index 0000000000..f630f591f6
--- /dev/null
+++ b/progs/miniglx/.gitignore
@@ -0,0 +1,6 @@
+manytex
+miniglxsample
+miniglxtest
+sample_server
+sample_server2
+texline
diff --git a/progs/osdemos/.gitignore b/progs/osdemos/.gitignore
new file mode 100644
index 0000000000..5c78f12481
--- /dev/null
+++ b/progs/osdemos/.gitignore
@@ -0,0 +1,8 @@
+osdemo
+osdemo16
+osdemo32
+ostest1
+readtex.c
+readtex.h
+showbuffer.c
+showbuffer.h
diff --git a/progs/samples/.gitignore b/progs/samples/.gitignore
index 12b0650567..f60d6e94ea 100644
--- a/progs/samples/.gitignore
+++ b/progs/samples/.gitignore
@@ -1,24 +1,41 @@
.cvsignore
accum
+anywin
+bdemo
+binfo
bitmap1
bitmap2
blendeq
blendxor
+bugger
copy
cursor
+demo
depth
eval
+ffset
fog
font
+font
+incopy
line
logo
+lthreads
+lxdemo
+lxgears
+lxheads
+lxinfo
+lxpixmap
nurb
oglinfo
olympic
overlay
+pend
point
prim
quad
+readtex.c
+readtex.h
select
shape
sphere
@@ -28,18 +45,3 @@ stretch
texture
tri
wave
-bugger
-pend
-lthreads
-lxdemo
-lxgears
-lxheads
-lxinfo
-lxpixmap
-anywin
-ffset
-bdemo
-binfo
-incopy
-demo
-font
diff --git a/progs/slang/.gitignore b/progs/slang/.gitignore
new file mode 100644
index 0000000000..8a42b018e6
--- /dev/null
+++ b/progs/slang/.gitignore
@@ -0,0 +1,3 @@
+cltest
+sotest
+vstest
diff --git a/progs/tests/.gitignore b/progs/tests/.gitignore
index cb3e09d5d5..eaa67c3a5d 100644
--- a/progs/tests/.gitignore
+++ b/progs/tests/.gitignore
@@ -1,5 +1,4 @@
.cvsignore
-getproclist.h
afsmultiarb
antialias
arbfpspec
@@ -34,17 +33,18 @@ fogcoord
fptest1
fptexture
getprocaddress
-jkrahntest
+getproclist.h
interleave
invert
+jkrahntest
manytex
mipmap_limits
multipal
no_s3tc
packedpixels
pbo
-projtex
prog_parameter
+projtex
random
readrate
readtex.c
diff --git a/progs/tools/trace/.gitignore b/progs/tools/trace/.gitignore
new file mode 100644
index 0000000000..afe0c5829e
--- /dev/null
+++ b/progs/tools/trace/.gitignore
@@ -0,0 +1 @@
+gltrace.cc
diff --git a/progs/trivial/.gitignore b/progs/trivial/.gitignore
new file mode 100644
index 0000000000..1c49fdd55f
--- /dev/null
+++ b/progs/trivial/.gitignore
@@ -0,0 +1,65 @@
+clear
+dlist-dangling
+dlist-edgeflag
+dlist-edgeflag-dangling
+drawarrays
+drawelements
+drawrange
+line
+line-clip
+line-cull
+line-userclip
+line-userclip-clip
+line-userclip-nop
+line-userclip-nop-clip
+lineloop
+lineloop-clip
+point
+point-clip
+point-param
+point-wide
+poly
+poly-flat
+poly-unfilled
+quad
+quad-clip
+quad-clip-all-vertices
+quad-clip-nearplane
+quad-degenerate
+quad-flat
+quad-offset-factor
+quad-offset-unfilled
+quad-offset-units
+quad-tex-2d
+quad-tex-3d
+quad-tex-pbo
+quad-unfilled
+quads
+quadstrip
+quadstrip-flat
+readtex.c
+readtex.h
+tri
+tri-blend
+tri-clip
+tri-cull
+tri-dlist
+tri-edgeflag
+tri-flat
+tri-flat-clip
+tri-tex-3d
+tri-unfilled
+tri-unfilled-clip
+tri-unfilled-smooth
+tri-unfilled-userclip
+tri-userclip
+tristrip
+tristrip-clip
+vbo-drawarrays
+vbo-drawelements
+vbo-drawrange
+vp-array
+vp-clip
+vp-line-clip
+vp-tri
+vp-unfilled
diff --git a/progs/vp/.gitignore b/progs/vp/.gitignore
new file mode 100644
index 0000000000..a5ff993525
--- /dev/null
+++ b/progs/vp/.gitignore
@@ -0,0 +1 @@
+vp-tris
diff --git a/progs/xdemos/.gitignore b/progs/xdemos/.gitignore
index f959ef26ec..250bc17d98 100644
--- a/progs/xdemos/.gitignore
+++ b/progs/xdemos/.gitignore
@@ -5,14 +5,14 @@ glxgears
glxgears_fbconfig
glxheads
glxinfo
-glxpixmap
glxpbdemo
+glxpixmap
glxswapcontrol
manywin
offset
overlay
-pbinfo
pbdemo
+pbinfo
texture_from_pixmap
wincopy
xdemo
diff --git a/progs/xdemos/Makefile b/progs/xdemos/Makefile
index c585026ad3..a7ba9afcac 100644
--- a/progs/xdemos/Makefile
+++ b/progs/xdemos/Makefile
@@ -8,7 +8,9 @@ INCDIR = $(TOP)/include
LIB_DEP = $(TOP)/$(LIB_DIR)/$(GL_LIB_NAME) $(TOP)/$(LIB_DIR)/$(GLU_LIB_NAME)
-PROGS = glthreads \
+PROGS = \
+ corender \
+ glthreads \
glxdemo \
glxgears \
glxgears_fbconfig \
@@ -17,6 +19,7 @@ PROGS = glthreads \
glxinfo \
glxpixmap \
glxpbdemo \
+ glxsnoop \
glxswapcontrol \
manywin \
offset \
@@ -82,3 +85,11 @@ xuserotfont.o: xuserotfont.c xuserotfont.h
xrotfontdemo.o: xrotfontdemo.c xuserotfont.h
$(CC) -c -I. -I$(INCDIR) $(X11_INCLUDES) $(CFLAGS) xrotfontdemo.c
+corender: corender.o ipc.o
+ $(CC) $(CFLAGS) corender.o ipc.o $(APP_LIB_DEPS) -o $@
+
+corender.o: corender.c ipc.h
+ $(CC) -c -I. -I$(INCDIR) $(X11_INCLUDES) $(CFLAGS) corender.c
+
+ipc.o: ipc.c ipc.h
+ $(CC) -c -I. -I$(INCDIR) $(X11_INCLUDES) $(CFLAGS) ipc.c \ No newline at end of file
diff --git a/progs/xdemos/corender.c b/progs/xdemos/corender.c
new file mode 100644
index 0000000000..02e4ac0216
--- /dev/null
+++ b/progs/xdemos/corender.c
@@ -0,0 +1,396 @@
+/**
+ * Example of cooperative rendering into one window by two processes.
+ * The first instance of the program creates the GLX window.
+ * The second instance of the program gets the window ID from the first
+ * and draws into it.
+ * Socket IPC is used for synchronization.
+ *
+ * Usage:
+ * 1. run 'corender &'
+ * 2. run 'corender 2' (any arg will do)
+ *
+ * Brian Paul
+ * 11 Oct 2007
+ */
+
+
+#include <GL/gl.h>
+#include <GL/glx.h>
+#include <assert.h>
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <X11/keysym.h>
+#include <unistd.h>
+#include "ipc.h"
+
+
+static int MyID = 0; /* 0 or 1 */
+static int WindowID = 0;
+static GLXContext Context = 0;
+static int Width = 700, Height = 350;
+static int Rot = 0;
+static int Sock = 0;
+
+static GLfloat Red[4] = {1.0, 0.2, 0.2, 1.0};
+static GLfloat Blue[4] = {0.2, 0.2, 1.0, 1.0};
+
+static int Sync = 1; /** synchronized rendering? */
+
+
+static void
+setup_ipc(void)
+{
+ int k, port = 10001;
+
+ if (MyID == 0) {
+ /* I'm the first one, wait for connection from second */
+ k = CreatePort(&port);
+ assert(k != -1);
+
+ printf("Waiting for connection from another 'corender'\n");
+ Sock = AcceptConnection(k);
+
+ printf("Got connection, sending windowID\n");
+
+ /* send windowID */
+ SendData(Sock, &WindowID, sizeof(WindowID));
+ }
+ else {
+ /* I'm the second one, connect to first */
+ char hostname[1000];
+
+ MyHostName(hostname, 1000);
+ Sock = Connect(hostname, port);
+ assert(Sock != -1);
+
+ /* get windowID */
+ ReceiveData(Sock, &WindowID, sizeof(WindowID));
+ printf("Contacted first 'corender', getting WindowID\n");
+ }
+}
+
+
+
+/** from GLUT */
+static void
+doughnut(GLfloat r, GLfloat R, GLint nsides, GLint rings)
+{
+ int i, j;
+ GLfloat theta, phi, theta1;
+ GLfloat cosTheta, sinTheta;
+ GLfloat cosTheta1, sinTheta1;
+ GLfloat ringDelta, sideDelta;
+
+ ringDelta = 2.0 * M_PI / rings;
+ sideDelta = 2.0 * M_PI / nsides;
+
+ theta = 0.0;
+ cosTheta = 1.0;
+ sinTheta = 0.0;
+ for (i = rings - 1; i >= 0; i--) {
+ theta1 = theta + ringDelta;
+ cosTheta1 = cos(theta1);
+ sinTheta1 = sin(theta1);
+ glBegin(GL_QUAD_STRIP);
+ phi = 0.0;
+ for (j = nsides; j >= 0; j--) {
+ GLfloat cosPhi, sinPhi, dist;
+
+ phi += sideDelta;
+ cosPhi = cos(phi);
+ sinPhi = sin(phi);
+ dist = R + r * cosPhi;
+
+ glNormal3f(cosTheta1 * cosPhi, -sinTheta1 * cosPhi, sinPhi);
+ glVertex3f(cosTheta1 * dist, -sinTheta1 * dist, r * sinPhi);
+ glNormal3f(cosTheta * cosPhi, -sinTheta * cosPhi, sinPhi);
+ glVertex3f(cosTheta * dist, -sinTheta * dist, r * sinPhi);
+ }
+ glEnd();
+ theta = theta1;
+ cosTheta = cosTheta1;
+ sinTheta = sinTheta1;
+ }
+}
+
+
+static void
+redraw(Display *dpy)
+{
+ int dbg = 0;
+
+ glXMakeCurrent(dpy, WindowID, Context);
+ glEnable(GL_LIGHTING);
+ glEnable(GL_LIGHT0);
+ glEnable(GL_DEPTH_TEST);
+ glClearColor(0.5, 0.5, 0.5, 0.0);
+
+ if (MyID == 0) {
+ /* First process */
+
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ glPushMatrix();
+ glTranslatef(-1, 0, 0);
+ glRotatef(Rot, 1, 0, 0);
+ glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, Red);
+ doughnut(0.5, 2.0, 20, 30);
+ glPopMatrix();
+
+ glFinish();
+ if (!Sync) {
+ usleep(1000*10);
+ }
+
+ /* signal second process to render */
+ if (Sync) {
+ int code = 1;
+ if (dbg) printf("0: send signal\n");
+ SendData(Sock, &code, sizeof(code));
+ SendData(Sock, &Rot, sizeof(Rot));
+ }
+
+ /* wait for second process to finish rendering */
+ if (Sync) {
+ int code = 0;
+ if (dbg) printf("0: wait signal\n");
+ ReceiveData(Sock, &code, sizeof(code));
+ if (dbg) printf("0: got signal\n");
+ assert(code == 2);
+ }
+
+ }
+ else {
+ /* Second process */
+
+ /* wait for first process's signal for me to render */
+ if (Sync) {
+ int code = 0;
+ if (dbg) printf("1: wait signal\n");
+ ReceiveData(Sock, &code, sizeof(code));
+ ReceiveData(Sock, &Rot, sizeof(Rot));
+
+ if (dbg) printf("1: got signal\n");
+ assert(code == 1);
+ }
+
+ /* XXX this clear should not be here, but for some reason, it
+ * makes things _mostly_ work correctly w/ NVIDIA's driver.
+ * There's only occasional glitches.
+ * Without this glClear(), depth buffer for the second process
+ * is pretty much broken.
+ */
+ //glClear(GL_DEPTH_BUFFER_BIT);
+
+ glPushMatrix();
+ glTranslatef(1, 0, 0);
+ glRotatef(Rot + 90 , 1, 0, 0);
+ glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, Blue);
+ doughnut(0.5, 2.0, 20, 30);
+ glPopMatrix();
+ glFinish();
+
+ glXSwapBuffers(dpy, WindowID);
+ usleep(1000*10);
+
+ /* signal first process that I'm done rendering */
+ if (Sync) {
+ int code = 2;
+ if (dbg) printf("1: send signal\n");
+ SendData(Sock, &code, sizeof(code));
+ }
+ }
+}
+
+
+static void
+resize(Display *dpy, int width, int height)
+{
+ float ar = (float) width / height;
+
+ glXMakeCurrent(dpy, WindowID, Context);
+
+ glViewport(0, 0, width, height);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glFrustum(-ar, ar, 1.0, -1.0, 5.0, 200.0);
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ glTranslatef(0, 0, -15);
+
+ Width = width;
+ Height = height;
+}
+
+
+
+static void
+set_window_title(Display *dpy, Window win, const char *title)
+{
+ XSizeHints sizehints;
+ sizehints.flags = 0;
+ XSetStandardProperties(dpy, win, title, title,
+ None, (char **)NULL, 0, &sizehints);
+}
+
+
+static Window
+make_gl_window(Display *dpy, XVisualInfo *visinfo, int width, int height)
+{
+ int scrnum;
+ XSetWindowAttributes attr;
+ unsigned long mask;
+ Window root;
+ Window win;
+ int x = 0, y = 0;
+ char *name = NULL;
+
+ scrnum = DefaultScreen( dpy );
+ root = RootWindow( dpy, scrnum );
+
+ /* window attributes */
+ attr.background_pixel = 0;
+ attr.border_pixel = 0;
+ attr.colormap = XCreateColormap( dpy, root, visinfo->visual, AllocNone);
+ attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
+ mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
+
+ win = XCreateWindow( dpy, root, x, y, width, height,
+ 0, visinfo->depth, InputOutput,
+ visinfo->visual, mask, &attr );
+
+ /* set hints and properties */
+ {
+ XSizeHints sizehints;
+ sizehints.x = x;
+ sizehints.y = y;
+ sizehints.width = width;
+ sizehints.height = height;
+ sizehints.flags = USSize | USPosition;
+ XSetNormalHints(dpy, win, &sizehints);
+ XSetStandardProperties(dpy, win, name, name,
+ None, (char **)NULL, 0, &sizehints);
+ }
+
+ return win;
+}
+
+
+static void
+set_event_mask(Display *dpy, Window win)
+{
+ XSetWindowAttributes attr;
+ attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
+ XChangeWindowAttributes(dpy, win, CWEventMask, &attr);
+}
+
+
+static void
+event_loop(Display *dpy)
+{
+ while (1) {
+ while (XPending(dpy) > 0) {
+ XEvent event;
+ XNextEvent(dpy, &event);
+
+ switch (event.type) {
+ case Expose:
+ redraw(dpy);
+ break;
+ case ConfigureNotify:
+ resize(dpy, event.xconfigure.width, event.xconfigure.height);
+ break;
+ case KeyPress:
+ {
+ char buffer[10];
+ int r, code;
+ code = XLookupKeysym(&event.xkey, 0);
+ if (code == XK_Left) {
+ }
+ else {
+ r = XLookupString(&event.xkey, buffer, sizeof(buffer),
+ NULL, NULL);
+ if (buffer[0] == 27) {
+ exit(0);
+ }
+ }
+ }
+ default:
+ /* nothing */
+ ;
+ }
+ }
+
+ if (MyID == 0 || !Sync)
+ Rot += 1;
+ redraw(dpy);
+ }
+}
+
+
+static XVisualInfo *
+choose_visual(Display *dpy)
+{
+ int attribs[] = { GLX_RGBA,
+ GLX_RED_SIZE, 1,
+ GLX_GREEN_SIZE, 1,
+ GLX_BLUE_SIZE, 1,
+ GLX_DOUBLEBUFFER,
+ GLX_DEPTH_SIZE, 1,
+ None };
+ int scrnum = DefaultScreen( dpy );
+ return glXChooseVisual(dpy, scrnum, attribs);
+}
+
+
+static void
+parse_opts(int argc, char *argv[])
+{
+ if (argc > 1) {
+ MyID = 1;
+ }
+}
+
+
+int
+main( int argc, char *argv[] )
+{
+ Display *dpy;
+ XVisualInfo *visinfo;
+
+ parse_opts(argc, argv);
+
+ dpy = XOpenDisplay(NULL);
+
+ visinfo = choose_visual(dpy);
+
+ Context = glXCreateContext( dpy, visinfo, NULL, True );
+ if (!Context) {
+ printf("Error: glXCreateContext failed\n");
+ exit(1);
+ }
+
+ if (MyID == 0) {
+ WindowID = make_gl_window(dpy, visinfo, Width, Height);
+ set_window_title(dpy, WindowID, "corender");
+ XMapWindow(dpy, WindowID);
+ /*printf("WindowID 0x%x\n", (int) WindowID);*/
+ }
+
+ /* do ipc hand-shake here */
+ setup_ipc();
+ assert(Sock);
+ assert(WindowID);
+
+ if (MyID == 1) {
+ set_event_mask(dpy, WindowID);
+ }
+
+ resize(dpy, Width, Height);
+
+ event_loop(dpy);
+
+ return 0;
+}
diff --git a/progs/xdemos/glxsnoop.c b/progs/xdemos/glxsnoop.c
new file mode 100644
index 0000000000..2e951345b5
--- /dev/null
+++ b/progs/xdemos/glxsnoop.c
@@ -0,0 +1,377 @@
+/**
+ * Display/snoop the z/stencil/back/front buffers of another app's window.
+ * Also, an example of the need for shared ancillary renderbuffers.
+ *
+ * Hint: use 'xwininfo' to get a window's ID.
+ *
+ * Brian Paul
+ * 11 Oct 2007
+ */
+
+#define GL_GLEXT_PROTOTYPES
+
+#include <GL/gl.h>
+#include <GL/glx.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <X11/keysym.h>
+
+
+#define Z_BUFFER 1
+#define STENCIL_BUFFER 2
+#define BACK_BUFFER 3
+#define FRONT_BUFFER 4
+
+
+static int Buffer = BACK_BUFFER;
+static int WindowID = 0;
+static const char *DisplayName = NULL;
+static GLXContext Context = 0;
+static int Width, Height;
+
+
+/**
+ * Grab the z/stencil/back/front image from the srcWin and display it
+ * (possibly converted to grayscale) in the dstWin.
+ */
+static void
+redraw(Display *dpy, Window srcWin, Window dstWin )
+{
+ GLubyte *image = malloc(Width * Height * 4);
+
+ glXMakeCurrent(dpy, srcWin, Context);
+ glPixelStorei(GL_PACK_ALIGNMENT, 1);
+ if (Buffer == BACK_BUFFER) {
+ glReadBuffer(GL_BACK);
+ glReadPixels(0, 0, Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, image);
+ }
+ else if (Buffer == FRONT_BUFFER) {
+ glReadBuffer(GL_FRONT);
+ glReadPixels(0, 0, Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, image);
+ }
+ else if (Buffer == Z_BUFFER) {
+ GLfloat *z = malloc(Width * Height * sizeof(GLfloat));
+ int i;
+ glReadPixels(0, 0, Width, Height, GL_DEPTH_COMPONENT, GL_FLOAT, z);
+ for (i = 0; i < Width * Height; i++) {
+ image[i*4+0] =
+ image[i*4+1] =
+ image[i*4+2] = (GLint) (255.0 * z[i]);
+ image[i*4+3] = 255;
+ }
+ free(z);
+ }
+ else if (Buffer == STENCIL_BUFFER) {
+ GLubyte *sten = malloc(Width * Height * sizeof(GLubyte));
+ int i, min = 100, max = -1;
+ float step;
+ int sz;
+ glGetIntegerv(GL_STENCIL_BITS, &sz);
+ glReadPixels(0, 0, Width, Height,
+ GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, sten);
+ /* find min/max for converting stencil to grayscale */
+ for (i = 0; i < Width * Height; i++) {
+ if (sten[i] < min)
+ min = sten[i];
+ if (sten[i] > max)
+ max = sten[i];
+ }
+ if (min == max)
+ step = 0;
+ else
+ step = 255.0 / (float) (max - min);
+ for (i = 0; i < Width * Height; i++) {
+ image[i*4+0] =
+ image[i*4+1] =
+ image[i*4+2] = (GLint) ((sten[i] - min) * step);
+ image[i*4+3] = 255;
+ }
+ free(sten);
+ }
+
+ glXMakeCurrent(dpy, dstWin, Context);
+ glWindowPos2iARB(0, 0);
+ glDrawBuffer(GL_FRONT);
+ glDrawPixels(Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, image);
+ glFlush();
+
+ free(image);
+}
+
+
+static void
+set_window_title(Display *dpy, Window win, const char *title)
+{
+ XSizeHints sizehints;
+ sizehints.flags = 0;
+ XSetStandardProperties(dpy, win, title, title,
+ None, (char **)NULL, 0, &sizehints);
+}
+
+
+static Window
+make_gl_window(Display *dpy, XVisualInfo *visinfo, int width, int height)
+{
+ int scrnum;
+ XSetWindowAttributes attr;
+ unsigned long mask;
+ Window root;
+ Window win;
+ int x = 0, y = 0;
+ char *name = NULL;
+
+ scrnum = DefaultScreen( dpy );
+ root = RootWindow( dpy, scrnum );
+
+ /* window attributes */
+ attr.background_pixel = 0;
+ attr.border_pixel = 0;
+ attr.colormap = XCreateColormap( dpy, root, visinfo->visual, AllocNone);
+ attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
+ mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
+
+ win = XCreateWindow( dpy, root, x, y, width, height,
+ 0, visinfo->depth, InputOutput,
+ visinfo->visual, mask, &attr );
+
+ /* set hints and properties */
+ {
+ XSizeHints sizehints;
+ sizehints.x = x;
+ sizehints.y = y;
+ sizehints.width = width;
+ sizehints.height = height;
+ sizehints.flags = USSize | USPosition;
+ XSetNormalHints(dpy, win, &sizehints);
+ XSetStandardProperties(dpy, win, name, name,
+ None, (char **)NULL, 0, &sizehints);
+ }
+
+ return win;
+}
+
+
+static void
+update_window_title(Display *dpy, Window win)
+{
+ char title[1000], *buf;
+
+ switch (Buffer) {
+ case Z_BUFFER:
+ buf = "Z";
+ break;
+ case STENCIL_BUFFER:
+ buf = "Stencil";
+ break;
+ case BACK_BUFFER:
+ buf = "Back";
+ break;
+ case FRONT_BUFFER:
+ buf = "Front";
+ break;
+ default:
+ buf = "";
+ }
+
+ sprintf(title, "glxsnoop window 0x%x (%s buffer)", (int) WindowID, buf);
+
+ set_window_title(dpy, win, title);
+}
+
+
+static void
+keypress(Display *dpy, Window win, char key)
+{
+ switch (key) {
+ case 27:
+ /* escape */
+ exit(0);
+ break;
+ case 's':
+ Buffer = STENCIL_BUFFER;
+ break;
+ case 'z':
+ Buffer = Z_BUFFER;
+ break;
+ case 'f':
+ Buffer = FRONT_BUFFER;
+ break;
+ case 'b':
+ Buffer = BACK_BUFFER;
+ break;
+ default:
+ return;
+ }
+
+ update_window_title(dpy, win);
+ redraw(dpy, WindowID, win);
+}
+
+
+static void
+event_loop(Display *dpy, Window win)
+{
+ XEvent event;
+
+ while (1) {
+ XNextEvent( dpy, &event );
+
+ switch (event.type) {
+ case Expose:
+ redraw(dpy, WindowID, win);
+ break;
+ case ConfigureNotify:
+ /*resize( event.xconfigure.width, event.xconfigure.height );*/
+ break;
+ case KeyPress:
+ {
+ char buffer[10];
+ int r, code;
+ code = XLookupKeysym(&event.xkey, 0);
+ if (code == XK_Left) {
+ }
+ else {
+ r = XLookupString(&event.xkey, buffer, sizeof(buffer),
+ NULL, NULL);
+ keypress(dpy, win, buffer[0]);
+ }
+ }
+ default:
+ /* nothing */
+ ;
+ }
+ }
+}
+
+
+static VisualID
+get_window_visualid(Display *dpy, Window win)
+{
+ XWindowAttributes attr;
+
+ if (XGetWindowAttributes(dpy, win, &attr)) {
+ return attr.visual->visualid;
+ }
+ else {
+ return 0;
+ }
+}
+
+
+static void
+get_window_size(Display *dpy, Window win, int *w, int *h)
+{
+ XWindowAttributes attr;
+
+ if (XGetWindowAttributes(dpy, win, &attr)) {
+ *w = attr.width;
+ *h = attr.height;
+ }
+ else {
+ *w = *h = 0;
+ }
+}
+
+
+static XVisualInfo *
+visualid_to_visualinfo(Display *dpy, VisualID vid)
+{
+ XVisualInfo *vinfo, templ;
+ long mask;
+ int n;
+
+ templ.visualid = vid;
+ mask = VisualIDMask;
+
+ vinfo = XGetVisualInfo(dpy, mask, &templ, &n);
+ return vinfo;
+}
+
+
+static void
+key_usage(void)
+{
+ printf("Keyboard:\n");
+ printf(" z - display Z buffer\n");
+ printf(" s - display stencil buffer\n");
+ printf(" f - display front color buffer\n");
+ printf(" b - display back buffer\n");
+}
+
+
+static void
+usage(void)
+{
+ printf("Usage: glxsnoop [-display dpy] windowID\n");
+ key_usage();
+}
+
+
+static void
+parse_opts(int argc, char *argv[])
+{
+ int i;
+
+ for (i = 1; i < argc; i++) {
+ if (strcmp(argv[i], "-h") == 0) {
+ usage();
+ exit(0);
+ }
+ else if (strcmp(argv[i], "-display") == 0) {
+ DisplayName = argv[i + 1];
+ i++;
+ }
+ else {
+ if (argv[i][0] == '0' && argv[i][1] == 'x') {
+ /* hex */
+ WindowID = strtol(argv[i], NULL, 16);
+ }
+ else {
+ WindowID = atoi(argv[i]);
+ }
+ break;
+ }
+ }
+
+ if (!WindowID) {
+ usage();
+ exit(0);
+ }
+}
+
+
+int
+main( int argc, char *argv[] )
+{
+ Display *dpy;
+ VisualID vid;
+ XVisualInfo *visinfo;
+ Window win;
+
+ parse_opts(argc, argv);
+
+ key_usage();
+
+ dpy = XOpenDisplay(DisplayName);
+
+ /* find the VisualID for the named window */
+ vid = get_window_visualid(dpy, WindowID);
+ get_window_size(dpy, WindowID, &Width, &Height);
+
+ visinfo = visualid_to_visualinfo(dpy, vid);
+
+ Context = glXCreateContext( dpy, visinfo, NULL, True );
+ if (!Context) {
+ printf("Error: glXCreateContext failed\n");
+ exit(1);
+ }
+
+ win = make_gl_window(dpy, visinfo, Width, Height);
+ XMapWindow(dpy, win);
+ update_window_title(dpy, win);
+
+ event_loop( dpy, win );
+
+ return 0;
+}
diff --git a/progs/xdemos/ipc.c b/progs/xdemos/ipc.c
new file mode 100644
index 0000000000..fa52b09076
--- /dev/null
+++ b/progs/xdemos/ipc.c
@@ -0,0 +1,264 @@
+/* Copyright (c) 2003 Tungsten Graphics, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files ("the
+ * Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions: The above copyright notice, the Tungsten
+ * Graphics splash screen, and this permission notice shall be included
+ * in all copies or substantial portions of the Software. THE SOFTWARE
+ * IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
+ * SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*
+ * Simple IPC API
+ * Brian Paul
+ */
+
+
+#include <assert.h>
+#include <stdio.h>
+#include <string.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include "ipc.h"
+
+#if defined(IRIX) || defined(irix)
+typedef int socklen_t;
+#endif
+
+#define NO_DELAY 1
+
+#define DEFAULT_MASTER_PORT 7011
+
+
+/*
+ * Return my hostname in <nameOut>.
+ * Return 1 for success, 0 for error.
+ */
+int
+MyHostName(char *nameOut, int maxNameLength)
+{
+ int k = gethostname(nameOut, maxNameLength);
+ return k==0;
+}
+
+
+/*
+ * Create a socket attached to a port. Later, we can call AcceptConnection
+ * on the socket returned from this function.
+ * Return the new socket number or -1 if error.
+ */
+int
+CreatePort(int *port)
+{
+ char hostname[1000];
+ struct sockaddr_in servaddr;
+ struct hostent *hp;
+ int so_reuseaddr = 1;
+ int tcp_nodelay = 1;
+ int sock, k;
+
+ /* create socket */
+ sock = socket(AF_INET, SOCK_STREAM, 0);
+ assert(sock > 2);
+
+ /* get my host name */
+ k = gethostname(hostname, 1000);
+ assert(k == 0);
+
+ /* get hostent info */
+ hp = gethostbyname(hostname);
+ assert(hp);
+
+ /* initialize the servaddr struct */
+ memset(&servaddr, 0, sizeof(servaddr) );
+ servaddr.sin_family = AF_INET;
+ servaddr.sin_port = htons((unsigned short) (*port));
+ memcpy((char *) &servaddr.sin_addr, hp->h_addr,
+ sizeof(servaddr.sin_addr));
+
+ /* deallocate when we exit */
+ k = setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
+ (char *) &so_reuseaddr, sizeof(so_reuseaddr));
+ assert(k==0);
+
+ /* send packets immediately */
+#if NO_DELAY
+ k = setsockopt(sock, IPPROTO_TCP, TCP_NODELAY,
+ (char *) &tcp_nodelay, sizeof(tcp_nodelay));
+ assert(k==0);
+#endif
+
+ if (*port == 0)
+ *port = DEFAULT_MASTER_PORT;
+
+ k = 1;
+ while (k && (*port < 65534)) {
+ /* bind our address to the socket */
+ servaddr.sin_port = htons((unsigned short) (*port));
+ k = bind(sock, (struct sockaddr *) &servaddr, sizeof(servaddr));
+ if (k)
+ *port = *port + 1;
+ }
+
+#if 0
+ printf("###### Real Port: %d\n", *port);
+#endif
+
+ /* listen for connections */
+ k = listen(sock, 100);
+ assert(k == 0);
+
+ return sock;
+}
+
+
+/*
+ * Accept a connection on the named socket.
+ * Return a new socket for the new connection, or -1 if error.
+ */
+int
+AcceptConnection(int socket)
+{
+ struct sockaddr addr;
+ socklen_t addrLen;
+ int newSock;
+
+ addrLen = sizeof(addr);
+ newSock = accept(socket, &addr, &addrLen);
+ if (newSock == 1)
+ return -1;
+ else
+ return newSock;
+}
+
+
+/*
+ * Contact the server running on the given host on the named port.
+ * Return socket number or -1 if error.
+ */
+int
+Connect(const char *hostname, int port)
+{
+ struct sockaddr_in servaddr;
+ struct hostent *hp;
+ int sock, k;
+ int tcp_nodelay = 1;
+
+ assert(port);
+
+ sock = socket(AF_INET, SOCK_STREAM, 0);
+ assert(sock >= 0);
+
+ hp = gethostbyname(hostname);
+ assert(hp);
+
+ memset(&servaddr, 0, sizeof(servaddr));
+ servaddr.sin_family = AF_INET;
+ servaddr.sin_port = htons((unsigned short) port);
+ memcpy((char *) &servaddr.sin_addr, hp->h_addr, sizeof(servaddr.sin_addr));
+
+ k = connect(sock, (struct sockaddr *) &servaddr, sizeof(servaddr));
+ if (k != 0) {
+ perror("Connect:");
+ return -1;
+ }
+
+#if NO_DELAY
+ /* send packets immediately */
+ k = setsockopt(sock, IPPROTO_TCP, TCP_NODELAY,
+ (char *) &tcp_nodelay, sizeof(tcp_nodelay));
+ assert(k==0);
+#endif
+
+ return sock;
+}
+
+
+void
+CloseSocket(int socket)
+{
+ close(socket);
+}
+
+
+int
+SendData(int socket, const void *data, int bytes)
+{
+ int sent = 0;
+ int b;
+
+ while (sent < bytes) {
+ b = write(socket, (char *) data + sent, bytes - sent);
+ if (b <= 0)
+ return -1; /* something broke */
+ sent += b;
+ }
+ return sent;
+}
+
+
+int
+ReceiveData(int socket, void *data, int bytes)
+{
+ int received = 0, b;
+
+ while (received < bytes) {
+ b = read(socket, (char *) data + received, bytes - received);
+ if (b <= 0)
+ return -1;
+ received += b;
+ }
+ return received;
+}
+
+
+int
+SendString(int socket, const char *str)
+{
+ const int len = strlen(str);
+ int sent, b;
+
+ /* first, send a 4-byte length indicator */
+ b = write(socket, &len, sizeof(len));
+ if (b <= 0)
+ return -1;
+
+ sent = SendData(socket, str, len);
+ assert(sent == len);
+ return sent;
+}
+
+
+int
+ReceiveString(int socket, char *str, int maxLen)
+{
+ int len, received, b;
+
+ /* first, read 4 bytes to see how long of string to receive */
+ b = read(socket, &len, sizeof(len));
+ if (b <= 0)
+ return -1;
+
+ assert(len <= maxLen); /* XXX fix someday */
+ assert(len >= 0);
+ received = ReceiveData(socket, str, len);
+ assert(received != -1);
+ assert(received == len);
+ str[len] = 0;
+ return received;
+}
diff --git a/progs/xdemos/ipc.h b/progs/xdemos/ipc.h
new file mode 100644
index 0000000000..3f434457c6
--- /dev/null
+++ b/progs/xdemos/ipc.h
@@ -0,0 +1,16 @@
+#ifndef IPC_H
+#define IPC_H
+
+
+extern int MyHostName(char *nameOut, int maxNameLength);
+extern int CreatePort(int *port);
+extern int AcceptConnection(int socket);
+extern int Connect(const char *hostname, int port);
+extern void CloseSocket(int socket);
+extern int SendData(int socket, const void *data, int bytes);
+extern int ReceiveData(int socket, void *data, int bytes);
+extern int SendString(int socket, const char *str);
+extern int ReceiveString(int socket, char *str, int maxLen);
+
+
+#endif /* IPC_H */