[Xquartz-changes] [277] AppleSGLX/trunk/tests

source_changes at macosforge.org source_changes at macosforge.org
Tue Mar 3 11:51:51 PST 2009


Revision: 277
          http://trac.macosforge.org/projects/xquartz/changeset/277
Author:   gstaplin at apple.com
Date:     2009-03-03 11:51:51 -0800 (Tue, 03 Mar 2009)
Log Message:
-----------
Add a torture test for surface creation and destruction.

You can verify it with:
env LIBGL_DIAGNOSTIC=1 ./testbuilds/triangle_glx_surface

It doesn't appear that the X server or libGL clients grow
with the test, so I believe the cleanup is occurring properly.

Modified Paths:
--------------
    AppleSGLX/trunk/tests/tests.mk
    AppleSGLX/trunk/tests/triangle_glx/triangle_glx.mk

Added Paths:
-----------
    AppleSGLX/trunk/tests/triangle_glx/triangle_glx_surface.c

Modified: AppleSGLX/trunk/tests/tests.mk
===================================================================
--- AppleSGLX/trunk/tests/tests.mk	2009-03-03 19:39:40 UTC (rev 276)
+++ AppleSGLX/trunk/tests/tests.mk	2009-03-03 19:51:51 UTC (rev 277)
@@ -31,5 +31,6 @@
   $(TEST_BUILD_DIR)/drawable_types \
   $(TEST_BUILD_DIR)/glxpixmap_destroy_invalid \
   $(TEST_BUILD_DIR)/multisample_glx \
-  $(TEST_BUILD_DIR)/glthreads
+  $(TEST_BUILD_DIR)/glthreads \
+  $(TEST_BUILD_DIR)/triangle_glx_surface
 

Modified: AppleSGLX/trunk/tests/triangle_glx/triangle_glx.mk
===================================================================
--- AppleSGLX/trunk/tests/triangle_glx/triangle_glx.mk	2009-03-03 19:39:40 UTC (rev 276)
+++ AppleSGLX/trunk/tests/triangle_glx/triangle_glx.mk	2009-03-03 19:51:51 UTC (rev 277)
@@ -1,2 +1,5 @@
 $(TEST_BUILD_DIR)/triangle_glx: tests/triangle_glx/triangle_glx.c $(LIBGL)
 	$(CC) tests/triangle_glx/triangle_glx.c -Iinclude -o $(TEST_BUILD_DIR)/triangle_glx $(LINK_TEST)
+
+$(TEST_BUILD_DIR)/triangle_glx_surface: tests/triangle_glx/triangle_glx_surface.c $(LIBGL)
+	$(CC) tests/triangle_glx/triangle_glx_surface.c -Iinclude -o $(TEST_BUILD_DIR)/triangle_glx_surface $(LINK_TEST)

Added: AppleSGLX/trunk/tests/triangle_glx/triangle_glx_surface.c
===================================================================
--- AppleSGLX/trunk/tests/triangle_glx/triangle_glx_surface.c	                        (rev 0)
+++ AppleSGLX/trunk/tests/triangle_glx/triangle_glx_surface.c	2009-03-03 19:51:51 UTC (rev 277)
@@ -0,0 +1,115 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <X11/Xlib.h>
+#include <GL/glx.h>
+
+Window mainwin;
+GLXContext ctx;
+
+void draw(Display *dpy, Window w) {
+    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+    glLoadIdentity();   
+    glColor3f(0.5f, 0.5f, 1.0f);
+    glBegin(GL_TRIANGLES);
+    glVertex3f( 0.0f, 1.0f, 0.0f);
+    glVertex3f(-1.0f,-1.0f, 0.0f);
+    glVertex3f( 1.0f,-1.0f, 0.0f);
+    glEnd();    
+    glXSwapBuffers(dpy, w);
+}
+
+void resize(Display *dpy, Window w, int width, int height) {
+    glViewport(0, 0, width, height);
+    draw(dpy, w);
+}
+
+void event_loop(Display *dpy) {
+    XEvent event;
+    
+    while(1) {
+	if(XPending(dpy) > 0) {
+	    XNextEvent(dpy, &event);
+	    
+	    switch(event.type) {
+	    case Expose:
+		draw(dpy, event.xexpose.window);
+		break;
+		
+	    case ConfigureNotify:
+		resize(dpy, event.xconfigure.window, event.xconfigure.width,
+		       event.xconfigure.height);
+		break;
+	    }	
+	}
+
+	draw(dpy, mainwin);
+	/* This should destroy the surface. */
+	glXMakeCurrent(dpy, None, ctx);
+	/* This should recreate the surface. */
+	glXMakeCurrent(dpy, mainwin, ctx);
+    }
+}
+
+int main() {
+    Display *dpy;
+    int attrib[] = { GLX_RGBA,
+		     GLX_RED_SIZE, 8,
+		     GLX_GREEN_SIZE, 8,
+		     GLX_BLUE_SIZE, 8,
+		     GLX_DEPTH_SIZE, 24,
+		     GLX_DOUBLEBUFFER,
+		     None };
+    int eventbase, errorbase;
+    int screen;
+    Window root, win;
+    XVisualInfo *visinfo;
+    XSetWindowAttributes attr;
+    
+    dpy = XOpenDisplay(NULL);
+    
+    if(NULL == dpy) {
+        fprintf(stderr, "error: unable to open display!\n");
+        return EXIT_FAILURE;
+    }
+    
+    if(!glXQueryExtension(dpy, &eventbase, &errorbase)) {
+        fprintf(stderr, "GLX is not available!\n");
+        return EXIT_FAILURE;
+    }
+    
+    screen = DefaultScreen(dpy);
+    root = RootWindow(dpy, screen);
+
+    visinfo = glXChooseVisual(dpy, screen, attrib);
+
+    if(!visinfo) {
+	fprintf(stderr, "error: couldn't get an RGBA, double-buffered visual!\n");
+	return EXIT_FAILURE;
+    }
+
+    attr.background_pixel = 0;
+    attr.border_pixel = 0;
+    attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone);
+    attr.event_mask = StructureNotifyMask | ExposureMask;
+
+    mainwin = win = XCreateWindow(dpy, root, /*x*/ 0, /*y*/ 0, 
+			/*width*/ 400, /*height*/ 400,
+			0, visinfo->depth, InputOutput,
+			visinfo->visual, 
+			CWBackPixel | CWBorderPixel | CWColormap | CWEventMask,
+			&attr);
+   
+    ctx = glXCreateContext(dpy, visinfo, NULL, True );
+    if(!ctx) {
+	fprintf(stderr, "error: glXCreateContext failed!\n");
+	return EXIT_FAILURE;
+    }
+    
+    XMapWindow(dpy, win);
+
+    glXMakeCurrent(dpy, win, ctx);
+
+    event_loop(dpy);
+
+    return EXIT_SUCCESS;
+}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/xquartz-changes/attachments/20090303/721524e5/attachment.html>


More information about the Xquartz-changes mailing list