summaryrefslogtreecommitdiff
path: root/progs
diff options
context:
space:
mode:
Diffstat (limited to 'progs')
-rw-r--r--progs/beos/.gitignore3
-rw-r--r--progs/demos/.gitignore14
-rw-r--r--progs/demos/Makefile17
-rw-r--r--progs/demos/copypix.c248
-rw-r--r--progs/demos/cubemap.c51
-rw-r--r--progs/demos/shadowtex.c62
-rw-r--r--progs/demos/streaming_rect.c25
-rw-r--r--progs/directfb/.gitignore4
-rw-r--r--progs/directfb/Makefile2
-rw-r--r--progs/egl/.gitignore5
-rw-r--r--progs/egl/Makefile10
-rw-r--r--progs/fbdev/.gitignore1
-rw-r--r--progs/fbdev/Makefile2
-rw-r--r--progs/fp/.gitignore42
-rw-r--r--progs/glsl/.gitignore13
-rw-r--r--progs/glsl/Makefile13
-rw-r--r--progs/glsl/bitmap.c368
-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/points.c305
-rw-r--r--progs/glsl/toyball.c6
-rw-r--r--progs/glsl/trirast.c326
-rw-r--r--progs/miniglx/.gitignore6
-rw-r--r--progs/miniglx/Makefile2
-rw-r--r--progs/osdemos/.gitignore8
-rw-r--r--progs/osdemos/Makefile10
-rw-r--r--progs/osdemos/ostest1.c7
-rw-r--r--progs/redbook/Makefile2
-rw-r--r--progs/samples/.gitignore32
-rw-r--r--progs/samples/Makefile4
-rw-r--r--progs/samples/Makefile.mgw22
-rw-r--r--progs/slang/.gitignore3
-rw-r--r--progs/slang/Makefile6
-rw-r--r--progs/tests/.gitignore24
-rw-r--r--progs/tests/Makefile46
-rw-r--r--progs/tests/cva.c6
-rw-r--r--progs/tests/dinoshade.c6
-rw-r--r--progs/tests/multipal.c6
-rw-r--r--progs/tools/trace/.gitignore1
-rw-r--r--progs/tools/trace/Makefile2
-rw-r--r--progs/trivial/.gitignore65
-rw-r--r--progs/trivial/Makefile6
-rw-r--r--progs/util/extfuncs.h19
-rw-r--r--progs/vp/.gitignore1
-rw-r--r--progs/vp/Makefile2
-rw-r--r--progs/xdemos/.gitignore11
-rw-r--r--progs/xdemos/Makefile35
-rw-r--r--progs/xdemos/corender.c396
-rw-r--r--progs/xdemos/glxgears.c13
-rw-r--r--progs/xdemos/glxinfo.c285
-rw-r--r--progs/xdemos/glxsnoop.c377
-rw-r--r--progs/xdemos/glxswapcontrol.c5
-rw-r--r--progs/xdemos/ipc.c264
-rw-r--r--progs/xdemos/ipc.h16
-rw-r--r--progs/xdemos/pbdemo.c9
-rw-r--r--progs/xdemos/pbutil.c72
-rw-r--r--progs/xdemos/pbutil.h3
58 files changed, 3075 insertions, 228 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 f764b3d117..ad20499f1e 100644
--- a/progs/demos/.gitignore
+++ b/progs/demos/.gitignore
@@ -1,17 +1,25 @@
.cvsignore
arbfplight
+arbfslight
arbocclude
bounce
clearspd
+copypix
cubemap
drawpix
+engine
+extfuncs.h
fire
+fogcoord
fplight
+fslight
gamma
+gearbox
gears
geartrain
glinfo
gloss
+glslnoise
gltestperf
glutfx
ipers
@@ -33,8 +41,11 @@ renormal
shadowtex
showbuffer.c
showbuffer.h
+singlebuffer
spectex
+spriteblast
stex3d
+streaming_rect
teapot
terrain
tessdemo
@@ -42,7 +53,10 @@ texcyl
texdown
texenv
texobj
+trackball.c
+trackball.h
trispd
tunnel
tunnel2
+vao_demo
winpos
diff --git a/progs/demos/Makefile b/progs/demos/Makefile
index cf96828ed7..4d9eb30b68 100644
--- a/progs/demos/Makefile
+++ b/progs/demos/Makefile
@@ -19,6 +19,7 @@ PROGS = \
arbocclude \
bounce \
clearspd \
+ copypix \
cubemap \
drawpix \
engine \
@@ -74,7 +75,7 @@ PROGS = \
# make executable from .c file:
.c: $(LIB_DEP) readtex.o
- $(CC) -I$(INCDIR) $(CFLAGS) $< readtex.o $(APP_LIB_DEPS) -o $@
+ $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) $< readtex.o $(APP_LIB_DEPS) -o $@
##### TARGETS #####
@@ -118,41 +119,45 @@ extfuncs.h: $(TOP)/progs/util/extfuncs.h
reflect: reflect.o showbuffer.o readtex.o
- $(CC) reflect.o showbuffer.o readtex.o $(APP_LIB_DEPS) -o $@
+ $(CC) $(LDFLAGS) reflect.o showbuffer.o readtex.o $(APP_LIB_DEPS) -o $@
reflect.o: reflect.c showbuffer.h
$(CC) -c -I$(INCDIR) $(CFLAGS) reflect.c
shadowtex: shadowtex.o showbuffer.o
- $(CC) shadowtex.o showbuffer.o $(APP_LIB_DEPS) -o $@
+ $(CC) $(LDFLAGS) shadowtex.o showbuffer.o $(APP_LIB_DEPS) -o $@
shadowtex.o: shadowtex.c showbuffer.h
$(CC) -c -I$(INCDIR) $(CFLAGS) shadowtex.c
gloss: gloss.o trackball.o readtex.o
- $(CC) gloss.o trackball.o readtex.o $(APP_LIB_DEPS) -o $@
+ $(CC) $(LDFLAGS) gloss.o trackball.o readtex.o $(APP_LIB_DEPS) -o $@
gloss.o: gloss.c trackball.h
$(CC) -c -I$(INCDIR) $(CFLAGS) gloss.c
engine: engine.o trackball.o readtex.o
- $(CC) engine.o trackball.o readtex.o $(APP_LIB_DEPS) -o $@
+ $(CC) $(LDFLAGS) engine.o trackball.o readtex.o $(APP_LIB_DEPS) -o $@
engine.o: engine.c trackball.h
$(CC) -c -I$(INCDIR) $(CFLAGS) engine.c
fslight: fslight.o
- $(CC) fslight.o $(APP_LIB_DEPS) -o $@
+ $(CC) $(LDFLAGS) fslight.o $(APP_LIB_DEPS) -o $@
fslight.o: fslight.c extfuncs.h
$(CC) -c -I$(INCDIR) $(CFLAGS) fslight.c
+viewdds: viewdds.c
+ $(CC) -I$(INCDIR) $(CFLAGS) $< readtex.o $(APP_LIB_DEPS) -L. -lgltc -o $@
+
+
clean:
-rm -f $(PROGS)
-rm -f *.o *~
diff --git a/progs/demos/copypix.c b/progs/demos/copypix.c
new file mode 100644
index 0000000000..15001e851b
--- /dev/null
+++ b/progs/demos/copypix.c
@@ -0,0 +1,248 @@
+/**
+ * glCopyPixels test
+ *
+ * Brian Paul
+ * 14 Sep 2007
+ */
+
+
+#define GL_GLEXT_PROTOTYPES
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <GL/glut.h>
+
+#include "readtex.h"
+
+#define IMAGE_FILE "../images/arch.rgb"
+
+static int ImgWidth, ImgHeight;
+static GLenum ImgFormat;
+static GLubyte *Image = NULL;
+
+static int WinWidth = 800, WinHeight = 800;
+static int Xpos, Ypos;
+static int Scissor = 0;
+static float Xzoom, Yzoom;
+static GLboolean DrawFront = GL_FALSE;
+static GLboolean Dither = GL_TRUE;
+
+
+static void Reset( void )
+{
+ Xpos = Ypos = 20;
+ Scissor = 0;
+ Xzoom = Yzoom = 1.0;
+}
+
+
+static void Display( void )
+{
+ const int dx = (WinWidth - ImgWidth) / 2;
+ const int dy = (WinHeight - ImgHeight) / 2;
+
+ if (DrawFront) {
+ glDrawBuffer(GL_FRONT);
+ glReadBuffer(GL_FRONT);
+ }
+ else {
+ glDrawBuffer(GL_BACK);
+ glReadBuffer(GL_BACK);
+ }
+
+ glClear( GL_COLOR_BUFFER_BIT );
+
+ /* draw original image */
+ glWindowPos2iARB(dx, dy);
+ glDrawPixels(ImgWidth, ImgHeight, ImgFormat, GL_UNSIGNED_BYTE, Image);
+
+ if (Scissor)
+ glEnable(GL_SCISSOR_TEST);
+
+ /* draw copy */
+ glPixelZoom(Xzoom, Yzoom);
+ glWindowPos2iARB(Xpos, Ypos);
+ glCopyPixels(dx, dy, ImgWidth, ImgHeight, GL_COLOR);
+ glPixelZoom(1, 1);
+
+ glDisable(GL_SCISSOR_TEST);
+
+ if (DrawFront)
+ glFinish();
+ else
+ glutSwapBuffers();
+}
+
+
+static void Reshape( int width, int height )
+{
+ WinWidth = width;
+ WinHeight = height;
+
+ glViewport( 0, 0, width, height );
+ glMatrixMode( GL_PROJECTION );
+ glLoadIdentity();
+ glOrtho( 0.0, width, 0.0, height, 0.0, 2.0 );
+ glMatrixMode( GL_MODELVIEW );
+ glLoadIdentity();
+
+ glScissor(width/4, height/4, width/2, height/2);
+}
+
+
+static void Key( unsigned char key, int x, int y )
+{
+ (void) x;
+ (void) y;
+ switch (key) {
+ case ' ':
+ Reset();
+ break;
+ case 'd':
+ Dither = !Dither;
+ if (Dither)
+ glEnable(GL_DITHER);
+ else
+ glDisable(GL_DITHER);
+ break;
+ case 's':
+ Scissor = !Scissor;
+ break;
+ case 'x':
+ Xzoom -= 0.1;
+ break;
+ case 'X':
+ Xzoom += 0.1;
+ break;
+ case 'y':
+ Yzoom -= 0.1;
+ break;
+ case 'Y':
+ Yzoom += 0.1;
+ break;
+ case 'f':
+ DrawFront = !DrawFront;
+ printf("glDrawBuffer(%s)\n", DrawFront ? "GL_FRONT" : "GL_BACK");
+ break;
+ case 27:
+ exit(0);
+ break;
+ }
+ glutPostRedisplay();
+}
+
+
+static void SpecialKey( int key, int x, int y )
+{
+ const int step = (glutGetModifiers() & GLUT_ACTIVE_SHIFT) ? 10 : 1;
+ (void) x;
+ (void) y;
+ switch (key) {
+ case GLUT_KEY_UP:
+ Ypos += step;
+ break;
+ case GLUT_KEY_DOWN:
+ Ypos -= step;
+ break;
+ case GLUT_KEY_LEFT:
+ Xpos -= step;
+ break;
+ case GLUT_KEY_RIGHT:
+ Xpos += step;
+ break;
+ }
+ glutPostRedisplay();
+}
+
+
+static void Init( GLboolean ciMode, const char *filename )
+{
+ printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
+ printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
+
+ Image = LoadRGBImage( filename, &ImgWidth, &ImgHeight, &ImgFormat );
+ if (!Image) {
+ printf("Couldn't read %s\n", filename);
+ exit(0);
+ }
+
+ if (ciMode) {
+ /* Convert RGB image to grayscale */
+ GLubyte *indexImage = (GLubyte *) malloc( ImgWidth * ImgHeight );
+ GLint i;
+ for (i=0; i<ImgWidth*ImgHeight; i++) {
+ int gray = Image[i*3] + Image[i*3+1] + Image[i*3+2];
+ indexImage[i] = gray / 3;
+ }
+ free(Image);
+ Image = indexImage;
+ ImgFormat = GL_COLOR_INDEX;
+
+ for (i=0;i<255;i++) {
+ float g = i / 255.0;
+ glutSetColor(i, g, g, g);
+ }
+ }
+
+ printf("Loaded %d by %d image\n", ImgWidth, ImgHeight );
+
+ glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+ glPixelStorei(GL_UNPACK_ROW_LENGTH, ImgWidth);
+
+ Reset();
+}
+
+
+static void Usage(void)
+{
+ printf("Keys:\n");
+ printf(" SPACE Reset Parameters\n");
+ printf(" Up/Down Move image up/down (SHIFT for large step)\n");
+ printf(" Left/Right Move image left/right (SHIFT for large step)\n");
+ printf(" x Decrease X-axis PixelZoom\n");
+ printf(" X Increase X-axis PixelZoom\n");
+ printf(" y Decrease Y-axis PixelZoom\n");
+ printf(" Y Increase Y-axis PixelZoom\n");
+ printf(" s Toggle GL_SCISSOR_TEST\n");
+ printf(" f Toggle front/back buffer drawing\n");
+ printf(" ESC Exit\n");
+}
+
+
+int main( int argc, char *argv[] )
+{
+ GLboolean ciMode = GL_FALSE;
+ const char *filename = IMAGE_FILE;
+ int i = 1;
+
+ if (argc > i && strcmp(argv[i], "-ci")==0) {
+ ciMode = GL_TRUE;
+ i++;
+ }
+ if (argc > i) {
+ filename = argv[i];
+ }
+
+ glutInit( &argc, argv );
+ glutInitWindowPosition( 0, 0 );
+ glutInitWindowSize( WinWidth, WinHeight );
+
+ if (ciMode)
+ glutInitDisplayMode( GLUT_INDEX | GLUT_DOUBLE );
+ else
+ glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE);
+
+ glutCreateWindow(argv[0]);
+
+ Init(ciMode, filename);
+ Usage();
+
+ glutReshapeFunc( Reshape );
+ glutKeyboardFunc( Key );
+ glutSpecialFunc( SpecialKey );
+ glutDisplayFunc( Display );
+
+ glutMainLoop();
+ return 0;
+}
diff --git a/progs/demos/cubemap.c b/progs/demos/cubemap.c
index ef5d235550..b3bdd64f68 100644
--- a/progs/demos/cubemap.c
+++ b/progs/demos/cubemap.c
@@ -47,6 +47,8 @@ static GLfloat Xrot = 0, Yrot = 0;
static GLfloat EyeDist = 10;
static GLboolean use_vertex_arrays = GL_FALSE;
static GLboolean anim = GL_TRUE;
+static GLboolean NoClear = GL_FALSE;
+static GLint FrameParity = 0;
#define eps1 0.99
#define br 20.0 /* box radius */
@@ -156,7 +158,30 @@ static void draw_skybox( void )
static void draw( void )
{
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ if (NoClear) {
+ /* This demonstrates how we can avoid calling glClear.
+ * This method only works if every pixel in the window is painted for
+ * every frame.
+ * We can simply skip clearing of the color buffer in this case.
+ * For the depth buffer, we alternately use a different subrange of
+ * the depth buffer for each frame. For the odd frame use the range
+ * [0, 0.5] with GL_LESS. For the even frames, use the range [1, 0.5]
+ * with GL_GREATER.
+ */
+ FrameParity = 1 - FrameParity;
+ if (FrameParity) {
+ glDepthRange(0.0, 0.5);
+ glDepthFunc(GL_LESS);
+ }
+ else {
+ glDepthRange(1.0, 0.5);
+ glDepthFunc(GL_GREATER);
+ }
+ }
+ else {
+ /* ordinary clearing */
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ }
glPushMatrix(); /*MODELVIEW*/
glTranslatef( 0.0, 0.0, -EyeDist );
@@ -452,6 +477,24 @@ static void usage(void)
}
+static void parse_args(int argc, char *argv[])
+{
+ int initFlag = 0;
+ int i;
+
+ for (i = 1; i < argc; i++) {
+ if (strcmp(argv[i], "-i") == 0)
+ initFlag = 1;
+ else if (strcmp(argv[i], "--noclear") == 0)
+ NoClear = GL_TRUE;
+ else {
+ fprintf(stderr, "Bad option: %s\n", argv[i]);
+ exit(1);
+ }
+ }
+ init (initFlag);
+}
+
int main( int argc, char *argv[] )
{
glutInit(&argc, argv);
@@ -459,17 +502,13 @@ int main( int argc, char *argv[] )
glutInitWindowSize(600, 500);
glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE );
glutCreateWindow("Texture Cube Mapping");
-
- if (argc > 1 && strcmp(argv[1] , "-i") == 0)
- init( 1 );
- else
- init( 0 );
glutReshapeFunc( reshape );
glutKeyboardFunc( key );
glutSpecialFunc( specialkey );
glutDisplayFunc( draw );
if (anim)
glutIdleFunc(idle);
+ parse_args(argc, argv);
usage();
glutMainLoop();
return 0;
diff --git a/progs/demos/shadowtex.c b/progs/demos/shadowtex.c
index 59253e8c1e..c2d40bda74 100644
--- a/progs/demos/shadowtex.c
+++ b/progs/demos/shadowtex.c
@@ -84,6 +84,7 @@ static const char *FragProgNames[] = {
"program with \"OPTION ARB_fragment_program_shadow\"",
};
+static GLboolean HaveShadow = GL_FALSE;
static GLboolean HaveFBO = GL_FALSE;
static GLboolean UseFBO = GL_FALSE;
static GLboolean HaveVP = GL_FALSE;
@@ -529,7 +530,10 @@ ShowShadowMap(void)
DisableTexgen();
/* interpret texture's depth values as luminance values */
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_NONE);
+ if (HaveShadow) {
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_NONE);
+ }
+
glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE_ARB, GL_LUMINANCE);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
@@ -596,7 +600,9 @@ Display(void)
}
if (DisplayMode == SHOW_DEPTH_MAPPING) {
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_NONE);
+ if (HaveShadow) {
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_NONE);
+ }
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glEnable(GL_TEXTURE_2D);
@@ -614,8 +620,10 @@ Display(void)
}
else {
assert(DisplayMode == SHOW_SHADOWS);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB,
- GL_COMPARE_R_TO_TEXTURE_ARB);
+ if (HaveShadow) {
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB,
+ GL_COMPARE_R_TO_TEXTURE_ARB);
+ }
if (curr_frag > 0) {
glEnable(GL_FRAGMENT_PROGRAM_ARB);
@@ -723,6 +731,10 @@ Key(unsigned char key, int x, int y)
break;
case 'M':
curr_frag = (1 + curr_frag) % max_frag;
+ if (!HaveShadow && (curr_frag == 0)) {
+ curr_frag = 1;
+ }
+
printf("Using fragment %s\n", FragProgNames[curr_frag]);
if (HaveFP) {
@@ -740,8 +752,10 @@ Key(unsigned char key, int x, int y)
if (Operator >= 8)
Operator = 0;
printf("Operator: %s\n", OperatorName[Operator]);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB,
- OperatorFunc[Operator]);
+ if (HaveShadow) {
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB,
+ OperatorFunc[Operator]);
+ }
}
break;
case 'p':
@@ -858,17 +872,31 @@ Init(void)
{
static const GLfloat borderColor[4] = {1.0, 0.0, 0.0, 0.0};
- if (!glutExtensionSupported("GL_ARB_depth_texture") ||
- !glutExtensionSupported("GL_ARB_shadow")) {
- printf("Sorry, this demo requires the GL_ARB_depth_texture and GL_ARB_shadow extensions\n");
+ if (!glutExtensionSupported("GL_ARB_depth_texture")) {
+ printf("Sorry, this demo requires the GL_ARB_depth_texture extension\n");
exit(1);
}
- printf("Using GL_ARB_depth_texture and GL_ARB_shadow\n");
+ HaveShadow = glutExtensionSupported("GL_ARB_shadow");
HaveVP = glutExtensionSupported("GL_ARB_vertex_program");
HaveFP = glutExtensionSupported("GL_ARB_fragment_program");
HaveFP_Shadow = glutExtensionSupported("GL_ARB_fragment_program_shadow");
+ if (!HaveShadow && !HaveFP) {
+ printf("Sorry, this demo requires either the GL_ARB_shadow extension "
+ "or the GL_ARB_fragment_program extension\n");
+ exit(1);
+ }
+
+ printf("Using GL_ARB_depth_texture\n");
+ if (HaveShadow) {
+ printf("and GL_ARB_shadow\n");
+ }
+
+ if (HaveFP) {
+ printf("and GL_ARB_fragment_program\n");
+ }
+
HaveShadowAmbient = glutExtensionSupported("GL_ARB_shadow_ambient");
if (HaveShadowAmbient) {
printf("and GL_ARB_shadow_ambient\n");
@@ -895,9 +923,12 @@ Init(void)
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB,
- GL_COMPARE_R_TO_TEXTURE_ARB);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL);
+
+ if (HaveShadow) {
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB,
+ GL_COMPARE_R_TO_TEXTURE_ARB);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL);
+ }
if (HaveShadowAmbient) {
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FAIL_VALUE_ARB, 0.3);
@@ -954,6 +985,11 @@ Init(void)
max_frag = 3;
}
+ if (!HaveShadow) {
+ curr_frag = 1;
+ glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, frag_progs[curr_frag]);
+ }
+
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
diff --git a/progs/demos/streaming_rect.c b/progs/demos/streaming_rect.c
index 86e00803c0..4c1d8535fd 100644
--- a/progs/demos/streaming_rect.c
+++ b/progs/demos/streaming_rect.c
@@ -1,13 +1,9 @@
-
/*
- * GL_ARB_multitexture demo
+ * GL_ARB_pixel_buffer_object test
*
* Command line options:
- * -info print GL implementation information
- *
+ * -w WIDTH -h HEIGHT sets window size
*
- * Brian Paul November 1998 This program is in the public domain.
- * Modified on 12 Feb 2002 for > 2 texture units.
*/
#define GL_GLEXT_PROTOTYPES
@@ -25,6 +21,8 @@
#define PBO 11
#define QUIT 100
+static GLuint DrawPBO;
+
static GLboolean Animate = GL_TRUE;
static GLboolean use_pbo = 1;
static GLboolean whole_rect = 1;
@@ -49,7 +47,7 @@ static void Idle( void )
}
}
-static int max( int a, int b ) { return a > b ? a : b; }
+/*static int max( int a, int b ) { return a > b ? a : b; }*/
static int min( int a, int b ) { return a < b ? a : b; }
static void DrawObject()
@@ -62,6 +60,7 @@ static void DrawObject()
* release the old copy of the texture and allocate a new one
* without waiting for outstanding rendering to complete.
*/
+ glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, DrawPBO);
glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_EXT, size, NULL, GL_STREAM_DRAW_ARB);
{
@@ -69,7 +68,7 @@ static void DrawObject()
printf("char %d\n", (unsigned char)(Drift * 255));
- memset(image, size, (unsigned char)(Drift * 255));
+ memset(image, (unsigned char)(Drift * 255), size);
glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT);
}
@@ -86,7 +85,9 @@ static void DrawObject()
if (image == NULL)
image = malloc(size);
- memset(image, size, (unsigned char)(Drift * 255));
+ glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, 0);
+
+ memset(image, (unsigned char)(Drift * 255), size);
/* BGRA should be the fast path for regular uploads as well.
*/
@@ -227,12 +228,12 @@ static void SpecialKey( int key, int x, int y )
static void Init( int argc, char *argv[] )
{
const char *exten = (const char *) glGetString(GL_EXTENSIONS);
- GLuint texObj, DrawPBO;
+ GLuint texObj;
GLint size;
- if (!strstr(exten, "GL_ARB_multitexture")) {
- printf("Sorry, GL_ARB_multitexture not supported by this renderer.\n");
+ if (!strstr(exten, "GL_ARB_pixel_buffer_object")) {
+ printf("Sorry, GL_ARB_pixel_buffer_object not supported by this renderer.\n");
exit(1);
}
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/directfb/Makefile b/progs/directfb/Makefile
index 53b100a18d..e03680e516 100644
--- a/progs/directfb/Makefile
+++ b/progs/directfb/Makefile
@@ -22,7 +22,7 @@ PROGS = df_gears \
.SUFFIXES: .c
.c: $(LIB_DEP)
- $(CC) -I$(INCDIR) $(CFLAGS) $< $(APP_LIB_DEPS) -o $@
+ $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) $< $(APP_LIB_DEPS) -o $@
##### TARGETS #####
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/egl/Makefile b/progs/egl/Makefile
index 33447a9d57..07215604d3 100644
--- a/progs/egl/Makefile
+++ b/progs/egl/Makefile
@@ -25,35 +25,35 @@ default: $(PROGRAMS)
demo1: demo1.o $(TOP)/$(LIB_DIR)/libEGL.so
- $(CC) $(CFLAGS) demo1.o -L$(TOP)/$(LIB_DIR) -lEGL $(LIBDRM_LIB) -o $@
+ $(CC) $(CFLAGS) $(LDFLAGS) demo1.o -L$(TOP)/$(LIB_DIR) -lEGL $(LIBDRM_LIB) -o $@
demo1.o: demo1.c $(HEADERS)
$(CC) -c $(CFLAGS) -I$(TOP)/include demo1.c
demo2: demo2.o $(TOP)/$(LIB_DIR)/libEGL.so
- $(CC) $(CFLAGS) demo2.o -L$(TOP)/$(LIB_DIR) -lEGL $(LIBDRM_LIB) $(APP_LIB_DEPS) -o $@
+ $(CC) $(CFLAGS) $(LDFLAGS) demo2.o -L$(TOP)/$(LIB_DIR) -lEGL $(LIBDRM_LIB) $(APP_LIB_DEPS) -o $@
demo2.o: demo2.c $(HEADERS)
$(CC) -c $(CFLAGS) -I$(TOP)/include demo2.c
demo3: demo3.o $(TOP)/$(LIB_DIR)/libEGL.so
- $(CC) $(CFLAGS) demo3.o -L$(TOP)/$(LIB_DIR) -lEGL $(LIBDRM_LIB) $(APP_LIB_DEPS) -o $@
+ $(CC) $(CFLAGS) $(LDFLAGS) demo3.o -L$(TOP)/$(LIB_DIR) -lEGL $(LIBDRM_LIB) $(APP_LIB_DEPS) -o $@
demo3.o: demo3.c $(HEADERS)
$(CC) -c $(CFLAGS) -I$(TOP)/include demo3.c
eglinfo: eglinfo.o $(TOP)/$(LIB_DIR)/libEGL.so
- $(CC) $(CFLAGS) eglinfo.o -L$(TOP)/$(LIB_DIR) -lEGL $(LIBDRM_LIB) -o $@
+ $(CC) $(CFLAGS) $(LDFLAGS) eglinfo.o -L$(TOP)/$(LIB_DIR) -lEGL $(LIBDRM_LIB) -o $@
eglinfo.o: eglinfo.c $(HEADERS)
$(CC) -c $(CFLAGS) -I$(TOP)/include eglinfo.c
eglgears: eglgears.o $(TOP)/$(LIB_DIR)/libEGL.so
- $(CC) $(CFLAGS) eglgears.o -L$(TOP)/$(LIB_DIR) -lEGL $(LIBDRM_LIB) $(APP_LIB_DEPS) -o $@
+ $(CC) $(CFLAGS) $(LDFLAGS) eglgears.o -L$(TOP)/$(LIB_DIR) -lEGL $(LIBDRM_LIB) $(APP_LIB_DEPS) -o $@
eglgears.o: eglgears.c $(HEADERS)
$(CC) -c $(CFLAGS) -I$(TOP)/include eglgears.c
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/fbdev/Makefile b/progs/fbdev/Makefile
index 0a0c77906f..92bfd043c1 100644
--- a/progs/fbdev/Makefile
+++ b/progs/fbdev/Makefile
@@ -22,7 +22,7 @@ INCLUDES = \
.SUFFIXES: .c
.c:
- $(CC) $(INCLUDES) $(CFLAGS) $< $(APP_LIB_DEPS) -o $@
+ $(CC) $(INCLUDES) $(CFLAGS) $(LDFLAGS) $< $(APP_LIB_DEPS) -o $@
.c.o:
$(CC) -c $(INCLUDES) $(CFLAGS) $< -o $@
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..b63693bbb5
--- /dev/null
+++ b/progs/glsl/.gitignore
@@ -0,0 +1,13 @@
+bitmap
+brick
+bump
+deriv
+extfuncs.h
+mandelbrot
+noise
+points
+readtex.c
+readtex.h
+texdemo1
+trirast
+toyball
diff --git a/progs/glsl/Makefile b/progs/glsl/Makefile
index 37fa312c30..8b44239b43 100644
--- a/progs/glsl/Makefile
+++ b/progs/glsl/Makefile
@@ -8,13 +8,16 @@ INCDIR = $(TOP)/include
LIB_DEP = $(TOP)/$(LIB_DIR)/$(GL_LIB_NAME) $(TOP)/$(LIB_DIR)/$(GLU_LIB_NAME) $(TOP)/$(LIB_DIR)/$(GLUT_LIB_NAME)
PROGS = \
+ bitmap \
brick \
bump \
deriv \
mandelbrot \
noise \
+ points \
+ texdemo1 \
toyball \
- texdemo1
+ trirast
##### RULES #####
@@ -25,7 +28,7 @@ PROGS = \
# make executable from .c file:
.c: $(LIB_DEP)
- $(CC) -I$(INCDIR) $(CFLAGS) $< $(APP_LIB_DEPS) -o $@
+ $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) $< $(APP_LIB_DEPS) -o $@
##### TARGETS #####
@@ -48,16 +51,20 @@ readtex.h: $(TOP)/progs/util/readtex.h
readtex.o: readtex.c readtex.h
$(CC) -c -I$(INCDIR) $(CFLAGS) readtex.c
+bitmap.c: extfuncs.h
+
brick.c: extfuncs.h
bump.c: extfuncs.h
mandelbrot.c: extfuncs.h
+points.c: extfuncs.h
+
toyball.c: extfuncs.h
texdemo1: texdemo1.o readtex.o
- $(CC) -I$(INCDIR) $(CFLAGS) texdemo1.o readtex.o $(APP_LIB_DEPS) -o $@
+ $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) texdemo1.o readtex.o $(APP_LIB_DEPS) -o $@
texdemo1.o: texdemo1.c readtex.h extfuncs.h
$(CC) -c -I$(INCDIR) $(CFLAGS) texdemo1.c
diff --git a/progs/glsl/bitmap.c b/progs/glsl/bitmap.c
new file mode 100644
index 0000000000..4b62686cbf
--- /dev/null
+++ b/progs/glsl/bitmap.c
@@ -0,0 +1,368 @@
+/**
+ * Implement glRasterPos + glBitmap with textures + shaders.
+ * Brian Paul
+ * 14 May 2007
+ */
+
+#include <assert.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include <GL/gl.h>
+#include <GL/glut.h>
+#include <GL/glext.h>
+#include "extfuncs.h"
+
+
+static GLuint FragShader;
+static GLuint VertShader;
+static GLuint Program;
+
+static GLint Win = 0;
+static GLint WinWidth = 500, WinHeight = 500;
+static GLboolean Anim = GL_TRUE;
+static GLboolean Bitmap = GL_FALSE;
+static GLfloat Xrot = 20.0f, Yrot = 70.0f;
+static GLint uTex, uScale;
+static GLuint Textures[2];
+
+#define TEX_WIDTH 16
+#define TEX_HEIGHT 8
+
+
+static void
+BitmapText(const char *s)
+{
+ while (*s) {
+ glutBitmapCharacter(GLUT_BITMAP_8_BY_13, (int) *s);
+ s++;
+ }
+}
+
+
+static void
+Redisplay(void)
+{
+ static const GLfloat px[3] = { 1.2, 0, 0};
+ static const GLfloat nx[3] = {-1.2, 0, 0};
+
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ glPushMatrix();
+ glRotatef(Xrot, 1.0f, 0.0f, 0.0f);
+ glRotatef(Yrot, 0.0f, 1.0f, 0.0f);
+
+ glEnable(GL_LIGHTING);
+
+ glPushMatrix();
+ glScalef(0.5, 0.5, 0.5);
+ glutSolidDodecahedron();
+ glPopMatrix();
+
+ glDisable(GL_LIGHTING);
+
+ glColor3f(0, 1, 0);
+ glBegin(GL_LINES);
+ glVertex3f(-1, 0, 0);
+ glVertex3f( 1, 0, 0);
+ glEnd();
+
+ glColor3f(1, 1, 0);
+
+ if (Bitmap) {
+ glRasterPos3fv(px);
+ BitmapText("+X");
+ glRasterPos3fv(nx);
+ BitmapText("-X");
+ }
+ else {
+ glUseProgram_func(Program);
+
+ /* vertex positions (deltas) depend on texture size and window size */
+ if (uScale != -1) {
+ glUniform2f_func(uScale,
+ 2.0 * TEX_WIDTH / WinWidth,
+ 2.0 * TEX_HEIGHT / WinHeight);
+ }
+
+ /* draw +X */
+ glBindTexture(GL_TEXTURE_2D, Textures[0]);
+ glBegin(GL_QUADS);
+ glTexCoord2f(0, 0); glVertex3fv(px);
+ glTexCoord2f(1, 0); glVertex3fv(px);
+ glTexCoord2f(1, 1); glVertex3fv(px);
+ glTexCoord2f(0, 1); glVertex3fv(px);
+ glEnd();
+
+ /* draw -X */
+ glBindTexture(GL_TEXTURE_2D, Textures[1]);
+ glBegin(GL_QUADS);
+ glTexCoord2f(0, 0); glVertex3fv(nx);
+ glTexCoord2f(1, 0); glVertex3fv(nx);
+ glTexCoord2f(1, 1); glVertex3fv(nx);
+ glTexCoord2f(0, 1); glVertex3fv(nx);
+ glEnd();
+
+ glUseProgram_func(0);
+ }
+
+ glPopMatrix();
+
+ glutSwapBuffers();
+}
+
+
+static void
+Idle(void)
+{
+ Yrot = glutGet(GLUT_ELAPSED_TIME) * 0.01;
+ glutPostRedisplay();
+}
+
+
+static void
+Reshape(int width, int height)
+{
+ WinWidth = width;
+ WinHeight = height;
+ glViewport(0, 0, width, height);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0);
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ glTranslatef(0.0f, 0.0f, -10.0f);
+}
+
+
+static void
+Key(unsigned char key, int x, int y)
+{
+ (void) x;
+ (void) y;
+
+ switch(key) {
+ case ' ':
+ case 'a':
+ Anim = !Anim;
+ if (Anim)
+ glutIdleFunc(Idle);
+ else
+ glutIdleFunc(NULL);
+ break;
+ case 'b':
+ Bitmap = !Bitmap;
+ if (Bitmap)
+ printf("Using glBitmap\n");
+ else
+ printf("Using billboard texture\n");
+ break;
+ case 27:
+ glDeleteShader_func(FragShader);
+ glDeleteShader_func(VertShader);
+ glDeleteProgram_func(Program);
+ glutDestroyWindow(Win);
+ exit(0);
+ }
+ glutPostRedisplay();
+}
+
+
+static void
+SpecialKey(int key, int x, int y)
+{
+ const GLfloat step = 0.125f;
+ switch(key) {
+ case GLUT_KEY_UP:
+ Xrot -= step;
+ break;
+ case GLUT_KEY_DOWN:
+ Xrot += step;
+ break;
+ case GLUT_KEY_LEFT:
+ Yrot -= step;
+ break;
+ case GLUT_KEY_RIGHT:
+ Yrot += step;
+ break;
+ }
+ /*printf("Xrot: %f Yrot: %f\n", Xrot, Yrot);*/
+ glutPostRedisplay();
+}
+
+
+static void
+MakeTexImage(const char *p, GLuint texobj)
+{
+ GLubyte image[TEX_HEIGHT][TEX_WIDTH];
+ GLuint i, j, k;
+
+ for (i = 0; i < TEX_HEIGHT; i++) {
+ for (j = 0; j < TEX_WIDTH; j++) {
+ k = i * TEX_WIDTH + j;
+ if (p[k] == ' ') {
+ image[i][j] = 0;
+ }
+ else {
+ image[i][j] = 255;
+ }
+ }
+ }
+
+ glBindTexture(GL_TEXTURE_2D, texobj);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_INTENSITY, TEX_WIDTH, TEX_HEIGHT, 0,
+ GL_RED, GL_UNSIGNED_BYTE, image);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+}
+
+
+static void
+MakeBitmapTextures(void)
+{
+ const char *px =
+ " X X "
+ " X X X "
+ " X X X "
+ " XXXXX X "
+ " X X X "
+ " X X X "
+ " X X "
+ " X X ";
+ const char *nx =
+ " X X "
+ " X X "
+ " X X "
+ " XXXXX X "
+ " X X "
+ " X X "
+ " X X "
+ " X X ";
+ glGenTextures(2, Textures);
+ MakeTexImage(px, Textures[0]);
+ MakeTexImage(nx, Textures[1]);
+}
+
+
+static void
+LoadAndCompileShader(GLuint shader, const char *text)
+{
+ GLint stat;
+
+ glShaderSource_func(shader, 1, (const GLchar **) &text, NULL);
+
+ glCompileShader_func(shader);
+
+ glGetShaderiv_func(shader, GL_COMPILE_STATUS, &stat);
+ if (!stat) {
+ GLchar log[1000];
+ GLsizei len;
+ glGetShaderInfoLog_func(shader, 1000, &len, log);
+ fprintf(stderr, "fslight: problem compiling shader:\n%s\n", log);
+ exit(1);
+ }
+}
+
+
+static void
+CheckLink(GLuint prog)
+{
+ GLint stat;
+ glGetProgramiv_func(prog, GL_LINK_STATUS, &stat);
+ if (!stat) {
+ GLchar log[1000];
+ GLsizei len;
+ glGetProgramInfoLog_func(prog, 1000, &len, log);
+ fprintf(stderr, "Linker error:\n%s\n", log);
+ }
+}
+
+
+static void
+Init(void)
+{
+ /* Fragment shader: modulate raster color by texture, discard fragments
+ * with alpha < 1.0
+ */
+ static const char *fragShaderText =
+ "uniform sampler2D tex2d; \n"
+ "void main() {\n"
+ " vec4 c = texture2D(tex2d, gl_TexCoord[0].xy); \n"
+ " if (c.w < 1.0) \n"
+ " discard; \n"
+ " gl_FragColor = c * gl_Color; \n"
+ "}\n";
+ /* Vertex shader: compute new vertex position based on incoming vertex pos,
+ * texcoords and special scale factor.
+ */
+ static const char *vertShaderText =
+ "uniform vec2 scale; \n"
+ "void main() {\n"
+ " vec4 p = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
+ " gl_Position.xy = p.xy + gl_MultiTexCoord0.xy * scale * p.w; \n"
+ " gl_Position.zw = p.zw; \n"
+ " gl_TexCoord[0] = gl_MultiTexCoord0; \n"
+ " gl_FrontColor = gl_Color; \n"
+ "}\n";
+ const char *version;
+
+ version = (const char *) glGetString(GL_VERSION);
+ if (version[0] != '2' || version[1] != '.') {
+ printf("This program requires OpenGL 2.x, found %s\n", version);
+ exit(1);
+ }
+ printf("GL_RENDERER = %s\n",(const char *) glGetString(GL_RENDERER));
+
+ GetExtensionFuncs();
+
+ FragShader = glCreateShader_func(GL_FRAGMENT_SHADER);
+ LoadAndCompileShader(FragShader, fragShaderText);
+
+ VertShader = glCreateShader_func(GL_VERTEX_SHADER);
+ LoadAndCompileShader(VertShader, vertShaderText);
+
+ Program = glCreateProgram_func();
+ glAttachShader_func(Program, FragShader);
+ glAttachShader_func(Program, VertShader);
+ glLinkProgram_func(Program);
+ CheckLink(Program);
+ glUseProgram_func(Program);
+
+ uScale = glGetUniformLocation_func(Program, "scale");
+ uTex = glGetUniformLocation_func(Program, "tex2d");
+ if (uTex != -1) {
+ glUniform1i_func(uTex, 0); /* tex unit 0 */
+ }
+
+ glUseProgram_func(0);
+
+ glClearColor(0.3f, 0.3f, 0.3f, 0.0f);
+ glEnable(GL_DEPTH_TEST);
+ glEnable(GL_NORMALIZE);
+ glEnable(GL_LIGHT0);
+
+ MakeBitmapTextures();
+}
+
+
+int
+main(int argc, char *argv[])
+{
+ glutInit(&argc, argv);
+ glutInitWindowSize(WinWidth, WinHeight);
+ glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
+ Win = glutCreateWindow(argv[0]);
+ glutReshapeFunc(Reshape);
+ glutKeyboardFunc(Key);
+ glutSpecialFunc(SpecialKey);
+ glutDisplayFunc(Redisplay);
+ if (Anim)
+ glutIdleFunc(Idle);
+ Init();
+ glutMainLoop();
+ return 0;
+}
+
+
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/points.c b/progs/glsl/points.c
new file mode 100644
index 0000000000..85115de504
--- /dev/null
+++ b/progs/glsl/points.c
@@ -0,0 +1,305 @@
+/**
+ * Implement smooth (AA) points with shaders.
+ * A simple variation could be used for sprite points.
+ * Brian Paul
+ * 29 July 2007
+ */
+
+#include <assert.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include <GL/gl.h>
+#include <GL/glut.h>
+#include <GL/glext.h>
+#include "extfuncs.h"
+
+
+static GLuint FragShader;
+static GLuint VertShader;
+static GLuint Program;
+
+static GLint Win = 0;
+static GLint WinWidth = 500, WinHeight = 200;
+static GLfloat Xpos = 0.0f, Ypos = 0.0f;
+static GLint uViewportInv;
+static GLboolean Smooth = GL_TRUE, Blend = GL_TRUE;
+
+
+/**
+ * Issue vertices for a "shader point".
+ * The position is duplicated, only texcoords (or other vertex attrib) change.
+ * The vertex program will compute the "real" quad corners.
+ */
+static void
+PointVertex3f(GLfloat x, GLfloat y, GLfloat z)
+{
+ glTexCoord2f(-1, -1);
+ glVertex3f(x, y, z);
+
+ glTexCoord2f( 1, -1);
+ glVertex3f(x, y, z);
+
+ glTexCoord2f( 1, 1);
+ glVertex3f(x, y, z);
+
+ glTexCoord2f(-1, 1);
+ glVertex3f(x, y, z);
+}
+
+
+static void
+DrawPoints(GLboolean shaderPoints)
+{
+ int i;
+ for (i = 0; i < 9; i++) {
+ GLfloat x = i - 4, y = 0, z = 0;
+ /* note: can't call glPointSize inside Begin/End :( */
+ glPointSize( 2 + i * 5 );
+ if (shaderPoints) {
+ glBegin(GL_QUADS);
+ PointVertex3f(x, y, z);
+ glEnd();
+ }
+ else {
+ glBegin(GL_POINTS);
+ glVertex3f(x, y, z);
+ glEnd();
+ }
+ }
+}
+
+
+/**
+ * Top row of points rendered convetionally,
+ * bottom row rendered with shaders.
+ */
+static void
+Redisplay(void)
+{
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ if (Smooth)
+ glEnable(GL_POINT_SMOOTH);
+ else
+ glDisable(GL_POINT_SMOOTH);
+
+ if (Blend)
+ glEnable(GL_BLEND);
+ else
+ glDisable(GL_BLEND);
+
+ glPushMatrix();
+ glTranslatef(Xpos, Ypos, 0);
+
+ /*
+ * regular points
+ */
+ glPushMatrix();
+ glTranslatef(0, 1.2, 0);
+ glUseProgram_func(0);
+ DrawPoints(GL_FALSE);
+ glPopMatrix();
+
+ /*
+ * shader points
+ */
+ glPushMatrix();
+ glTranslatef(0, -1.2, 0);
+ glUseProgram_func(Program);
+ if (uViewportInv != -1) {
+ glUniform2f_func(uViewportInv, 1.0 / WinWidth, 1.0 / WinHeight);
+ }
+ DrawPoints(GL_TRUE);
+ glPopMatrix();
+
+ glPopMatrix();
+
+ glutSwapBuffers();
+}
+
+
+static void
+Reshape(int width, int height)
+{
+ WinWidth = width;
+ WinHeight = height;
+ glViewport(0, 0, width, height);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glFrustum(-1.0, 1.0, -1.0, 1.0, 4.0, 30.0);
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ glTranslatef(0.0f, 0.0f, -20.0f);
+}
+
+
+static void
+Key(unsigned char key, int x, int y)
+{
+ (void) x;
+ (void) y;
+
+ switch(key) {
+ case 'b':
+ Blend = !Blend;
+ break;
+ case 's':
+ Smooth = !Smooth;
+ break;
+ case 27:
+ glDeleteShader_func(FragShader);
+ glDeleteShader_func(VertShader);
+ glDeleteProgram_func(Program);
+ glutDestroyWindow(Win);
+ exit(0);
+ }
+ glutPostRedisplay();
+}
+
+
+static void
+SpecialKey(int key, int x, int y)
+{
+ const GLfloat step = 1/100.0;
+ switch(key) {
+ case GLUT_KEY_UP:
+ Ypos += step;
+ break;
+ case GLUT_KEY_DOWN:
+ Ypos -= step;
+ break;
+ case GLUT_KEY_LEFT:
+ Xpos -= step;
+ break;
+ case GLUT_KEY_RIGHT:
+ Xpos += step;
+ break;
+ }
+ glutPostRedisplay();
+}
+
+
+static void
+LoadAndCompileShader(GLuint shader, const char *text)
+{
+ GLint stat;
+
+ glShaderSource_func(shader, 1, (const GLchar **) &text, NULL);
+
+ glCompileShader_func(shader);
+
+ glGetShaderiv_func(shader, GL_COMPILE_STATUS, &stat);
+ if (!stat) {
+ GLchar log[1000];
+ GLsizei len;
+ glGetShaderInfoLog_func(shader, 1000, &len, log);
+ fprintf(stderr, "fslight: problem compiling shader:\n%s\n", log);
+ exit(1);
+ }
+}
+
+
+static void
+CheckLink(GLuint prog)
+{
+ GLint stat;
+ glGetProgramiv_func(prog, GL_LINK_STATUS, &stat);
+ if (!stat) {
+ GLchar log[1000];
+ GLsizei len;
+ glGetProgramInfoLog_func(prog, 1000, &len, log);
+ fprintf(stderr, "Linker error:\n%s\n", log);
+ }
+}
+
+
+static void
+Init(void)
+{
+ /* Fragment shader: compute distance of fragment from center of point
+ * (we're using texcoords but another varying could be used).
+ * if dist > 1, discard (coverage==0)
+ * if dist < k, coverage = 1
+ * else, coverage = func(dist)
+ * Note: length() uses sqrt() and may be expensive. The distance could
+ * be squared instead (with adjustments to the threshold (k) test)
+ */
+ static const char *fragShaderText =
+ "void main() {\n"
+ " float cover; \n"
+ " float k = 2.0 / gl_Point.size; \n"
+ " float d = length(gl_TexCoord[0].xy); \n"
+ " if (d >= 1.0) \n"
+ " discard; \n"
+ " if (d < 1.0 - k) \n"
+ " cover = 1.0; \n"
+ " else \n"
+ " cover = (1.0 - d) * 0.5 * gl_Point.size; \n"
+ " gl_FragColor.rgb = gl_Color.rgb; \n"
+ " gl_FragColor.a = cover; \n"
+ "}\n";
+ /* Vertex shader: compute new vertex position based on incoming vertex pos,
+ * texcoords, point size, and inverse viewport scale factor.
+ * Note: should compute point size attenuation here too.
+ */
+ static const char *vertShaderText =
+ "uniform vec2 viewportInv; \n"
+ "void main() {\n"
+ " vec4 pos = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
+ " gl_Position.xy = pos.xy + gl_MultiTexCoord0.xy * viewportInv \n"
+ " * gl_Point.size * pos.w; \n"
+ " gl_Position.zw = pos.zw; \n"
+ " gl_TexCoord[0] = gl_MultiTexCoord0; \n"
+ " gl_FrontColor = gl_Color; \n"
+ "}\n";
+ const char *version;
+
+ version = (const char *) glGetString(GL_VERSION);
+ if (version[0] != '2' || version[1] != '.') {
+ printf("This program requires OpenGL 2.x, found %s\n", version);
+ exit(1);
+ }
+ printf("GL_RENDERER = %s\n",(const char *) glGetString(GL_RENDERER));
+
+ GetExtensionFuncs();
+
+ FragShader = glCreateShader_func(GL_FRAGMENT_SHADER);
+ LoadAndCompileShader(FragShader, fragShaderText);
+
+ VertShader = glCreateShader_func(GL_VERTEX_SHADER);
+ LoadAndCompileShader(VertShader, vertShaderText);
+
+ Program = glCreateProgram_func();
+ glAttachShader_func(Program, FragShader);
+ glAttachShader_func(Program, VertShader);
+ glLinkProgram_func(Program);
+ CheckLink(Program);
+ glUseProgram_func(Program);
+
+ uViewportInv = glGetUniformLocation_func(Program, "viewportInv");
+
+ glUseProgram_func(0);
+
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+}
+
+
+int
+main(int argc, char *argv[])
+{
+ glutInit(&argc, argv);
+ glutInitWindowSize(WinWidth, WinHeight);
+ glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
+ Win = glutCreateWindow(argv[0]);
+ glutReshapeFunc(Reshape);
+ glutKeyboardFunc(Key);
+ glutSpecialFunc(SpecialKey);
+ glutDisplayFunc(Redisplay);
+ Init();
+ glutMainLoop();
+ return 0;
+}
+
+
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/glsl/trirast.c b/progs/glsl/trirast.c
new file mode 100644
index 0000000000..e4325deb1f
--- /dev/null
+++ b/progs/glsl/trirast.c
@@ -0,0 +1,326 @@
+/**
+ * Demonstration of doing triangle rasterization with a fragment program.
+ * Basic idea:
+ * 1. Draw screen-aligned quad / bounding box around the triangle verts.
+ * 2. For each pixel in the quad, determine if pixel is inside/outside
+ * the triangle edges.
+ *
+ * Brian Paul
+ * 1 Aug 2007
+ */
+
+
+#include <assert.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include <GL/gl.h>
+#include <GL/glut.h>
+#include <GL/glext.h>
+#include "extfuncs.h"
+
+
+static GLint WinWidth = 300, WinHeight = 300;
+static char *FragProgFile = NULL;
+static char *VertProgFile = NULL;
+static GLuint fragShader;
+static GLuint vertShader;
+static GLuint program;
+static GLint win = 0;
+static GLboolean anim = GL_TRUE;
+static GLfloat Zrot = 0.0f;
+static GLint uv0, uv1, uv2;
+
+
+static const GLfloat TriVerts[3][2] = {
+ { 50, 50 },
+ { 250, 50 },
+ { 150, 250 }
+};
+
+
+static void
+RotateVerts(GLfloat a,
+ GLuint n, const GLfloat vertsIn[][2], GLfloat vertsOut[][2])
+{
+ GLuint i;
+ GLfloat cx = WinWidth / 2, cy = WinHeight / 2;
+ for (i = 0; i < n; i++) {
+ float x = vertsIn[i][0] - cx;
+ float y = vertsIn[i][1] - cy;
+
+ vertsOut[i][0] = x * cos(a) + y * sin(a) + cx;
+ vertsOut[i][1] = -x * sin(a) + y * cos(a) + cy;
+ }
+}
+
+static void
+ComputeBounds(GLuint n, GLfloat vertsIn[][2],
+ GLfloat *xmin, GLfloat *ymin,
+ GLfloat *xmax, GLfloat *ymax)
+{
+ GLuint i;
+ *xmin = *xmax = vertsIn[0][0];
+ *ymin = *ymax = vertsIn[0][1];
+ for (i = 1; i < n; i++) {
+ if (vertsIn[i][0] < *xmin)
+ *xmin = vertsIn[i][0];
+ else if (vertsIn[i][0] > *xmax)
+ *xmax = vertsIn[i][0];
+ if (vertsIn[i][1] < *ymin)
+ *ymin = vertsIn[i][1];
+ else if (vertsIn[i][1] > *ymax)
+ *ymax = vertsIn[i][1];
+ }
+}
+
+
+static void
+Redisplay(void)
+{
+ GLfloat v[3][2], xmin, ymin, xmax, ymax;
+
+ RotateVerts(Zrot, 3, TriVerts, v);
+ ComputeBounds(3, v, &xmin, &ymin, &xmax, &ymax);
+
+ glUniform2fv_func(uv0, 1, v[0]);
+ glUniform2fv_func(uv1, 1, v[1]);
+ glUniform2fv_func(uv2, 1, v[2]);
+
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ glPushMatrix();
+ glBegin(GL_POLYGON);
+ glVertex2f(xmin, ymin);
+ glVertex2f(xmax, ymin);
+ glVertex2f(xmax, ymax);
+ glVertex2f(xmin, ymax);
+ glEnd();
+ glPopMatrix();
+
+ glutSwapBuffers();
+}
+
+
+static void
+Idle(void)
+{
+ Zrot = glutGet(GLUT_ELAPSED_TIME) * 0.0005;
+ glutPostRedisplay();
+}
+
+
+static void
+Reshape(int width, int height)
+{
+ glViewport(0, 0, width, height);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glOrtho(0, width, 0, height, -1, 1);
+
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+}
+
+
+static void
+CleanUp(void)
+{
+ glDeleteShader_func(fragShader);
+ glDeleteShader_func(vertShader);
+ glDeleteProgram_func(program);
+ glutDestroyWindow(win);
+}
+
+
+static void
+Key(unsigned char key, int x, int y)
+{
+ (void) x;
+ (void) y;
+
+ switch(key) {
+ case ' ':
+ case 'a':
+ anim = !anim;
+ if (anim)
+ glutIdleFunc(Idle);
+ else
+ glutIdleFunc(NULL);
+ break;
+ case 27:
+ CleanUp();
+ exit(0);
+ break;
+ }
+ glutPostRedisplay();
+}
+
+
+static void
+LoadAndCompileShader(GLuint shader, const char *text)
+{
+ GLint stat;
+
+ glShaderSource_func(shader, 1, (const GLchar **) &text, NULL);
+
+ glCompileShader_func(shader);
+
+ glGetShaderiv_func(shader, GL_COMPILE_STATUS, &stat);
+ if (!stat) {
+ GLchar log[1000];
+ GLsizei len;
+ glGetShaderInfoLog_func(shader, 1000, &len, log);
+ fprintf(stderr, "fslight: problem compiling shader:\n%s\n", log);
+ exit(1);
+ }
+}
+
+
+/**
+ * Read a shader from a file.
+ */
+static void
+ReadShader(GLuint shader, const char *filename)
+{
+ const int max = 100*1000;
+ int n;
+ char *buffer = (char*) malloc(max);
+ FILE *f = fopen(filename, "r");
+ if (!f) {
+ fprintf(stderr, "fslight: Unable to open shader file %s\n", filename);
+ exit(1);
+ }
+
+ n = fread(buffer, 1, max, f);
+ printf("fslight: read %d bytes from shader file %s\n", n, filename);
+ if (n > 0) {
+ buffer[n] = 0;
+ LoadAndCompileShader(shader, buffer);
+ }
+
+ fclose(f);
+ free(buffer);
+}
+
+
+static void
+CheckLink(GLuint prog)
+{
+ GLint stat;
+ glGetProgramiv_func(prog, GL_LINK_STATUS, &stat);
+ if (!stat) {
+ GLchar log[1000];
+ GLsizei len;
+ glGetProgramInfoLog_func(prog, 1000, &len, log);
+ fprintf(stderr, "Linker error:\n%s\n", log);
+ }
+}
+
+
+static void
+Init(void)
+{
+ static const char *fragShaderText =
+ "uniform vec2 v0, v1, v2; \n"
+ "float crs(const vec2 u, const vec2 v) \n"
+ "{ \n"
+ " return u.x * v.y - u.y * v.x; \n"
+ "} \n"
+ "\n"
+ "void main() {\n"
+ " vec2 p = gl_FragCoord.xy; \n"
+ " if (crs(v1 - v0, p - v0) >= 0 && \n"
+ " crs(v2 - v1, p - v1) >= 0 && \n"
+ " crs(v0 - v2, p - v2) >= 0) \n"
+ " gl_FragColor = vec4(1.0); \n"
+ " else \n"
+ " gl_FragColor = vec4(0.5); \n"
+ "}\n";
+ static const char *vertShaderText =
+ "void main() {\n"
+ " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
+ "}\n";
+ const char *version;
+
+ version = (const char *) glGetString(GL_VERSION);
+ if (version[0] != '2' || version[1] != '.') {
+ printf("This program requires OpenGL 2.x, found %s\n", version);
+ exit(1);
+ }
+
+ GetExtensionFuncs();
+
+ fragShader = glCreateShader_func(GL_FRAGMENT_SHADER);
+ if (FragProgFile)
+ ReadShader(fragShader, FragProgFile);
+ else
+ LoadAndCompileShader(fragShader, fragShaderText);
+
+ vertShader = glCreateShader_func(GL_VERTEX_SHADER);
+ if (VertProgFile)
+ ReadShader(vertShader, VertProgFile);
+ else
+ LoadAndCompileShader(vertShader, vertShaderText);
+
+ program = glCreateProgram_func();
+ glAttachShader_func(program, fragShader);
+ glAttachShader_func(program, vertShader);
+ glLinkProgram_func(program);
+ CheckLink(program);
+ glUseProgram_func(program);
+
+ uv0 = glGetUniformLocation_func(program, "v0");
+ uv1 = glGetUniformLocation_func(program, "v1");
+ uv2 = glGetUniformLocation_func(program, "v2");
+ printf("Uniforms: %d %d %d\n", uv0, uv1, uv2);
+
+ /*assert(glGetError() == 0);*/
+
+ glClearColor(0.3f, 0.3f, 0.3f, 0.0f);
+ glEnable(GL_DEPTH_TEST);
+
+ printf("GL_RENDERER = %s\n",(const char *) glGetString(GL_RENDERER));
+
+ assert(glIsProgram_func(program));
+ assert(glIsShader_func(fragShader));
+ assert(glIsShader_func(vertShader));
+
+ glColor3f(1, 0, 0);
+}
+
+
+static void
+ParseOptions(int argc, char *argv[])
+{
+ int i;
+ for (i = 1; i < argc; i++) {
+ if (strcmp(argv[i], "-fs") == 0) {
+ FragProgFile = argv[i+1];
+ }
+ else if (strcmp(argv[i], "-vs") == 0) {
+ VertProgFile = argv[i+1];
+ }
+ }
+}
+
+
+int
+main(int argc, char *argv[])
+{
+ glutInit(&argc, argv);
+ glutInitWindowPosition( 0, 0);
+ glutInitWindowSize(WinWidth, WinHeight);
+ glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
+ win = glutCreateWindow(argv[0]);
+ glutReshapeFunc(Reshape);
+ glutKeyboardFunc(Key);
+ glutDisplayFunc(Redisplay);
+ if (anim)
+ glutIdleFunc(Idle);
+ ParseOptions(argc, argv);
+ Init();
+ glutMainLoop();
+ return 0;
+}
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/miniglx/Makefile b/progs/miniglx/Makefile
index 7f1e162186..56cecf4081 100644
--- a/progs/miniglx/Makefile
+++ b/progs/miniglx/Makefile
@@ -27,7 +27,7 @@ INCLUDES = \
.SUFFIXES: .c
.c:
- $(CC) $(INCLUDES) $(CFLAGS) $< $(APP_LIB_DEPS) -o $@
+ $(CC) $(INCLUDES) $(CFLAGS) $(LDFLAGS) $< $(APP_LIB_DEPS) -o $@
.c.o:
$(CC) -c $(INCLUDES) $(CFLAGS) $< -o $@
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/osdemos/Makefile b/progs/osdemos/Makefile
index f8cba9ee99..7e657744e3 100644
--- a/progs/osdemos/Makefile
+++ b/progs/osdemos/Makefile
@@ -26,7 +26,7 @@ PROGS = \
# make executable from .c file:
.c: $(LIB_DEP) readtex.o
- $(CC) -I$(INCDIR) $(CFLAGS) $< readtex.o $(APP_LIB_DEPS) -o $@
+ $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) $< readtex.o $(APP_LIB_DEPS) -o $@
##### TARGETS #####
@@ -56,19 +56,19 @@ showbuffer.o: showbuffer.c showbuffer.h
# special case: need the -lOSMesa library:
osdemo: osdemo.c
- $(CC) -I$(INCDIR) $(CFLAGS) osdemo.c $(OSMESA_LIBS) -o $@
+ $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) osdemo.c $(OSMESA_LIBS) -o $@
# special case: need the -lOSMesa library:
ostest1: ostest1.c
- $(CC) -I$(INCDIR) $(CFLAGS) ostest1.c $(OSMESA_LIBS) -o $@
+ $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) ostest1.c $(OSMESA_LIBS) -o $@
# another special case: need the -lOSMesa16 library:
osdemo16: osdemo16.c
- $(CC) -I$(INCDIR) $(CFLAGS) osdemo16.c $(OSMESA16_LIBS) -o $@
+ $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) osdemo16.c $(OSMESA16_LIBS) -o $@
# another special case: need the -lOSMesa32 library:
osdemo32: osdemo32.c
- $(CC) -I$(INCDIR) $(CFLAGS) osdemo32.c $(OSMESA32_LIBS) -o $@
+ $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) osdemo32.c $(OSMESA32_LIBS) -o $@
diff --git a/progs/osdemos/ostest1.c b/progs/osdemos/ostest1.c
index 001e368616..2c7adfc353 100644
--- a/progs/osdemos/ostest1.c
+++ b/progs/osdemos/ostest1.c
@@ -409,6 +409,8 @@ test(GLenum type, GLint bits, const char *filename)
printf("Rendering %d bit/channel image: %s\n", bits, filename);
+ OSMesaColorClamp(GL_TRUE);
+
init_context();
render_image();
if (Gradient)
@@ -421,7 +423,7 @@ test(GLenum type, GLint bits, const char *filename)
if (WriteFiles && filename != NULL) {
if (type == GL_UNSIGNED_SHORT) {
GLushort *buffer16 = (GLushort *) buffer;
- GLubyte *buffer8 = malloc(WIDTH * HEIGHT * 4);
+ GLubyte *buffer8 = (GLubyte *) malloc(WIDTH * HEIGHT * 4);
int i;
for (i = 0; i < WIDTH * HEIGHT * 4; i++)
buffer8[i] = buffer16[i] >> 8;
@@ -430,8 +432,9 @@ test(GLenum type, GLint bits, const char *filename)
}
else if (type == GL_FLOAT) {
GLfloat *buffer32 = (GLfloat *) buffer;
- GLubyte *buffer8 = malloc(WIDTH * HEIGHT * 4);
+ GLubyte *buffer8 = (GLubyte *) malloc(WIDTH * HEIGHT * 4);
int i;
+ /* colors may be outside [0,1] so we need to clamp */
for (i = 0; i < WIDTH * HEIGHT * 4; i++)
buffer8[i] = (GLubyte) (buffer32[i] * 255.0);
write_ppm(filename, buffer8, WIDTH, HEIGHT);
diff --git a/progs/redbook/Makefile b/progs/redbook/Makefile
index febc74441b..078f19125a 100644
--- a/progs/redbook/Makefile
+++ b/progs/redbook/Makefile
@@ -24,7 +24,7 @@ PROGS = aaindex aapoly aargb accanti accpersp alpha alpha3D anti \
.SUFFIXES: .c
.c: $(LIB_DEP)
- $(CC) -I$(INCDIR) $(CFLAGS) $< $(APP_LIB_DEPS) -o $@
+ $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) $< $(APP_LIB_DEPS) -o $@
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/samples/Makefile b/progs/samples/Makefile
index 063008dccf..8c99e8df25 100644
--- a/progs/samples/Makefile
+++ b/progs/samples/Makefile
@@ -18,7 +18,7 @@ PROGS = accum bitmap1 bitmap2 blendeq blendxor copy cursor depth eval fog \
.SUFFIXES: .c
.c: $(LIB_DEP)
- $(CC) -I$(INCDIR) $(CFLAGS) $< $(APP_LIB_DEPS) -o $@
+ $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) $< $(APP_LIB_DEPS) -o $@
##### TARGETS #####
@@ -27,7 +27,7 @@ default: $(PROGS)
sphere: sphere.o readtex.o
- $(CC) -I$(INCDIR) $(CFLAGS) sphere.o readtex.o $(APP_LIB_DEPS) -o $@
+ $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) sphere.o readtex.o $(APP_LIB_DEPS) -o $@
sphere.o: sphere.c readtex.h
$(CC) -c -I$(INCDIR) $(CFLAGS) sphere.c
diff --git a/progs/samples/Makefile.mgw b/progs/samples/Makefile.mgw
index 1193540578..8bb975be9d 100644
--- a/progs/samples/Makefile.mgw
+++ b/progs/samples/Makefile.mgw
@@ -26,6 +26,15 @@
# Email : dborca@users.sourceforge.net
# Web : http://www.geocities.com/dborca
+# MinGW samples makefile updated for Mesa 7.0
+#
+# Updated : by Heromyth, on 2007-7-21
+# Email : zxpmyth@yahoo.com.cn
+# Bugs : 1) All the default settings work fine. But the setting X86=1 can't work.
+# The others havn't been tested yet.
+# 2) The generated DLLs are *not* compatible with the ones built
+# with the other compilers like VC8, especially for GLUT.
+# 3) Although more tests are needed, it can be used individually!
#
# Available options:
@@ -45,14 +54,14 @@
TOP = ../..
CC = mingw32-gcc
-CFLAGS = -Wall -W -pedantic
-CFLAGS += -O2 -ffast-math
+CFLAGS = -Wall -pedantic
+CFLAGS += -O2 -ffast-math -D_DLL
CFLAGS += -I$(TOP)/include -I../util
ifeq ($(FX),1)
-CFLAGS += -DFX
+ CFLAGS += -DFX
endif
-CFLAGS += -DGLUT_DISABLE_ATEXIT_HACK -D_STDCALL_SUPPORTED
-CFLAGS += -D_WINDEF_ -D_WINGDI_
+
+CFLAGS += -DGLUT_DISABLE_ATEXIT_HACK
LD = mingw32-g++
LDFLAGS = -s -L$(TOP)/lib
@@ -62,7 +71,8 @@ LDLIBS = -lglut32 -lglu32 -lopengl32
.c.o:
$(CC) -o $@ $(CFLAGS) -c $<
%.exe: ../util/readtex.o ../util/showbuffer.o %.o
- $(LD) -o $@ $(LDFLAGS) $^ $(LDLIBS)
+ $(LD) -o $@ $(LDFLAGS) $(LDLIBS) $^
+
all:
$(error Must specify <filename.exe> to build)
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/slang/Makefile b/progs/slang/Makefile
index 1c602ce49c..61db26d080 100644
--- a/progs/slang/Makefile
+++ b/progs/slang/Makefile
@@ -29,13 +29,13 @@ clean:
#
cltest: cltest.o framework.o $(LIB_DEP)
- $(CC) cltest.o framework.o $(APP_LIB_DEPS) -o cltest
+ $(CC) $(LDFLAGS) cltest.o framework.o $(APP_LIB_DEPS) -o cltest
sotest: sotest.o framework.o $(LIB_DEP)
- $(CC) sotest.o framework.o $(APP_LIB_DEPS) -o sotest
+ $(CC) $(LDFLAGS) sotest.o framework.o $(APP_LIB_DEPS) -o sotest
vstest: vstest.o framework.o $(LIB_DEP)
- $(CC) vstest.o framework.o $(APP_LIB_DEPS) -o vstest
+ $(CC) $(LDFLAGS) vstest.o framework.o $(APP_LIB_DEPS) -o vstest
#
# objects
diff --git a/progs/tests/.gitignore b/progs/tests/.gitignore
index 2c0e16c35e..eaa67c3a5d 100644
--- a/progs/tests/.gitignore
+++ b/progs/tests/.gitignore
@@ -1,23 +1,31 @@
.cvsignore
-getproclist.h
+afsmultiarb
antialias
arbfpspec
arbfptest1
arbfptexture
arbfptrig
+arbnpot
+arbnpot-mipmap
arbvptest1
arbvptest3
arbvptorus
arbvpwarpmesh
+arraytexture
blendminmax
blendsquare
bufferobj
+bug_3050
bug_3101
bug_3195
+copypixrate
crossbar
cva
dinoshade
+drawbuffers
+extfuncs.h
fbotest1
+fbotest2
fbotexture
floattex
fog
@@ -25,24 +33,38 @@ fogcoord
fptest1
fptexture
getprocaddress
+getproclist.h
+interleave
invert
+jkrahntest
manytex
+mipmap_limits
multipal
no_s3tc
packedpixels
pbo
+prog_parameter
projtex
+random
+readrate
+readtex.c
+readtex.h
seccolor
sharedtex
stencil_wrap
stencilwrap
+subtexrate
tex1d
texcmp
+texcompress2
+texfilt
texgenmix
texline
texobjshare
texrect
texwrap
+vao-01
+vao-02
vparray
vptest1
vptest2
diff --git a/progs/tests/Makefile b/progs/tests/Makefile
index 9016efe9e7..e8d0edda3a 100644
--- a/progs/tests/Makefile
+++ b/progs/tests/Makefile
@@ -88,13 +88,22 @@ INCLUDES = -I. -I$(TOP)/include
UTIL_FILES = readtex.h readtex.c
+##### TARGETS #####
+
+default: $(UTIL_FILES) $(PROGS)
+
+clean:
+ rm -f $(PROGS)
+ rm -f *.o
+ rm -f getproclist.h
+
##### RULES #####
.SUFFIXES:
.SUFFIXES: .c
.c:
- $(CC) $(INCLUDES) $(CFLAGS) $< $(LIBS) -o $@
+ $(CC) $(INCLUDES) $(CFLAGS) $(LDFLAGS) $< $(LIBS) -o $@
.c.o:
$(CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) $< -o $@
@@ -102,17 +111,6 @@ UTIL_FILES = readtex.h readtex.c
.S.o:
$(CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) $< -o $@
-
-##### TARGETS #####
-
-default: $(UTIL_FILES) $(PROGS)
-
-clean:
- rm -f $(PROGS)
- rm -f *.o
- rm -f getproclist.h
-
-
# auto code generation
getprocaddress: getprocaddress.c getproclist.h
@@ -123,40 +121,40 @@ arraytexture: arraytexture.o readtex.o
$(CC) $(CFLAGS) arraytexture.o readtex.o $(LIBS) -o $@
arraytexture.o: arraytexture.c readtex.h
- $(CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) $< -o $@
+ $(CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) arraytexture.c -o $@
afsmultiarb: afsmultiarb.o readtex.o
- $(CC) $(CFLAGS) afsmultiarb.o readtex.o $(LIBS) -o $@
+ $(CC) $(CFLAGS) $(LDFLAGS) afsmultiarb.o readtex.o $(LIBS) -o $@
afsmultiarb.o: afsmultiarb.c readtex.h
- $(CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) $< -o $@
+ $(CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) afsmultiarb.c -o $@
drawbuffers: drawbuffers.o
- $(CC) $(CFLAGS) drawbuffers.o $(LIBS) -o $@
+ $(CC) $(CFLAGS) $(LDFLAGS) drawbuffers.o $(LIBS) -o $@
drawbuffers.o: drawbuffers.c extfuncs.h
- $(CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) $< -o $@
+ $(CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) drawbuffers.c -o $@
texrect: texrect.o readtex.o
- $(CC) $(CFLAGS) texrect.o readtex.o $(LIBS) -o $@
+ $(CC) $(CFLAGS) $(LDFLAGS) texrect.o readtex.o $(LIBS) -o $@
texrect.o: texrect.c readtex.h
- $(CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) $< -o $@
+ $(CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) texrect.c -o $@
bug_3195: bug_3195.o readtex.o
- $(CC) $(CFLAGS) bug_3195.o readtex.o $(LIBS) -o $@
+ $(CC) $(CFLAGS) $(LDFLAGS) bug_3195.o readtex.o $(LIBS) -o $@
bug_3195.o: bug_3195.c readtex.h
- $(CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) $< -o $@
+ $(CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) bug_3195.c -o $@
invert: invert.o readtex.o
- $(CC) $(CFLAGS) invert.o readtex.o $(LIBS) -o $@
+ $(CC) $(CFLAGS) $(LDFLAGS) invert.o readtex.o $(LIBS) -o $@
invert.o: invert.c readtex.h
- $(CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) $< -o $@
+ $(CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) invert.c -o $@
readtex.o: readtex.c
- $(CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) $< -o $@
+ $(CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) readtex.c -o $@
readtex.h: $(TOP)/progs/util/readtex.h
diff --git a/progs/tests/cva.c b/progs/tests/cva.c
index c7677990bf..ed965e748a 100644
--- a/progs/tests/cva.c
+++ b/progs/tests/cva.c
@@ -11,11 +11,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
-#ifdef __VMS
-# include <stddef.h> /* for ptrdiff_t, referenced by GL.h when GL_GLEXT_LEGACY defined */
-#else
-# include <malloc.h> /* for ptrdiff_t, referenced by GL.h when GL_GLEXT_LEGACY defined */
-#endif
+#include <stddef.h> /* for ptrdiff_t, referenced by GL.h when GL_GLEXT_LEGACY defined */
#ifdef _WIN32
#include <windows.h>
#endif
diff --git a/progs/tests/dinoshade.c b/progs/tests/dinoshade.c
index ed7b879bc7..504b4af526 100644
--- a/progs/tests/dinoshade.c
+++ b/progs/tests/dinoshade.c
@@ -38,11 +38,7 @@
#include <stdlib.h>
#include <string.h>
#include <math.h> /* for cos(), sin(), and sqrt() */
-#ifdef __VMS
-# include <stddef.h> /* for ptrdiff_t, referenced by GL.h when GL_GLEXT_LEGACY defined */
-#else
-# include <malloc.h> /* for ptrdiff_t, referenced by GL.h when GL_GLEXT_LEGACY defined */
-#endif
+#include <stddef.h> /* for ptrdiff_t, referenced by GL.h when GL_GLEXT_LEGACY defined */
#ifdef _WIN32
#include <windows.h>
#endif
diff --git a/progs/tests/multipal.c b/progs/tests/multipal.c
index c824b38703..fac652f4e0 100644
--- a/progs/tests/multipal.c
+++ b/progs/tests/multipal.c
@@ -9,11 +9,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#ifdef __VMS
-# include <stddef.h> /* for ptrdiff_t, referenced by GL.h when GL_GLEXT_LEGACY defined */
-#else
-# include <malloc.h> /* for ptrdiff_t, referenced by GL.h when GL_GLEXT_LEGACY defined */
-#endif
+#include <stddef.h> /* for ptrdiff_t, referenced by GL.h when GL_GLEXT_LEGACY defined */
#ifdef _WIN32
#include <windows.h>
#endif
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/tools/trace/Makefile b/progs/tools/trace/Makefile
index 3f7bdcbc93..4b05fd87a5 100644
--- a/progs/tools/trace/Makefile
+++ b/progs/tools/trace/Makefile
@@ -17,7 +17,7 @@ default: $(TRACER)
$(TRACER): $(OBJECTS)
$(TOP)/bin/mklib -o $(TRACER) -noprefix -cplusplus \
- $(MKLIB_OPTIONS) $(OBJECTS)
+ -ldflags '$(LDFLAGS)' $(MKLIB_OPTIONS) $(OBJECTS)
gltrace.cc: gltrace.py
PYTHONPATH=$(TOP)/src/mesa/glapi python gltrace.py -f $(TOP)/src/mesa/glapi/gl_API.xml > 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/trivial/Makefile b/progs/trivial/Makefile
index 341c115c07..259e20aa57 100644
--- a/progs/trivial/Makefile
+++ b/progs/trivial/Makefile
@@ -88,7 +88,7 @@ UTIL_FILES = readtex.h readtex.c
.SUFFIXES: .c
.c:
- $(CC) $(INCLUDES) $(CFLAGS) $< $(LIBS) -o $@
+ $(CC) $(INCLUDES) $(CFLAGS) $(LDFLAGS) $< $(LIBS) -o $@
.c.o:
$(CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) $< -o $@
@@ -115,13 +115,13 @@ getproclist.h: $(TOP)/src/mesa/glapi/gl_API.xml getprocaddress.c getprocaddress.
texrect: texrect.o readtex.o
- $(CC) texrect.o readtex.o $(LIBS) -o $@
+ $(CC) $(LDFLAGS) texrect.o readtex.o $(LIBS) -o $@
texrect.o: texrect.c readtex.h
$(CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) $< -o $@
invert: invert.o readtex.o
- $(CC) invert.o readtex.o $(LIBS) -o $@
+ $(CC) $(LDFLAGS) invert.o readtex.o $(LIBS) -o $@
invert.o: invert.c readtex.h
$(CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) $< -o $@
diff --git a/progs/util/extfuncs.h b/progs/util/extfuncs.h
index 5d647cdae7..716bb7df3b 100644
--- a/progs/util/extfuncs.h
+++ b/progs/util/extfuncs.h
@@ -26,6 +26,13 @@ static PFNGLISSHADERPROC glIsShader_func = NULL;
static PFNGLLINKPROGRAMPROC glLinkProgram_func = NULL;
static PFNGLSHADERSOURCEPROC glShaderSource_func = NULL;
static PFNGLUNIFORM1IPROC glUniform1i_func = NULL;
+static PFNGLUNIFORM2IPROC glUniform2i_func = NULL;
+static PFNGLUNIFORM3IPROC glUniform3i_func = NULL;
+static PFNGLUNIFORM4IPROC glUniform4i_func = NULL;
+static PFNGLUNIFORM1FPROC glUniform1f_func = NULL;
+static PFNGLUNIFORM2FPROC glUniform2f_func = NULL;
+static PFNGLUNIFORM3FPROC glUniform3f_func = NULL;
+static PFNGLUNIFORM4FPROC glUniform4f_func = NULL;
static PFNGLUNIFORM1FVPROC glUniform1fv_func = NULL;
static PFNGLUNIFORM2FVPROC glUniform2fv_func = NULL;
static PFNGLUNIFORM3FVPROC glUniform3fv_func = NULL;
@@ -47,6 +54,9 @@ static PFNGLUNIFORMMATRIX4X2FVPROC glUniformMatrix4x2fv_func = NULL;
static PFNGLUNIFORMMATRIX3X4FVPROC glUniformMatrix3x4fv_func = NULL;
static PFNGLUNIFORMMATRIX4X3FVPROC glUniformMatrix4x3fv_func = NULL;
+/* OpenGL 1.4 */
+static PFNGLPOINTPARAMETERFVPROC glPointParameterfv_func = NULL;
+
/* GL_ARB_vertex/fragment_program */
static PFNGLBINDPROGRAMARBPROC glBindProgramARB_func = NULL;
static PFNGLDELETEPROGRAMSARBPROC glDeleteProgramsARB_func = NULL;
@@ -94,6 +104,13 @@ GetExtensionFuncs(void)
glLinkProgram_func = (PFNGLLINKPROGRAMPROC) glutGetProcAddress("glLinkProgram");
glShaderSource_func = (PFNGLSHADERSOURCEPROC) glutGetProcAddress("glShaderSource");
glUniform1i_func = (PFNGLUNIFORM1IPROC) glutGetProcAddress("glUniform1i");
+ glUniform2i_func = (PFNGLUNIFORM2IPROC) glutGetProcAddress("glUniform2i");
+ glUniform3i_func = (PFNGLUNIFORM3IPROC) glutGetProcAddress("glUniform3i");
+ glUniform4i_func = (PFNGLUNIFORM4IPROC) glutGetProcAddress("glUniform3i");
+ glUniform1f_func = (PFNGLUNIFORM1FPROC) glutGetProcAddress("glUniform1f");
+ glUniform2f_func = (PFNGLUNIFORM2FPROC) glutGetProcAddress("glUniform2f");
+ glUniform3f_func = (PFNGLUNIFORM3FPROC) glutGetProcAddress("glUniform3f");
+ glUniform4f_func = (PFNGLUNIFORM4FPROC) glutGetProcAddress("glUniform3f");
glUniform1fv_func = (PFNGLUNIFORM1FVPROC) glutGetProcAddress("glUniform1fv");
glUniform2fv_func = (PFNGLUNIFORM2FVPROC) glutGetProcAddress("glUniform2fv");
glUniform3fv_func = (PFNGLUNIFORM3FVPROC) glutGetProcAddress("glUniform3fv");
@@ -115,6 +132,8 @@ GetExtensionFuncs(void)
glUniformMatrix3x4fv_func = (PFNGLUNIFORMMATRIX3X4FVPROC) glutGetProcAddress("glUniformMatrix3x4fv");
glUniformMatrix4x3fv_func = (PFNGLUNIFORMMATRIX4X3FVPROC) glutGetProcAddress("glUniformMatrix4x3fv");
+ glPointParameterfv_func = (PFNGLPOINTPARAMETERFVPROC) glutGetProcAddress("glPointParameterfv");
+
/* GL_ARB_vertex/fragment_program */
glBindProgramARB_func = (PFNGLBINDPROGRAMARBPROC) glutGetProcAddress("glBindProgramARB");
glDeleteProgramsARB_func = (PFNGLDELETEPROGRAMSARBPROC) glutGetProcAddress("glDeleteProgramsARB");
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/vp/Makefile b/progs/vp/Makefile
index c3faeb5b60..4952a52fc9 100644
--- a/progs/vp/Makefile
+++ b/progs/vp/Makefile
@@ -26,7 +26,7 @@ INCLUDES = -I. -I$(TOP)/include -I../samples
.SUFFIXES: .c
.c:
- $(CC) $(INCLUDES) $(CFLAGS) $< $(LIBS) -o $@
+ $(CC) $(INCLUDES) $(CFLAGS) $(LDFLAGS) $< $(LIBS) -o $@
.c.o:
$(CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) $< -o $@
diff --git a/progs/xdemos/.gitignore b/progs/xdemos/.gitignore
index 4adffda2d1..25022c112d 100644
--- a/progs/xdemos/.gitignore
+++ b/progs/xdemos/.gitignore
@@ -1,16 +1,23 @@
+corender
glthreads
+glxcontexts
glxdemo
glxgears
+glxgears_fbconfig
glxheads
glxinfo
-glxpixmap
glxpbdemo
+glxpixmap
+glxsnoop
glxswapcontrol
manywin
offset
-pbinfo
+overlay
pbdemo
+pbinfo
+texture_from_pixmap
wincopy
xdemo
xfont
xrotfontdemo
+yuvrect_client
diff --git a/progs/xdemos/Makefile b/progs/xdemos/Makefile
index d1d7fecea1..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 \
@@ -38,7 +41,7 @@ PROGS = glthreads \
.SUFFIXES: .c
.c: $(LIB_DEP)
- $(CC) -I$(INCDIR) $(CFLAGS) $< $(APP_LIB_DEPS) -o $@
+ $(CC) -I$(INCDIR) $(X11_INCLUDES) $(CFLAGS) $(LDFLAGS) $< $(APP_LIB_DEPS) -o $@
##### TARGETS #####
@@ -53,32 +56,40 @@ clean:
# special cases
pbinfo: pbinfo.o pbutil.o
- $(CC) -I$(INCDIR) $(CFLAGS) pbinfo.o pbutil.o $(APP_LIB_DEPS) -o $@
+ $(CC) $(LDFLAGS) pbinfo.o pbutil.o $(APP_LIB_DEPS) -o $@
pbdemo: pbdemo.o pbutil.o
- $(CC) -I$(INCDIR) $(CFLAGS) pbdemo.o pbutil.o $(APP_LIB_DEPS) -o $@
+ $(CC) $(LDFLAGS) pbdemo.o pbutil.o $(APP_LIB_DEPS) -o $@
pbinfo.o: pbinfo.c pbutil.h
- $(CC) -c -I. -I$(INCDIR) $(CFLAGS) pbinfo.c
+ $(CC) -c -I. -I$(INCDIR) $(X11_INCLUDES) $(CFLAGS) pbinfo.c
pbdemo.o: pbdemo.c pbutil.h
- $(CC) -c -I. -I$(INCDIR) $(CFLAGS) pbdemo.c
+ $(CC) -c -I. -I$(INCDIR) $(X11_INCLUDES) $(CFLAGS) pbdemo.c
pbutil.o: pbutil.c pbutil.h
- $(CC) -c -I. -I$(INCDIR) $(CFLAGS) pbutil.c
+ $(CC) -c -I. -I$(INCDIR) $(X11_INCLUDES) $(CFLAGS) pbutil.c
glxgears_fbconfig: glxgears_fbconfig.o pbutil.o
- $(CC) -I$(INCDIR) $(CFLAGS) glxgears_fbconfig.o pbutil.o $(APP_LIB_DEPS) -o $@
+ $(CC) $(LDFLAGS) glxgears_fbconfig.o pbutil.o $(APP_LIB_DEPS) -o $@
glxgears_fbconfig.o: glxgears_fbconfig.c pbutil.h
- $(CC) -I$(INCDIR) $(CFLAGS) -c -I. $(CFLAGS) glxgears_fbconfig.c
+ $(CC) -I$(INCDIR) $(X11_INCLUDES) $(CFLAGS) -c -I. $(CFLAGS) glxgears_fbconfig.c
xrotfontdemo: xrotfontdemo.o xuserotfont.o
- $(CC) -I$(INCDIR) $(CFLAGS) xrotfontdemo.o xuserotfont.o $(APP_LIB_DEPS) -o $@
+ $(CC) $(LDFLAGS) xrotfontdemo.o xuserotfont.o $(APP_LIB_DEPS) -o $@
xuserotfont.o: xuserotfont.c xuserotfont.h
- $(CC) -c -I. -I$(INCDIR) $(CFLAGS) xuserotfont.c
+ $(CC) -c -I. -I$(INCDIR) $(X11_INCLUDES) $(CFLAGS) xuserotfont.c
xrotfontdemo.o: xrotfontdemo.c xuserotfont.h
- $(CC) -c -I. -I$(INCDIR) $(CFLAGS) xrotfontdemo.c
+ $(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/glxgears.c b/progs/xdemos/glxgears.c
index 75d63e51a2..ec431c16f0 100644
--- a/progs/xdemos/glxgears.c
+++ b/progs/xdemos/glxgears.c
@@ -433,7 +433,7 @@ make_window( Display *dpy, const char *name,
attr.override_redirect = fullscreen;
mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect;
- win = XCreateWindow( dpy, root, 0, 0, width, height,
+ win = XCreateWindow( dpy, root, x, y, width, height,
0, visinfo->depth, InputOutput,
visinfo->visual, mask, &attr );
@@ -548,13 +548,16 @@ usage(void)
printf(" -stereo run in stereo mode\n");
printf(" -fullscreen run in fullscreen mode\n");
printf(" -info display OpenGL renderer info\n");
+ printf(" -winwidth <width> window width (default: 300)\n");
+ printf(" -winheight <height> window height (default: 300)\n");
}
int
main(int argc, char *argv[])
{
- const int winWidth = 300, winHeight = 300;
+ unsigned int winWidth = 300, winHeight = 300;
+ int x = 0, y = 0;
Display *dpy;
Window win;
GLXContext ctx;
@@ -576,6 +579,10 @@ main(int argc, char *argv[])
else if (strcmp(argv[i], "-fullscreen") == 0) {
fullscreen = GL_TRUE;
}
+ else if (i < argc-1 && strcmp(argv[i], "-geometry") == 0) {
+ XParseGeometry(argv[i+1], &x, &y, &winWidth, &winHeight);
+ i++;
+ }
else {
usage();
return -1;
@@ -589,7 +596,7 @@ main(int argc, char *argv[])
return -1;
}
- make_window(dpy, "glxgears", 0, 0, winWidth, winHeight, &win, &ctx);
+ make_window(dpy, "glxgears", x, y, winWidth, winHeight, &win, &ctx);
XMapWindow(dpy, win);
glXMakeCurrent(dpy, win, ctx);
diff --git a/progs/xdemos/glxinfo.c b/progs/xdemos/glxinfo.c
index 3e8e0be520..db7d1ed08e 100644
--- a/progs/xdemos/glxinfo.c
+++ b/progs/xdemos/glxinfo.c
@@ -52,6 +52,13 @@
#define GLX_TRANSPARENT_RGB 0x8008
#endif
+#ifndef GLX_RGBA_BIT
+#define GLX_RGBA_BIT 0x00000001
+#endif
+
+#ifndef GLX_COLOR_INDEX_BIT
+#define GLX_COLOR_INDEX_BIT 0x00000002
+#endif
typedef enum
{
@@ -81,7 +88,7 @@ struct visual_attribs
int transparentIndexValue;
int bufferSize;
int level;
- int rgba;
+ int render_type;
int doubleBuffer;
int stereo;
int auxBuffers;
@@ -388,20 +395,61 @@ print_screen_info(Display *dpy, int scrnum, Bool allowDirect, GLboolean limits)
XSetWindowAttributes attr;
unsigned long mask;
Window root;
- GLXContext ctx;
+ GLXContext ctx = NULL;
XVisualInfo *visinfo;
int width = 100, height = 100;
root = RootWindow(dpy, scrnum);
visinfo = glXChooseVisual(dpy, scrnum, attribSingle);
- if (!visinfo) {
+ if (!visinfo)
visinfo = glXChooseVisual(dpy, scrnum, attribDouble);
- if (!visinfo) {
- fprintf(stderr, "Error: couldn't find RGB GLX visual\n");
- return;
+
+ if (visinfo)
+ ctx = glXCreateContext( dpy, visinfo, NULL, allowDirect );
+
+#ifdef GLX_VERSION_1_3
+ {
+ int fbAttribSingle[] = {
+ GLX_RENDER_TYPE, GLX_RGBA_BIT,
+ GLX_RED_SIZE, 1,
+ GLX_GREEN_SIZE, 1,
+ GLX_BLUE_SIZE, 1,
+ GLX_DOUBLEBUFFER, GL_TRUE,
+ None };
+ int fbAttribDouble[] = {
+ GLX_RENDER_TYPE, GLX_RGBA_BIT,
+ GLX_RED_SIZE, 1,
+ GLX_GREEN_SIZE, 1,
+ GLX_BLUE_SIZE, 1,
+ None };
+ GLXFBConfig *configs = NULL;
+ int nConfigs;
+
+ if (!visinfo)
+ configs = glXChooseFBConfig(dpy, scrnum, fbAttribSingle, &nConfigs);
+ if (!visinfo)
+ configs = glXChooseFBConfig(dpy, scrnum, fbAttribDouble, &nConfigs);
+
+ if (configs) {
+ visinfo = glXGetVisualFromFBConfig(dpy, configs[0]);
+ ctx = glXCreateNewContext(dpy, configs[0], GLX_RGBA_TYPE, NULL, allowDirect);
+ XFree(configs);
}
}
+#endif
+
+ if (!visinfo) {
+ fprintf(stderr, "Error: couldn't find RGB GLX visual or fbconfig\n");
+ return;
+ }
+
+ if (!ctx) {
+ fprintf(stderr, "Error: glXCreateContext failed\n");
+ XFree(visinfo);
+ XDestroyWindow(dpy, win);
+ return;
+ }
attr.background_pixel = 0;
attr.border_pixel = 0;
@@ -412,14 +460,6 @@ print_screen_info(Display *dpy, int scrnum, Bool allowDirect, GLboolean limits)
0, visinfo->depth, InputOutput,
visinfo->visual, mask, &attr);
- ctx = glXCreateContext( dpy, visinfo, NULL, allowDirect );
- if (!ctx) {
- fprintf(stderr, "Error: glXCreateContext failed\n");
- XFree(visinfo);
- XDestroyWindow(dpy, win);
- return;
- }
-
if (glXMakeCurrent(dpy, win, ctx)) {
const char *serverVendor = glXQueryServerString(dpy, scrnum, GLX_VENDOR);
const char *serverVersion = glXQueryServerString(dpy, scrnum, GLX_VERSION);
@@ -541,12 +581,27 @@ visual_class_abbrev(int cls)
}
}
+static const char *
+visual_render_type_name(int type)
+{
+ switch (type) {
+ case GLX_RGBA_BIT:
+ return "rgba";
+ case GLX_COLOR_INDEX_BIT:
+ return "ci";
+ case GLX_RGBA_BIT | GLX_COLOR_INDEX_BIT:
+ return "rgba|ci";
+ default:
+ return "";
+ }
+}
-static void
+static GLboolean
get_visual_attribs(Display *dpy, XVisualInfo *vInfo,
struct visual_attribs *attribs)
{
const char *ext = glXQueryExtensionsString(dpy, vInfo->screen);
+ int rgba;
memset(attribs, 0, sizeof(struct visual_attribs));
@@ -563,11 +618,17 @@ get_visual_attribs(Display *dpy, XVisualInfo *vInfo,
attribs->colormapSize = vInfo->colormap_size;
attribs->bitsPerRGB = vInfo->bits_per_rgb;
- if (glXGetConfig(dpy, vInfo, GLX_USE_GL, &attribs->supportsGL) != 0)
- return;
+ if (glXGetConfig(dpy, vInfo, GLX_USE_GL, &attribs->supportsGL) != 0 ||
+ !attribs->supportsGL)
+ return GL_FALSE;
glXGetConfig(dpy, vInfo, GLX_BUFFER_SIZE, &attribs->bufferSize);
glXGetConfig(dpy, vInfo, GLX_LEVEL, &attribs->level);
- glXGetConfig(dpy, vInfo, GLX_RGBA, &attribs->rgba);
+ glXGetConfig(dpy, vInfo, GLX_RGBA, &rgba);
+ if (rgba)
+ attribs->render_type = GLX_RGBA_BIT;
+ else
+ attribs->render_type = GLX_COLOR_INDEX_BIT;
+
glXGetConfig(dpy, vInfo, GLX_DOUBLEBUFFER, &attribs->doubleBuffer);
glXGetConfig(dpy, vInfo, GLX_STEREO, &attribs->stereo);
glXGetConfig(dpy, vInfo, GLX_AUX_BUFFERS, &attribs->auxBuffers);
@@ -616,8 +677,97 @@ get_visual_attribs(Display *dpy, XVisualInfo *vInfo,
#else
attribs->visualCaveat = 0;
#endif
+
+ return GL_TRUE;
}
+#ifdef GLX_VERSION_1_3
+
+static int
+glx_token_to_visual_class(int visual_type)
+{
+ switch (visual_type) {
+ case GLX_TRUE_COLOR:
+ return TrueColor;
+ case GLX_DIRECT_COLOR:
+ return DirectColor;
+ case GLX_PSEUDO_COLOR:
+ return PseudoColor;
+ case GLX_STATIC_COLOR:
+ return StaticColor;
+ case GLX_GRAY_SCALE:
+ return GrayScale;
+ case GLX_STATIC_GRAY:
+ return StaticGray;
+ case GLX_NONE:
+ default:
+ return None;
+ }
+}
+
+static GLboolean
+get_fbconfig_attribs(Display *dpy, GLXFBConfig fbconfig,
+ struct visual_attribs *attribs)
+{
+ int visual_type;
+
+ memset(attribs, 0, sizeof(struct visual_attribs));
+
+ glXGetFBConfigAttrib(dpy, fbconfig, GLX_FBCONFIG_ID, &attribs->id);
+
+#if 0
+ attribs->depth = vInfo->depth;
+ attribs->redMask = vInfo->red_mask;
+ attribs->greenMask = vInfo->green_mask;
+ attribs->blueMask = vInfo->blue_mask;
+ attribs->colormapSize = vInfo->colormap_size;
+ attribs->bitsPerRGB = vInfo->bits_per_rgb;
+#endif
+
+ glXGetFBConfigAttrib(dpy, fbconfig, GLX_X_VISUAL_TYPE, &visual_type);
+ attribs->klass = glx_token_to_visual_class(visual_type);
+
+ glXGetFBConfigAttrib(dpy, fbconfig, GLX_BUFFER_SIZE, &attribs->bufferSize);
+ glXGetFBConfigAttrib(dpy, fbconfig, GLX_LEVEL, &attribs->level);
+ glXGetFBConfigAttrib(dpy, fbconfig, GLX_RENDER_TYPE, &attribs->render_type);
+ glXGetFBConfigAttrib(dpy, fbconfig, GLX_DOUBLEBUFFER, &attribs->doubleBuffer);
+ glXGetFBConfigAttrib(dpy, fbconfig, GLX_STEREO, &attribs->stereo);
+ glXGetFBConfigAttrib(dpy, fbconfig, GLX_AUX_BUFFERS, &attribs->auxBuffers);
+
+ glXGetFBConfigAttrib(dpy, fbconfig, GLX_RED_SIZE, &attribs->redSize);
+ glXGetFBConfigAttrib(dpy, fbconfig, GLX_GREEN_SIZE, &attribs->greenSize);
+ glXGetFBConfigAttrib(dpy, fbconfig, GLX_BLUE_SIZE, &attribs->blueSize);
+ glXGetFBConfigAttrib(dpy, fbconfig, GLX_ALPHA_SIZE, &attribs->alphaSize);
+ glXGetFBConfigAttrib(dpy, fbconfig, GLX_DEPTH_SIZE, &attribs->depthSize);
+ glXGetFBConfigAttrib(dpy, fbconfig, GLX_STENCIL_SIZE, &attribs->stencilSize);
+
+ glXGetFBConfigAttrib(dpy, fbconfig, GLX_ACCUM_RED_SIZE, &attribs->accumRedSize);
+ glXGetFBConfigAttrib(dpy, fbconfig, GLX_ACCUM_GREEN_SIZE, &attribs->accumGreenSize);
+ glXGetFBConfigAttrib(dpy, fbconfig, GLX_ACCUM_BLUE_SIZE, &attribs->accumBlueSize);
+ glXGetFBConfigAttrib(dpy, fbconfig, GLX_ACCUM_ALPHA_SIZE, &attribs->accumAlphaSize);
+
+ /* get transparent pixel stuff */
+ glXGetFBConfigAttrib(dpy, fbconfig,GLX_TRANSPARENT_TYPE, &attribs->transparentType);
+ if (attribs->transparentType == GLX_TRANSPARENT_RGB) {
+ glXGetFBConfigAttrib(dpy, fbconfig, GLX_TRANSPARENT_RED_VALUE, &attribs->transparentRedValue);
+ glXGetFBConfigAttrib(dpy, fbconfig, GLX_TRANSPARENT_GREEN_VALUE, &attribs->transparentGreenValue);
+ glXGetFBConfigAttrib(dpy, fbconfig, GLX_TRANSPARENT_BLUE_VALUE, &attribs->transparentBlueValue);
+ glXGetFBConfigAttrib(dpy, fbconfig, GLX_TRANSPARENT_ALPHA_VALUE, &attribs->transparentAlphaValue);
+ }
+ else if (attribs->transparentType == GLX_TRANSPARENT_INDEX) {
+ glXGetFBConfigAttrib(dpy, fbconfig, GLX_TRANSPARENT_INDEX_VALUE, &attribs->transparentIndexValue);
+ }
+
+ glXGetFBConfigAttrib(dpy, fbconfig, GLX_SAMPLE_BUFFERS, &attribs->numMultisample);
+ glXGetFBConfigAttrib(dpy, fbconfig, GLX_SAMPLES, &attribs->numSamples);
+ glXGetFBConfigAttrib(dpy, fbconfig, GLX_CONFIG_CAVEAT, &attribs->visualCaveat);
+
+ return GL_TRUE;
+}
+
+#endif
+
+
static void
print_visual_attribs_verbose(const struct visual_attribs *attribs)
@@ -625,7 +775,8 @@ print_visual_attribs_verbose(const struct visual_attribs *attribs)
printf("Visual ID: %x depth=%d class=%s\n",
attribs->id, attribs->depth, visual_class_name(attribs->klass));
printf(" bufferSize=%d level=%d renderType=%s doubleBuffer=%d stereo=%d\n",
- attribs->bufferSize, attribs->level, attribs->rgba ? "rgba" : "ci",
+ attribs->bufferSize, attribs->level,
+ visual_render_type_name(attribs->render_type),
attribs->doubleBuffer, attribs->stereo);
printf(" rgba: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n",
attribs->redSize, attribs->greenSize,
@@ -683,16 +834,17 @@ print_visual_attribs_short(const struct visual_attribs *attribs)
caveat = "None";
#endif
- printf("0x%2x %2d %2s %2d %2d %2d %1s %2s %2s %2d %2d %2d %2d %2d %2d %2d",
+ printf("0x%02x %2d %2s %2d %2d %2d %c%c %c %c %2d %2d %2d %2d %2d %2d %2d",
attribs->id,
attribs->depth,
visual_class_abbrev(attribs->klass),
attribs->transparentType != GLX_NONE,
attribs->bufferSize,
attribs->level,
- attribs->rgba ? "r" : "c",
- attribs->doubleBuffer ? "y" : ".",
- attribs->stereo ? "y" : ".",
+ (attribs->render_type & GLX_RGBA_BIT) ? 'r' : ' ',
+ (attribs->render_type & GLX_COLOR_INDEX_BIT) ? 'c' : ' ',
+ attribs->doubleBuffer ? 'y' : '.',
+ attribs->stereo ? 'y' : '.',
attribs->redSize, attribs->greenSize,
attribs->blueSize, attribs->alphaSize,
attribs->auxBuffers,
@@ -728,7 +880,7 @@ print_visual_attribs_long(const struct visual_attribs *attribs)
attribs->transparentType != GLX_NONE,
attribs->bufferSize,
attribs->level,
- attribs->rgba ? "rgba" : "ci ",
+ visual_render_type_name(attribs->render_type),
attribs->doubleBuffer,
attribs->stereo,
attribs->redSize, attribs->greenSize,
@@ -751,42 +903,86 @@ print_visual_info(Display *dpy, int scrnum, InfoMode mode)
{
XVisualInfo theTemplate;
XVisualInfo *visuals;
- int numVisuals;
+ int numVisuals, numGlxVisuals;
long mask;
int i;
+ struct visual_attribs attribs;
/* get list of all visuals on this screen */
theTemplate.screen = scrnum;
mask = VisualScreenMask;
visuals = XGetVisualInfo(dpy, mask, &theTemplate, &numVisuals);
- if (mode == Verbose) {
- for (i = 0; i < numVisuals; i++) {
- struct visual_attribs attribs;
- get_visual_attribs(dpy, &visuals[i], &attribs);
- print_visual_attribs_verbose(&attribs);
- }
+ numGlxVisuals = 0;
+ for (i = 0; i < numVisuals; i++) {
+ if (get_visual_attribs(dpy, &visuals[i], &attribs))
+ numGlxVisuals++;
}
- else if (mode == Normal) {
+
+ if (numGlxVisuals == 0)
+ return;
+
+ printf("%d GLX Visuals\n", numGlxVisuals);
+
+ if (mode == Normal)
print_visual_attribs_short_header();
- for (i = 0; i < numVisuals; i++) {
- struct visual_attribs attribs;
- get_visual_attribs(dpy, &visuals[i], &attribs);
+ else if (mode == Wide)
+ print_visual_attribs_long_header();
+
+ for (i = 0; i < numVisuals; i++) {
+ if (!get_visual_attribs(dpy, &visuals[i], &attribs))
+ continue;
+
+ if (mode == Verbose)
+ print_visual_attribs_verbose(&attribs);
+ else if (mode == Normal)
print_visual_attribs_short(&attribs);
- }
+ else if (mode == Wide)
+ print_visual_attribs_long(&attribs);
}
- else if (mode == Wide) {
+ printf("\n");
+
+ XFree(visuals);
+}
+
+#ifdef GLX_VERSION_1_3
+
+static void
+print_fbconfig_info(Display *dpy, int scrnum, InfoMode mode)
+{
+ int numFBConfigs;
+ struct visual_attribs attribs;
+ GLXFBConfig *fbconfigs;
+ int i;
+
+ /* get list of all fbconfigs on this screen */
+ fbconfigs = glXGetFBConfigs(dpy, scrnum, &numFBConfigs);
+
+ if (numFBConfigs == 0)
+ return;
+
+ printf("%d GLXFBConfigs:\n", numFBConfigs);
+ if (mode == Normal)
+ print_visual_attribs_short_header();
+ else if (mode == Wide)
print_visual_attribs_long_header();
- for (i = 0; i < numVisuals; i++) {
- struct visual_attribs attribs;
- get_visual_attribs(dpy, &visuals[i], &attribs);
+
+ for (i = 0; i < numFBConfigs; i++) {
+ get_fbconfig_attribs(dpy, fbconfigs[i], &attribs);
+
+ if (mode == Verbose)
+ print_visual_attribs_verbose(&attribs);
+ else if (mode == Normal)
+ print_visual_attribs_short(&attribs);
+ else if (mode == Wide)
print_visual_attribs_long(&attribs);
- }
}
+ printf("\n");
- XFree(visuals);
+ XFree(fbconfigs);
}
+#endif
/*
* Stand-alone Mesa doesn't really implement the GLX protocol so it
@@ -860,7 +1056,7 @@ find_best_visual(Display *dpy, int scrnum)
/* see if this vis is better than bestVis */
if ((!bestVis.supportsGL && vis.supportsGL) ||
(bestVis.visualCaveat != GLX_NONE_EXT) ||
- (!bestVis.rgba && vis.rgba) ||
+ (!(bestVis.render_type & GLX_RGBA_BIT) && (vis.render_type & GLX_RGBA_BIT)) ||
(!bestVis.doubleBuffer && vis.doubleBuffer) ||
(bestVis.redSize < vis.redSize) ||
(bestVis.greenSize < vis.greenSize) ||
@@ -957,6 +1153,9 @@ main(int argc, char *argv[])
print_screen_info(dpy, scrnum, allowDirect, limits);
printf("\n");
print_visual_info(dpy, scrnum, mode);
+#ifdef GLX_VERSION_1_3
+ print_fbconfig_info(dpy, scrnum, mode);
+#endif
if (scrnum + 1 < numScreens)
printf("\n\n");
}
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/glxswapcontrol.c b/progs/xdemos/glxswapcontrol.c
index d9be984be5..e429d58ecc 100644
--- a/progs/xdemos/glxswapcontrol.c
+++ b/progs/xdemos/glxswapcontrol.c
@@ -814,6 +814,11 @@ main(int argc, char *argv[])
init();
+ /* Set initial projection/viewing transformation.
+ * same as glxgears.c
+ */
+ reshape(300, 300);
+
event_loop(dpy, win);
glXDestroyContext(dpy, ctx);
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 */
diff --git a/progs/xdemos/pbdemo.c b/progs/xdemos/pbdemo.c
index efdfdfa452..7db0017b33 100644
--- a/progs/xdemos/pbdemo.c
+++ b/progs/xdemos/pbdemo.c
@@ -93,7 +93,7 @@ MakePbuffer( Display *dpy, int screen, int width, int height )
None
},
{
- /* Single bufferd, without depth buffer */
+ /* Single buffered, without depth buffer */
GLX_RENDER_TYPE, GLX_RGBA_BIT,
GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT,
GLX_RED_SIZE, 1,
@@ -105,7 +105,7 @@ MakePbuffer( Display *dpy, int screen, int width, int height )
None
},
{
- /* Double bufferd, without depth buffer */
+ /* Double buffered, without depth buffer */
GLX_RENDER_TYPE, GLX_RGBA_BIT,
GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT,
GLX_RED_SIZE, 1,
@@ -130,9 +130,8 @@ MakePbuffer( Display *dpy, int screen, int width, int height )
/* Get list of possible frame buffer configurations */
fbConfigs = ChooseFBConfig(dpy, screen, fbAttribs[attempt], &nConfigs);
if (nConfigs==0 || !fbConfigs) {
- printf("Error: glXChooseFBConfig failed\n");
- XCloseDisplay(dpy);
- return 0;
+ printf("Note: glXChooseFBConfig(%s) failed\n", fbString[attempt]);
+ continue;
}
#if 0 /*DEBUG*/
diff --git a/progs/xdemos/pbutil.c b/progs/xdemos/pbutil.c
index d0bbd1b0fc..ce133d012d 100644
--- a/progs/xdemos/pbutil.c
+++ b/progs/xdemos/pbutil.c
@@ -18,12 +18,12 @@
* Test if we pixel buffers are available for a particular X screen.
* Input: dpy - the X display
* screen - screen number
- * Return: 0 = pixel buffers not available.
- * 1 = pixel buffers are available via GLX 1.3.
- * 2 = pixel buffers are available via GLX_SGIX_fbconfig/pbuffer.
+ * Return: 0 = fbconfigs not available.
+ * 1 = fbconfigs are available via GLX 1.3.
+ * 2 = fbconfigs and pbuffers are available via GLX_SGIX_fbconfig
*/
int
-QueryPbuffers(Display *dpy, int screen)
+QueryFBConfig(Display *dpy, int screen)
{
#if defined(GLX_VERSION_1_3)
{
@@ -40,36 +40,55 @@ QueryPbuffers(Display *dpy, int screen)
}
#endif
-#if defined(GLX_SGIX_fbconfig) && defined(GLX_SGIX_pbuffer)
/* Try the SGIX extensions */
{
char *extensions;
extensions = (char *) glXQueryServerString(dpy, screen, GLX_EXTENSIONS);
- if (!extensions ||
- !strstr(extensions,"GLX_SGIX_fbconfig") ||
- !strstr(extensions,"GLX_SGIX_pbuffer")) {
- return 0;
+ if (extensions && strstr(extensions,"GLX_SGIX_fbconfig")) {
+ return 2;
}
- return 2;
}
-#endif
return 0;
}
+/**
+ * Test if we pixel buffers are available for a particular X screen.
+ * Input: dpy - the X display
+ * screen - screen number
+ * Return: 0 = pixel buffers not available.
+ * 1 = pixel buffers are available via GLX 1.3.
+ * 2 = pixel buffers are available via GLX_SGIX_fbconfig/pbuffer.
+ */
+int
+QueryPbuffers(Display *dpy, int screen)
+{
+ int ret;
+ ret = QueryFBConfig(dpy, screen);
+ if (ret == 2) {
+ char *extensions;
+ extensions = (char *) glXQueryServerString(dpy, screen, GLX_EXTENSIONS);
+ if (extensions && strstr(extensions, "GLX_SGIX_pbuffer"))
+ return 2;
+ else
+ return 0;
+ }
+ else
+ return ret;
+}
FBCONFIG *
ChooseFBConfig(Display *dpy, int screen, const int attribs[], int *nConfigs)
{
- int pbSupport = QueryPbuffers(dpy, screen);
+ int fbcSupport = QueryPbuffers(dpy, screen);
#if defined(GLX_VERSION_1_3)
- if (pbSupport == 1) {
+ if (fbcSupport == 1) {
return glXChooseFBConfig(dpy, screen, attribs, nConfigs);
}
#endif
#if defined(GLX_SGIX_fbconfig) && defined(GLX_SGIX_pbuffer)
- if (pbSupport == 2) {
+ if (fbcSupport == 2) {
return glXChooseFBConfigSGIX(dpy, screen, (int *) attribs, nConfigs);
}
#endif
@@ -80,14 +99,14 @@ ChooseFBConfig(Display *dpy, int screen, const int attribs[], int *nConfigs)
FBCONFIG *
GetAllFBConfigs(Display *dpy, int screen, int *nConfigs)
{
- int pbSupport = QueryPbuffers(dpy, screen);
+ int fbcSupport = QueryFBConfig(dpy, screen);
#if defined(GLX_VERSION_1_3)
- if (pbSupport == 1) {
+ if (fbcSupport == 1) {
return glXGetFBConfigs(dpy, screen, nConfigs);
}
#endif
#if defined(GLX_SGIX_fbconfig) && defined(GLX_SGIX_pbuffer)
- if (pbSupport == 2) {
+ if (fbcSupport == 2) {
/* The GLX_SGIX_fbconfig extensions says to pass NULL to get list
* of all available configurations.
*/
@@ -101,14 +120,14 @@ GetAllFBConfigs(Display *dpy, int screen, int *nConfigs)
XVisualInfo *
GetVisualFromFBConfig(Display *dpy, int screen, FBCONFIG config)
{
- int pbSupport = QueryPbuffers(dpy, screen);
+ int fbcSupport = QueryFBConfig(dpy, screen);
#if defined(GLX_VERSION_1_3)
- if (pbSupport == 1) {
+ if (fbcSupport == 1) {
return glXGetVisualFromFBConfig(dpy, config);
}
#endif
#if defined(GLX_SGIX_fbconfig) && defined(GLX_SGIX_pbuffer)
- if (pbSupport == 2) {
+ if (fbcSupport == 2) {
return glXGetVisualFromFBConfigSGIX(dpy, config);
}
#endif
@@ -130,11 +149,11 @@ GetFBConfigAttrib(Display *dpy, int screen,
int attrib
)
{
- int pbSupport = QueryPbuffers(dpy, screen);
+ int fbcSupport = QueryFBConfig(dpy, screen);
int value = 0;
#if defined(GLX_VERSION_1_3)
- if (pbSupport == 1) {
+ if (fbcSupport == 1) {
/* ok */
if (glXGetFBConfigAttrib(dpy, config, attrib, &value) != 0) {
value = 0;
@@ -145,7 +164,7 @@ GetFBConfigAttrib(Display *dpy, int screen,
#endif
#if defined(GLX_SGIX_fbconfig) && defined(GLX_SGIX_pbuffer)
- if (pbSupport == 2) {
+ if (fbcSupport == 2) {
if (glXGetFBConfigAttribSGIX(dpy, config, attrib, &value) != 0) {
value = 0;
}
@@ -295,9 +314,9 @@ PrintFBConfigInfo(Display *dpy, int screen, FBCONFIG config, Bool horizFormat)
GLXContext
CreateContext(Display *dpy, int screen, FBCONFIG config)
{
- int pbSupport = QueryPbuffers(dpy, screen);
+ int fbcSupport = QueryFBConfig(dpy, screen);
#if defined(GLX_VERSION_1_3)
- if (pbSupport == 1) {
+ if (fbcSupport == 1) {
/* GLX 1.3 */
GLXContext c;
c = glXCreateNewContext(dpy, config, GLX_RGBA_TYPE, NULL, True);
@@ -309,7 +328,7 @@ CreateContext(Display *dpy, int screen, FBCONFIG config)
}
#endif
#if defined(GLX_SGIX_fbconfig) && defined(GLX_SGIX_pbuffer)
- if (pbSupport == 2) {
+ if (fbcSupport == 2) {
GLXContext c;
c = glXCreateContextWithConfigSGIX(dpy, config, GLX_RGBA_TYPE_SGIX, NULL, True);
if (!c) {
@@ -393,6 +412,7 @@ CreatePbuffer(Display *dpy, int screen, FBCONFIG config,
pBuffer = None;
}
+ XSync(dpy, False);
/* Restore original X error handler */
(void) XSetErrorHandler(oldHandler);
diff --git a/progs/xdemos/pbutil.h b/progs/xdemos/pbutil.h
index e95b2565a2..d420522ff0 100644
--- a/progs/xdemos/pbutil.h
+++ b/progs/xdemos/pbutil.h
@@ -27,6 +27,9 @@
extern int
+QueryFBConfig(Display *dpy, int screen);
+
+extern int
QueryPbuffers(Display *dpy, int screen);