From 414a933ad24e11e9655dc00ae55d8753f2021fe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Fonseca?= Date: Fri, 19 Oct 2007 11:37:45 +0100 Subject: Ignore generated files. --- progs/xdemos/.gitignore | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'progs/xdemos') diff --git a/progs/xdemos/.gitignore b/progs/xdemos/.gitignore index 4adffda2d1..250bc17d98 100644 --- a/progs/xdemos/.gitignore +++ b/progs/xdemos/.gitignore @@ -1,16 +1,21 @@ glthreads +glxcontexts glxdemo glxgears +glxgears_fbconfig glxheads glxinfo -glxpixmap glxpbdemo +glxpixmap glxswapcontrol manywin offset -pbinfo +overlay pbdemo +pbinfo +texture_from_pixmap wincopy xdemo xfont xrotfontdemo +yuvrect_client -- cgit v1.2.3 From 918ea5168baaecdf70f5ea37e5815cacf9558163 Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Mon, 29 Oct 2007 19:50:10 +0000 Subject: Rename 'mms-config.' to 'mms.config'. It looks like Windows does not like filenames ending with a dot, in effect renaming it to 'mms-config'. --- progs/xdemos/descrip.mms | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'progs/xdemos') diff --git a/progs/xdemos/descrip.mms b/progs/xdemos/descrip.mms index aa74daff59..fe6a3c44e6 100644 --- a/progs/xdemos/descrip.mms +++ b/progs/xdemos/descrip.mms @@ -5,7 +5,7 @@ .first define gl [--.include.gl] -.include [--]mms-config. +.include [--]mms.config ##### MACROS ##### -- cgit v1.2.3 From 2d38d1b3005c02273abf3941df5dddc245a6b792 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Fonseca?= Date: Mon, 25 Feb 2008 17:11:28 +0900 Subject: Remove files of unsupported build systems. --- progs/xdemos/descrip.mms | 83 ------------------------------------------------ 1 file changed, 83 deletions(-) delete mode 100644 progs/xdemos/descrip.mms (limited to 'progs/xdemos') diff --git a/progs/xdemos/descrip.mms b/progs/xdemos/descrip.mms deleted file mode 100644 index fe6a3c44e6..0000000000 --- a/progs/xdemos/descrip.mms +++ /dev/null @@ -1,83 +0,0 @@ -# Makefile for GLUT-based demo programs for VMS -# contributed by Jouk Jansen joukj@hrem.stm.tudelft.nl - - -.first - define gl [--.include.gl] - -.include [--]mms.config - -##### MACROS ##### - -INCDIR = ([--.include],[-.util]) -CFLAGS = /include=$(INCDIR)/prefix=all/name=(as_is,short)/nowarn/float=ieee/ieee=denorm - -.ifdef SHARE -GL_LIBS = $(XLIBS) -.else -GL_LIBS = [--.lib]libGLUT/l,libMesaGLU/l,libMesaGL/l,$(XLIBS) -.endif - -LIB_DEP = [--.lib]$(GL_LIB) [--.lib]$(GLU_LIB) [--.lib]$(GLUT_LIB) - -PROGS =glthreads.exe,\ - glxdemo.exe,\ - glxgears.exe,\ - glxheads.exe,\ - glxinfo.exe,\ - glxpixmap.exe,\ - manywin.exe,\ - offset.exe,\ - pbinfo.exe,\ - pbdemo.exe,\ - wincopy.exe,\ - xdemo.exe,\ - xfont.exe - -##### RULES ##### -.obj.exe : - cxxlink $(MMS$TARGET_NAME),$(GL_LIBS) - -##### TARGETS ##### -default : - $(MMS)$(MMSQUALIFIERS) $(PROGS) - -clean : - delete *.obj;* - -realclean : - delete $(PROGS) - delete *.obj;* - - -glthreads.exe : glthreads.obj $(LIB_DEP) -glxdemo.exe : glxdemo.obj $(LIB_DEP) -glxgears.exe : glxgears.obj $(LIB_DEP) -glxheads.exe : glxheads.obj $(LIB_DEP) -glxinfo.exe : glxinfo.obj $(LIB_DEP) -glxpixmap.exe : glxpixmap.obj $(LIB_DEP) -manywin.exe : manywin.obj $(LIB_DEP) -offset.exe : offset.obj $(LIB_DEP) -pbinfo.exe : pbinfo.obj pbutil.obj $(LIB_DEP) - cxxlink pbinfo.obj,pbutil.obj,$(GL_LIBS) -pbdemo.exe : pbdemo.obj pbutil.obj $(LIB_DEP) - cxxlink pbdemo.obj,pbutil.obj,$(GL_LIBS) -wincopy.exe : wincopy.obj $(LIB_DEP) -xdemo.exe : xdemo.obj $(LIB_DEP) -xfont.exe :xfont.obj $(LIB_DEP) - - -glthreads.obj : glthreads.c -glxdemo.obj : glxdemo.c -glxgears.obj : glxgears.c -glxheads.obj : glxheads.c -glxinfo.obj : glxinfo.c -glxpixmap.obj : glxpixmap.c -manywin.obj : manywin.c -offset.obj : offset.c -pbinfo.obj : pbinfo.c -pbutil.obj : pbutil.c -pbdemo.obj : pbdemo.c -wincopy.obj : wincopy.c -xdemo.obj : xdemo.c -xfont.obj :xfont.c -- cgit v1.2.3 From 07b551f7cfc02cb16225298414b145b306b360b4 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 30 Apr 2008 14:43:28 -0600 Subject: added xdemos/sharedtex.c test Test that modifications to a texture object in one rendering context are seen in a second rendering context. Press 't' to change the texture's image/colors. --- progs/xdemos/Makefile | 1 + progs/xdemos/sharedtex.c | 324 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 325 insertions(+) create mode 100644 progs/xdemos/sharedtex.c (limited to 'progs/xdemos') diff --git a/progs/xdemos/Makefile b/progs/xdemos/Makefile index d1d7fecea1..896b160878 100644 --- a/progs/xdemos/Makefile +++ b/progs/xdemos/Makefile @@ -23,6 +23,7 @@ PROGS = glthreads \ overlay \ pbinfo \ pbdemo \ + sharedtex \ texture_from_pixmap \ wincopy \ xfont \ diff --git a/progs/xdemos/sharedtex.c b/progs/xdemos/sharedtex.c new file mode 100644 index 0000000000..81703fe0e7 --- /dev/null +++ b/progs/xdemos/sharedtex.c @@ -0,0 +1,324 @@ +/* + * Test sharing of texture objects by two rendering contexts. + * In particular, test that changing a texture object in one context + * effects the texture in the second context. + * + * Brian Paul + * 30 Apr 2008 + * + * Copyright (C) 2008 Brian Paul All Rights Reserved. + * + * 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 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 + * BRIAN PAUL 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. + */ + + +#include +#include +#include +#include +#include +#include +#include +#include + + +#define MAX_CONTEXTS 2 + +#define TEX_SIZE 32 + +static const char *DisplayName = NULL; +static Display *Dpy; +static XVisualInfo *VisInfo; +static Window Win; +static GLXContext Contexts[MAX_CONTEXTS]; +static int WinWidth = 300, WinHeight = 300; + +static int DrawContext = 0, TexContext = 1; + +static GLuint TexObj = 0; +static GLboolean NewTexture = GL_FALSE; + + +static void +Error(const char *msg) +{ + fprintf(stderr, "sharedtex error: %s\n", msg); + exit(1); +} + + +static void +CreateWindow(const char *name) +{ + int attrib[] = { GLX_RGBA, + GLX_RED_SIZE, 1, + GLX_GREEN_SIZE, 1, + GLX_BLUE_SIZE, 1, + GLX_DOUBLEBUFFER, + None }; + int scrnum; + XSetWindowAttributes attr; + unsigned long mask; + Window root; + int xpos = 0, ypos = 0; + static int n = 0; + + scrnum = DefaultScreen(Dpy); + root = RootWindow(Dpy, scrnum); + + VisInfo = glXChooseVisual(Dpy, scrnum, attrib); + if (!VisInfo) { + Error("Unable to find RGB, double-buffered visual"); + } + + /* window attributes */ + xpos = (n % 10) * 100; + ypos = (n / 10) * 100; + n++; + + 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, xpos, ypos, WinWidth, WinHeight, + 0, VisInfo->depth, InputOutput, + VisInfo->visual, mask, &attr); + if (!Win) { + Error("Couldn't create window"); + } + + { + XSizeHints sizehints; + sizehints.x = xpos; + sizehints.y = ypos; + sizehints.width = WinWidth; + sizehints.height = WinHeight; + sizehints.flags = USSize | USPosition; + XSetNormalHints(Dpy, Win, &sizehints); + XSetStandardProperties(Dpy, Win, name, name, + None, (char **)NULL, 0, &sizehints); + } + + XMapWindow(Dpy, Win); +} + + +/** + * Change texture image, using TexContext + */ +static void +ModifyTexture(void) +{ + GLuint tex[TEX_SIZE][TEX_SIZE]; + GLuint c0, c1; + int i, j; + + if (Win && !glXMakeCurrent(Dpy, Win, Contexts[TexContext])) { + Error("glXMakeCurrent failed"); + } + + /* choose two random colors */ + c0 = rand() & 0xffffffff; + c1 = rand() & 0xffffffff; + + for (i = 0; i < TEX_SIZE; i++) { + for (j = 0; j < TEX_SIZE; j++) { + if (((i / 4) ^ (j / 4)) & 1) { + tex[i][j] = c0; + } + else { + tex[i][j] = c1; + } + } + } + + glBindTexture(GL_TEXTURE_2D, TexObj); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TEX_SIZE, TEX_SIZE, 0, + GL_RGBA, GL_UNSIGNED_BYTE, tex); + + NewTexture = GL_TRUE; +} + + +static void +InitContext(void) +{ + glGenTextures(1, &TexObj); + assert(TexObj); + glBindTexture(GL_TEXTURE_2D, TexObj); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glEnable(GL_TEXTURE_2D); + + printf("GL_RENDERER = %s\n", (char*) glGetString(GL_RENDERER)); +} + + +static void +Setup(void) +{ + int i; + + Dpy = XOpenDisplay(DisplayName); + if (!Dpy) { + Error("Unable to open display"); + } + + CreateWindow("sharedtex"); + + for (i = 0; i < MAX_CONTEXTS; i++) { + GLXContext share = i > 0 ? Contexts[0] : 0; + + Contexts[i] = glXCreateContext(Dpy, VisInfo, share, True); + if (!Contexts[i]) { + Error("Unable to create GLX context"); + } + + if (!glXMakeCurrent(Dpy, Win, Contexts[i])) { + Error("glXMakeCurrent failed"); + } + + InitContext(); + } + + ModifyTexture(); +} + + +/** + * Redraw window, using DrawContext + */ +static void +Redraw(void) +{ + static float rot = 0.0; + float ar; + + rot += 1.0; + + if (Win && !glXMakeCurrent(Dpy, Win, Contexts[DrawContext])) { + Error("glXMakeCurrent failed"); + } + + glViewport(0, 0, WinWidth, WinHeight); + ar = (float) WinWidth / (float) WinHeight; + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-ar, ar, -1.0, 1.0, -1.0, 1.0); + glMatrixMode(GL_MODELVIEW); + + glShadeModel(GL_FLAT); + glClearColor(0.5, 0.5, 0.5, 1.0); + glClear(GL_COLOR_BUFFER_BIT); + + glPushMatrix(); + glRotatef(rot, 0, 0, 1); + glScalef(0.7, 0.7, 0.7); + + if (NewTexture) { + /* rebind to get new contents */ + glBindTexture(GL_TEXTURE_2D, TexObj); + NewTexture = GL_FALSE; + } + + /* draw textured quad */ + glBegin(GL_POLYGON); + glTexCoord2f( 0.0, 0.0 ); glVertex2f( -1.0, -1.0 ); + glTexCoord2f( 1.0, 0.0 ); glVertex2f( 1.0, -1.0 ); + glTexCoord2f( 1.0, 1.0 ); glVertex2f( 1.0, 1.0 ); + glTexCoord2f( 0.0, 1.0 ); glVertex2f( -1.0, 1.0 ); + glEnd(); + + glPopMatrix(); + + if (Win) + glXSwapBuffers(Dpy, Win); +} + + +static void +EventLoop(void) +{ + while (1) { + while (XPending(Dpy) > 0) { + XEvent event; + XNextEvent(Dpy, &event); + + switch (event.type) { + case Expose: + Redraw(); + break; + case ConfigureNotify: + WinWidth = event.xconfigure.width; + WinHeight = event.xconfigure.height; + break; + case KeyPress: + { + char buf[100]; + KeySym keySym; + XComposeStatus stat; + XLookupString(&event.xkey, buf, sizeof(buf), &keySym, &stat); + switch (keySym) { + case XK_Escape: + exit(0); + break; + case XK_t: + case XK_T: + ModifyTexture(); + break; + default: + ; + } + } + Redraw(); + break; + default: + /*no-op*/ ; + } + } + + Redraw(); + usleep(10000); + } +} + + + + +int +main(int argc, char *argv[]) +{ + int i; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-display") == 0 && i < argc) { + DisplayName = argv[i+1]; + i++; + } + } + + Setup(); + + printf("Press 't' to change texture image/colors\n"); + + EventLoop(); + + return 0; +} -- cgit v1.2.3 From f34a30bf791b7126b13abaa1965c70ff9633f38e Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 7 May 2008 11:56:24 -0600 Subject: mesa: add texturing to thread test Run with -t to enable texture mapping. Press 't' to update the texture image. When the texture is changed in one thread it should also get updated in the other threads since textures are shared by all contexts. --- progs/xdemos/glthreads.c | 304 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 237 insertions(+), 67 deletions(-) (limited to 'progs/xdemos') diff --git a/progs/xdemos/glthreads.c b/progs/xdemos/glthreads.c index 989697fbca..767aef9e41 100644 --- a/progs/xdemos/glthreads.c +++ b/progs/xdemos/glthreads.c @@ -24,18 +24,33 @@ * This program tests GLX thread safety. * Command line options: * -p Open a display connection for each thread + * -l Enable application-side locking * -n Number of threads to create (default is 2) * -display Specify X display (default is :0.0) + * -t Use texture mapping * * Brian Paul 20 July 2000 */ +/* + * Notes: + * - Each thread gets its own GLX context. + * + * - The GLX contexts share texture objects. + * + * - When 't' is pressed to update the texture image, the window/thread which + * has input focus is signalled to change the texture. The other threads + * should see the updated texture the next time they call glBindTexture. + */ + + #if defined(PTHREADS) /* defined by Mesa on Linux and other platforms */ #include #include #include +#include #include #include #include @@ -55,6 +70,8 @@ struct winthread { float Angle; int WinWidth, WinHeight; GLboolean NewSize; + GLboolean Initialized; + GLboolean MakeNewTexture; }; @@ -65,8 +82,13 @@ static volatile GLboolean ExitFlag = GL_FALSE; static GLboolean MultiDisplays = 0; static GLboolean Locking = 0; +static GLboolean Texture = GL_FALSE; +static GLuint TexObj = 12; +static GLboolean Animate = GL_TRUE; static pthread_mutex_t Mutex; +static pthread_cond_t CondVar; +static pthread_mutex_t CondMutex; static void @@ -77,6 +99,59 @@ Error(const char *msg) } +static void +signal_redraw(void) +{ + pthread_mutex_lock(&CondMutex); + pthread_cond_broadcast(&CondVar); + pthread_mutex_unlock(&CondMutex); +} + + +static void +MakeNewTexture(struct winthread *wt) +{ +#define TEX_SIZE 128 + static float step = 0.0; + GLfloat image[TEX_SIZE][TEX_SIZE][4]; + GLint width; + int i, j; + + for (j = 0; j < TEX_SIZE; j++) { + for (i = 0; i < TEX_SIZE; i++) { + float dt = 5.0 * (j - 0.5 * TEX_SIZE) / TEX_SIZE; + float ds = 5.0 * (i - 0.5 * TEX_SIZE) / TEX_SIZE; + float r = dt * dt + ds * ds + step; + image[j][i][0] = + image[j][i][1] = + image[j][i][2] = 0.75 + 0.25 * cos(r); + image[j][i][3] = 1.0; + } + } + + step += 0.5; + + glBindTexture(GL_TEXTURE_2D, TexObj); + + glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width); + if (width) { + assert(width == TEX_SIZE); + /* sub-tex replace */ + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, TEX_SIZE, TEX_SIZE, + GL_RGBA, GL_FLOAT, image); + } + else { + /* create new */ + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TEX_SIZE, TEX_SIZE, 0, + GL_RGBA, GL_FLOAT, image); + } +} + + + /* draw a colored cube */ static void draw_object(void) @@ -85,52 +160,61 @@ draw_object(void) glScalef(0.75, 0.75, 0.75); glColor3f(1, 0, 0); - glBegin(GL_POLYGON); - glVertex3f(1, -1, -1); - glVertex3f(1, 1, -1); - glVertex3f(1, 1, 1); - glVertex3f(1, -1, 1); - glEnd(); + if (Texture) { + glBindTexture(GL_TEXTURE_2D, TexObj); + glEnable(GL_TEXTURE_2D); + } + else { + glDisable(GL_TEXTURE_2D); + } + + glBegin(GL_QUADS); + + /* -X */ glColor3f(0, 1, 1); - glBegin(GL_POLYGON); - glVertex3f(-1, -1, -1); - glVertex3f(-1, 1, -1); - glVertex3f(-1, 1, 1); - glVertex3f(-1, -1, 1); - glEnd(); + glTexCoord2f(0, 0); glVertex3f(-1, -1, -1); + glTexCoord2f(1, 0); glVertex3f(-1, 1, -1); + glTexCoord2f(1, 1); glVertex3f(-1, 1, 1); + glTexCoord2f(0, 1); glVertex3f(-1, -1, 1); - glColor3f(0, 1, 0); - glBegin(GL_POLYGON); - glVertex3f(-1, 1, -1); - glVertex3f( 1, 1, -1); - glVertex3f( 1, 1, 1); - glVertex3f(-1, 1, 1); - glEnd(); + /* +X */ + glColor3f(1, 0, 0); + glTexCoord2f(0, 0); glVertex3f(1, -1, -1); + glTexCoord2f(1, 0); glVertex3f(1, 1, -1); + glTexCoord2f(1, 1); glVertex3f(1, 1, 1); + glTexCoord2f(0, 1); glVertex3f(1, -1, 1); + /* -Y */ glColor3f(1, 0, 1); - glBegin(GL_POLYGON); - glVertex3f(-1, -1, -1); - glVertex3f( 1, -1, -1); - glVertex3f( 1, -1, 1); - glVertex3f(-1, -1, 1); - glEnd(); + glTexCoord2f(0, 0); glVertex3f(-1, -1, -1); + glTexCoord2f(1, 0); glVertex3f( 1, -1, -1); + glTexCoord2f(1, 1); glVertex3f( 1, -1, 1); + glTexCoord2f(0, 1); glVertex3f(-1, -1, 1); - glColor3f(0, 0, 1); - glBegin(GL_POLYGON); - glVertex3f(-1, -1, 1); - glVertex3f( 1, -1, 1); - glVertex3f( 1, 1, 1); - glVertex3f(-1, 1, 1); - glEnd(); + /* +Y */ + glColor3f(0, 1, 0); + glTexCoord2f(0, 0); glVertex3f(-1, 1, -1); + glTexCoord2f(1, 0); glVertex3f( 1, 1, -1); + glTexCoord2f(1, 1); glVertex3f( 1, 1, 1); + glTexCoord2f(0, 1); glVertex3f(-1, 1, 1); + /* -Z */ glColor3f(1, 1, 0); - glBegin(GL_POLYGON); - glVertex3f(-1, -1, -1); - glVertex3f( 1, -1, -1); - glVertex3f( 1, 1, -1); - glVertex3f(-1, 1, -1); + glTexCoord2f(0, 0); glVertex3f(-1, -1, -1); + glTexCoord2f(1, 0); glVertex3f( 1, -1, -1); + glTexCoord2f(1, 1); glVertex3f( 1, 1, -1); + glTexCoord2f(0, 1); glVertex3f(-1, 1, -1); + + /* +Y */ + glColor3f(0, 0, 1); + glTexCoord2f(0, 0); glVertex3f(-1, -1, 1); + glTexCoord2f(1, 0); glVertex3f( 1, -1, 1); + glTexCoord2f(1, 1); glVertex3f( 1, 1, 1); + glTexCoord2f(0, 1); glVertex3f(-1, 1, 1); + glEnd(); + glPopMatrix(); } @@ -142,6 +226,8 @@ resize(struct winthread *wt, int w, int h) wt->NewSize = GL_TRUE; wt->WinWidth = w; wt->WinHeight = h; + if (!Animate) + signal_redraw(); } @@ -151,18 +237,19 @@ resize(struct winthread *wt, int w, int h) static void draw_loop(struct winthread *wt) { - GLboolean firstIter = GL_TRUE; - while (!ExitFlag) { if (Locking) pthread_mutex_lock(&Mutex); glXMakeCurrent(wt->Dpy, wt->Win, wt->Context); - if (firstIter) { + if (!wt->Initialized) { printf("glthreads: %d: GL_RENDERER = %s\n", wt->Index, (char *) glGetString(GL_RENDERER)); - firstIter = GL_FALSE; + if (Texture /*&& wt->Index == 0*/) { + MakeNewTexture(wt); + } + wt->Initialized = GL_TRUE; } if (Locking) @@ -182,10 +269,15 @@ draw_loop(struct winthread *wt) wt->NewSize = GL_FALSE; } + if (wt->MakeNewTexture) { + MakeNewTexture(wt); + wt->MakeNewTexture = GL_FALSE; + } + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); - glRotatef(wt->Angle, 0, 0, 1); + glRotatef(wt->Angle, 0, 1, 0); glRotatef(wt->Angle, 1, 0, 0); glScalef(0.7, 0.7, 0.7); draw_object(); @@ -199,12 +291,63 @@ draw_loop(struct winthread *wt) if (Locking) pthread_mutex_unlock(&Mutex); - usleep(5000); + if (Animate) { + usleep(5000); + } + else { + /* wait for signal to draw */ + pthread_mutex_lock(&CondMutex); + pthread_cond_wait(&CondVar, &CondMutex); + pthread_mutex_unlock(&CondMutex); + } wt->Angle += 1.0; } } +static void +keypress(XEvent *event, struct winthread *wt) +{ + char buf[100]; + KeySym keySym; + XComposeStatus stat; + + XLookupString(&event->xkey, buf, sizeof(buf), &keySym, &stat); + + switch (keySym) { + case XK_Escape: + /* tell all threads to exit */ + if (!Animate) { + signal_redraw(); + } + ExitFlag = GL_TRUE; + /*printf("exit draw_loop %d\n", wt->Index);*/ + return; + case XK_t: + case XK_T: + if (Texture) { + wt->MakeNewTexture = GL_TRUE; + if (!Animate) + signal_redraw(); + } + break; + case XK_a: + case XK_A: + Animate = !Animate; + if (Animate) /* yes, prev Animate state! */ + signal_redraw(); + break; + case XK_s: + case XK_S: + if (!Animate) + signal_redraw(); + break; + default: + ; /* nop */ + } +} + + /* * The main process thread runs this loop. * Single display connection for all threads. @@ -250,10 +393,14 @@ event_loop(Display *dpy) } break; case KeyPress: - /* tell all threads to exit */ - ExitFlag = GL_TRUE; - /*printf("exit draw_loop %d\n", wt->Index);*/ - return; + for (i = 0; i < NumWinThreads; i++) { + struct winthread *wt = &WinThreads[i]; + if (event.xkey.window == wt->Win) { + keypress(&event, wt); + break; + } + } + break; default: /*no-op*/ ; } @@ -281,12 +428,10 @@ event_loop_multi(void) resize(wt, event.xconfigure.width, event.xconfigure.height); break; case KeyPress: - /* tell all threads to exit */ - ExitFlag = GL_TRUE; - /*printf("exit draw_loop %d\n", wt->Index);*/ - return; + keypress(&event, wt); + break; default: - /*no-op*/ ; + ; /* nop */ } } w = (w + 1) % NumWinThreads; @@ -300,7 +445,7 @@ event_loop_multi(void) * we'll call this once for each thread, before the threads are created. */ static void -create_window(struct winthread *wt) +create_window(struct winthread *wt, GLXContext shareCtx) { Window win; GLXContext ctx; @@ -316,9 +461,9 @@ create_window(struct winthread *wt) unsigned long mask; Window root; XVisualInfo *visinfo; - int width = 80, height = 80; - int xpos = (wt->Index % 10) * 90; - int ypos = (wt->Index / 10) * 100; + int width = 160, height = 160; + int xpos = (wt->Index % 8) * (width + 10); + int ypos = (wt->Index / 8) * (width + 20); scrnum = DefaultScreen(wt->Dpy); root = RootWindow(wt->Dpy, scrnum); @@ -355,7 +500,7 @@ create_window(struct winthread *wt) } - ctx = glXCreateContext(wt->Dpy, visinfo, NULL, True); + ctx = glXCreateContext(wt->Dpy, visinfo, shareCtx, True); if (!ctx) { Error("Couldn't create GLX context"); } @@ -405,6 +550,23 @@ clean_up(void) } +static void +usage(void) +{ + printf("glthreads: test of GL thread safety (any key = exit)\n"); + printf("Usage:\n"); + printf(" glthreads [options]\n"); + printf("Options:\n"); + printf(" -display DISPLAYNAME Specify display string\n"); + printf(" -n NUMTHREADS Number of threads to create\n"); + printf(" -p Use a separate display connection for each thread\n"); + printf(" -l Use application-side locking\n"); + printf(" -t Enable texturing\n"); + printf("Keyboard:\n"); + printf(" Esc Exit\n"); + printf(" t Change texture image (requires -t option)\n"); +} + int main(int argc, char *argv[]) @@ -416,9 +578,7 @@ main(int argc, char *argv[]) Status threadStat; if (argc == 1) { - printf("glthreads: test of GL thread safety (any key = exit)\n"); - printf("Usage:\n"); - printf(" glthreads [-display dpyName] [-n numthreads]\n"); + usage(); } else { int i; @@ -433,6 +593,9 @@ main(int argc, char *argv[]) else if (strcmp(argv[i], "-l") == 0) { Locking = 1; } + else if (strcmp(argv[i], "-t") == 0) { + Texture = 1; + } else if (strcmp(argv[i], "-n") == 0 && i + 1 < argc) { numThreads = atoi(argv[i + 1]); if (numThreads < 1) @@ -442,13 +605,14 @@ main(int argc, char *argv[]) i++; } else { - fprintf(stderr, "glthreads: unexpected flag: %s\n", argv[i]); + usage(); + exit(1); } } } if (Locking) - printf("glthreads: Using explict locks around Xlib calls.\n"); + printf("glthreads: Using explicit locks around Xlib calls.\n"); else printf("glthreads: No explict locking.\n"); @@ -478,9 +642,9 @@ main(int argc, char *argv[]) } } - if (Locking) { - pthread_mutex_init(&Mutex, NULL); - } + pthread_mutex_init(&Mutex, NULL); + pthread_mutex_init(&CondMutex, NULL); + pthread_cond_init(&CondVar, NULL); printf("glthreads: creating windows\n"); @@ -488,6 +652,8 @@ main(int argc, char *argv[]) /* Create the GLX windows and contexts */ for (i = 0; i < numThreads; i++) { + GLXContext share; + if (MultiDisplays) { WinThreads[i].Dpy = XOpenDisplay(displayName); assert(WinThreads[i].Dpy); @@ -496,7 +662,11 @@ main(int argc, char *argv[]) WinThreads[i].Dpy = dpy; } WinThreads[i].Index = i; - create_window(&WinThreads[i]); + WinThreads[i].Initialized = GL_FALSE; + + share = (Texture && i > 0) ? WinThreads[0].Context : 0; + + create_window(&WinThreads[i], share); } printf("glthreads: creating threads\n"); @@ -505,7 +675,7 @@ main(int argc, char *argv[]) for (i = 0; i < numThreads; i++) { pthread_create(&WinThreads[i].Thread, NULL, thread_function, (void*) &WinThreads[i]); - printf("glthreads: Created thread %u\n", (unsigned int) WinThreads[i].Thread); + printf("glthreads: Created thread %p\n", (void *) WinThreads[i].Thread); } if (MultiDisplays) -- cgit v1.2.3 From 8f76459f62aaf6f3a130e9be75aa7fe565406d28 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 7 May 2008 11:57:03 -0600 Subject: mesa: document a/s keys --- progs/xdemos/glthreads.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'progs/xdemos') diff --git a/progs/xdemos/glthreads.c b/progs/xdemos/glthreads.c index 767aef9e41..b90e6b4f31 100644 --- a/progs/xdemos/glthreads.c +++ b/progs/xdemos/glthreads.c @@ -565,6 +565,8 @@ usage(void) printf("Keyboard:\n"); printf(" Esc Exit\n"); printf(" t Change texture image (requires -t option)\n"); + printf(" a Toggle animation\n"); + printf(" s Step rotation (when not animating)\n"); } -- cgit v1.2.3 From f869ddf29771253e9f7634384a7354eb14f4cadd Mon Sep 17 00:00:00 2001 From: Zack Rusin Date: Tue, 20 May 2008 19:18:22 -0400 Subject: add new binaries to ignore to make 'git status' cleaner --- progs/xdemos/.gitignore | 1 + 1 file changed, 1 insertion(+) (limited to 'progs/xdemos') diff --git a/progs/xdemos/.gitignore b/progs/xdemos/.gitignore index 250bc17d98..34551101cb 100644 --- a/progs/xdemos/.gitignore +++ b/progs/xdemos/.gitignore @@ -13,6 +13,7 @@ offset overlay pbdemo pbinfo +sharedtex texture_from_pixmap wincopy xdemo -- cgit v1.2.3 From 77ce568ff704e6cdcfaa557965c894752d19e462 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Fonseca?= Date: Mon, 26 May 2008 20:14:40 +0900 Subject: Remove CVS keywords. --- progs/xdemos/vgears.c | 1 - 1 file changed, 1 deletion(-) (limited to 'progs/xdemos') diff --git a/progs/xdemos/vgears.c b/progs/xdemos/vgears.c index 13d030a8be..f579e8b421 100644 --- a/progs/xdemos/vgears.c +++ b/progs/xdemos/vgears.c @@ -1,4 +1,3 @@ -/* $ID$ */ /* * Spinning gears demo for Linux SVGA/Mesa interface in 32K color mode. -- cgit v1.2.3 From d8de01ba4138d603a2ffcd1ae3cd13186cdb98e3 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 4 Jun 2008 16:54:26 -0600 Subject: sync up with glxgears.c from master --- progs/xdemos/glxgears.c | 196 ++++++++++++++++++++++++++++++------------------ 1 file changed, 121 insertions(+), 75 deletions(-) (limited to 'progs/xdemos') diff --git a/progs/xdemos/glxgears.c b/progs/xdemos/glxgears.c index 75d63e51a2..c98c3157b5 100644 --- a/progs/xdemos/glxgears.c +++ b/progs/xdemos/glxgears.c @@ -88,12 +88,18 @@ current_time(void) #endif +/** Event handler results: */ +#define NOP 0 +#define EXIT 1 +#define DRAW 2 + static GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0; static GLint gear1, gear2, gear3; static GLfloat angle = 0.0; static GLboolean fullscreen = GL_FALSE; /* Create a single fullscreen window */ static GLboolean stereo = GL_FALSE; /* Enable stereo. */ +static GLboolean animate = GL_TRUE; /* Animation */ static GLfloat eyesep = 5.0; /* Eye separation. */ static GLfloat fix_point = 40.0; /* Fixation point distance. */ static GLfloat left, right, asp; /* Stereo frustum params. */ @@ -239,7 +245,7 @@ gear(GLfloat inner_radius, GLfloat outer_radius, GLfloat width, static void -do_draw(void) +draw(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -269,8 +275,9 @@ do_draw(void) glPopMatrix(); } + static void -draw(void) +draw_gears(void) { if (stereo) { /* First left eye. */ @@ -284,7 +291,7 @@ draw(void) glPushMatrix(); glTranslated(+0.5 * eyesep, 0.0, 0.0); - do_draw(); + draw(); glPopMatrix(); /* Then right eye. */ @@ -298,10 +305,50 @@ draw(void) glPushMatrix(); glTranslated(-0.5 * eyesep, 0.0, 0.0); - do_draw(); + draw(); glPopMatrix(); - } else - do_draw(); + } + else { + draw(); + } +} + + +/** Draw single frame, do SwapBuffers, compute FPS */ +static void +draw_frame(Display *dpy, Window win) +{ + static int frames = 0; + static double tRot0 = -1.0, tRate0 = -1.0; + double dt, t = current_time(); + + if (tRot0 < 0.0) + tRot0 = t; + dt = t - tRot0; + tRot0 = t; + + if (animate) { + /* advance rotation for next frame */ + angle += 70.0 * dt; /* 70 degrees per second */ + if (angle > 3600.0) + angle -= 3600.0; + } + + draw_gears(); + glXSwapBuffers(dpy, win); + + frames++; + + if (tRate0 < 0.0) + tRate0 = t; + if (t - tRate0 >= 5.0) { + GLfloat seconds = t - tRate0; + GLfloat fps = frames / seconds; + printf("%d frames in %3.1f seconds = %6.3f FPS\n", frames, seconds, + fps); + tRate0 = t; + frames = 0; + } } @@ -319,7 +366,8 @@ reshape(int width, int height) left = -5.0 * ((w - 0.5 * eyesep) / fix_point); right = 5.0 * ((w + 0.5 * eyesep) / fix_point); - } else { + } + else { GLfloat h = (GLfloat) height / (GLfloat) width; glMatrixMode(GL_PROJECTION); @@ -430,10 +478,11 @@ make_window( Display *dpy, const char *name, attr.border_pixel = 0; attr.colormap = XCreateColormap( dpy, root, visinfo->visual, AllocNone); attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask; + /* XXX this is a bad way to get a borderless window! */ 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 ); @@ -463,79 +512,70 @@ make_window( Display *dpy, const char *name, } +/** + * Handle one X event. + * \return NOP, EXIT or DRAW + */ +static int +handle_event(Display *dpy, Window win, XEvent *event) +{ + switch (event->type) { + case Expose: + return DRAW; + case ConfigureNotify: + reshape(event->xconfigure.width, event->xconfigure.height); + break; + case KeyPress: + { + char buffer[10]; + int r, code; + code = XLookupKeysym(&event->xkey, 0); + if (code == XK_Left) { + view_roty += 5.0; + } + else if (code == XK_Right) { + view_roty -= 5.0; + } + else if (code == XK_Up) { + view_rotx += 5.0; + } + else if (code == XK_Down) { + view_rotx -= 5.0; + } + else { + r = XLookupString(&event->xkey, buffer, sizeof(buffer), + NULL, NULL); + if (buffer[0] == 27) { + /* escape */ + return EXIT; + } + else if (buffer[0] == 'a' || buffer[0] == 'A') { + animate = !animate; + } + } + return DRAW; + } + } + return NOP; +} + + static void event_loop(Display *dpy, Window win) { while (1) { - while (XPending(dpy) > 0) { + int op; + while (!animate || XPending(dpy) > 0) { XEvent event; XNextEvent(dpy, &event); - switch (event.type) { - case Expose: - /* we'll redraw below */ - break; - case ConfigureNotify: - reshape(event.xconfigure.width, event.xconfigure.height); - break; - case KeyPress: - { - char buffer[10]; - int r, code; - code = XLookupKeysym(&event.xkey, 0); - if (code == XK_Left) { - view_roty += 5.0; - } - else if (code == XK_Right) { - view_roty -= 5.0; - } - else if (code == XK_Up) { - view_rotx += 5.0; - } - else if (code == XK_Down) { - view_rotx -= 5.0; - } - else { - r = XLookupString(&event.xkey, buffer, sizeof(buffer), - NULL, NULL); - if (buffer[0] == 27) { - /* escape */ - return; - } - } - } - } + op = handle_event(dpy, win, &event); + if (op == EXIT) + return; + else if (op == DRAW) + break; } - { - static int frames = 0; - static double tRot0 = -1.0, tRate0 = -1.0; - double dt, t = current_time(); - if (tRot0 < 0.0) - tRot0 = t; - dt = t - tRot0; - tRot0 = t; - - /* advance rotation for next frame */ - angle += 70.0 * dt; /* 70 degrees per second */ - if (angle > 3600.0) - angle -= 3600.0; - - draw(); - glXSwapBuffers(dpy, win); - - frames++; - - if (tRate0 < 0.0) - tRate0 = t; - if (t - tRate0 >= 5.0) { - GLfloat seconds = t - tRate0; - GLfloat fps = frames / seconds; - printf("%d frames in %3.1f seconds = %6.3f FPS\n", frames, seconds, - fps); - tRate0 = t; - frames = 0; - } - } + draw_frame(dpy, win); } } @@ -548,13 +588,15 @@ usage(void) printf(" -stereo run in stereo mode\n"); printf(" -fullscreen run in fullscreen mode\n"); printf(" -info display OpenGL renderer info\n"); + printf(" -geometry WxH+X+Y window geometry\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 +618,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 +635,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); -- cgit v1.2.3 From 90c93bbeeec1a8ca75b68004afc5d8cb689860bc Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Thu, 11 Sep 2008 11:00:54 -0600 Subject: define new APP_CC configuration variable for building apps/demos/tests For Cell, need to use different compilers for the libraries vs. the demos/tests to avoid strange link error regarding "_Unwind_GetIPInfo@GCC_4.2.0" --- progs/xdemos/Makefile | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'progs/xdemos') diff --git a/progs/xdemos/Makefile b/progs/xdemos/Makefile index 896b160878..38f3884d58 100644 --- a/progs/xdemos/Makefile +++ b/progs/xdemos/Makefile @@ -39,7 +39,7 @@ PROGS = glthreads \ .SUFFIXES: .c .c: $(LIB_DEP) - $(CC) -I$(INCDIR) $(CFLAGS) $< $(APP_LIB_DEPS) -o $@ + $(APP_CC) -I$(INCDIR) $(CFLAGS) $< $(APP_LIB_DEPS) -o $@ ##### TARGETS ##### @@ -54,32 +54,32 @@ clean: # special cases pbinfo: pbinfo.o pbutil.o - $(CC) -I$(INCDIR) $(CFLAGS) pbinfo.o pbutil.o $(APP_LIB_DEPS) -o $@ + $(APP_CC) -I$(INCDIR) $(CFLAGS) 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 $@ + $(APP_CC) -I$(INCDIR) $(CFLAGS) pbdemo.o pbutil.o $(APP_LIB_DEPS) -o $@ pbinfo.o: pbinfo.c pbutil.h - $(CC) -c -I. -I$(INCDIR) $(CFLAGS) pbinfo.c + $(APP_CC) -c -I. -I$(INCDIR) $(CFLAGS) pbinfo.c pbdemo.o: pbdemo.c pbutil.h - $(CC) -c -I. -I$(INCDIR) $(CFLAGS) pbdemo.c + $(APP_CC) -c -I. -I$(INCDIR) $(CFLAGS) pbdemo.c pbutil.o: pbutil.c pbutil.h - $(CC) -c -I. -I$(INCDIR) $(CFLAGS) pbutil.c + $(APP_CC) -c -I. -I$(INCDIR) $(CFLAGS) pbutil.c glxgears_fbconfig: glxgears_fbconfig.o pbutil.o - $(CC) -I$(INCDIR) $(CFLAGS) glxgears_fbconfig.o pbutil.o $(APP_LIB_DEPS) -o $@ + $(APP_CC) -I$(INCDIR) $(CFLAGS) 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 + $(APP_CC) -I$(INCDIR) $(CFLAGS) -c -I. $(CFLAGS) glxgears_fbconfig.c xrotfontdemo: xrotfontdemo.o xuserotfont.o - $(CC) -I$(INCDIR) $(CFLAGS) xrotfontdemo.o xuserotfont.o $(APP_LIB_DEPS) -o $@ + $(APP_CC) -I$(INCDIR) $(CFLAGS) xrotfontdemo.o xuserotfont.o $(APP_LIB_DEPS) -o $@ xuserotfont.o: xuserotfont.c xuserotfont.h - $(CC) -c -I. -I$(INCDIR) $(CFLAGS) xuserotfont.c + $(APP_CC) -c -I. -I$(INCDIR) $(CFLAGS) xuserotfont.c xrotfontdemo.o: xrotfontdemo.c xuserotfont.h - $(CC) -c -I. -I$(INCDIR) $(CFLAGS) xrotfontdemo.c + $(APP_CC) -c -I. -I$(INCDIR) $(CFLAGS) xrotfontdemo.c -- cgit v1.2.3