diff options
Diffstat (limited to 'progs')
94 files changed, 13643 insertions, 363 deletions
diff --git a/progs/demos/cubemap.c b/progs/demos/cubemap.c index 26db42aed5..1f9f290575 100644 --- a/progs/demos/cubemap.c +++ b/progs/demos/cubemap.c @@ -52,6 +52,7 @@ static GLboolean NoClear = GL_FALSE; static GLint FrameParity = 0; static GLenum FilterIndex = 0; static GLint ClampIndex = 0; +static GLboolean supportFBO = GL_FALSE; static struct { @@ -403,6 +404,10 @@ static void init_checkers( void ) glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + if (!supportFBO) + glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_GENERATE_MIPMAP_SGIS, GL_TRUE); + + /* make colored checkerboard cube faces */ for (f = 0; f < 6; f++) { for (i = 0; i < CUBE_TEX_SIZE; i++) { @@ -426,7 +431,8 @@ static void init_checkers( void ) GL_BGRA, GL_UNSIGNED_BYTE, image); } - glGenerateMipmapEXT(GL_TEXTURE_CUBE_MAP_ARB); + if (supportFBO) + glGenerateMipmapEXT(GL_TEXTURE_CUBE_MAP_ARB); } @@ -503,10 +509,13 @@ static void init( GLboolean useImageFiles ) exit(0); } - /* Needed for glGenerateMipmapEXT + /* Needed for glGenerateMipmapEXT / auto mipmapping */ - if (!strstr(exten, "GL_EXT_framebuffer_object")) { - printf("Sorry, this demo requires GL_EXT_framebuffer_object\n"); + if (strstr(exten, "GL_EXT_framebuffer_object")) { + supportFBO = GL_TRUE; + } + else if (!strstr(exten, "GL_SGIS_generate_mipmap")) { + printf("Sorry, this demo requires GL_EXT_framebuffer_object or GL_SGIS_generate_mipmap\n"); exit(0); } } diff --git a/progs/demos/isosurf.c b/progs/demos/isosurf.c index 6923ca2bba..2e9dff1726 100644 --- a/progs/demos/isosurf.c +++ b/progs/demos/isosurf.c @@ -847,8 +847,8 @@ static void Init(int argc, char *argv[]) glClearColor(0.0, 0.0, 1.0, 0.0); glEnable( GL_DEPTH_TEST ); - glEnable( GL_VERTEX_ARRAY_EXT ); - glEnable( GL_NORMAL_ARRAY_EXT ); + glEnableClientState( GL_VERTEX_ARRAY ); + glEnableClientState( GL_NORMAL_ARRAY ); glMatrixMode(GL_PROJECTION); glLoadIdentity(); diff --git a/progs/demos/pointblast.c b/progs/demos/pointblast.c index 2a91b76ad3..2d70b72589 100644 --- a/progs/demos/pointblast.c +++ b/progs/demos/pointblast.c @@ -194,11 +194,11 @@ redraw(void) { int i; + glDepthMask(GL_TRUE); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); if (newModel) recalcModelView(); - glDepthMask(GL_FALSE); /* Draw the floor. */ /* glEnable(GL_TEXTURE_2D);*/ @@ -215,7 +215,7 @@ redraw(void) glEnd(); /* Allow particles to blend with each other. */ - glDepthMask(GL_TRUE); + glDepthMask(GL_FALSE); if (blend) glEnable(GL_BLEND); diff --git a/progs/demos/spriteblast.c b/progs/demos/spriteblast.c index f6630c25d0..d73b680b79 100644 --- a/progs/demos/spriteblast.c +++ b/progs/demos/spriteblast.c @@ -209,13 +209,13 @@ redraw(void) { int i; + glDepthMask(GL_TRUE); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); glRotatef(15.0, 1.0, 0.0, 0.0); glRotatef(angle, 0.0, 1.0, 0.0); - glDepthMask(GL_FALSE); /* Draw the floor. */ /* glEnable(GL_TEXTURE_2D);*/ @@ -232,7 +232,7 @@ redraw(void) glEnd(); /* Allow particles to blend with each other. */ - glDepthMask(GL_TRUE); + glDepthMask(GL_FALSE); if (blend) glEnable(GL_BLEND); diff --git a/progs/demos/vao_demo.c b/progs/demos/vao_demo.c index ce416712fe..206e06fc6c 100644 --- a/progs/demos/vao_demo.c +++ b/progs/demos/vao_demo.c @@ -260,6 +260,8 @@ static void Key( unsigned char key, int x, int y ) (void) y; switch (key) { case 27: + (*delete_vertex_arrays)( 1, & cube_array_obj ); + (*delete_vertex_arrays)( 1, & oct_array_obj ); glutDestroyWindow(Win); exit(0); break; diff --git a/progs/egl/.gitignore b/progs/egl/.gitignore index 793c6c0f61..f417aefb93 100644 --- a/progs/egl/.gitignore +++ b/progs/egl/.gitignore @@ -7,4 +7,5 @@ eglscreen egltri peglgears xeglgears +xeglthreads xegl_tri diff --git a/progs/egl/Makefile b/progs/egl/Makefile index e1fdb1ce63..fd72f540ca 100644 --- a/progs/egl/Makefile +++ b/progs/egl/Makefile @@ -17,7 +17,9 @@ PROGRAMS = \ eglgears \ eglscreen \ peglgears \ + xeglbindtex \ xeglgears \ + xeglthreads \ xegl_tri @@ -83,6 +85,12 @@ peglgears.o: peglgears.c $(HEADERS) $(CC) -c $(CFLAGS) -I$(TOP)/include peglgears.c +xeglbindtex: xeglbindtex.o $(TOP)/$(LIB_DIR)/libEGL.so + $(CC) $(CFLAGS) xeglbindtex.o -L$(TOP)/$(LIB_DIR) -lEGL -lGL $(LIBDRM_LIB) $(APP_LIB_DEPS) -o $@ + +xeglbindtex.o: xeglbindtex.c $(HEADERS) + $(CC) -c $(CFLAGS) -I$(TOP)/include xeglbindtex.c + xeglgears: xeglgears.o $(TOP)/$(LIB_DIR)/libEGL.so $(CC) $(CFLAGS) xeglgears.o -L$(TOP)/$(LIB_DIR) -lEGL -lGL $(LIBDRM_LIB) $(APP_LIB_DEPS) -o $@ @@ -90,6 +98,13 @@ xeglgears.o: xeglgears.c $(HEADERS) $(CC) -c $(CFLAGS) -I$(TOP)/include xeglgears.c +xeglthreads: xeglthreads.o $(TOP)/$(LIB_DIR)/libEGL.so + $(CC) $(CFLAGS) xeglthreads.o -L$(TOP)/$(LIB_DIR) -lEGL -lGL $(LIBDRM_LIB) $(APP_LIB_DEPS) -o $@ + +xeglthreads.o: xeglthreads.c $(HEADERS) + $(CC) -c $(CFLAGS) -I$(TOP)/include xeglthreads.c + + xegl_tri: xegl_tri.o $(TOP)/$(LIB_DIR)/libEGL.so $(CC) $(CFLAGS) xegl_tri.o -L$(TOP)/$(LIB_DIR) -lEGL -lGL $(LIBDRM_LIB) $(APP_LIB_DEPS) -o $@ diff --git a/progs/egl/xeglbindtex.c b/progs/egl/xeglbindtex.c new file mode 100644 index 0000000000..fdd9fe2b87 --- /dev/null +++ b/progs/egl/xeglbindtex.c @@ -0,0 +1,474 @@ +/* + * Simple demo for eglBindTexImage. Based on xegl_tri.c by + * + * 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. + */ + +/* + * The spec says that eglBindTexImage supports only OpenGL ES context, but this + * demo uses OpenGL context. Keep in mind that this is non-standard. + */ + +#include <math.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <X11/Xlib.h> +#include <X11/Xutil.h> +#include <X11/keysym.h> +#include <GL/gl.h> +#include <EGL/egl.h> + +static EGLDisplay dpy; +static EGLContext ctx_win, ctx_pbuf; +static EGLSurface surf_win, surf_pbuf; +static GLuint tex_pbuf; + +static GLfloat view_rotx = 0.0, view_roty = 0.0, view_rotz = 0.0; +static GLboolean blend = GL_TRUE; +static GLuint color_flow; + +static void +make_pbuffer(int width, int height) +{ + static const EGLint config_attribs[] = { + EGL_RED_SIZE, 8, + EGL_GREEN_SIZE, 8, + EGL_BLUE_SIZE, 8, + EGL_BIND_TO_TEXTURE_RGB, EGL_TRUE, + EGL_NONE + }; + EGLint pbuf_attribs[] = { + EGL_WIDTH, width, + EGL_HEIGHT, height, + EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGB, + EGL_TEXTURE_TARGET, EGL_TEXTURE_2D, + EGL_NONE + }; + EGLConfig config; + EGLint num_configs; + + if (!eglChooseConfig(dpy, config_attribs, &config, 1, &num_configs)) { + printf("Error: couldn't get an EGL visual config for pbuffer\n"); + exit(1); + } + + eglBindAPI(EGL_OPENGL_API); + ctx_pbuf = eglCreateContext(dpy, config, EGL_NO_CONTEXT, NULL ); + surf_pbuf = eglCreatePbufferSurface(dpy, config, pbuf_attribs); + if (surf_pbuf == EGL_NO_SURFACE) { + printf("failed to allocate pbuffer\n"); + exit(1); + } + + glGenTextures(1, &tex_pbuf); +} + +static void +use_pbuffer(void) +{ + static int initialized; + + eglMakeCurrent(dpy, surf_pbuf, surf_pbuf, ctx_pbuf); + if (!initialized) { + EGLint width, height; + GLfloat ar; + + initialized = 1; + + eglQuerySurface(dpy, surf_pbuf, EGL_WIDTH, &width); + eglQuerySurface(dpy, surf_pbuf, EGL_WIDTH, &height); + ar = (GLfloat) width / (GLfloat) height; + + glViewport(0, 0, (GLint) width, (GLint) height); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-ar, ar, -1, 1, 1.0, 10.0); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + + /* y-inverted */ + glScalef(1.0, -1.0, 1.0); + + glTranslatef(0.0, 0.0, -5.0); + + glClearColor(0.2, 0.2, 0.2, 0.0); + } +} + +static void +make_window(Display *x_dpy, const char *name, + int x, int y, int width, int height, + Window *winRet) +{ + static const EGLint attribs[] = { + EGL_RED_SIZE, 8, + EGL_GREEN_SIZE, 8, + EGL_BLUE_SIZE, 8, + EGL_ALPHA_SIZE, 8, + EGL_DEPTH_SIZE, 8, + EGL_NONE + }; + + int scrnum; + XSetWindowAttributes attr; + unsigned long mask; + Window root; + Window win; + XVisualInfo *visInfo, visTemplate; + int num_visuals; + EGLConfig config; + EGLint num_configs, vid; + + scrnum = DefaultScreen( x_dpy ); + root = RootWindow( x_dpy, scrnum ); + + if (!eglChooseConfig(dpy, attribs, &config, 1, &num_configs)) { + printf("Error: couldn't get an EGL visual config\n"); + exit(1); + } + + if (!eglGetConfigAttrib(dpy, config, EGL_NATIVE_VISUAL_ID, &vid)) { + printf("Error: eglGetConfigAttrib() failed\n"); + exit(1); + } + + /* The X window visual must match the EGL config */ + visTemplate.visualid = vid; + visInfo = XGetVisualInfo(x_dpy, VisualIDMask, &visTemplate, &num_visuals); + if (!visInfo) { + printf("Error: couldn't get X visual\n"); + exit(1); + } + + /* window attributes */ + attr.background_pixel = 0; + attr.border_pixel = 0; + attr.colormap = XCreateColormap( x_dpy, root, visInfo->visual, AllocNone); + attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask; + attr.override_redirect = 0; + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect; + + win = XCreateWindow( x_dpy, root, 0, 0, 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(x_dpy, win, &sizehints); + XSetStandardProperties(x_dpy, win, name, name, + None, (char **)NULL, 0, &sizehints); + } + + eglBindAPI(EGL_OPENGL_API); + ctx_win = eglCreateContext(dpy, config, EGL_NO_CONTEXT, NULL ); + if (!ctx_win) { + printf("Error: glXCreateContext failed\n"); + exit(1); + } + + surf_win = eglCreateWindowSurface(dpy, config, win, NULL); + + XFree(visInfo); + + *winRet = win; +} + +static void +use_window(void) +{ + static int initialized; + + eglMakeCurrent(dpy, surf_win, surf_win, ctx_win); + if (!initialized) { + initialized = 1; + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, tex_pbuf); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + } +} + +static void +draw_triangle(void) +{ + static const GLfloat verts[3][2] = { + { -3, -3 }, + { 3, -3 }, + { 0, 3 } + }; + GLfloat colors[3][3] = { + { 1, 0, 0 }, + { 0, 1, 0 }, + { 0, 0, 1 } + }; + GLint i; + + /* flow the color */ + for (i = 0; i < 3; i++) { + GLint first = (i + color_flow / 256) % 3; + GLint second = (first + 1) % 3; + GLint third = (second + 1) % 3; + GLfloat c = (color_flow % 256) / 256.0f; + + c = c * c * c; + colors[i][first] = 1.0f - c; + colors[i][second] = c; + colors[i][third] = 0.0f; + } + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glVertexPointer(2, GL_FLOAT, 0, verts); + glColorPointer(3, GL_FLOAT, 0, colors); + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_COLOR_ARRAY); + + glDrawArrays(GL_TRIANGLES, 0, 3); + + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); +} + +static void +draw_textured_cube(void) +{ + static const GLfloat verts[][2] = { + { -4, -4 }, + { 4, -4 }, + { 4, 4 }, + { -4, 4 } + }; + static const GLfloat colors[][4] = { + { 1, 1, 1, 0.5 }, + { 1, 1, 1, 0.5 }, + { 1, 1, 1, 0.5 }, + { 1, 1, 1, 0.5 } + }; + static const GLfloat texs[][2] = { + { 0, 0 }, + { 1, 0 }, + { 1, 1 }, + { 0, 1 } + }; + static const GLfloat xforms[6][4] = { + { 0, 0, 1, 0 }, + { 90, 0, 1, 0 }, + { 180, 0, 1, 0 }, + { 270, 0, 1, 0 }, + { 90, 1, 0, 0 }, + { -90, 1, 0, 0 } + }; + GLint i; + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + if (blend) { + glDisable(GL_DEPTH_TEST); + glEnable(GL_BLEND); + } else { + glEnable(GL_DEPTH_TEST); + glDisable(GL_BLEND); + } + + glVertexPointer(2, GL_FLOAT, 0, verts); + glColorPointer(4, GL_FLOAT, 0, colors); + glTexCoordPointer(2, GL_FLOAT, 0, texs); + + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_COLOR_ARRAY); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + + for (i = 0; i < 6; i++) { + glPushMatrix(); + glRotatef(xforms[i][0], xforms[i][1], xforms[i][2], xforms[i][3]); + glTranslatef(0, 0, 4.1); + glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + glPopMatrix(); + } + + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); +} + +static void +draw(void) +{ + use_pbuffer(); + draw_triangle(); + + use_window(); + + eglBindTexImage(dpy, surf_pbuf, EGL_BACK_BUFFER); + + glPushMatrix(); + glRotatef(view_rotx, 1, 0, 0); + glRotatef(view_roty, 0, 1, 0); + glRotatef(view_rotz, 0, 0, 1); + + draw_textured_cube(); + + glPopMatrix(); + + eglReleaseTexImage(dpy, surf_pbuf, EGL_BACK_BUFFER); +} + +/* new window size or exposure */ +static void +reshape(int width, int height) +{ + GLfloat ar = (GLfloat) width / (GLfloat) height; + + use_window(); + + glViewport(0, 0, (GLint) width, (GLint) height); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-ar, ar, -1, 1, 5.0, 60.0); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0.0, 0.0, -40.0); +} + +static void +event_loop(Display *x_dpy, Window win) +{ + while (1) { + int redraw = 1; + + if (XPending(x_dpy) > 0) { + XEvent event; + XNextEvent(x_dpy, &event); + + switch (event.type) { + case Expose: + redraw = 1; + 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 if (code == XK_b) { + blend = !blend; + } + else { + r = XLookupString(&event.xkey, buffer, sizeof(buffer), + NULL, NULL); + if (buffer[0] == 27) { + /* escape */ + return; + } + } + } + redraw = 1; + break; + default: + ; /*no-op*/ + } + } + + if (redraw) { + view_rotx += 1.0; + view_roty += 2.0; + view_rotz += 1.5; + color_flow += 20; + draw(); + eglSwapBuffers(dpy, surf_win); + } + } +} + +int +main(int argc, char *argv[]) +{ + const int winWidth = 300, winHeight = 300; + Display *x_dpy; + Window win; + char *dpyName = NULL; + EGLint egl_major, egl_minor; + const char *s; + + x_dpy = XOpenDisplay(dpyName); + if (!x_dpy) { + printf("Error: couldn't open display %s\n", + dpyName ? dpyName : getenv("DISPLAY")); + return -1; + } + + dpy = eglGetDisplay(x_dpy); + if (!dpy) { + printf("Error: eglGetDisplay() failed\n"); + return -1; + } + + if (!eglInitialize(dpy, &egl_major, &egl_minor)) { + printf("Error: eglInitialize() failed\n"); + return -1; + } + + s = eglQueryString(dpy, EGL_VERSION); + printf("EGL_VERSION = %s\n", s); + + make_window(x_dpy, "color flow", 0, 0, winWidth, winHeight, &win); + make_pbuffer(winWidth, winHeight); + + XMapWindow(x_dpy, win); + + reshape(winWidth, winHeight); + event_loop(x_dpy, win); + + glDeleteTextures(1, &tex_pbuf); + + eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + eglTerminate(dpy); + + XDestroyWindow(x_dpy, win); + XCloseDisplay(x_dpy); + + return 0; +} diff --git a/progs/egl/xeglthreads.c b/progs/egl/xeglthreads.c new file mode 100644 index 0000000000..508dbc0943 --- /dev/null +++ b/progs/egl/xeglthreads.c @@ -0,0 +1,773 @@ +/* + * Copyright (C) 2000 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. + * + * Ported to EGL by Chia-I Wu <olvaffe@gmail.com> + */ + + +/* + * This program tests EGL thread safety. + * Command line options: + * -p Open a display connection for each thread + * -l Enable application-side locking + * -n <num threads> Number of threads to create (default is 2) + * -display <display name> Specify X display (default is $DISPLAY) + * -t Use texture mapping + * + * Brian Paul 20 July 2000 + */ + + +/* + * Notes: + * - Each thread gets its own EGL context. + * + * - The EGL 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 <assert.h> +#include <X11/Xlib.h> +#include <X11/Xutil.h> +#include <GL/gl.h> +#include <EGL/egl.h> +#include <math.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <pthread.h> + + +/* + * Each window/thread/context: + */ +struct winthread { + Display *Dpy; + int Index; + pthread_t Thread; + Window Win; + EGLDisplay Display; + EGLContext Context; + EGLSurface Surface; + float Angle; + int WinWidth, WinHeight; + GLboolean NewSize; + GLboolean Initialized; + GLboolean MakeNewTexture; +}; + + +#define MAX_WINTHREADS 100 +static struct winthread WinThreads[MAX_WINTHREADS]; +static int NumWinThreads = 0; +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 +Error(const char *msg) +{ + fprintf(stderr, "Error: %s\n", msg); + exit(1); +} + + +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) +{ + glPushMatrix(); + glScalef(0.75, 0.75, 0.75); + + glColor3f(1, 0, 0); + + if (Texture) { + glBindTexture(GL_TEXTURE_2D, TexObj); + glEnable(GL_TEXTURE_2D); + } + else { + glDisable(GL_TEXTURE_2D); + } + + glBegin(GL_QUADS); + + /* -X */ + glColor3f(0, 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); + + /* +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); + 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, 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); + 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(); +} + + +/* signal resize of given window */ +static void +resize(struct winthread *wt, int w, int h) +{ + wt->NewSize = GL_TRUE; + wt->WinWidth = w; + wt->WinHeight = h; + if (!Animate) + signal_redraw(); +} + + +/* + * We have an instance of this for each thread. + */ +static void +draw_loop(struct winthread *wt) +{ + while (!ExitFlag) { + + if (Locking) + pthread_mutex_lock(&Mutex); + + if (!wt->Initialized) { + eglMakeCurrent(wt->Display, wt->Surface, wt->Surface, wt->Context); + printf("xeglthreads: %d: GL_RENDERER = %s\n", wt->Index, + (char *) glGetString(GL_RENDERER)); + if (Texture /*&& wt->Index == 0*/) { + MakeNewTexture(wt); + } + wt->Initialized = GL_TRUE; + } + + if (Locking) + pthread_mutex_unlock(&Mutex); + + eglBindAPI(EGL_OPENGL_API); + if (eglGetCurrentContext() != wt->Context) { + printf("xeglthreads: current context %p != %p\n", + eglGetCurrentContext(), wt->Context); + } + + glEnable(GL_DEPTH_TEST); + + if (wt->NewSize) { + GLfloat w = (float) wt->WinWidth / (float) wt->WinHeight; + glViewport(0, 0, wt->WinWidth, wt->WinHeight); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-w, w, -1.0, 1.0, 1.5, 10); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0, 0, -2.5); + 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, 1, 0); + glRotatef(wt->Angle, 1, 0, 0); + glScalef(0.7, 0.7, 0.7); + draw_object(); + glPopMatrix(); + + if (Locking) + pthread_mutex_lock(&Mutex); + + eglSwapBuffers(wt->Display, wt->Surface); + + if (Locking) + pthread_mutex_unlock(&Mutex); + + 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; + } + eglMakeCurrent(wt->Display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); +} + + +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. + */ +static void +event_loop(Display *dpy) +{ + XEvent event; + int i; + + assert(!MultiDisplays); + + while (!ExitFlag) { + + if (Locking) { + while (1) { + int k; + pthread_mutex_lock(&Mutex); + k = XPending(dpy); + if (k) { + XNextEvent(dpy, &event); + pthread_mutex_unlock(&Mutex); + break; + } + pthread_mutex_unlock(&Mutex); + usleep(5000); + } + } + else { + XNextEvent(dpy, &event); + } + + switch (event.type) { + case ConfigureNotify: + /* Find winthread for this event's window */ + for (i = 0; i < NumWinThreads; i++) { + struct winthread *wt = &WinThreads[i]; + if (event.xconfigure.window == wt->Win) { + resize(wt, event.xconfigure.width, + event.xconfigure.height); + break; + } + } + break; + case KeyPress: + 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*/ ; + } + } +} + + +/* + * Separate display connection for each thread. + */ +static void +event_loop_multi(void) +{ + XEvent event; + int w = 0; + + assert(MultiDisplays); + + while (!ExitFlag) { + struct winthread *wt = &WinThreads[w]; + if (XPending(wt->Dpy)) { + XNextEvent(wt->Dpy, &event); + switch (event.type) { + case ConfigureNotify: + resize(wt, event.xconfigure.width, event.xconfigure.height); + break; + case KeyPress: + keypress(&event, wt); + break; + default: + ; /* nop */ + } + } + w = (w + 1) % NumWinThreads; + usleep(5000); + } +} + + + +/* + * we'll call this once for each thread, before the threads are created. + */ +static void +create_window(struct winthread *wt, EGLContext shareCtx) +{ + Window win; + EGLContext ctx; + EGLSurface surf; + EGLint attribs[] = { EGL_RED_SIZE, 1, + EGL_GREEN_SIZE, 1, + EGL_BLUE_SIZE, 1, + EGL_DEPTH_SIZE, 1, + EGL_NONE }; + EGLConfig config; + EGLint num_configs; + EGLint vid; + int scrnum; + XSetWindowAttributes attr; + unsigned long mask; + Window root; + XVisualInfo *visinfo, visTemplate; + int num_visuals; + 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); + + if (!eglChooseConfig(wt->Display, attribs, &config, 1, &num_configs)) { + Error("Unable to choose an EGL config"); + } + + assert(config); + assert(num_configs > 0); + + if (!eglGetConfigAttrib(wt->Display, config, EGL_NATIVE_VISUAL_ID, &vid)) { + Error("Unable to get visual id of EGL config\n"); + } + + visTemplate.visualid = vid; + visinfo = XGetVisualInfo(wt->Dpy, VisualIDMask, + &visTemplate, &num_visuals); + if (!visinfo) { + Error("Unable to find RGB, Z, double-buffered visual"); + } + + /* window attributes */ + attr.background_pixel = 0; + attr.border_pixel = 0; + attr.colormap = XCreateColormap(wt->Dpy, root, visinfo->visual, AllocNone); + attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask; + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; + + win = XCreateWindow(wt->Dpy, root, xpos, ypos, width, height, + 0, visinfo->depth, InputOutput, + visinfo->visual, mask, &attr); + if (!win) { + Error("Couldn't create window"); + } + + XFree(visinfo); + + { + XSizeHints sizehints; + sizehints.x = xpos; + sizehints.y = ypos; + sizehints.width = width; + sizehints.height = height; + sizehints.flags = USSize | USPosition; + XSetNormalHints(wt->Dpy, win, &sizehints); + XSetStandardProperties(wt->Dpy, win, "xeglthreads", "xeglthreads", + None, (char **)NULL, 0, &sizehints); + } + + eglBindAPI(EGL_OPENGL_API); + + ctx = eglCreateContext(wt->Display, config, shareCtx, NULL); + if (!ctx) { + Error("Couldn't create EGL context"); + } + surf = eglCreateWindowSurface(wt->Display, config, win, NULL); + if (!surf) { + Error("Couldn't create EGL surface"); + } + + XMapWindow(wt->Dpy, win); + XSync(wt->Dpy, 0); + + /* save the info for this window/context */ + wt->Win = win; + wt->Context = ctx; + wt->Surface = surf; + wt->Angle = 0.0; + wt->WinWidth = width; + wt->WinHeight = height; + wt->NewSize = GL_TRUE; +} + + +/* + * Called by pthread_create() + */ +static void * +thread_function(void *p) +{ + struct winthread *wt = (struct winthread *) p; + draw_loop(wt); + return NULL; +} + + +/* + * called before exit to wait for all threads to finish + */ +static void +clean_up(void) +{ + int i; + + /* wait for threads to finish */ + for (i = 0; i < NumWinThreads; i++) { + pthread_join(WinThreads[i].Thread, NULL); + } + + for (i = 0; i < NumWinThreads; i++) { + eglDestroyContext(WinThreads[i].Display, WinThreads[i].Context); + XDestroyWindow(WinThreads[i].Dpy, WinThreads[i].Win); + } +} + + +static void +usage(void) +{ + printf("xeglthreads: test of EGL/GL thread safety (any key = exit)\n"); + printf("Usage:\n"); + printf(" xeglthreads [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"); + printf(" a Toggle animation\n"); + printf(" s Step rotation (when not animating)\n"); +} + + +int +main(int argc, char *argv[]) +{ + char *displayName = NULL; + int numThreads = 2; + Display *dpy = NULL; + EGLDisplay *egl_dpy = NULL; + int i; + Status threadStat; + + if (argc == 1) { + usage(); + } + else { + int i; + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-display") == 0 && i + 1 < argc) { + displayName = argv[i + 1]; + i++; + } + else if (strcmp(argv[i], "-p") == 0) { + MultiDisplays = 1; + } + 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) + numThreads = 1; + else if (numThreads > MAX_WINTHREADS) + numThreads = MAX_WINTHREADS; + i++; + } + else { + usage(); + exit(1); + } + } + } + + if (Locking) + printf("xeglthreads: Using explicit locks around Xlib calls.\n"); + else + printf("xeglthreads: No explict locking.\n"); + + if (MultiDisplays) + printf("xeglthreads: Per-thread display connections.\n"); + else + printf("xeglthreads: Single display connection.\n"); + + /* + * VERY IMPORTANT: call XInitThreads() before any other Xlib functions. + */ + if (!MultiDisplays) { + if (!Locking) { + threadStat = XInitThreads(); + if (threadStat) { + printf("XInitThreads() returned %d (success)\n", + (int) threadStat); + } + else { + printf("XInitThreads() returned 0 " + "(failure- this program may fail)\n"); + } + } + + dpy = XOpenDisplay(displayName); + if (!dpy) { + fprintf(stderr, "Unable to open display %s\n", + XDisplayName(displayName)); + return -1; + } + egl_dpy = eglGetDisplay(dpy); + if (!egl_dpy) { + fprintf(stderr, "Unable to get EGL display\n"); + XCloseDisplay(dpy); + return -1; + } + if (!eglInitialize(egl_dpy, NULL, NULL)) { + fprintf(stderr, "Unable to initialize EGL display\n"); + return -1; + } + } + + pthread_mutex_init(&Mutex, NULL); + pthread_mutex_init(&CondMutex, NULL); + pthread_cond_init(&CondVar, NULL); + + printf("xeglthreads: creating windows\n"); + + NumWinThreads = numThreads; + + /* Create the EGL windows and contexts */ + for (i = 0; i < numThreads; i++) { + EGLContext share; + + if (MultiDisplays) { + WinThreads[i].Dpy = XOpenDisplay(displayName); + assert(WinThreads[i].Dpy); + WinThreads[i].Display = eglGetDisplay(WinThreads[i].Dpy); + assert(eglInitialize(WinThreads[i].Display, NULL, NULL)); + } + else { + WinThreads[i].Dpy = dpy; + WinThreads[i].Display = egl_dpy; + } + WinThreads[i].Index = i; + WinThreads[i].Initialized = GL_FALSE; + + share = (Texture && i > 0) ? WinThreads[0].Context : 0; + + create_window(&WinThreads[i], share); + } + + printf("xeglthreads: creating threads\n"); + + /* Create the threads */ + for (i = 0; i < numThreads; i++) { + pthread_create(&WinThreads[i].Thread, NULL, thread_function, + (void*) &WinThreads[i]); + printf("xeglthreads: Created thread %p\n", + (void *) WinThreads[i].Thread); + } + + if (MultiDisplays) + event_loop_multi(); + else + event_loop(dpy); + + clean_up(); + + if (MultiDisplays) { + for (i = 0; i < numThreads; i++) { + eglTerminate(WinThreads[i].Display); + XCloseDisplay(WinThreads[i].Dpy); + } + } + else { + eglTerminate(egl_dpy); + XCloseDisplay(dpy); + } + + return 0; +} + + +#else /* PTHREADS */ + + +#include <stdio.h> + +int +main(int argc, char *argv[]) +{ + printf("Sorry, this program wasn't compiled with PTHREADS defined.\n"); + return 0; +} + + +#endif /* PTHREADS */ diff --git a/progs/glsl/Makefile b/progs/glsl/Makefile index eedd866c95..0875bdd795 100644 --- a/progs/glsl/Makefile +++ b/progs/glsl/Makefile @@ -14,6 +14,11 @@ LIBS = -L$(TOP)/$(LIB_DIR) -l$(GLUT_LIB) -l$(GLEW_LIB) -l$(GLU_LIB) -l$(GL_LIB) INCLUDE_DIRS = -I$(TOP)/progs/util +# using : to avoid APP_CC pointing to CC loop +CC:=$(APP_CC) +CFLAGS += -I$(INCDIR) +LDLIBS=$(LIBS) + DEMO_SOURCES = \ array.c \ bitmap.c \ @@ -33,6 +38,7 @@ DEMO_SOURCES = \ points.c \ samplers.c \ shadow_sampler.c \ + shtest.c \ skinning.c \ texaaline.c \ texdemo1.c \ @@ -52,28 +58,16 @@ UTIL_SOURCES = \ readtex.c UTIL_OBJS = $(UTIL_SOURCES:.c=.o) - - +PROG_OBJS = $(DEMO_SOURCES:.c=.o) PROGS = $(DEMO_SOURCES:%.c=%) - - -##### RULES ##### - -# make .o file from .c file: -.c.o: - $(APP_CC) -c -I$(INCDIR) $(CFLAGS) $< -o $@ - - -# make executable from .o files -.o: - $(APP_CC) $(INCLUDES) $(CFLAGS) $(LDFLAGS) $< $(UTIL_OBJS) $(LIBS) -o $@ - - ##### TARGETS ##### default: $(PROGS) +$(PROG_OBJS): $(UTIL_HEADERS) + +$(PROGS): $(UTIL_OBJS) clean: -rm -f $(PROGS) @@ -83,7 +77,6 @@ clean: -rm -f readtex.* - ##### Extra dependencies extfuncs.h: $(TOP)/progs/util/extfuncs.h @@ -101,138 +94,3 @@ shaderutil.c: $(TOP)/progs/util/shaderutil.c shaderutil.h: $(TOP)/progs/util/shaderutil.h cp $< . - - -array.o: $(UTIL_HEADERS) - -array: array.o $(UTIL_OBJS) - - -bitmap.o: $(UTIL_HEADERS) - -bitmap: bitmap.o $(UTIL_OBJS) - - -brick.o: $(UTIL_HEADERS) - -brick: brick.o $(UTIL_OBJS) - - -bump.o: $(UTIL_HEADERS) - -bump: bump.o $(UTIL_OBJS) - - -convolutions.o: $(UTIL_HEADERS) - -convolutions: convolutions.o $(UTIL_OBJS) - - -deriv.o: deriv.c $(UTIL_HEADERS) - -deriv: deriv.o $(UTIL_OBJS) - - -identity.o: $(UTIL_HEADERS) - -identity: identity.o $(UTIL_OBJS) - - -fragcoord.o: $(UTIL_HEADERS) - -fragcoord: fragcoord.o $(UTIL_OBJS) - - -linktest.o: $(UTIL_HEADERS) - -linktest: linktest.o $(UTIL_OBJS) - - -mandelbrot.o: $(UTIL_HEADERS) - -mandelbrot: mandelbrot.o $(UTIL_OBJS) - - -multinoise.o: $(UTIL_HEADERS) - -multinoise: multinoise.o $(UTIL_OBJS) - - -multitex.o: $(UTIL_HEADERS) - -multitex: multitex.o $(UTIL_OBJS) - - -noise.o: $(UTIL_HEADERS) - -noise: noise.o $(UTIL_OBJS) - - -noise2.o: $(UTIL_HEADERS) - -noise2: noise2.o $(UTIL_OBJS) - - -points.o: $(UTIL_HEADERS) - -points: points.o $(UTIL_OBJS) - - -pointcoord.o: $(UTIL_HEADERS) - -pointcoord: pointcoord.o $(UTIL_OBJS) - - -samplers.o: $(UTIL_HEADERS) - -samplers: samplers.o $(UTIL_OBJS) - - -samplers_array.o: $(UTIL_HEADERS) - -samplers_array: samplers_array.o $(UTIL_OBJS) - - -shadow_sampler.o: $(UTIL_HEADERS) - -shadow_sampler: shadow_sampler.o $(UTIL_OBJS) - - -skinning.o: $(UTIL_HEADERS) - -skinning: skinning.o $(UTIL_OBJS) - - -texaaline.o: $(UTIL_HEADERS) - -texaaline: texaaline.o $(UTIL_OBJS) - - -texdemo1.o: $(UTIL_HEADERS) - -texdemo1: texdemo1.o $(UTIL_OBJS) - - -toyball.o: $(UTIL_HEADERS) - -toyball: toyball.o $(UTIL_OBJS) - - -twoside.o: $(UTIL_HEADERS) - -twoside: twoside.o $(UTIL_OBJS) - - -trirast.o: $(UTIL_HEADERS) - -trirast: trirast.o $(UTIL_OBJS) - - -vert-or-frag-only.o: $(UTIL_HEADERS) - -vert-or-frag-only: vert-or-frag-only.o $(UTIL_OBJS) - - -vert-tex.o: $(UTIL_HEADERS) - -vert-tex: vert-tex.o $(UTIL_OBJS) diff --git a/progs/glsl/brick.c b/progs/glsl/brick.c index 1d08b231e7..0653c592e5 100644 --- a/progs/glsl/brick.c +++ b/progs/glsl/brick.c @@ -24,12 +24,12 @@ static GLuint program; static struct uniform_info Uniforms[] = { /* vert */ - { "LightPosition", 3, GL_FLOAT, { 0.1, 0.1, 9.0, 0}, -1 }, + { "LightPosition", 1, GL_FLOAT_VEC3, { 0.1, 0.1, 9.0, 0}, -1 }, /* frag */ - { "BrickColor", 3, GL_FLOAT, { 0.8, 0.2, 0.2, 0 }, -1 }, - { "MortarColor", 3, GL_FLOAT, { 0.6, 0.6, 0.6, 0 }, -1 }, - { "BrickSize", 2, GL_FLOAT, { 1.0, 0.3, 0, 0 }, -1 }, - { "BrickPct", 2, GL_FLOAT, { 0.9, 0.8, 0, 0 }, -1 }, + { "BrickColor", 1, GL_FLOAT_VEC3, { 0.8, 0.2, 0.2, 0 }, -1 }, + { "MortarColor", 1, GL_FLOAT_VEC3, { 0.6, 0.6, 0.6, 0 }, -1 }, + { "BrickSize", 1, GL_FLOAT_VEC2, { 1.0, 0.3, 0, 0 }, -1 }, + { "BrickPct", 1, GL_FLOAT_VEC2, { 0.9, 0.8, 0, 0 }, -1 }, END_OF_UNIFORMS }; @@ -148,7 +148,8 @@ Init(void) glUseProgram(program); - InitUniforms(program, Uniforms); + SetUniformValues(program, Uniforms); + PrintUniforms(Uniforms); assert(glGetError() == 0); diff --git a/progs/glsl/brick.shtest b/progs/glsl/brick.shtest new file mode 100644 index 0000000000..8a2152692e --- /dev/null +++ b/progs/glsl/brick.shtest @@ -0,0 +1,8 @@ +vs CH06-brick.vert +fs CH06-brick.frag +uniform LightPosition GL_FLOAT_VEC3 0.1 0.1 9.0 +uniform BrickColor GL_FLOAT_VEC3 0.8 0.2 0.2 +uniform MortarColor GL_FLOAT_VEC3 0.6 0.6 0.6 +uniform BrickSize GL_FLOAT_VEC2 1.0 0.3 +uniform BrickPct GL_FLOAT_VEC2 0.9 0.8 + diff --git a/progs/glsl/bump.c b/progs/glsl/bump.c index ddb986abcb..c0d39c049d 100644 --- a/progs/glsl/bump.c +++ b/progs/glsl/bump.c @@ -24,11 +24,11 @@ static GLuint program; static struct uniform_info Uniforms[] = { - { "LightPosition", 3, GL_FLOAT, { 0.57737, 0.57735, 0.57735, 0.0 }, -1 }, - { "SurfaceColor", 3, GL_FLOAT, { 0.8, 0.8, 0.2, 0 }, -1 }, - { "BumpDensity", 1, GL_FLOAT, { 10.0, 0, 0, 0 }, -1 }, - { "BumpSize", 1, GL_FLOAT, { 0.125, 0, 0, 0 }, -1 }, - { "SpecularFactor", 1, GL_FLOAT, { 0.5, 0, 0, 0 }, -1 }, + { "LightPosition", 1, GL_FLOAT_VEC3, { 0.57737, 0.57735, 0.57735, 0.0 }, -1 }, + { "SurfaceColor", 1, GL_FLOAT_VEC3, { 0.8, 0.8, 0.2, 0 }, -1 }, + { "BumpDensity", 1, GL_FLOAT, { 10.0, 0, 0, 0 }, -1 }, + { "BumpSize", 1, GL_FLOAT, { 0.125, 0, 0, 0 }, -1 }, + { "SpecularFactor", 1, GL_FLOAT, { 0.5, 0, 0, 0 }, -1 }, END_OF_UNIFORMS }; @@ -242,7 +242,8 @@ Init(void) CheckError(__LINE__); - InitUniforms(program, Uniforms); + SetUniformValues(program, Uniforms); + PrintUniforms(Uniforms); CheckError(__LINE__); diff --git a/progs/glsl/mandelbrot.c b/progs/glsl/mandelbrot.c index 38dffc3e74..729a6f125a 100644 --- a/progs/glsl/mandelbrot.c +++ b/progs/glsl/mandelbrot.c @@ -25,7 +25,7 @@ static GLuint program; static struct uniform_info Uniforms[] = { /* vert */ - { "LightPosition", 3, GL_FLOAT, { 0.1, 0.1, 9.0, 0}, -1 }, + { "LightPosition", 1, GL_FLOAT_VEC3, { 0.1, 0.1, 9.0, 0}, -1 }, { "SpecularContribution", 1, GL_FLOAT, { 0.5, 0, 0, 0 }, -1 }, { "DiffuseContribution", 1, GL_FLOAT, { 0.5, 0, 0, 0 }, -1 }, { "Shininess", 1, GL_FLOAT, { 20.0, 0, 0, 0 }, -1 }, @@ -34,9 +34,9 @@ static struct uniform_info Uniforms[] = { { "Zoom", 1, GL_FLOAT, { 0.125, 0, 0, 0 }, -1 }, { "Xcenter", 1, GL_FLOAT, { -1.5, 0, 0, 0 }, -1 }, { "Ycenter", 1, GL_FLOAT, { .005, 0, 0, 0 }, -1 }, - { "InnerColor", 3, GL_FLOAT, { 1, 0, 0, 0 }, -1 }, - { "OuterColor1", 3, GL_FLOAT, { 0, 1, 0, 0 }, -1 }, - { "OuterColor2", 3, GL_FLOAT, { 0, 0, 1, 0 }, -1 }, + { "InnerColor", 1, GL_FLOAT_VEC3, { 1, 0, 0, 0 }, -1 }, + { "OuterColor1", 1, GL_FLOAT_VEC3, { 0, 1, 0, 0 }, -1 }, + { "OuterColor2", 1, GL_FLOAT_VEC3, { 0, 0, 1, 0 }, -1 }, END_OF_UNIFORMS }; @@ -159,7 +159,8 @@ Init(void) glUseProgram(program); - InitUniforms(program, Uniforms); + SetUniformValues(program, Uniforms); + PrintUniforms(Uniforms); uZoom = glGetUniformLocation(program, "Zoom"); uXcenter = glGetUniformLocation(program, "Xcenter"); diff --git a/progs/glsl/mandelbrot.shtest b/progs/glsl/mandelbrot.shtest new file mode 100644 index 0000000000..4f4e5c747e --- /dev/null +++ b/progs/glsl/mandelbrot.shtest @@ -0,0 +1,13 @@ +vs CH18-mandel.vert +fs CH18-mandel.frag +uniform LightPosition GL_FLOAT_VEC3 0.1 0.1 9.0 +uniform SpecularContribution GL_FLOAT 0.5 +uniform DiffuseContribution GL_FLOAT 0.5 +uniform Shininess GL_FLOAT 20.0 +uniform Iterations GL_FLOAT 12 +uniform Zoom GL_FLOAT 0.125 +uniform Xcenter GL_FLOAT -1.5 +uniform Ycenter GL_FLOAT .005 +uniform InnerColor GL_FLOAT_VEC3 1 0 0 +uniform OuterColor1 GL_FLOAT_VEC3 0 1 0 +uniform OuterColor2 GL_FLOAT_VEC3 0 0 1 diff --git a/progs/glsl/multitex.c b/progs/glsl/multitex.c index 913f73be17..6ec9c833e6 100644 --- a/progs/glsl/multitex.c +++ b/progs/glsl/multitex.c @@ -51,14 +51,16 @@ static GLfloat Xrot = 0.0, Yrot = .0, Zrot = 0.0; static GLfloat EyeDist = 10; static GLboolean Anim = GL_TRUE; static GLboolean UseArrays = GL_TRUE; +static GLboolean UseVBO = GL_TRUE; +static GLuint VBO = 0; static GLint VertCoord_attr = -1, TexCoord0_attr = -1, TexCoord1_attr = -1; /* value[0] = tex unit */ static struct uniform_info Uniforms[] = { - { "tex1", 1, GL_INT, { 0, 0, 0, 0 }, -1 }, - { "tex2", 1, GL_INT, { 1, 0, 0, 0 }, -1 }, + { "tex1", 1, GL_SAMPLER_2D, { 0, 0, 0, 0 }, -1 }, + { "tex2", 1, GL_SAMPLER_2D, { 1, 0, 0, 0 }, -1 }, END_OF_UNIFORMS }; @@ -76,28 +78,81 @@ static const GLfloat VertCoords[4][2] = { }; + +static void +SetupVertexBuffer(void) +{ + glGenBuffersARB(1, &VBO); + glBindBufferARB(GL_ARRAY_BUFFER_ARB, VBO); + + glBufferDataARB(GL_ARRAY_BUFFER_ARB, + sizeof(VertCoords) + + sizeof(Tex0Coords) + + sizeof(Tex1Coords), + NULL, + GL_STATIC_DRAW_ARB); + + /* non-interleaved vertex arrays */ + + glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, + 0, /* offset */ + sizeof(VertCoords), /* size */ + VertCoords); /* data */ + + glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, + sizeof(VertCoords), /* offset */ + sizeof(Tex0Coords), /* size */ + Tex0Coords); /* data */ + + glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, + sizeof(VertCoords) + + sizeof(Tex0Coords), /* offset */ + sizeof(Tex1Coords), /* size */ + Tex1Coords); /* data */ + + glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); +} + + static void DrawPolygonArray(void) { + void *vertPtr, *tex0Ptr, *tex1Ptr; + + if (UseVBO) { + glBindBufferARB(GL_ARRAY_BUFFER_ARB, VBO); + vertPtr = (void *) 0; + tex0Ptr = (void *) sizeof(VertCoords); + tex1Ptr = (void *) (sizeof(VertCoords) + sizeof(Tex0Coords)); + } + else { + glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); + vertPtr = VertCoords; + tex0Ptr = Tex0Coords; + tex1Ptr = Tex1Coords; + } + if (VertCoord_attr >= 0) { glVertexAttribPointer(VertCoord_attr, 2, GL_FLOAT, GL_FALSE, - 0, VertCoords); + 0, vertPtr); glEnableVertexAttribArray(VertCoord_attr); } else { - glVertexPointer(2, GL_FLOAT, 0, VertCoords); - glEnable(GL_VERTEX_ARRAY); + glVertexPointer(2, GL_FLOAT, 0, vertPtr); + glEnableClientState(GL_VERTEX_ARRAY); } glVertexAttribPointer(TexCoord0_attr, 2, GL_FLOAT, GL_FALSE, - 0, Tex0Coords); + 0, tex0Ptr); glEnableVertexAttribArray(TexCoord0_attr); glVertexAttribPointer(TexCoord1_attr, 2, GL_FLOAT, GL_FALSE, - 0, Tex1Coords); + 0, tex1Ptr); glEnableVertexAttribArray(TexCoord1_attr); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + + glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); } @@ -163,6 +218,10 @@ key(unsigned char k, int x, int y) UseArrays = !UseArrays; printf("Arrays: %d\n", UseArrays); break; + case 'v': + UseVBO = !UseVBO; + printf("Use VBO: %d\n", UseVBO); + break; case ' ': Anim = !Anim; if (Anim) @@ -269,7 +328,8 @@ CreateProgram(const char *vertProgFile, const char *fragProgFile, glUseProgram(program); - InitUniforms(program, uniforms); + SetUniformValues(program, uniforms); + PrintUniforms(Uniforms); VertCoord_attr = glGetAttribLocation(program, "VertCoord"); if (VertCoord_attr > 0) { @@ -314,10 +374,18 @@ InitGL(void) /*exit(1);*/ } printf("GL_RENDERER = %s\n",(const char *) glGetString(GL_RENDERER)); + printf("Usage:\n"); + printf(" a - toggle arrays vs. immediate mode rendering\n"); + printf(" v - toggle VBO usage for array rendering\n"); + printf(" z/Z - change viewing distance\n"); + printf(" SPACE - toggle animation\n"); + printf(" Esc - exit\n"); InitTextures(); InitPrograms(); + SetupVertexBuffer(); + glEnable(GL_DEPTH_TEST); glClearColor(.6, .6, .9, 0); diff --git a/progs/glsl/multitex.shtest b/progs/glsl/multitex.shtest new file mode 100644 index 0000000000..5be45f6c7c --- /dev/null +++ b/progs/glsl/multitex.shtest @@ -0,0 +1,6 @@ +vs multitex.vert +fs multitex.frag +texture 0 ../images/tile.rgb +texture 1 ../images/tree2.rgba +uniform tex1 GL_SAMPLER_2D 0 +uniform tex2 GL_SAMPLER_2D 1 diff --git a/progs/glsl/noise.c b/progs/glsl/noise.c index 59f594e78b..8c36e1c59b 100644 --- a/progs/glsl/noise.c +++ b/progs/glsl/noise.c @@ -35,8 +35,8 @@ static const char *FragShaderText = static struct uniform_info Uniforms[] = { - { "Scale", 4, GL_FLOAT, { 0.5, 0.4, 0.0, 0}, -1 }, - { "Bias", 4, GL_FLOAT, { 0.5, 0.3, 0.0, 0}, -1 }, + { "Scale", 1, GL_FLOAT_VEC4, { 0.5, 0.4, 0.0, 0}, -1 }, + { "Bias", 1, GL_FLOAT_VEC4, { 0.5, 0.3, 0.0, 0}, -1 }, { "Slice", 1, GL_FLOAT, { 0.5, 0, 0, 0}, -1 }, END_OF_UNIFORMS }; @@ -179,7 +179,8 @@ Init(void) glUseProgram(program); - InitUniforms(program, Uniforms); + SetUniformValues(program, Uniforms); + PrintUniforms(Uniforms); assert(glGetError() == 0); diff --git a/progs/glsl/shtest.c b/progs/glsl/shtest.c new file mode 100644 index 0000000000..97f6f9f8a4 --- /dev/null +++ b/progs/glsl/shtest.c @@ -0,0 +1,630 @@ +/* + * Simple shader test harness. + * Brian Paul + * 13 Aug 2009 + * + * Usage: + * shtest --vs vertShaderFile --fs fragShaderFile + * + * In this case the given vertex/frag shaders are read and compiled. + * Random values are assigned to the uniforms. + * + * or: + * shtest configFile + * + * In this case a config file is read that specifies the file names + * of the shaders plus initial values for uniforms. + * + * Example config file: + * + * vs shader.vert + * fs shader.frag + * uniform pi 3.14159 + * uniform v1 1.0 0.5 0.2 0.3 + * + */ + + +#include <assert.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <math.h> +#include <GL/glew.h> +#include <GL/glu.h> +#include <GL/glut.h> +#include "shaderutil.h" +#include "readtex.h" + + +typedef enum +{ + SPHERE, + CUBE, + NUM_SHAPES +} shape; + + +static char *FragShaderFile = NULL; +static char *VertShaderFile = NULL; +static char *ConfigFile = NULL; + +/* program/shader objects */ +static GLuint fragShader; +static GLuint vertShader; +static GLuint Program; + + +#define MAX_UNIFORMS 100 +static struct uniform_info Uniforms[MAX_UNIFORMS]; +static GLuint NumUniforms = 0; + + +#define MAX_ATTRIBS 100 +static struct attrib_info Attribs[MAX_ATTRIBS]; +static GLuint NumAttribs = 0; + + +/** + * Config file info. + */ +struct config_file +{ + struct name_value + { + char name[100]; + float value[4]; + int type; + } uniforms[100]; + + int num_uniforms; +}; + + +static GLint win = 0; +static GLboolean Anim = GL_FALSE; +static GLfloat TexRot = 0.0; +static GLfloat xRot = 0.0f, yRot = 0.0f, zRot = 0.0f; +static shape Object = SPHERE; + + +static float +RandomFloat(float min, float max) +{ + int k = rand() % 10000; + float x = min + (max - min) * k / 10000.0; + return x; +} + + +/** Set new random values for uniforms */ +static void +RandomUniformValues(void) +{ + GLuint i; + for (i = 0; i < NumUniforms; i++) { + if (Uniforms[i].type == GL_FLOAT) { + Uniforms[i].value[0] = RandomFloat(0.0, 1.0); + } + else { + Uniforms[i].value[0] = RandomFloat(-1.0, 2.0); + Uniforms[i].value[1] = RandomFloat(-1.0, 2.0); + Uniforms[i].value[2] = RandomFloat(-1.0, 2.0); + Uniforms[i].value[3] = RandomFloat(-1.0, 2.0); + } + } +} + + +static void +Idle(void) +{ + yRot += 2.0; + if (yRot > 360.0) + yRot -= 360.0; + glutPostRedisplay(); +} + + + +static void +SquareVertex(GLfloat s, GLfloat t, GLfloat size) +{ + GLfloat x = -size + s * 2.0 * size; + GLfloat y = -size + t * 2.0 * size; + GLuint i; + + glMultiTexCoord2f(GL_TEXTURE0, s, t); + glMultiTexCoord2f(GL_TEXTURE1, s, t); + glMultiTexCoord2f(GL_TEXTURE2, s, t); + glMultiTexCoord2f(GL_TEXTURE3, s, t); + + /* assign (s,t) to the generic attributes */ + for (i = 0; i < NumAttribs; i++) { + if (Attribs[i].location >= 0) { + glVertexAttrib2f(Attribs[i].location, s, t); + } + } + + glVertex2f(x, y); +} + + +/* + * Draw a square, specifying normal and tangent vectors. + */ +static void +Square(GLfloat size) +{ + GLint tangentAttrib = 1; + glNormal3f(0, 0, 1); + glVertexAttrib3f(tangentAttrib, 1, 0, 0); + glBegin(GL_POLYGON); +#if 1 + SquareVertex(0, 0, size); + SquareVertex(1, 0, size); + SquareVertex(1, 1, size); + SquareVertex(0, 1, size); +#else + glTexCoord2f(0, 0); glVertex2f(-size, -size); + glTexCoord2f(1, 0); glVertex2f( size, -size); + glTexCoord2f(1, 1); glVertex2f( size, size); + glTexCoord2f(0, 1); glVertex2f(-size, size); +#endif + glEnd(); +} + + +static void +Cube(GLfloat size) +{ + /* +X */ + glPushMatrix(); + glRotatef(90, 0, 1, 0); + glTranslatef(0, 0, size); + Square(size); + glPopMatrix(); + + /* -X */ + glPushMatrix(); + glRotatef(-90, 0, 1, 0); + glTranslatef(0, 0, size); + Square(size); + glPopMatrix(); + + /* +Y */ + glPushMatrix(); + glRotatef(90, 1, 0, 0); + glTranslatef(0, 0, size); + Square(size); + glPopMatrix(); + + /* -Y */ + glPushMatrix(); + glRotatef(-90, 1, 0, 0); + glTranslatef(0, 0, size); + Square(size); + glPopMatrix(); + + + /* +Z */ + glPushMatrix(); + glTranslatef(0, 0, size); + Square(size); + glPopMatrix(); + + /* -Z */ + glPushMatrix(); + glRotatef(180, 0, 1, 0); + glTranslatef(0, 0, size); + Square(size); + glPopMatrix(); +} + + +static void +Sphere(GLfloat radius, GLint slices, GLint stacks) +{ + static GLUquadricObj *q = NULL; + + if (!q) { + q = gluNewQuadric(); + gluQuadricDrawStyle(q, GLU_FILL); + gluQuadricNormals(q, GLU_SMOOTH); + gluQuadricTexture(q, GL_TRUE); + } + + gluSphere(q, radius, slices, stacks); +} + + +static void +Redisplay(void) +{ + 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); + glRotatef(zRot, 0.0f, 0.0f, 1.0f); + + glMatrixMode(GL_TEXTURE); + glLoadIdentity(); + glRotatef(TexRot, 0.0f, 1.0f, 0.0f); + glMatrixMode(GL_MODELVIEW); + + if (Object == SPHERE) { + Sphere(2.0, 20, 10); + } + else if (Object == CUBE) { + Cube(2.0); + } + + glPopMatrix(); + + glutSwapBuffers(); +} + + +static void +Reshape(int width, int 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, -15.0f); +} + + +static void +CleanUp(void) +{ + glDeleteShader(fragShader); + glDeleteShader(vertShader); + glDeleteProgram(Program); + glutDestroyWindow(win); +} + + +static void +Key(unsigned char key, int x, int y) +{ + const GLfloat step = 2.0; + (void) x; + (void) y; + + switch(key) { + case 'a': + Anim = !Anim; + if (Anim) + glutIdleFunc(Idle); + else + glutIdleFunc(NULL); + break; + case 'z': + zRot += step; + break; + case 'Z': + zRot -= step; + break; + case 'o': + Object = (Object + 1) % NUM_SHAPES; + break; + case 'r': + RandomUniformValues(); + SetUniformValues(Program, Uniforms); + PrintUniforms(Uniforms); + break; + case 27: + CleanUp(); + exit(0); + break; + } + glutPostRedisplay(); +} + + +static void +SpecialKey(int key, int x, int y) +{ + const GLfloat step = 2.0; + + (void) x; + (void) y; + + 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; + } + glutPostRedisplay(); +} + + +static void +InitUniforms(const struct config_file *conf, + struct uniform_info uniforms[]) +{ + int i; + + for (i = 0; i < conf->num_uniforms; i++) { + int j; + for (j = 0; uniforms[j].name; j++) { + if (strcmp(uniforms[j].name, conf->uniforms[i].name) == 0) { + uniforms[j].type = conf->uniforms[i].type; + uniforms[j].value[0] = conf->uniforms[i].value[0]; + uniforms[j].value[1] = conf->uniforms[i].value[1]; + uniforms[j].value[2] = conf->uniforms[i].value[2]; + uniforms[j].value[3] = conf->uniforms[i].value[3]; + } + } + } +} + + +static void +LoadTexture(GLint unit, const char *texFileName) +{ + GLint imgWidth, imgHeight; + GLenum imgFormat; + GLubyte *image = NULL; + GLuint tex; + GLenum filter = GL_LINEAR; + + image = LoadRGBImage(texFileName, &imgWidth, &imgHeight, &imgFormat); + if (!image) { + printf("Couldn't read %s\n", texFileName); + exit(1); + } + + printf("Load Texture: unit %d: %s %d x %d\n", + unit, texFileName, imgWidth, imgHeight); + + glActiveTexture(GL_TEXTURE0 + unit); + glGenTextures(1, &tex); + glBindTexture(GL_TEXTURE_2D, tex); + + gluBuild2DMipmaps(GL_TEXTURE_2D, 4, imgWidth, imgHeight, + imgFormat, GL_UNSIGNED_BYTE, image); + free(image); + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter); +} + + +static GLenum +TypeFromName(const char *n) +{ + static const struct { + const char *name; + GLenum type; + } types[] = { + { "GL_FLOAT", GL_FLOAT }, + { "GL_FLOAT_VEC2", GL_FLOAT_VEC2 }, + { "GL_FLOAT_VEC3", GL_FLOAT_VEC3 }, + { "GL_FLOAT_VEC4", GL_FLOAT_VEC4 }, + { "GL_INT", GL_INT }, + { "GL_INT_VEC2", GL_INT_VEC2 }, + { "GL_INT_VEC3", GL_INT_VEC3 }, + { "GL_INT_VEC4", GL_INT_VEC4 }, + { "GL_SAMPLER_2D", GL_SAMPLER_2D }, + { NULL, 0 } + }; + GLuint i; + + for (i = 0; types[i].name; i++) { + if (strcmp(types[i].name, n) == 0) + return types[i].type; + } + abort(); + return GL_NONE; +} + + + +/** + * Read a config file. + */ +static void +ReadConfigFile(const char *filename, struct config_file *conf) +{ + char line[1000]; + FILE *f; + + f = fopen(filename, "r"); + if (!f) { + fprintf(stderr, "Unable to open config file %s\n", filename); + exit(1); + } + + conf->num_uniforms = 0; + + /* ugly but functional parser */ + while (!feof(f)) { + fgets(line, sizeof(line), f); + if (!feof(f) && line[0]) { + if (strncmp(line, "vs ", 3) == 0) { + VertShaderFile = strdup(line + 3); + VertShaderFile[strlen(VertShaderFile) - 1] = 0; + } + else if (strncmp(line, "fs ", 3) == 0) { + FragShaderFile = strdup(line + 3); + FragShaderFile[strlen(FragShaderFile) - 1] = 0; + } + else if (strncmp(line, "texture ", 8) == 0) { + char texFileName[100]; + int unit, k; + k = sscanf(line + 8, "%d %s", &unit, texFileName); + assert(k == 2); + LoadTexture(unit, texFileName); + } + else if (strncmp(line, "uniform ", 8) == 0) { + char name[1000], typeName[100]; + int k; + float v1 = 0.0F, v2 = 0.0F, v3 = 0.0F, v4 = 0.0F; + GLenum type; + + k = sscanf(line + 8, "%s %s %f %f %f %f", name, typeName, + &v1, &v2, &v3, &v4); + + type = TypeFromName(typeName); + + strcpy(conf->uniforms[conf->num_uniforms].name, name); + conf->uniforms[conf->num_uniforms].value[0] = v1; + conf->uniforms[conf->num_uniforms].value[1] = v2; + conf->uniforms[conf->num_uniforms].value[2] = v3; + conf->uniforms[conf->num_uniforms].value[3] = v4; + conf->uniforms[conf->num_uniforms].type = type; + conf->num_uniforms++; + } + else { + if (strlen(line) > 1) { + fprintf(stderr, "syntax error in: %s\n", line); + break; + } + } + } + } + + fclose(f); +} + + +static void +Init(void) +{ + struct config_file config; + memset(&config, 0, sizeof(config)); + + if (ConfigFile) + ReadConfigFile(ConfigFile, &config); + + if (!VertShaderFile) { + fprintf(stderr, "Error: no vertex shader\n"); + exit(1); + } + + if (!FragShaderFile) { + fprintf(stderr, "Error: no fragment shader\n"); + exit(1); + } + + if (!ShadersSupported()) + exit(1); + + vertShader = CompileShaderFile(GL_VERTEX_SHADER, VertShaderFile); + fragShader = CompileShaderFile(GL_FRAGMENT_SHADER, FragShaderFile); + Program = LinkShaders(vertShader, fragShader); + + glUseProgram(Program); + + NumUniforms = GetUniforms(Program, Uniforms); + if (config.num_uniforms) { + InitUniforms(&config, Uniforms); + } + else { + RandomUniformValues(); + } + SetUniformValues(Program, Uniforms); + PrintUniforms(Uniforms); + + NumAttribs = GetAttribs(Program, Attribs); + PrintAttribs(Attribs); + + //assert(glGetError() == 0); + + glClearColor(0.4f, 0.4f, 0.8f, 0.0f); + + glEnable(GL_DEPTH_TEST); + + glColor3f(1, 0, 0); +} + + +static void +Keys(void) +{ + printf("Keyboard:\n"); + printf(" a Animation toggle\n"); + printf(" r Randomize uniform values\n"); + printf(" o Change object\n"); + printf(" arrows Rotate object\n"); + printf(" ESC Exit\n"); +} + + +static void +Usage(void) +{ + printf("Usage:\n"); + printf(" shtest config.shtest\n"); + printf(" Run w/ given config file.\n"); + printf(" shtest --vs vertShader --fs fragShader\n"); + printf(" Load/compile given shaders.\n"); +} + + +static void +ParseOptions(int argc, char *argv[]) +{ + int i; + + if (argc == 1) { + Usage(); + exit(1); + } + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "--fs") == 0) { + FragShaderFile = argv[i+1]; + i++; + } + else if (strcmp(argv[i], "--vs") == 0) { + VertShaderFile = argv[i+1]; + i++; + } + else { + /* assume the arg is a config file */ + ConfigFile = argv[i]; + break; + } + } +} + + +int +main(int argc, char *argv[]) +{ + glutInit(&argc, argv); + glutInitWindowPosition( 0, 0); + glutInitWindowSize(400, 400); + glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); + win = glutCreateWindow(argv[0]); + glewInit(); + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutSpecialFunc(SpecialKey); + glutDisplayFunc(Redisplay); + ParseOptions(argc, argv); + Init(); + Keys(); + glutMainLoop(); + return 0; +} + diff --git a/progs/glsl/texdemo1.c b/progs/glsl/texdemo1.c index d55f9e7dd9..5b1913a722 100644 --- a/progs/glsl/texdemo1.c +++ b/progs/glsl/texdemo1.c @@ -53,14 +53,14 @@ static int win = 0; static struct uniform_info ReflectUniforms[] = { - { "cubeTex", 1, GL_INT, { 0, 0, 0, 0 }, -1 }, - { "lightPos", 3, GL_FLOAT, { 10, 10, 20, 0 }, -1 }, + { "cubeTex", 1, GL_SAMPLER_CUBE, { 0, 0, 0, 0 }, -1 }, + { "lightPos", 1, GL_FLOAT_VEC3, { 10, 10, 20, 0 }, -1 }, END_OF_UNIFORMS }; static struct uniform_info SimpleUniforms[] = { - { "tex2d", 1, GL_INT, { 1, 0, 0, 0 }, -1 }, - { "lightPos", 3, GL_FLOAT, { 10, 10, 20, 0 }, -1 }, + { "tex2d", 1, GL_SAMPLER_2D, { 1, 0, 0, 0 }, -1 }, + { "lightPos", 1, GL_FLOAT_VEC3, { 10, 10, 20, 0 }, -1 }, END_OF_UNIFORMS }; @@ -382,7 +382,8 @@ CreateProgram(const char *vertProgFile, const char *fragProgFile, glUseProgram(program); - InitUniforms(program, uniforms); + SetUniformValues(program, uniforms); + PrintUniforms(uniforms); return program; } diff --git a/progs/glsl/toyball.c b/progs/glsl/toyball.c index 7fe27aebfe..89733d6175 100644 --- a/progs/glsl/toyball.c +++ b/progs/glsl/toyball.c @@ -24,18 +24,18 @@ static GLuint program; static struct uniform_info Uniforms[] = { - { "LightDir", 4, GL_FLOAT, { 0.57737, 0.57735, 0.57735, 0.0 }, -1 }, - { "HVector", 4, GL_FLOAT, { 0.32506, 0.32506, 0.88808, 0.0 }, -1 }, - { "BallCenter", 4, GL_FLOAT, { 0.0, 0.0, 0.0, 1.0 }, -1 }, - { "SpecularColor", 4, GL_FLOAT, { 0.4, 0.4, 0.4, 60.0 }, -1 }, - { "Red", 4, GL_FLOAT, { 0.6, 0.0, 0.0, 1.0 }, -1 }, - { "Blue", 4, GL_FLOAT, { 0.0, 0.3, 0.6, 1.0 }, -1 }, - { "Yellow", 4, GL_FLOAT, { 0.6, 0.5, 0.0, 1.0 }, -1 }, - { "HalfSpace0", 4, GL_FLOAT, { 1.0, 0.0, 0.0, 0.2 }, -1 }, - { "HalfSpace1", 4, GL_FLOAT, { 0.309016994, 0.951056516, 0.0, 0.2 }, -1 }, - { "HalfSpace2", 4, GL_FLOAT, { -0.809016994, 0.587785252, 0.0, 0.2 }, -1 }, - { "HalfSpace3", 4, GL_FLOAT, { -0.809016994, -0.587785252, 0.0, 0.2 }, -1 }, - { "HalfSpace4", 4, GL_FLOAT, { 0.309116994, -0.951056516, 0.0, 0.2 }, -1 }, + { "LightDir", 1, GL_FLOAT_VEC4, { 0.57737, 0.57735, 0.57735, 0.0 }, -1 }, + { "HVector", 1, GL_FLOAT_VEC4, { 0.32506, 0.32506, 0.88808, 0.0 }, -1 }, + { "BallCenter", 1, GL_FLOAT_VEC4, { 0.0, 0.0, 0.0, 1.0 }, -1 }, + { "SpecularColor", 1, GL_FLOAT_VEC4, { 0.4, 0.4, 0.4, 60.0 }, -1 }, + { "Red", 1, GL_FLOAT_VEC4, { 0.6, 0.0, 0.0, 1.0 }, -1 }, + { "Blue", 1, GL_FLOAT_VEC4, { 0.0, 0.3, 0.6, 1.0 }, -1 }, + { "Yellow", 1, GL_FLOAT_VEC4, { 0.6, 0.5, 0.0, 1.0 }, -1 }, + { "HalfSpace0", 1, GL_FLOAT_VEC4, { 1.0, 0.0, 0.0, 0.2 }, -1 }, + { "HalfSpace1", 1, GL_FLOAT_VEC4, { 0.309016994, 0.951056516, 0.0, 0.2 }, -1 }, + { "HalfSpace2", 1, GL_FLOAT_VEC4, { -0.809016994, 0.587785252, 0.0, 0.2 }, -1 }, + { "HalfSpace3", 1, GL_FLOAT_VEC4, { -0.809016994, -0.587785252, 0.0, 0.2 }, -1 }, + { "HalfSpace4", 1, GL_FLOAT_VEC4, { 0.309116994, -0.951056516, 0.0, 0.2 }, -1 }, { "InOrOutInit", 1, GL_FLOAT, { -3.0, 0, 0, 0 }, -1 }, { "StripeWidth", 1, GL_FLOAT, { 0.3, 0, 0, 0 }, -1 }, { "FWidth", 1, GL_FLOAT, { 0.005, 0, 0, 0 }, -1 }, @@ -173,7 +173,8 @@ Init(void) glUseProgram(program); - InitUniforms(program, Uniforms); + SetUniformValues(program, Uniforms); + PrintUniforms(Uniforms); assert(glGetError() == 0); diff --git a/progs/glsl/toyball.shtest b/progs/glsl/toyball.shtest new file mode 100644 index 0000000000..887663abd3 --- /dev/null +++ b/progs/glsl/toyball.shtest @@ -0,0 +1,17 @@ +vs CH11-toyball.vert +fs CH11-toyball.frag +uniform LightDir GL_FLOAT_VEC4 0.57737 0.57735 0.57735 0.0 +uniform HVector GL_FLOAT_VEC4 0.32506 0.32506 0.88808 0.0 +uniform BallCenter GL_FLOAT_VEC4 0.0 0.0 0.0 1.0 +uniform SpecularColor GL_FLOAT_VEC4 0.4 0.4 0.4 60.0 +uniform Red GL_FLOAT_VEC4 0.6 0.0 0.0 1.0 +uniform Blue GL_FLOAT_VEC4 0.0 0.3 0.6 1.0 +uniform Yellow GL_FLOAT_VEC4 0.6 0.5 0.0 1.0 +uniform HalfSpace0 GL_FLOAT_VEC4 1.0 0.0 0.0 0.2 +uniform HalfSpace1 GL_FLOAT_VEC4 .309016994 0.951056516 0.0 0.2 +uniform HalfSpace2 GL_FLOAT_VEC4 -0.809016994 0.587785252 0.0 0.2 +uniform HalfSpace3 GL_FLOAT_VEC4 -0.809016994 -0.587785252 0.0 0.2 +uniform HalfSpace4 GL_FLOAT_VEC4 .309116994 -0.951056516 0.0 0.2 +uniform InOrOutInit GL_FLOAT -3.0 +uniform StripeWidth GL_FLOAT 0.3 +uniform FWidth GL_FLOAT .005 diff --git a/progs/glsl/vert-tex.c b/progs/glsl/vert-tex.c index e791a5759a..4c8bfa587a 100644 --- a/progs/glsl/vert-tex.c +++ b/progs/glsl/vert-tex.c @@ -43,7 +43,7 @@ static GLfloat xRot = -70.0f, yRot = 0.0f, zRot = 0.0f; /* value[0] = tex unit */ static struct uniform_info Uniforms[] = { - { "tex1", 1, GL_INT, { 0, 0, 0, 0 }, -1 }, + { "tex1", 1, GL_SAMPLER_2D, { 0, 0, 0, 0 }, -1 }, END_OF_UNIFORMS }; diff --git a/progs/openvg/demos/Makefile b/progs/openvg/demos/Makefile new file mode 100644 index 0000000000..6e15342c7f --- /dev/null +++ b/progs/openvg/demos/Makefile @@ -0,0 +1,39 @@ +# progs/vg/Makefile + +TOP = ../../.. +include $(TOP)/configs/current + +VG_LIBS=-lm -pthread -lEGL -lOpenVG +INCLUDE_DIRS = -I$(TOP)/include + +PROGRAMS = \ + lion \ + sp + +.c.o: + $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $< -o $@ + + + +default: $(PROGRAMS) + +lion: lion.o lion-render.o + $(CC) $(CFLAGS) lion.o lion-render.o -L$(TOP)/$(LIB_DIR) $(VG_LIBS) -o $@ + +lion.o: lion.c lion-render.h $(HEADERS) + $(CC) -c $(CFLAGS) -I$(TOP)/include lion.c +lion-render.o: lion-render.c lion-render.h $(HEADERS) + $(CC) -c $(CFLAGS) -I$(TOP)/include lion-render.c + + +sp: sp.c eglcommon.o + $(CC) $(INCLUDE_DIRS) $(CFLAGS) $^ -L$(TOP)/$(LIB_DIR) $(LIBS) $(VG_LIBS) $(APP_LIB_DEPS) -o $@ + +eglcommon.o: eglcommon.c $(HEADERS) + $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) eglcommon.c + + +clean: + rm -f *.o *~ + rm -f *.so + rm -f $(PROGRAMS) diff --git a/progs/openvg/demos/eglcommon.c b/progs/openvg/demos/eglcommon.c new file mode 100644 index 0000000000..bacd5685d7 --- /dev/null +++ b/progs/openvg/demos/eglcommon.c @@ -0,0 +1,288 @@ +#include "eglcommon.h" + + +#include <assert.h> +#include <math.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <X11/Xlib.h> +#include <X11/Xutil.h> +#include <X11/keysym.h> +#include <VG/openvg.h> /* using full OpenGL for now */ +#include <GLES/egl.h> + + +static init_func init = 0; +static draw_func draw = 0; +static reshape_func reshape = 0; +static key_func keyPress = 0; +static VGint width = 300, height = 300; + + +void set_window_size(int w, int h) +{ + width = w; + height = h; +} + +/* + * Create an RGB, double-buffered X window. + * Return the window and context handles. + */ +static void +make_x_window(Display *x_dpy, EGLDisplay egl_dpy, + const char *name, + int x, int y, int width, int height, + Window *winRet, + EGLContext *ctxRet, + EGLSurface *surfRet) +{ + static const EGLint attribs[] = { + EGL_RED_SIZE, 1, + EGL_GREEN_SIZE, 1, + EGL_BLUE_SIZE, 1, + EGL_NONE + }; + + int scrnum; + XSetWindowAttributes attr; + unsigned long mask; + Window root; + Window win; + XVisualInfo *visInfo, visTemplate; + int num_visuals; + EGLContext ctx; + EGLConfig config; + EGLint num_configs; + EGLint vid; + + scrnum = DefaultScreen( x_dpy ); + root = RootWindow( x_dpy, scrnum ); + + if (!eglChooseConfig( egl_dpy, attribs, &config, 1, &num_configs)) { + printf("Error: couldn't get an EGL visual config\n"); + exit(1); + } + + assert(config); + assert(num_configs > 0); + + if (!eglGetConfigAttrib(egl_dpy, config, EGL_NATIVE_VISUAL_ID, &vid)) { + printf("Error: eglGetConfigAttrib() failed\n"); + exit(1); + } + + /* The X window visual must match the EGL config */ + visTemplate.visualid = vid; + visInfo = XGetVisualInfo(x_dpy, VisualIDMask, &visTemplate, &num_visuals); + if (!visInfo) { + printf("Error: couldn't get X visual\n"); + exit(1); + } + + /* window attributes */ + attr.background_pixel = 0; + attr.border_pixel = 0; + attr.colormap = XCreateColormap( x_dpy, root, visInfo->visual, AllocNone); + attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask; + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; + + win = XCreateWindow( x_dpy, root, 0, 0, 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(x_dpy, win, &sizehints); + XSetStandardProperties(x_dpy, win, name, name, + None, (char **)NULL, 0, &sizehints); + } + + eglBindAPI(EGL_OPENVG_API); + + ctx = eglCreateContext(egl_dpy, config, EGL_NO_CONTEXT, NULL ); + if (!ctx) { + printf("Error: eglCreateContext failed\n"); + exit(1); + } + + *surfRet = eglCreateWindowSurface(egl_dpy, config, win, NULL); + + if (!*surfRet) { + printf("Error: eglCreateWindowSurface failed\n"); + exit(1); + } + + XFree(visInfo); + + *winRet = win; + *ctxRet = ctx; +} + +static void +event_loop(Display *dpy, Window win, + EGLDisplay egl_dpy, EGLSurface egl_surf) +{ + while (1) { + int redraw = 0; + XEvent event; + + XNextEvent(dpy, &event); + + switch (event.type) { + case Expose: + redraw = 1; + break; + case ConfigureNotify: + if (reshape) { + width = event.xconfigure.width; + height = event.xconfigure.height; + reshape(event.xconfigure.width, event.xconfigure.height); + } + break; + case KeyPress: + { + char buffer[10]; + int r, code; + code = XLookupKeysym(&event.xkey, 0); + if (!keyPress || !keyPress(code)) { + r = XLookupString(&event.xkey, buffer, sizeof(buffer), + NULL, NULL); + if (buffer[0] == 27) { + /* escape */ + return; + } + } + } + redraw = 1; + break; + default: + ; /*no-op*/ + } + + if (redraw) { + draw(); + eglSwapBuffers(egl_dpy, egl_surf); + } + } +} + +int window_width(void) +{ + return width; +} + +int window_height(void) +{ + return height; +} + +static void +usage(void) +{ + printf("Usage:\n"); + printf(" -display <displayname> set the display to run on\n"); + printf(" -info display OpenGL renderer info\n"); +} + +int run(int argc, char **argv, + init_func init_f, + reshape_func resh_f, + draw_func draw_f, + key_func key_f) +{ + const int winWidth = width, winHeight = height; + Display *x_dpy; + Window win; + EGLSurface egl_surf; + EGLContext egl_ctx; + EGLDisplay egl_dpy; + char *dpyName = NULL; + GLboolean printInfo = GL_FALSE; + EGLint egl_major, egl_minor; + int i; + const char *s; + + init = init_f; + draw = draw_f; + reshape = resh_f; + keyPress = key_f; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-display") == 0) { + dpyName = argv[i+1]; + i++; + } + else if (strcmp(argv[i], "-info") == 0) { + printInfo = GL_TRUE; + } + } + + x_dpy = XOpenDisplay(dpyName); + if (!x_dpy) { + printf("Error: couldn't open display %s\n", + dpyName ? dpyName : getenv("DISPLAY")); + return -1; + } + + egl_dpy = eglGetDisplay(x_dpy); + if (!egl_dpy) { + printf("Error: eglGetDisplay() failed\n"); + return -1; + } + + if (!eglInitialize(egl_dpy, &egl_major, &egl_minor)) { + printf("Error: eglInitialize() failed\n"); + return -1; + } + + s = eglQueryString(egl_dpy, EGL_VERSION); + printf("EGL_VERSION = %s\n", s); + + make_x_window(x_dpy, egl_dpy, + "OpenVG Example", 0, 0, winWidth, winHeight, + &win, &egl_ctx, &egl_surf); + + XMapWindow(x_dpy, win); + if (!eglMakeCurrent(egl_dpy, egl_surf, egl_surf, egl_ctx)) { + printf("Error: eglMakeCurrent() failed\n"); + return -1; + } + + if (printInfo) { + printf("VG_RENDERER = %s\n", (char *) vgGetString(VG_RENDERER)); + printf("VG_VERSION = %s\n", (char *) vgGetString(VG_VERSION)); + printf("VG_VENDOR = %s\n", (char *) vgGetString(VG_VENDOR)); + } + + if (init) + init(); + + /* Set initial projection/viewing transformation. + * We can't be sure we'll get a ConfigureNotify event when the window + * first appears. + */ + if (reshape) + reshape(winWidth, winHeight); + + event_loop(x_dpy, win, egl_dpy, egl_surf); + + eglMakeCurrent(egl_dpy, 0, 0, 0); + eglDestroyContext(egl_dpy, egl_ctx); + eglDestroySurface(egl_dpy, egl_surf); + eglTerminate(egl_dpy); + + + XDestroyWindow(x_dpy, win); + XCloseDisplay(x_dpy); + + return 0; +} + diff --git a/progs/openvg/demos/eglcommon.h b/progs/openvg/demos/eglcommon.h new file mode 100644 index 0000000000..958dae9f98 --- /dev/null +++ b/progs/openvg/demos/eglcommon.h @@ -0,0 +1,20 @@ +#ifndef EGLCOMMON_H +#define EGLCOMMON_H + +typedef void (*init_func)(); +typedef void (*reshape_func)(int, int); +typedef void (*draw_func)(); +typedef int (*key_func)(unsigned key); + + +void set_window_size(int width, int height); +int window_width(void); +int window_height(void); + +int run(int argc, char **argv, + init_func init, + reshape_func resh, + draw_func draw, + key_func key); + +#endif diff --git a/progs/openvg/demos/lion-render.c b/progs/openvg/demos/lion-render.c new file mode 100644 index 0000000000..f3f151f552 --- /dev/null +++ b/progs/openvg/demos/lion-render.c @@ -0,0 +1,1573 @@ +#include "lion-render.h" + +#include <stdlib.h> +#include <stdio.h> + +#define ELEMENTS(x) (sizeof(x)/sizeof((x)[0])) + +static void init(struct lion *l, int i, VGint hexColor, const VGfloat *coords, int elems) +{ + static VGubyte cmds[128]; + VGfloat color[4]; + VGint j; + + color[0] = ((hexColor >> 16) & 0xff) / 255.f; + color[1] = ((hexColor >> 8) & 0xff) / 255.f; + color[2] = ((hexColor >> 0) & 0xff) / 255.f; + color[3] = 1.0; + + l->paths[i] = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1.0f, 0.0f, + 0, 0, (unsigned int)VG_PATH_CAPABILITY_ALL); + l->fills[i] = vgCreatePaint(); + vgSetParameterfv(l->fills[i], VG_PAINT_COLOR, 4, color); + + cmds[0] = VG_MOVE_TO_ABS; + for (j = 1; j < elems; ++j) { + cmds[j] = VG_LINE_TO_ABS; + } + + vgAppendPathData(l->paths[i], elems, cmds, coords); +} + +static void poly0(struct lion *l) +{ + VGfloat color = 0xf2cc99; + static const VGfloat coords[] = {69,18, 82,8, 99,3, 118,5, 135,12, 149,21, 156,13, 165,9, 177,13, 183,28, + 180,50, 164,91, 155,107, 154,114, 151,121, 141,127, 139,136, 155,206, 157,251, 126,342, + 133,357, 128,376, 83,376, 75,368, 67,350, 61,350, 53,369, 4,369, 2,361, 5,354, + 12,342, 16,321, 4,257, 4,244, 7,218, 9,179, 26,127, 43,93, 32,77, 30,70, + 24,67, 16,49, 17,35, 18,23, 30,12, 40,7, 53,7, 62,12 + }; + + init(l, 0, color, coords, ELEMENTS(coords)/2); +} + +static void poly1(struct lion *l) +{ + VGfloat color = 0xe5b27f; + static const VGfloat coords[] = {142,79, 136,74, 138,82, 133,78, 133,84, 127,78, 128,85, + 124,80, 125,87, 119,82, 119,90, 125,99, 125,96, 128,100, 128,94, + 131,98, 132,93, 135,97, 136,93, 138,97, 139,94, 141,98, 143,94, + 144,85 + }; + + init(l, 1, color, coords, ELEMENTS(coords)/2); +} + +static void poly2(struct lion *l) +{ + VGfloat color = 0xeb8080; + static const VGfloat coords[] = {127,101, 132,100, 137,99, 144,101, 143,105, 135,110 + }; + + init(l, 2, color, coords, ELEMENTS(coords)/2); +} + +static void poly3(struct lion *l) +{ + VGfloat color = 0xf2cc99; + static const VGfloat coords[] = {178,229, 157,248, 139,296, 126,349, 137,356, + 158,357, 183,342, 212,332, 235,288, 235,261, + 228,252, 212,250, 188,251 + }; + + init(l, 3, color, coords, ELEMENTS(coords)/2); +} + +static void poly4(struct lion *l) +{ + VGfloat color = 0x9c826b; + static const VGfloat coords[] = {56,229, 48,241, 48,250, 57,281, 63,325, 71,338, + 81,315, 76,321, 79,311, 83,301, 75,308, 80,298, + 73,303, 76,296, 71,298, 74,292, 69,293, 74,284, + 78,278, 71,278, 74,274, 68,273, 70,268, 66,267, + 68,261, 60,266, 62,259, 65,253, 57,258, 59,251, + 55,254, 55,248, 60,237, 54,240, 58,234, 54,236 + }; + + init(l, 4, color, coords, ELEMENTS(coords)/2); +} + +static void poly5(struct lion *l) +{ + VGfloat color = 0x9c826b; + static const VGfloat coords[] = {74,363, 79,368, 81,368, 85,362, 89,363, 92,370, 96,373, + 101,372, 108,361, 110,371, 113,373, 116,371, 120,358, 122,363, + 123,371, 126,371, 129,367, 132,357, 135,361, 130,376, 127,377, + 94,378, 84,376, 76,371 + }; + + init(l, 5, color, coords, ELEMENTS(coords)/2); +} + +static void poly6(struct lion *l) +{ + VGfloat color = 0x9c826b; + static const VGfloat coords[] = {212,250, 219,251, 228,258, 236,270, 235,287, 225,304, + 205,332, 177,343, 171,352, 158,357, 166,352, 168,346, + 168,339, 165,333, 155,327, 155,323, 161,320, 165,316, + 169,316, 167,312, 171,313, 168,308, 173,309, 170,306, + 177,306, 175,308, 177,311, 174,311, 176,316, 171,315, + 174,319, 168,320, 168,323, 175,327, 179,332, 183,326, + 184,332, 189,323, 190,328, 194,320, 194,325, 199,316, + 201,320, 204,313, 206,316, 208,310, 211,305, 219,298, + 226,288, 229,279, 228,266, 224,259, 217,253 + }; + + init(l, 6, color, coords, ELEMENTS(coords)/2); +} + +static void poly7(struct lion *l) +{ + VGfloat color = 0x9c826b; + static const VGfloat coords[] = {151,205, 151,238, 149,252, 141,268, 128,282, 121,301, + 130,300, 126,313, 118,324, 116,337, 120,346, 133,352, + 133,340, 137,333, 145,329, 156,327, 153,319, 153,291, + 157,271, 170,259, 178,277, 193,250, 174,216 + }; + + init(l, 7, color, coords, ELEMENTS(coords)/2); +} + +static void poly8(struct lion *l) +{ + VGfloat color = 0x9c826b; + static const VGfloat coords[] = {78,127, 90,142, 95,155, 108,164, 125,167, 139,175, + 150,206, 152,191, 141,140, 121,148, 100,136 + }; + + init(l, 8, color, coords, ELEMENTS(coords)/2); +} + +static void poly9(struct lion *l) +{ + VGfloat color = 0x9c826b; + static const VGfloat coords[] = {21,58, 35,63, 38,68, 32,69, 42,74, 40,79, 47,80, 54,83, + 45,94, 34,81, 32,73, 24,66 + }; + + init(l, 9, color, coords, ELEMENTS(coords)/2); +} + +static void poly10(struct lion *l) +{ + VGfloat color = 0x9c826b; + static const VGfloat coords[] = {71,34, 67,34, 66,27, 59,24, 54,17, 48,17, 39,22, + 30,26, 28,31, 31,39, 38,46, 29,45, 36,54, 41,61, + 41,70, 50,69, 54,71, 55,58, 67,52, 76,43, 76,39, + 68,44 + }; + + init(l, 10, color, coords, ELEMENTS(coords)/2); +} + +static void poly11(struct lion *l) +{ + VGfloat color = 0x9c826b; + static const VGfloat coords[] = {139,74, 141,83, 143,89, 144,104, 148,104, 155,106, + 154,86, 157,77, 155,72, 150,77, 144,77 + }; + + init(l, 11, color, coords, ELEMENTS(coords)/2); +} + +static void poly12(struct lion *l) +{ + VGfloat color = 0x9c826b; + static const VGfloat coords[] = {105,44, 102,53, 108,58, 111,62, 112,55 + }; + + init(l, 12, color, coords, ELEMENTS(coords)/2); +} + +static void poly13(struct lion *l) +{ + VGfloat color = 0x9c826b; + static const VGfloat coords[] = {141,48, 141,54, 144,58, 139,62, 137,66, 136,59, 137,52 + }; + + init(l, 13, color, coords, ELEMENTS(coords)/2); +} + +static void poly14(struct lion *l) +{ + VGfloat color = 0x9c826b; + static const VGfloat coords[] = {98,135, 104,130, 105,134, 108,132, 108,135, 112,134, + 113,137, 116,136, 116,139, 119,139, 124,141, 128,140, + 133,138, 140,133, 139,140, 126,146, 104,144 + }; + + init(l, 14, color, coords, ELEMENTS(coords)/2); +} + +static void poly15(struct lion *l) +{ + VGfloat color = 0x9c826b; + static const VGfloat coords[] = {97,116, 103,119, 103,116, 111,118, 116,117, 122,114, + 127,107, 135,111, 142,107, 141,114, 145,118, 149,121, + 145,125, 140,124, 127,121, 113,125, 100,124 + }; + + init(l, 15, color, coords, ELEMENTS(coords)/2); +} + +static void poly16(struct lion *l) +{ + VGfloat color = 0x9c826b; + static const VGfloat coords[] = {147,33, 152,35, 157,34, 153,31, 160,31, 156,28, 161,28, + 159,24, 163,25, 163,21, 165,22, 170,23, 167,17, 172,21, + 174,18, 175,23, 176,22, 177,28, 177,33, 174,37, 176,39, + 174,44, 171,49, 168,53, 164,57, 159,68, 156,70, 154,60, + 150,51, 146,43, 144,35 + }; + + init(l, 16, color, coords, ELEMENTS(coords)/2); +} + +static void poly17(struct lion *l) +{ + VGfloat color = 0x9c826b; + static const VGfloat coords[] = {85,72, 89,74, 93,75, 100,76, 105,75, 102,79, 94,79, 88,76 + }; + + init(l, 17, color, coords, ELEMENTS(coords)/2); +} + +static void poly18(struct lion *l) +{ + VGfloat color = 0x9c826b; + static const VGfloat coords[] = {86,214, 79,221, 76,232, 82,225, 78,239, 82,234, 78,245, + 81,243, 79,255, 84,250, 84,267, 87,254, 90,271, 90,257, + 95,271, 93,256, 95,249, 92,252, 93,243, 89,253, 89,241, + 86,250, 87,236, 83,245, 87,231, 82,231, 90,219, 84,221 + }; + + init(l, 18, color, coords, ELEMENTS(coords)/2); +} + +static void poly19(struct lion *l) +{ + VGfloat color = 0xffcc7f; + static const VGfloat coords[] = {93,68, 96,72, 100,73, 106,72, 108,66, 105,63, 100,62 + }; + + init(l, 19, color, coords, ELEMENTS(coords)/2); +} + +static void poly20(struct lion *l) +{ + VGfloat color = 0xffcc7f; + static const VGfloat coords[] = {144,64, 142,68, 142,73, 146,74, 150,73, 154,64, 149,62 + }; + + init(l, 20, color, coords, ELEMENTS(coords)/2); +} + +static void poly21(struct lion *l) +{ + VGfloat color = 0x9c826b; + static const VGfloat coords[] = {57,91, 42,111, 52,105, 41,117, 53,112, 46,120, 53,116, + 50,124, 57,119, 55,127, 61,122, 60,130, 67,126, 66,134, + 71,129, 72,136, 77,130, 76,137, 80,133, 82,138, 86,135, + 96,135, 94,129, 86,124, 83,117, 77,123, 79,117, 73,120, + 75,112, 68,116, 71,111, 65,114, 69,107, 63,110, 68,102, + 61,107, 66,98, 61,103, 63,97, 57,99 + }; + + init(l, 21, color, coords, ELEMENTS(coords)/2); +} + +static void poly22(struct lion *l) +{ + VGfloat color = 0x9c826b; + static const VGfloat coords[] = {83,79, 76,79, 67,82, 75,83, 65,88, 76,87, 65,92, 76,91, + 68,96, 77,95, 70,99, 80,98, 72,104, 80,102, 76,108, 85,103, + 92,101, 87,98, 93,96, 86,94, 91,93, 85,91, 93,89, 99,89, 105,93, + 107,85, 102,82, 92,80 + }; + + init(l, 22, color, coords, ELEMENTS(coords)/2); +} + +static void poly23(struct lion *l) +{ + VGfloat color = 0x9c826b; + static const VGfloat coords[] = {109,77, 111,83, 109,89, 113,94, 117,90, 117,81, 114,78 + }; + + init(l, 23, color, coords, ELEMENTS(coords)/2); +} + +static void poly24(struct lion *l) +{ + VGfloat color = 0x9c826b; + static const VGfloat coords[] = {122,128, 127,126, 134,127, 136,129, 134,130, 130,128, 124,129 + }; + + init(l, 24, color, coords, ELEMENTS(coords)/2); +} + +static void poly25(struct lion *l) +{ + VGfloat color = 0x9c826b; + static const VGfloat coords[] = {78,27, 82,32, 80,33, 82,36, 78,37, 82,40, 78,42, 81,46, 76,47, + 78,49, 74,50, 82,52, 87,50, 83,48, 91,46, 86,45, 91,42, 88,40, + 92,37, 86,34, 90,31, 86,29, 89,26 + }; + + init(l, 25, color, coords, ELEMENTS(coords)/2); +} + +static void poly26(struct lion *l) +{ + VGfloat color = 0x9c826b; + static const VGfloat coords[] = {82,17, 92,20, 79,21, 90,25, 81,25, 94,28, 93,26, 101,30, + 101,26, 107,33, 108,28, 111,40, 113,34, 115,45, 117,39, + 119,54, 121,46, 124,58, 126,47, 129,59, 130,49, 134,58, + 133,44, 137,48, 133,37, 137,40, 133,32, 126,20, 135,26, + 132,19, 138,23, 135,17, 142,18, 132,11, 116,6, 94,6, 78,11, + 92,12, 80,14, 90,16 + }; + + init(l, 26, color, coords, ELEMENTS(coords)/2); +} + +static void poly27(struct lion *l) +{ + VGfloat color = 0x9c826b; + static const VGfloat coords[] = {142,234, 132,227, 124,223, 115,220, 110,225, 118,224, 127,229, + 135,236, 122,234, 115,237, 113,242, 121,238, 139,243, 121,245, + 111,254, 95,254, 102,244, 104,235, 110,229, 100,231, 104,224, + 113,216, 122,215, 132,217, 141,224, 145,230, 149,240 + }; + + init(l, 27, color, coords, ELEMENTS(coords)/2); +} + +static void poly28(struct lion *l) +{ + VGfloat color = 0x9c826b; + static const VGfloat coords[] = {115,252, 125,248, 137,249, 143,258, 134,255, 125,254 + }; + + init(l, 28, color, coords, ELEMENTS(coords)/2); +} + +static void poly29(struct lion *l) +{ + VGfloat color = 0x9c826b; + static const VGfloat coords[] = {114,212, 130,213, 140,219, 147,225, 144,214, 137,209, 128,207 + }; + + init(l, 29, color, coords, ELEMENTS(coords)/2); +} + +static void poly30(struct lion *l) +{ + VGfloat color = 0x9c826b; + static const VGfloat coords[] = {102,263, 108,258, 117,257, 131,258, 116,260, 109,265 + }; + + init(l, 30, color, coords, ELEMENTS(coords)/2); +} + +static void poly31(struct lion *l) +{ + VGfloat color = 0x9c826b; + static const VGfloat coords[] = {51,241, 35,224, 40,238, 23,224, 31,242, 19,239, 28,247, 17,246, + 25,250, 37,254, 39,263, 44,271, 47,294, 48,317, 51,328, 60,351, + 60,323, 53,262, 47,246 + }; + + init(l, 31, color, coords, ELEMENTS(coords)/2); +} + +static void poly32(struct lion *l) +{ + VGfloat color = 0x9c826b; + static const VGfloat coords[] = {2,364, 9,367, 14,366, 18,355, 20,364, 26,366, 31,357, 35,364, + 39,364, 42,357, 47,363, 53,360, 59,357, 54,369, 7,373 + }; + + init(l, 32, color, coords, ELEMENTS(coords)/2); +} + +static void poly33(struct lion *l) +{ + VGfloat color = 0x9c826b; + static const VGfloat coords[] = {7,349, 19,345, 25,339, 18,341, 23,333, 28,326, 23,326, 27,320, + 23,316, 25,311, 20,298, 15,277, 12,264, 9,249, 10,223, 3,248, + 5,261, 15,307, 17,326, 11,343 + }; + + init(l, 33, color, coords, ELEMENTS(coords)/2); +} + +static void poly34(struct lion *l) +{ + VGfloat color = 0x9c826b; + static const VGfloat coords[] = {11,226, 15,231, 25,236, 18,227 + }; + + init(l, 34, color, coords, ELEMENTS(coords)/2); +} + +static void poly35(struct lion *l) +{ + VGfloat color = 0x9c826b; + static const VGfloat coords[] = {13,214, 19,217, 32,227, 23,214, 16,208, 15,190, 24,148, + 31,121, 24,137, 14,170, 8,189 + }; + + init(l, 35, color, coords, ELEMENTS(coords)/2); +} + +static void poly36(struct lion *l) +{ + VGfloat color = 0x9c826b; + static const VGfloat coords[] = {202,254, 195,258, 199,260, 193,263, 197,263, 190,268, + 196,268, 191,273, 188,282, 200,272, 194,272, 201,266, + 197,265, 204,262, 200,258, 204,256 + }; + + init(l, 36, color, coords, ELEMENTS(coords)/2); +} + +static void poly37(struct lion *l) +{ + VGfloat color = 0x845433; + static const VGfloat coords[] = {151,213, 165,212, 179,225, 189,246, 187,262, 179,275, + 176,263, 177,247, 171,233, 163,230, 165,251, 157,264, + 146,298, 145,321, 133,326, 143,285, 154,260, 153,240 + }; + + init(l, 37, color, coords, ELEMENTS(coords)/2); +} + +static void poly38(struct lion *l) +{ + VGfloat color = 0x845433; + static const VGfloat coords[] = {91,132, 95,145, 97,154, 104,148, 107,155, 109,150, 111,158, + 115,152, 118,159, 120,153, 125,161, 126,155, 133,164, 132,154, + 137,163, 137,152, 142,163, 147,186, 152,192, 148,167, 141,143, + 124,145, 105,143 + }; + + init(l, 38, color, coords, ELEMENTS(coords)/2); +} + +static void poly39(struct lion *l) +{ + VGfloat color = 0x9c826b; + static const VGfloat coords[] = {31,57, 23,52, 26,51, 20,44, 23,42, 21,36, 22,29, 25,23, + 24,32, 30,43, 26,41, 30,50, 26,48 + }; + + init(l, 39, color, coords, ELEMENTS(coords)/2); +} + +static void poly40(struct lion *l) +{ + VGfloat color = 0x9c826b; + static const VGfloat coords[] = {147,21, 149,28, 155,21, 161,16, 167,14, 175,15, 173,11, 161,9 + }; + + init(l, 40, color, coords, ELEMENTS(coords)/2); +} + +static void poly41(struct lion *l) +{ + VGfloat color = 0x9c826b; + static const VGfloat coords[] = {181,39, 175,51, 169,57, 171,65, 165,68, 165,75, 160,76, + 162,91, 171,71, 180,51 + }; + + init(l, 41, color, coords, ELEMENTS(coords)/2); +} + +static void poly42(struct lion *l) +{ + VGfloat color = 0x9c826b; + static const VGfloat coords[] = {132,346, 139,348, 141,346, 142,341, 147,342, 143,355, 133,350 + }; + + init(l, 42, color, coords, ELEMENTS(coords)/2); +} + +static void poly43(struct lion *l) +{ + VGfloat color = 0x9c826b; + static const VGfloat coords[] = {146,355, 151,352, 155,348, 157,343, 160,349, 151,356, 147,357 + }; + + init(l, 43, color, coords, ELEMENTS(coords)/2); +} + +static void poly44(struct lion *l) +{ + VGfloat color = 0x9c826b; + static const VGfloat coords[] = {99,266, 100,281, 94,305, 86,322, 78,332, 72,346, 73,331, 91,291 + }; + + init(l, 44, color, coords, ELEMENTS(coords)/2); +} + +static void poly45(struct lion *l) +{ + VGfloat color = 0x9c826b; + static const VGfloat coords[] = {20,347, 32,342, 45,340, 54,345, 45,350, 42,353, 38,350, + 31,353, 29,356, 23,350, 19,353, 15,349 + }; + + init(l, 45, color, coords, ELEMENTS(coords)/2); +} + +static void poly46(struct lion *l) +{ + VGfloat color = 0x9c826b; + static const VGfloat coords[] = {78,344, 86,344, 92,349, 88,358, 84,352 + }; + + init(l, 46, color, coords, ELEMENTS(coords)/2); +} + +static void poly47(struct lion *l) +{ + VGfloat color = 0x9c826b; + static const VGfloat coords[] = {93,347, 104,344, 117,345, 124,354, 121,357, 116,351, + 112,351, 108,355, 102,351 + }; + + init(l, 47, color, coords, ELEMENTS(coords)/2); +} + +static void poly48(struct lion *l) +{ + VGfloat color = 0x000000; + static const VGfloat coords[] = {105,12, 111,18, 113,24, 113,29, 119,34, 116,23, 112,16 + }; + + init(l, 48, color, coords, ELEMENTS(coords)/2); +} + +static void poly49(struct lion *l) +{ + VGfloat color = 0x000000; + static const VGfloat coords[] = {122,27, 125,34, 127,43, 128,34, 125,29 + }; + + init(l, 49, color, coords, ELEMENTS(coords)/2); +} + +static void poly50(struct lion *l) +{ + VGfloat color = 0x000000; + static const VGfloat coords[] = {115,13, 122,19, 122,15, 113,10 + }; + + init(l, 50, color, coords, ELEMENTS(coords)/2); +} + +static void poly51(struct lion *l) +{ + VGfloat color = 0xffe5b2; + static const VGfloat coords[] = {116,172, 107,182, 98,193, 98,183, 90,199, 89,189, 84,207, + 88,206, 87,215, 95,206, 93,219, 91,230, 98,216, 97,226, + 104,214, 112,209, 104,208, 113,202, 126,200, 139,207, 132,198, + 142,203, 134,192, 142,195, 134,187, 140,185, 130,181, 136,177, + 126,177, 125,171, 116,180 + }; + + init(l, 51, color, coords, ELEMENTS(coords)/2); +} + +static void poly52(struct lion *l) +{ + VGfloat color = 0xffe5b2; + static const VGfloat coords[] = {74,220, 67,230, 67,221, 59,235, 63,233, 60,248, 70,232, 65,249, + 71,243, 67,256, 73,250, 69,262, 73,259, 71,267, 76,262, 72,271, + 78,270, 76,275, 82,274, 78,290, 86,279, 86,289, 92,274, 88,275, + 87,264, 82,270, 82,258, 77,257, 78,247, 73,246, 77,233, 72,236 + }; + + init(l, 52, color, coords, ELEMENTS(coords)/2); +} + +static void poly53(struct lion *l) +{ + VGfloat color = 0xffe5b2; + static const VGfloat coords[] = {133,230, 147,242, 148,250, 145,254, 138,247, 129,246, 142,245, + 138,241, 128,237, 137,238 + }; + + init(l, 53, color, coords, ELEMENTS(coords)/2); +} + +static void poly54(struct lion *l) +{ + VGfloat color = 0xffe5b2; + static const VGfloat coords[] = {133,261, 125,261, 116,263, 111,267, 125,265 + }; + + init(l, 54, color, coords, ELEMENTS(coords)/2); +} + +static void poly55(struct lion *l) +{ + VGfloat color = 0xffe5b2; + static const VGfloat coords[] = {121,271, 109,273, 103,279, 99,305, 92,316, 85,327, 83,335, + 89,340, 97,341, 94,336, 101,336, 96,331, 103,330, 97,327, 108,325, + 99,322, 109,321, 100,318, 110,317, 105,314, 110,312, 107,310, 113,308, + 105,306, 114,303, 105,301, 115,298, 107,295, 115,294, 108,293, 117,291, + 109,289, 117,286, 109,286, 118,283, 112,281, 118,279, 114,278, + 119,276, 115,274 + }; + + init(l, 55, color, coords, ELEMENTS(coords)/2); +} + +static void poly56(struct lion *l) +{ + VGfloat color = 0xffe5b2; + static const VGfloat coords[] = {79,364, 74,359, 74,353, 76,347, 80,351, 83,356, 82,360 + }; + + init(l, 56, color, coords, ELEMENTS(coords)/2); +} + +static void poly57(struct lion *l) +{ + VGfloat color = 0xffe5b2; + static const VGfloat coords[] = {91,363, 93,356, 97,353, 103,355, 105,360, 103,366, 99,371, 94,368 + }; + + init(l, 57, color, coords, ELEMENTS(coords)/2); +} + +static void poly58(struct lion *l) +{ + VGfloat color = 0xffe5b2; + static const VGfloat coords[] = {110,355, 114,353, 118,357, 117,363, 113,369, 111,362 + }; + + init(l, 58, color, coords, ELEMENTS(coords)/2); +} + +static void poly59(struct lion *l) +{ + VGfloat color = 0xffe5b2; + static const VGfloat coords[] = {126,354, 123,358, 124,367, 126,369, 129,361, 129,357 + }; + + init(l, 59, color, coords, ELEMENTS(coords)/2); +} + +static void poly60(struct lion *l) +{ + VGfloat color = 0xffe5b2; + static const VGfloat coords[] = {30,154, 24,166, 20,182, 23,194, 29,208, 37,218, 41,210, 41,223, + 46,214, 46,227, 52,216, 52,227, 61,216, 59,225, 68,213, 73,219, + 70,207, 77,212, 69,200, 77,202, 70,194, 78,197, 68,187, 76,182, + 64,182, 58,175, 58,185, 53,177, 50,186, 46,171, 44,182, 39,167, + 36,172, 36,162, 30,166 + }; + + init(l, 60, color, coords, ELEMENTS(coords)/2); +} + +static void poly61(struct lion *l) +{ + VGfloat color = 0xffe5b2; + static const VGfloat coords[] = {44,130, 41,137, 45,136, 43,150, 48,142, 48,157, 53,150, + 52,164, 60,156, 61,169, 64,165, 66,175, 70,167, 74,176, + 77,168, 80,183, 85,172, 90,182, 93,174, 98,181, 99,173, + 104,175, 105,169, 114,168, 102,163, 95,157, 94,166, 90,154, + 87,162, 82,149, 75,159, 72,148, 68,155, 67,143, 62,148, 62,138, + 58,145, 56,133, 52,142, 52,128, 49,134, 47,125 + }; + + init(l, 61, color, coords, ELEMENTS(coords)/2); +} + +static void poly62(struct lion *l) +{ + VGfloat color = 0xffe5b2; + static const VGfloat coords[] = {13,216, 19,219, 36,231, 22,223, 16,222, 22,227, 12,224, 13,220, 16,220 + }; + + init(l, 62, color, coords, ELEMENTS(coords)/2); +} + +static void poly63(struct lion *l) +{ + VGfloat color = 0xffe5b2; + static const VGfloat coords[] = {10,231, 14,236, 25,239, 27,237, 19,234 + }; + + init(l, 63, color, coords, ELEMENTS(coords)/2); +} + +static void poly64(struct lion *l) +{ + VGfloat color = 0xffe5b2; + static const VGfloat coords[] = {9,245, 14,242, 25,245, 13,245 + }; + + init(l, 64, color, coords, ELEMENTS(coords)/2); +} + +static void poly65(struct lion *l) +{ + VGfloat color = 0xffe5b2; + static const VGfloat coords[] = {33,255, 26,253, 18,254, 25,256, 18,258, 27,260, 18,263, + 27,265, 19,267, 29,270, 21,272, 29,276, 21,278, 30,281, + 22,283, 31,287, 24,288, 32,292, 23,293, 34,298, 26,299, + 37,303, 32,305, 39,309, 33,309, 39,314, 34,314, 40,318, + 34,317, 40,321, 34,321, 41,326, 33,326, 40,330, 33,332, + 39,333, 33,337, 42,337, 54,341, 49,337, 52,335, 47,330, + 50,330, 45,325, 49,325, 45,321, 48,321, 45,316, 46,306, + 45,286, 43,274, 36,261 + }; + + init(l, 65, color, coords, ELEMENTS(coords)/2); +} + +static void poly66(struct lion *l) +{ + VGfloat color = 0xffe5b2; + static const VGfloat coords[] = {7,358, 9,351, 14,351, 17,359, 11,364 + }; + + init(l, 66, color, coords, ELEMENTS(coords)/2); +} + +static void poly67(struct lion *l) +{ + VGfloat color = 0xffe5b2; + static const VGfloat coords[] = {44,354, 49,351, 52,355, 49,361 + }; + + init(l, 67, color, coords, ELEMENTS(coords)/2); +} + +static void poly68(struct lion *l) +{ + VGfloat color = 0xffe5b2; + static const VGfloat coords[] = {32,357, 37,353, 40,358, 36,361 + }; + + init(l, 68, color, coords, ELEMENTS(coords)/2); +} + +static void poly69(struct lion *l) +{ + VGfloat color = 0xffe5b2; + static const VGfloat coords[] = {139,334, 145,330, 154,330, 158,334, 154,341, 152,348, + 145,350, 149,340, 147,336, 141,339, 139,345, 136,342, + 136,339 + }; + + init(l, 69, color, coords, ELEMENTS(coords)/2); +} + +static void poly70(struct lion *l) +{ + VGfloat color = 0xffe5b2; + static const VGfloat coords[] = {208,259, 215,259, 212,255, 220,259, 224,263, 225,274, 224,283, + 220,292, 208,300, 206,308, 203,304, 199,315, 197,309, 195,318, + 193,313, 190,322, 190,316, 185,325, 182,318, 180,325, 172,321, + 178,320, 176,313, 186,312, 180,307, 188,307, 184,303, 191,302, + 186,299, 195,294, 187,290, 197,288, 192,286, 201,283, 194,280, + 203,277, 198,275, 207,271, 200,269, 209,265, 204,265, 212,262 + }; + + init(l, 70, color, coords, ELEMENTS(coords)/2); +} + +static void poly71(struct lion *l) +{ + VGfloat color = 0xffe5b2; + static const VGfloat coords[] = {106,126, 106,131, 109,132, 111,134, 115,132, 115,135, 119,133, 118,137, + 123,137, 128,137, 133,134, 136,130, 136,127, 132,124, 118,128, 112,128, + 106,126, 106,126, 106,126 + }; + + init(l, 71, color, coords, ELEMENTS(coords)/2); +} + +static void poly72(struct lion *l) +{ + VGfloat color = 0xffe5b2; + static const VGfloat coords[] = {107,114, 101,110, 98,102, 105,97, 111,98, 119,102, 121,108, 118,112, 113,115 + }; + + init(l, 72, color, coords, ELEMENTS(coords)/2); +} + +static void poly73(struct lion *l) +{ + VGfloat color = 0xffe5b2; + static const VGfloat coords[] = {148,106, 145,110, 146,116, 150,118, 152,111, 151,107 + }; + + init(l, 73, color, coords, ELEMENTS(coords)/2); +} + +static void poly74(struct lion *l) +{ + VGfloat color = 0xffe5b2; + static const VGfloat coords[] = {80,55, 70,52, 75,58, 63,57, 72,61, 57,61, 67,66, 57,67, 62,69, 54,71, + 61,73, 54,77, 63,78, 53,85, 60,84, 56,90, 69,84, 63,82, 75,76, 70,75, + 77,72, 72,71, 78,69, 72,66, 81,67, 78,64, 82,63, 80,60, 86,62 + }; + + init(l, 74, color, coords, ELEMENTS(coords)/2); +} + +static void poly75(struct lion *l) +{ + VGfloat color = 0xffe5b2; + static const VGfloat coords[] = {87,56, 91,52, 96,50, 102,56, 98,56, 92,60 + }; + + init(l, 75, color, coords, ELEMENTS(coords)/2); +} + +static void poly76(struct lion *l) +{ + VGfloat color = 0xffe5b2; + static const VGfloat coords[] = {85,68, 89,73, 98,76, 106,74, 96,73, 91,70 + }; + + init(l, 76, color, coords, ELEMENTS(coords)/2); +} + +static void poly77(struct lion *l) +{ + VGfloat color = 0xffe5b2; + static const VGfloat coords[] = {115,57, 114,64, 111,64, 115,75, 122,81, 122,74, 126,79, + 126,74, 131,78, 130,72, 133,77, 131,68, 126,61, 119,57 + }; + + init(l, 77, color, coords, ELEMENTS(coords)/2); +} + +static void poly78(struct lion *l) +{ + VGfloat color = 0xffe5b2; + static const VGfloat coords[] = {145,48, 143,53, 147,59, 151,59, 150,55 + }; + + init(l, 78, color, coords, ELEMENTS(coords)/2); +} + +static void poly79(struct lion *l) +{ + VGfloat color = 0xffe5b2; + static const VGfloat coords[] = {26,22, 34,15, 43,10, 52,10, 59,16, 47,15, 32,22 + }; + + init(l, 79, color, coords, ELEMENTS(coords)/2); +} + +static void poly80(struct lion *l) +{ + VGfloat color = 0xffe5b2; + static const VGfloat coords[] = {160,19, 152,26, 149,34, 154,33, 152,30, 157,30, 155,26, 158,27, + 157,23, 161,23 + }; + + init(l, 80, color, coords, ELEMENTS(coords)/2); +} + +static void poly81(struct lion *l) +{ + VGfloat color = 0x000000; + static const VGfloat coords[] = {98,117, 105,122, 109,122, 105,117, 113,120, 121,120, 130,112, 128,108, + 123,103, 123,99, 128,101, 132,106, 135,109, 142,105, 142,101, 145,101, + 145,91, 148,101, 145,105, 136,112, 135,116, 143,124, 148,120, 150,122, + 142,128, 133,122, 121,125, 112,126, 103,125, 100,129, 96,124 + }; + + init(l, 81, color, coords, ELEMENTS(coords)/2); +} + +static void poly82(struct lion *l) +{ + VGfloat color = 0x000000; + static const VGfloat coords[] = {146,118, 152,118, 152,115, 149,115 + }; + + init(l, 82, color, coords, ELEMENTS(coords)/2); +} + +static void poly83(struct lion *l) +{ + VGfloat color = 0x000000; + static const VGfloat coords[] = {148,112, 154,111, 154,109, 149,109 + }; + + init(l, 83, color, coords, ELEMENTS(coords)/2); +} + +static void poly84(struct lion *l) +{ + VGfloat color = 0x000000; + static const VGfloat coords[] = {106,112, 108,115, 114,116, 118,114 + }; + + init(l, 84, color, coords, ELEMENTS(coords)/2); +} + +static void poly85(struct lion *l) +{ + VGfloat color = 0x000000; + static const VGfloat coords[] = {108,108, 111,110, 116,110, 119,108 + }; + + init(l, 85, color, coords, ELEMENTS(coords)/2); +} + +static void poly86(struct lion *l) +{ + VGfloat color = 0x000000; + static const VGfloat coords[] = {106,104, 109,105, 117,106, 115,104 + }; + + init(l, 86, color, coords, ELEMENTS(coords)/2); +} + +static void poly87(struct lion *l) +{ + VGfloat color = 0x000000; + static const VGfloat coords[] = {50,25, 41,26, 34,33, 39,43, 49,58, 36,51, 47,68, 55,69, 54,59, + 61,57, 74,46, 60,52, 67,42, 57,48, 61,40, 54,45, 60,36, 59,29, + 48,38, 52,30, 47,32 + }; + + init(l, 87, color, coords, ELEMENTS(coords)/2); +} + +static void poly88(struct lion *l) +{ + VGfloat color = 0x000000; + static const VGfloat coords[] = {147,34, 152,41, 155,49, 161,53, 157,47, 164,47, 158,43, 168,44, + 159,40, 164,37, 169,37, 164,33, 169,34, 165,28, 170,30, 170,25, + 173,29, 175,27, 176,32, 173,36, 175,39, 172,42, 172,46, 168,49, + 170,55, 162,57, 158,63, 155,58, 153,50, 149,46 + }; + + init(l, 88, color, coords, ELEMENTS(coords)/2); +} + +static void poly89(struct lion *l) +{ + VGfloat color = 0x000000; + static const VGfloat coords[] = {155,71, 159,80, 157,93, 157,102, 155,108, 150,101, 149,93, + 154,101, 152,91, 151,83, 155,79 + }; + + init(l, 89, color, coords, ELEMENTS(coords)/2); +} + +static void poly90(struct lion *l) +{ + VGfloat color = 0x000000; + static const VGfloat coords[] = {112,78, 115,81, 114,91, 112,87, 113,82 + }; + + init(l, 90, color, coords, ELEMENTS(coords)/2); +} + +static void poly91(struct lion *l) +{ + VGfloat color = 0x000000; + static const VGfloat coords[] = {78,28, 64,17, 58,11, 47,9, 36,10, 28,16, 21,26, 18,41, + 20,51, 23,61, 33,65, 28,68, 37,74, 36,81, 43,87, 48,90, + 43,100, 40,98, 39,90, 31,80, 30,72, 22,71, 17,61, 14,46, + 16,28, 23,17, 33,9, 45,6, 54,6, 65,12 + }; + + init(l, 91, color, coords, ELEMENTS(coords)/2); +} + +static void poly92(struct lion *l) +{ + VGfloat color = 0x000000; + static const VGfloat coords[] = {67,18, 76,9, 87,5, 101,2, 118,3, 135,8, 149,20, 149,26, + 144,19, 132,12, 121,9, 105,7, 89,8, 76,14, 70,20 + }; + + init(l, 92, color, coords, ELEMENTS(coords)/2); +} + +static void poly93(struct lion *l) +{ + VGfloat color = 0x000000; + static const VGfloat coords[] = {56,98, 48,106, 56,103, 47,112, 56,110, 52,115, 57,113, 52,121, 62,115, + 58,123, 65,119, 63,125, 69,121, 68,127, 74,125, 74,129, 79,128, 83,132, + 94,135, 93,129, 85,127, 81,122, 76,126, 75,121, 71,124, 71,117, 66,121, + 66,117, 62,117, 64,112, 60,113, 60,110, 57,111, 61,105, 57,107, 60,101, + 55,102 + }; + + init(l, 93, color, coords, ELEMENTS(coords)/2); +} + +static void poly94(struct lion *l) +{ + VGfloat color = 0x000000; + static const VGfloat coords[] = {101,132, 103,138, 106,134, 106,139, 112,136, 111,142, 115,139, + 114,143, 119,142, 125,145, 131,142, 135,138, 140,134, 140,129, + 143,135, 145,149, 150,171, 149,184, 145,165, 141,150, 136,147, + 132,151, 131,149, 126,152, 125,150, 121,152, 117,148, 111,152, + 110,148, 105,149, 104,145, 98,150, 96,138, 94,132, 94,130, 98,132 + }; + + init(l, 94, color, coords, ELEMENTS(coords)/2); +} + +static void poly95(struct lion *l) +{ + VGfloat color = 0x000000; + static const VGfloat coords[] = {41,94, 32,110, 23,132, 12,163, 6,190, 7,217, 5,236, + 3,247, 9,230, 12,211, 12,185, 18,160, 26,134, 35,110, + 43,99 + }; + + init(l, 95, color, coords, ELEMENTS(coords)/2); +} + +static void poly96(struct lion *l) +{ + VGfloat color = 0x000000; + static const VGfloat coords[] = {32,246, 41,250, 50,257, 52,267, 53,295, 53,323, 59,350, + 54,363, 51,365, 44,366, 42,360, 40,372, 54,372, 59,366, + 62,353, 71,352, 75,335, 73,330, 66,318, 68,302, 64,294, + 67,288, 63,286, 63,279, 59,275, 58,267, 56,262, 50,247, + 42,235, 44,246, 32,236, 35,244 + }; + + init(l, 96, color, coords, ELEMENTS(coords)/2); +} + +static void poly97(struct lion *l) +{ + VGfloat color = 0x000000; + static const VGfloat coords[] = {134,324, 146,320, 159,322, 173,327, 179,337, 179,349, + 172,355, 158,357, 170,350, 174,343, 170,333, 163,328, 152,326, + 134,329 + }; + + init(l, 97, color, coords, ELEMENTS(coords)/2); +} + +static void poly98(struct lion *l) +{ + VGfloat color = 0x000000; + static const VGfloat coords[] = {173,339, 183,334, 184,338, 191,329, 194,332, 199,323, 202,325, + 206,318, 209,320, 213,309, 221,303, 228,296, 232,289, 234,279, + 233,269, 230,262, 225,256, 219,253, 208,252, 198,252, 210,249, + 223,250, 232,257, 237,265, 238,277, 238,291, 232,305, 221,323, + 218,335, 212,342, 200,349, 178,348 + }; + + init(l, 98, color, coords, ELEMENTS(coords)/2); +} + +static void poly99(struct lion *l) +{ + VGfloat color = 0x000000; + static const VGfloat coords[] = {165,296, 158,301, 156,310, 156,323, 162,324, 159,318, + 162,308, 162,304 + }; + + init(l, 99, color, coords, ELEMENTS(coords)/2); +} + +static void poly100(struct lion *l) +{ + VGfloat color = 0x000000; + static const VGfloat coords[] = {99,252, 105,244, 107,234, 115,228, 121,228, 131,235, + 122,233, 113,235, 109,246, 121,239, 133,243, 121,243, + 110,251 + }; + + init(l, 100, color, coords, ELEMENTS(coords)/2); +} + +static void poly101(struct lion *l) +{ + VGfloat color = 0x000000; + static const VGfloat coords[] = {117,252, 124,247, 134,249, 136,253, 126,252 + }; + + init(l, 101, color, coords, ELEMENTS(coords)/2); +} + +static void poly102(struct lion *l) +{ + VGfloat color = 0x000000; + static const VGfloat coords[] = {117,218, 132,224, 144,233, 140,225, 132,219, 117,218, + 117,218, 117,218 + }; + + init(l, 102, color, coords, ELEMENTS(coords)/2); +} + +static void poly103(struct lion *l) +{ + VGfloat color = 0x000000; + static const VGfloat coords[] = {122,212, 134,214, 143,221, 141,213, 132,210 + }; + + init(l, 103, color, coords, ELEMENTS(coords)/2); +} + +static void poly104(struct lion *l) +{ + VGfloat color = 0x000000; + static const VGfloat coords[] = {69,352, 70,363, 76,373, 86,378, 97,379, 108,379, 120,377, + 128,378, 132,373, 135,361, 133,358, 132,366, 127,375, 121,374, + 121,362, 119,367, 117,374, 110,376, 110,362, 107,357, 106,371, + 104,375, 97,376, 90,375, 90,368, 86,362, 83,364, 86,369, 85,373, + 78,370, 73,362, 71,351 + }; + + init(l, 104, color, coords, ELEMENTS(coords)/2); +} + +static void poly105(struct lion *l) +{ + VGfloat color = 0x000000; + static const VGfloat coords[] = {100,360, 96,363, 99,369, 102,364 + }; + + init(l, 105, color, coords, ELEMENTS(coords)/2); +} + +static void poly106(struct lion *l) +{ + VGfloat color = 0x000000; + static const VGfloat coords[] = {115,360, 112,363, 114,369, 117,364 + }; + + init(l, 106, color, coords, ELEMENTS(coords)/2); +} + +static void poly107(struct lion *l) +{ + VGfloat color = 0x000000; + static const VGfloat coords[] = {127,362, 125,364, 126,369, 128,365 + }; + + init(l, 107, color, coords, ELEMENTS(coords)/2); +} + +static void poly108(struct lion *l) +{ + VGfloat color = 0x000000; + static const VGfloat coords[] = {5,255, 7,276, 11,304, 15,320, 13,334, 6,348, 2,353, 0,363, + 5,372, 12,374, 25,372, 38,372, 44,369, 42,367, 36,368, 31,369, + 30,360, 27,368, 20,370, 16,361, 15,368, 10,369, 3,366, 3,359, 6,352, + 11,348, 17,331, 19,316, 12,291, 9,274 + }; + + init(l, 108, color, coords, ELEMENTS(coords)/2); +} + +static void poly109(struct lion *l) +{ + VGfloat color = 0x000000; + static const VGfloat coords[] = {10,358, 7,362, 10,366, 11,362 + }; + + init(l, 109, color, coords, ELEMENTS(coords)/2); +} + +static void poly110(struct lion *l) +{ + VGfloat color = 0x000000; + static const VGfloat coords[] = {25,357, 22,360, 24,366, 27,360 + }; + + init(l, 110, color, coords, ELEMENTS(coords)/2); +} + +static void poly111(struct lion *l) +{ + VGfloat color = 0x000000; + static const VGfloat coords[] = {37,357, 34,361, 36,365, 38,361 + }; + + init(l, 111, color, coords, ELEMENTS(coords)/2); +} + +static void poly112(struct lion *l) +{ + VGfloat color = 0x000000; + static const VGfloat coords[] = {49,356, 46,359, 47,364, 50,360 + }; + + init(l, 112, color, coords, ELEMENTS(coords)/2); +} + +static void poly113(struct lion *l) +{ + VGfloat color = 0x000000; + static const VGfloat coords[] = {130,101, 132,102, 135,101, 139,102, 143,103, + 142,101, 137,100, 133,100 + }; + + init(l, 113, color, coords, ELEMENTS(coords)/2); +} + +static void poly114(struct lion *l) +{ + VGfloat color = 0x000000; + static const VGfloat coords[] = {106,48, 105,52, 108,56, 109,52 + }; + + init(l, 114, color, coords, ELEMENTS(coords)/2); +} + +static void poly115(struct lion *l) +{ + VGfloat color = 0x000000; + static const VGfloat coords[] = {139,52, 139,56, 140,60, 142,58, 141,56 + }; + + init(l, 115, color, coords, ELEMENTS(coords)/2); +} + +static void poly116(struct lion *l) +{ + VGfloat color = 0x000000; + static const VGfloat coords[] = {25,349, 29,351, 30,355, 33,350, 37,348, 42,351, 45,347, + 49,345, 44,343, 36,345 + }; + + init(l, 116, color, coords, ELEMENTS(coords)/2); +} + +static void poly117(struct lion *l) +{ + VGfloat color = 0x000000; + static const VGfloat coords[] = {98,347, 105,351, 107,354, 109,349, 115,349, 120,353, 118,349, + 113,346, 104,346 + }; + + init(l, 117, color, coords, ELEMENTS(coords)/2); +} + +static void poly118(struct lion *l) +{ + VGfloat color = 0x000000; + static const VGfloat coords[] = {83,348, 87,352, 87,357, 89,351, 87,348 + }; + + init(l, 118, color, coords, ELEMENTS(coords)/2); +} + +static void poly119(struct lion *l) +{ + VGfloat color = 0x000000; + static const VGfloat coords[] = {155,107, 163,107, 170,107, 186,108, 175,109, 155,109 + }; + + init(l, 119, color, coords, ELEMENTS(coords)/2); +} + +static void poly120(struct lion *l) +{ + VGfloat color = 0x000000; + static const VGfloat coords[] = {153,114, 162,113, 175,112, 192,114, 173,114, 154,115 + }; + + init(l, 120, color, coords, ELEMENTS(coords)/2); +} + +static void poly121(struct lion *l) +{ + VGfloat color = 0x000000; + static const VGfloat coords[] = {152,118, 164,120, 180,123, 197,129, 169,123, 151,120 + }; + + init(l, 121, color, coords, ELEMENTS(coords)/2); +} + +static void poly122(struct lion *l) +{ + VGfloat color = 0x000000; + static const VGfloat coords[] = {68,109, 87,106, 107,106, 106,108, 88,108 + }; + + init(l, 122, color, coords, ELEMENTS(coords)/2); +} + +static void poly123(struct lion *l) +{ + VGfloat color = 0x000000; + static const VGfloat coords[] = {105,111, 95,112, 79,114, 71,116, 85,115, 102,113 + }; + + init(l, 123, color, coords, ELEMENTS(coords)/2); +} + +static void poly124(struct lion *l) +{ + VGfloat color = 0x000000; + static const VGfloat coords[] = {108,101, 98,99, 87,99, 78,99, 93,100, 105,102 + }; + + init(l, 124, color, coords, ELEMENTS(coords)/2); +} + +static void poly125(struct lion *l) +{ + VGfloat color = 0x000000; + static const VGfloat coords[] = {85,63, 91,63, 97,60, 104,60, 108,62, 111,69, 112,75, + 110,74, 108,71, 103,73, 106,69, 105,65, 103,64, 103,67, + 102,70, 99,70, 97,66, 94,67, 97,72, 88,67, 84,66 + }; + + init(l, 125, color, coords, ELEMENTS(coords)/2); +} + +static void poly126(struct lion *l) +{ + VGfloat color = 0x000000; + static const VGfloat coords[] = {140,74, 141,66, 144,61, 150,61, 156,62, 153,70, 150,73, + 152,65, 150,65, 151,68, 149,71, 146,71, 144,66, 143,70, + 143,74 + }; + + init(l, 126, color, coords, ELEMENTS(coords)/2); +} + +static void poly127(struct lion *l) +{ + VGfloat color = 0x000000; + static const VGfloat coords[] = {146,20, 156,11, 163,9, 172,9, 178,14, 182,18, 184,32, 182,42, + 182,52, 177,58, 176,67, 171,76, 165,90, 157,105, 160,92, 164,85, + 168,78, 167,73, 173,66, 172,62, 175,59, 174,55, 177,53, 180,46, + 181,29, 179,21, 173,13, 166,11, 159,13, 153,18, 148,23 + }; + + init(l, 127, color, coords, ELEMENTS(coords)/2); +} + +static void poly128(struct lion *l) +{ + VGfloat color = 0x000000; + static const VGfloat coords[] = {150,187, 148,211, 150,233, 153,247, 148,267, 135,283, 125,299, + 136,292, 131,313, 122,328, 122,345, 129,352, 133,359, 133,367, + 137,359, 148,356, 140,350, 131,347, 129,340, 132,332, 140,328, + 137,322, 140,304, 154,265, 157,244, 155,223, 161,220, 175,229, + 186,247, 185,260, 176,275, 178,287, 185,277, 188,261, 196,253, + 189,236, 174,213 + }; + + init(l, 128, color, coords, ELEMENTS(coords)/2); +} + +static void poly129(struct lion *l) +{ + VGfloat color = 0x000000; + static const VGfloat coords[] = {147,338, 142,341, 143,345, 141,354, 147,343 + }; + + init(l, 129, color, coords, ELEMENTS(coords)/2); +} + +static void poly130(struct lion *l) +{ + VGfloat color = 0x000000; + static const VGfloat coords[] = {157,342, 156,349, 150,356, 157,353, 163,346, 162,342 + }; + + init(l, 130, color, coords, ELEMENTS(coords)/2); +} + +static void poly131(struct lion *l) +{ + VGfloat color = 0x000000; + static const VGfloat coords[] = {99,265, 96,284, 92,299, 73,339, 73,333, 87,300 + }; + + init(l, 131, color, coords, ELEMENTS(coords)/2); +} + + +struct lion * lion_create(void) +{ + struct lion *l = calloc(1, sizeof(struct lion)); + + poly0(l); + poly1(l); + poly2(l); + poly3(l); + poly4(l); + poly5(l); + poly6(l); + poly7(l); + poly8(l); + poly9(l); + + poly10(l); + poly11(l); + poly12(l); + poly13(l); + poly14(l); + poly15(l); + poly16(l); + poly17(l); + poly18(l); + poly19(l); + + poly20(l); + poly21(l); + poly22(l); + poly23(l); + poly24(l); + poly25(l); + poly26(l); + poly27(l); + poly28(l); + poly29(l); + + poly30(l); + poly31(l); + poly32(l); + poly33(l); + poly34(l); + poly35(l); + poly36(l); + poly37(l); + poly38(l); + poly39(l); + + poly40(l); + poly41(l); + poly42(l); + poly43(l); + poly44(l); + poly45(l); + poly46(l); + poly47(l); + poly48(l); + poly49(l); + + poly50(l); + poly51(l); + poly52(l); + poly53(l); + poly54(l); + poly55(l); + poly56(l); + poly57(l); + poly58(l); + poly59(l); + + poly60(l); + poly61(l); + poly62(l); + poly63(l); + poly64(l); + poly65(l); + poly66(l); + poly67(l); + poly68(l); + poly69(l); + + poly70(l); + poly71(l); + poly72(l); + poly73(l); + poly74(l); + poly75(l); + poly76(l); + poly77(l); + poly78(l); + poly79(l); + + poly80(l); + poly81(l); + poly82(l); + poly83(l); + poly84(l); + poly85(l); + poly86(l); + poly87(l); + poly88(l); + poly89(l); + + poly90(l); + poly91(l); + poly92(l); + poly93(l); + poly94(l); + poly95(l); + poly96(l); + poly97(l); + poly98(l); + poly99(l); + + poly100(l); + poly101(l); + poly102(l); + poly103(l); + poly104(l); + poly105(l); + poly106(l); + poly107(l); + poly108(l); + poly109(l); + + poly110(l); + poly111(l); + poly112(l); + poly113(l); + poly114(l); + poly115(l); + poly116(l); + poly117(l); + poly118(l); + poly119(l); + + poly120(l); + poly121(l); + poly122(l); + poly123(l); + poly124(l); + poly125(l); + poly126(l); + poly127(l); + poly128(l); + poly129(l); + + poly130(l); + poly131(l); + + return l; +} + +void lion_render(struct lion *l) +{ + VGint i; + + for (i = 0; i < LION_SIZE; ++i) { + vgSetPaint(l->fills[i], VG_FILL_PATH); + vgDrawPath(l->paths[i], VG_FILL_PATH); + } +} + +void lion_destroy(struct lion *l) +{ + VGint i; + for (i = 0; i < LION_SIZE; ++i) { + vgDestroyPaint(l->fills[i]); + vgDestroyPath(l->paths[i]); + } + free(l); +} diff --git a/progs/openvg/demos/lion-render.h b/progs/openvg/demos/lion-render.h new file mode 100644 index 0000000000..c4c020b7ed --- /dev/null +++ b/progs/openvg/demos/lion-render.h @@ -0,0 +1,16 @@ +#ifndef LION_RENDER_H +#define LION_RENDER_H + +#include <VG/openvg.h> + +#define LION_SIZE 132 +struct lion { + VGPath paths[LION_SIZE]; + VGPaint fills[LION_SIZE]; +}; + +struct lion *lion_create(void); +void lion_render(struct lion *l); +void lion_destroy(struct lion *l); + +#endif diff --git a/progs/openvg/demos/lion.c b/progs/openvg/demos/lion.c new file mode 100644 index 0000000000..7224fed399 --- /dev/null +++ b/progs/openvg/demos/lion.c @@ -0,0 +1,288 @@ +#include <assert.h> +#include <math.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <X11/Xlib.h> +#include <X11/Xutil.h> +#include <X11/keysym.h> +#include <VG/openvg.h> +#include <GLES/egl.h> + +#include "lion-render.h" + +static VGint width, height; +struct lion *lion = 0; +VGfloat angle = 0; + +static void +draw(void) +{ + vgClear(0, 0, width, height); + + vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); + vgLoadIdentity(); + vgTranslate(width/2, height/2); + vgRotate(angle); + vgTranslate(-width/2, -height/2); + + lion_render(lion); + + ++angle; +} + + +/* new window size or exposure */ +static void +reshape(int w, int h) +{ + width = w; + height = h; +} + + +static void +init(void) +{ + float clear_color[4] = {1.0, 1.0, 1.0, 1.0}; + vgSetfv(VG_CLEAR_COLOR, 4, clear_color); + + lion = lion_create(); +} + + +/* + * Create an RGB, double-buffered X window. + * Return the window and context handles. + */ +static void +make_x_window(Display *x_dpy, EGLDisplay egl_dpy, + const char *name, + int x, int y, int width, int height, + Window *winRet, + EGLContext *ctxRet, + EGLSurface *surfRet) +{ + static const EGLint attribs[] = { + EGL_RED_SIZE, 1, + EGL_GREEN_SIZE, 1, + EGL_BLUE_SIZE, 1, + EGL_NONE + }; + + int scrnum; + XSetWindowAttributes attr; + unsigned long mask; + Window root; + Window win; + XVisualInfo *visInfo, visTemplate; + int num_visuals; + EGLContext ctx; + EGLConfig config; + EGLint num_configs; + EGLint vid; + + scrnum = DefaultScreen( x_dpy ); + root = RootWindow( x_dpy, scrnum ); + + if (!eglChooseConfig( egl_dpy, attribs, &config, 1, &num_configs)) { + printf("Error: couldn't get an EGL visual config\n"); + exit(1); + } + + assert(config); + assert(num_configs > 0); + + if (!eglGetConfigAttrib(egl_dpy, config, EGL_NATIVE_VISUAL_ID, &vid)) { + printf("Error: eglGetConfigAttrib() failed\n"); + exit(1); + } + + /* The X window visual must match the EGL config */ + visTemplate.visualid = vid; + visInfo = XGetVisualInfo(x_dpy, VisualIDMask, &visTemplate, &num_visuals); + if (!visInfo) { + printf("Error: couldn't get X visual\n"); + exit(1); + } + + /* window attributes */ + attr.background_pixel = 0; + attr.border_pixel = 0; + attr.colormap = XCreateColormap( x_dpy, root, visInfo->visual, AllocNone); + attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask; + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; + + win = XCreateWindow( x_dpy, root, 0, 0, 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(x_dpy, win, &sizehints); + XSetStandardProperties(x_dpy, win, name, name, + None, (char **)NULL, 0, &sizehints); + } + + eglBindAPI(EGL_OPENVG_API); + + ctx = eglCreateContext(egl_dpy, config, EGL_NO_CONTEXT, NULL ); + if (!ctx) { + printf("Error: eglCreateContext failed\n"); + exit(1); + } + + *surfRet = eglCreateWindowSurface(egl_dpy, config, win, NULL); + + if (!*surfRet) { + printf("Error: eglCreateWindowSurface failed\n"); + exit(1); + } + + XFree(visInfo); + + *winRet = win; + *ctxRet = ctx; +} + + +static void +event_loop(Display *dpy, Window win, + EGLDisplay egl_dpy, EGLSurface egl_surf) +{ + while (1) { + XEvent event; + + while (XPending(dpy) > 0) { + XNextEvent(dpy, &event); + + switch (event.type) { + case Expose: + break; + case ConfigureNotify: + reshape(event.xconfigure.width, event.xconfigure.height); + break; + case KeyPress: + { + char buffer[10]; + int r, code; + code = XLookupKeysym(&event.xkey, 0); + r = XLookupString(&event.xkey, buffer, sizeof(buffer), + NULL, NULL); + if (buffer[0] == 27) { + /* escape */ + return; + } + } + break; + default: + ; /*no-op*/ + } + } + + draw(); + eglSwapBuffers(egl_dpy, egl_surf); + } +} + + +static void +usage(void) +{ + printf("Usage:\n"); + printf(" -display <displayname> set the display to run on\n"); + printf(" -info display OpenGL renderer info\n"); +} + +int +main(int argc, char *argv[]) +{ + const int winWidth = 350, winHeight = 450; + Display *x_dpy; + Window win; + EGLSurface egl_surf; + EGLContext egl_ctx; + EGLDisplay egl_dpy; + char *dpyName = NULL; + GLboolean printInfo = GL_FALSE; + EGLint egl_major, egl_minor; + int i; + const char *s; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-display") == 0) { + dpyName = argv[i+1]; + i++; + } + else if (strcmp(argv[i], "-info") == 0) { + printInfo = GL_TRUE; + } + else { + usage(); + return -1; + } + } + + x_dpy = XOpenDisplay(dpyName); + if (!x_dpy) { + printf("Error: couldn't open display %s\n", + dpyName ? dpyName : getenv("DISPLAY")); + return -1; + } + + egl_dpy = eglGetDisplay(x_dpy); + if (!egl_dpy) { + printf("Error: eglGetDisplay() failed\n"); + return -1; + } + + if (!eglInitialize(egl_dpy, &egl_major, &egl_minor)) { + printf("Error: eglInitialize() failed\n"); + return -1; + } + + s = eglQueryString(egl_dpy, EGL_VERSION); + printf("EGL_VERSION = %s\n", s); + + make_x_window(x_dpy, egl_dpy, + "Lion Example", 0, 0, winWidth, winHeight, + &win, &egl_ctx, &egl_surf); + + XMapWindow(x_dpy, win); + if (!eglMakeCurrent(egl_dpy, egl_surf, egl_surf, egl_ctx)) { + printf("Error: eglMakeCurrent() failed\n"); + return -1; + } + + if (printInfo) { + printf("VG_RENDERER = %s\n", (char *) vgGetString(VG_RENDERER)); + printf("VG_VERSION = %s\n", (char *) vgGetString(VG_VERSION)); + printf("VG_VENDOR = %s\n", (char *) vgGetString(VG_VENDOR)); + } + + init(); + + /* Set initial projection/viewing transformation. + * We can't be sure we'll get a ConfigureNotify event when the window + * first appears. + */ + reshape(winWidth, winHeight); + + event_loop(x_dpy, win, egl_dpy, egl_surf); + + eglDestroyContext(egl_dpy, egl_ctx); + eglDestroySurface(egl_dpy, egl_surf); + eglTerminate(egl_dpy); + + + XDestroyWindow(x_dpy, win); + XCloseDisplay(x_dpy); + + return 0; +} diff --git a/progs/openvg/demos/sp.c b/progs/openvg/demos/sp.c new file mode 100644 index 0000000000..424ec47d69 --- /dev/null +++ b/progs/openvg/demos/sp.c @@ -0,0 +1,537 @@ +#include "eglcommon.h" + +#include <VG/openvg.h> +#include <VG/vgu.h> +#include <stdio.h> +#include <math.h> +#include <stdlib.h> +#include <string.h> + +#include <X11/keysym.h> + +#define ELEMENTS(x) (sizeof(x)/sizeof((x)[0])) + +struct object { + VGPath path; + VGPaint fill; + VGPaint stroke; + VGint draw_mode; + VGfloat matrix[9]; + VGfloat stroke_width; +}; + +struct character { + struct object objects[32]; + VGint num_objects; +}; +VGfloat identity_matrix[] = {1, 0, 0, 0, 1, 0, 0, 0, 1}; + +struct character cartman; + +static void add_object_fill(const VGubyte *segments, VGint num_segments, + const VGfloat *coords, + VGuint color) +{ + struct object object; + + object.path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, + 1, 0, 0, 0, VG_PATH_CAPABILITY_ALL); + vgAppendPathData(object.path, num_segments, segments, coords); + + object.fill = vgCreatePaint(); + vgSetColor(object.fill, color); + memcpy(object.matrix, identity_matrix, 9 * sizeof(VGfloat)); + object.draw_mode = VG_FILL_PATH; + + cartman.objects[cartman.num_objects] = object; + ++cartman.num_objects; +} + + +static void add_object_stroke(const VGubyte *segments, VGint num_segments, + const VGfloat *coords, + VGuint color, VGfloat width) +{ + struct object object; + + object.path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, + 1, 0, 0, 0, VG_PATH_CAPABILITY_ALL); + vgAppendPathData(object.path, num_segments, segments, coords); + + object.stroke = vgCreatePaint(); + vgSetColor(object.stroke, color); + memcpy(object.matrix, identity_matrix, 9 * sizeof(VGfloat)); + object.draw_mode = VG_STROKE_PATH; + object.stroke_width = width; + + cartman.objects[cartman.num_objects] = object; + ++cartman.num_objects; +} + + +static void add_object_fillm(const VGubyte *segments, VGint num_segments, + const VGfloat *coords, + VGuint color, + VGfloat *matrix) +{ + struct object object; + + object.path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, + 1, 0, 0, 0, VG_PATH_CAPABILITY_ALL); + vgAppendPathData(object.path, num_segments, segments, coords); + + object.fill = vgCreatePaint(); + vgSetColor(object.fill, color); + memcpy(object.matrix, matrix, 9 * sizeof(VGfloat)); + object.draw_mode = VG_FILL_PATH; + + cartman.objects[cartman.num_objects] = object; + ++cartman.num_objects; +} + + +static void add_object_m(const VGubyte *segments, VGint num_segments, + const VGfloat *coords, + VGuint fill_color, + VGuint stroke_color, VGfloat stroke_width, + VGfloat *matrix) +{ + struct object object; + + object.path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, + 1, 0, 0, 0, VG_PATH_CAPABILITY_ALL); + vgAppendPathData(object.path, num_segments, segments, coords); + memcpy(object.matrix, matrix, 9 * sizeof(VGfloat)); + + object.fill = vgCreatePaint(); + vgSetColor(object.fill, fill_color); + object.draw_mode = VG_FILL_PATH | VG_STROKE_PATH; + + object.stroke = vgCreatePaint(); + vgSetColor(object.stroke, stroke_color); + object.stroke_width = stroke_width; + + cartman.objects[cartman.num_objects] = object; + ++cartman.num_objects; +} + +static void init_character() +{ + { + const VGubyte segments[] = {VG_MOVE_TO_ABS, + VG_CUBIC_TO_ABS, + VG_CUBIC_TO_ABS, + VG_CUBIC_TO_ABS, + VG_CUBIC_TO_ABS, + VG_CLOSE_PATH}; + const VGfloat coords[] = {181.83267, 102.60408, + 181.83267,102.60408, 185.53793,114.5749, 186.5355,115.00243, + 187.53306,115.42996, 286.0073,115.00243, 286.0073,115.00243, + 286.0073,115.00243, 292.70526,103.45914, 290.85263,101.03648, + 289.00001,98.61381, 181.54765,102.31906, 181.83267,102.60408 + }; + VGuint color = 0x7c4e32ff; + add_object_fill(segments, ELEMENTS(segments), + coords, color); + } + { + const VGubyte segments[] = { + VG_MOVE_TO_ABS, + VG_CUBIC_TO_ABS, + VG_CUBIC_TO_ABS, + VG_LINE_TO_ABS, + VG_CUBIC_TO_ABS, + VG_CUBIC_TO_ABS, + VG_CUBIC_TO_ABS, + VG_CUBIC_TO_ABS, + VG_CUBIC_TO_ABS, + VG_CUBIC_TO_ABS, + VG_CLOSE_PATH + }; + const VGfloat coords[] = {188.62208,50.604156, + 188.62208,50.604156, 176.73127,60.479579, 170.68509,69.548844, + 164.63892,78.618109, 175.11895,79.827344, 175.11895,79.827344, + 176.52973,98.368952, + 176.52973,98.368952, 189.83131,110.05823, 208.97754,110.25976, + 228.12377,110.46131, 244.24691,111.67054, 247.06846,110.25976, + 249.89,108.849, 258.95927,106.8336, 260.16851,105.01975, + 261.37774,103.2059, 296.84865,106.43053, 297.05019,91.919698, + 297.25172,77.408874, 306.11945,64.308824, 282.13628,51.611853, + 258.15311,38.914882, 189.2267,49.999539, 188.62208,50.604156 + }; + + VGuint color = 0xe30000ff; + add_object_fill(segments, ELEMENTS(segments), + coords, color); + } + { + const VGubyte segments[] = { + VG_MOVE_TO_ABS, + VG_CUBIC_TO_ABS, + VG_CUBIC_TO_ABS, + VG_CUBIC_TO_ABS, + VG_CUBIC_TO_ABS, + VG_CLOSE_PATH + }; + const VGfloat coords[] = { + 68.25, 78.875, + 68.25,93.296, 54.642,105, 37.875,105, + 21.108,105, 7.5,93.296, 7.5,78.875, + 7.5,64.454, 21.108,52.75, 37.875,52.75, + 54.642,52.75, 68.25,64.454, 68.25,78.875 + }; + + VGuint color = 0xffe1c4ff; + VGfloat matrix[] = { + 1.6529, 0, 0, + 0, 1.582037, 0, + 172.9649,-90.0116, 1 + }; + add_object_fillm(segments, ELEMENTS(segments), + coords, color, matrix); + } + { + const VGubyte segments[] = { + VG_MOVE_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, + VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, VG_CLOSE_PATH + }; + const VGfloat coords[] = { + 170.14687,71.536958, + 173.53626,68.814326, 176.70232,68.971782, 180.55009,71.679467, + 184.39785,74.387153, 199.19294,80.036105, 191.52334,86.500482, + 189.02942,88.6025, 183.97032,85.787933, 180.26507,86.928011, + 178.8737,87.356121, 174.71827,89.783259, 171.8028,87.494856, + 166.95426,83.689139, 163.51779,76.861986, 170.14687,71.536958 + }; + + VGuint color = 0xfff200ff; + add_object_fill(segments, ELEMENTS(segments), + coords, color); + } + { + const VGubyte segments[] = { + VG_MOVE_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, + VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, + VG_CUBIC_TO_ABS, VG_CLOSE_PATH + }; + const VGfloat coords[] = { + 299.83075,66.834136, + 299.83075,66.834136, 287.85993,64.69649, 284.15467,72.962055, + 280.44942,81.227621, 280.1644,78.234916, 280.1644,79.374994, + 280.1644,80.515072, 278.16927,84.077816, 284.86722,83.792796, + 291.56518,83.507777, 291.99271,86.785501, 294.84291,86.642991, + 297.6931,86.500482, 303.536,85.645423, 303.67851,80.657582, + 303.82102,75.66974, 302.68094,65.551548, 299.83075,66.834136 + }; + + VGuint color = 0xfff200ff; + add_object_fill(segments, ELEMENTS(segments), + coords, color); + } + { + const VGubyte segments[] = { + VG_MOVE_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS + }; + const VGfloat coords[] = { + 240.83171,75.81225, + 240.83171,75.81225, 241.54426,88.495618, 242.25681,91.488323, + 242.96936,94.481028, 240.6892,108.01945, 240.83171,110.01459, + 240.97422,112.00973, 240.97422,111.01216, 240.97422,111.01216 + }; + VGuint color = 0x000000ff; + VGfloat swidth = 1.14007807; + add_object_stroke(segments, ELEMENTS(segments), coords, color, swidth); + } + { + const VGubyte segments[] = { + VG_MOVE_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, + VG_CUBIC_TO_ABS, VG_LINE_TO_ABS, VG_LINE_TO_ABS, VG_CLOSE_PATH + }; + const VGfloat coords[] = { + 83.375, 95.5, + 83.375,96.121, 83.067,96.625, 82.6875,96.625, + 82.308,96.625, 82,96.121, 82,95.5, + 82,94.879, 82.308,94.375, 82.6875,94.375, + 83.066677,94.375, 83.374492,94.878024, 83.374999,95.498494, + 82.6875,95.5, + 83.375,95.5 + }; + VGuint fill_color = 0x000000ff; + VGuint stroke_color = 0x000000ff; + VGfloat swidth = 0.60000002; + VGfloat matrix1[] = { + 1.140078, 0, 0, + 0, 1.140078, 0, + 145.4927, -15.10897, 1 + }; + VGfloat matrix2[] = { + 1.140078,0, 0, + 0,1.140078, 0, + 144.2814,-27.93485, 1 + }; + VGfloat matrix3[] = { + 1.140078,0, 0, + 0,1.140078, 0, + 144.1388,-3.70819, 1 + }; + add_object_m(segments, ELEMENTS(segments), coords, + fill_color, stroke_color, swidth, matrix1); + add_object_m(segments, ELEMENTS(segments), coords, + fill_color, stroke_color, swidth, matrix2); + add_object_m(segments, ELEMENTS(segments), coords, + fill_color, stroke_color, swidth, matrix3); + } + { + const VGubyte segments[] = { + VG_MOVE_TO_ABS, + VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, + VG_LINE_TO_ABS, VG_CLOSE_PATH + }; + const VGfloat coords[] = { + 179.41001,115.28745, + 179.41001,115.28745, 207.48443,109.30204, 236.84144,115.14494, + 236.84144,115.14494, 274.74903,109.87208, 291.8502,115.42996, + 179.41001,115.28745 + }; + + VGuint color = 0x000000ff; + add_object_fill(segments, ELEMENTS(segments), + coords, color); + } + { + const VGubyte segments[] = { + VG_MOVE_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, + VG_CUBIC_TO_ABS, VG_LINE_TO_ABS, VG_LINE_TO_ABS, VG_CLOSE_PATH + }; + const VGfloat coords[] = { + 83.792156,68.157364, + 83.792156,69.669865, 82.72301,70.897403, 81.40567,70.897403, + 80.08833,70.897403, 79.019185,69.669865, 79.019185,68.157364, + 79.019185,66.644862, 80.08833,65.417325, 81.40567,65.417325, + 82.721887,65.417325, 83.790391,66.642485, 83.792153,68.153696, + 81.40567,68.157364, + 83.792156,68.157364 + }; + VGuint fill_color = 0x000000ff; + VGuint stroke_color = 0x000000ff; + VGfloat swidth = 0.52891117; + VGfloat matrix1[] = { + 1.140078,0, 0, + 0,1.140078, 0, + 145.2489,-15.58714, 1 + }; + add_object_m(segments, ELEMENTS(segments), coords, + fill_color, stroke_color, swidth, matrix1); + } + { + const VGubyte segments[] = { + VG_MOVE_TO_ABS, VG_CUBIC_TO_ABS + }; + const VGfloat coords[] = { + 232.28113,66.976646, + 232.28113,66.976646, 237.98152,70.539389, 245.39202,66.549116 + }; + VGuint color = 0x000000ff; + VGfloat swidth = 0.60299999; + add_object_stroke(segments, ELEMENTS(segments), coords, color, swidth); + } + { + const VGubyte segments[] = { + VG_MOVE_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, + VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, VG_CLOSE_PATH + }; + const VGfloat coords[] = { + 185.96908,30.061986, + 185.96908,30.061986, 187.76995,14.508377, 203.23909,3.7427917, + 209.95028,-0.92779696, 219.37764,-4.9841866, 232.1078,-6.00046, + 246.13578,-7.1203411, 256.92106,-2.8560739, 264.81774,1.9451947, + 280.60485,11.543934, 284.31582,25.937274, 284.08015,26.526452, + 283.7266,27.410336, 240.83461,1.9346323, 185.96908,30.061986 + }; + VGuint color = 0x8ed8f8ff; + add_object_fill(segments, ELEMENTS(segments), coords, color); + } + { + const VGubyte segments[] = { + VG_MOVE_TO_ABS, VG_LINE_TO_ABS, VG_CUBIC_TO_ABS, + VG_LINE_TO_ABS, VG_CUBIC_TO_ABS, VG_CLOSE_PATH + }; + const VGfloat coords[] = { + 185.39542,32.061757, + 185.82295,29.211562, + 185.82295,29.211562, 234.70379,2.277219, 284.01217,25.078779, + 284.86722,27.643954, + 284.86722,27.643954, 236.69893,4.5573746, 185.39542,32.061757 + }; + VGuint color = 0xfff200ff; + add_object_fill(segments, ELEMENTS(segments), coords, color); + } + + { + const VGubyte segments[] = { + VG_MOVE_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, + VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, + VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, + VG_CUBIC_TO_ABS, VG_CLOSE_PATH + }; + const VGfloat coords[] = { + 219.74027,-5.917093, + 220.49206,-8.44929, 225.15564,-10.904934, 230.21473,-11.189954, + 235.27383,-11.474973, 243.27521,-13.287236, 249.21385,-5.724198, + 249.89961,-4.850868, 249.28247,-4.332166, 248.62298,-3.971398, + 247.79117,-3.516361, 247.13703,-3.392737, 246.16222,-3.408047, + 243.63973,-3.447664, 242.54183,-3.850701, 242.54183,-3.850701, + 242.54183,-3.850701, 238.78367,-1.737343, 236.20014,-3.565682, + 233.88436,-5.204544, 234.27626,-4.56325, 234.27626,-4.56325, + 234.27626,-4.56325, 232.33303,-2.975658, 230.85603,-2.995643, + 228.59433,-3.025282, 227.73672,-4.501857, 227.21966,-4.93027, + 226.76318,-4.932008, 226.50948,-4.491995, 226.50948,-4.491995, + 226.50948,-4.491995, 224.53199,-2.085883, 222.51431,-2.467064, + 221.48814,-2.66093, 218.91968,-3.15318, 219.74027,-5.917093 + }; + VGuint color = 0xfff200ff; + add_object_fill(segments, ELEMENTS(segments), coords, color); + } + { + const VGubyte segments[] = { + VG_MOVE_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, + VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, VG_CLOSE_PATH + }; + const VGfloat coords[] = { + 178.97347,166.06432, + 178.97347,181.2154, 168.0245,193.51193, 154.53381,193.51193, + 141.04312,193.51193, 130.09416,181.2154, 130.09416,166.06432, + 130.09416,150.91323, 141.04312,138.6167, 154.53381,138.6167, + 168.0245,138.6167, 178.97347,150.91323, 178.97347,166.06432 + }; + VGuint color = 0xffffffff; + VGfloat matrix1[] = { + 0.466614,-0.23492, 0, + 0.108683,0.436638, 0, + 134.5504,-0.901632, 1 + }; + VGfloat matrix2[] = { + -0.466614,-0.23492, 0, + -0.108683,0.436638, 0, + 338.4496,-0.512182, 1 + }; + add_object_fillm(segments, ELEMENTS(segments), coords, color, matrix1); + add_object_fillm(segments, ELEMENTS(segments), coords, color, matrix2); + } + { + const VGubyte segments[] = { + VG_MOVE_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, + VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, VG_CLOSE_PATH + }; + const VGfloat coords[] = { + 123.82758,165.06168, + 123.82758,166.79125, 122.59232,168.19497, 121.07029,168.19497, + 119.54826,168.19497, 118.313,166.79125, 118.313,165.06168, + 118.313,163.3321, 119.54826,161.92839, 121.07029,161.92839, + 122.59232,161.92839, 123.82758,163.3321, 123.82758,165.06168 + }; + VGuint color = 0x000000ff; + VGfloat matrix1[] = { + 0.525719,0, 0, + 0,0.479931, 0, + 178.9702,-43.3532, 1 + }; + VGfloat matrix2[] = { + 0.525719,0, 0, + 0,0.479931, 0, + 165.258,-43.46162, 1 + }; + add_object_fillm(segments, ELEMENTS(segments), coords, color, matrix1); + add_object_fillm(segments, ELEMENTS(segments), coords, color, matrix2); + } + { + const VGubyte segments[] = { + VG_MOVE_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS + }; + const VGfloat coords[] = { + 197.25,54.5, + 197.25,54.5, 211.75,71.5, 229.25,71.5, + 246.75,71.5, 261.74147,71.132714, 277.75,50.75 + }; + VGuint color = 0x000000ff; + VGfloat swidth = 0.60299999; + add_object_stroke(segments, ELEMENTS(segments), coords, color, swidth); + } +} + + +static void +init(void) +{ + float clear_color[4] = {1.0, 1.0, 1.0, 1.0}; + vgSetfv(VG_CLEAR_COLOR, 4, clear_color); + + init_character(); +} + +/* new window size or exposure */ +static void +reshape(int w, int h) +{ +} + +static int +key_press(unsigned key) +{ + switch(key) { + case XK_Right: + + break; + case XK_Left: + break; + case XK_Up: + break; + case XK_Down: + break; + case 'a': + break; + case 's': + break; + default: + break; + } + return VG_FALSE; +} + +static void +draw(void) +{ + VGint i; + VGfloat save_matrix[9]; + + vgClear(0, 0, window_width(), window_height()); + + vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); + vgLoadIdentity(); + vgScale(2, 2); + vgTranslate(160, 60); + vgRotate(180); + vgTranslate(-160, -100); + vgGetMatrix(save_matrix); + for (i = 0; i < cartman.num_objects; ++i) { + struct object object = cartman.objects[i]; + if ((object.draw_mode & VG_STROKE_PATH)) { + vgSetf(VG_STROKE_LINE_WIDTH, object.stroke_width); + vgSetPaint(object.stroke, VG_STROKE_PATH); + } + if ((object.draw_mode & VG_FILL_PATH)) + vgSetPaint(object.fill, VG_FILL_PATH); + vgMultMatrix(object.matrix); + vgDrawPath(object.path, object.draw_mode); + vgLoadMatrix(save_matrix); + } + + vgFlush(); +} + + +int main(int argc, char **argv) +{ + set_window_size(400, 400); + return run(argc, argv, init, reshape, draw, key_press); +} diff --git a/progs/openvg/trivial/Makefile b/progs/openvg/trivial/Makefile new file mode 100644 index 0000000000..362360e596 --- /dev/null +++ b/progs/openvg/trivial/Makefile @@ -0,0 +1,127 @@ +# These programs aren't intended to be included with the normal distro. +# They're not too interesting but they're good for testing. + +TOP = ../../../ +include $(TOP)/configs/current + +INCLUDES = -I. -I$(TOP)/include +LIBS=-L$(TOP)/$(LIB_DIR) -lm -lEGL -lOpenVG -lpthread +CFLAGS += $(INCLUDES) + +HEADERS=eglcommon.h + +PROGRAMS = \ + arc \ + cap \ + clear \ + coord \ + dash \ + ellipse \ + filter \ + gradorigin \ + lineto \ + lingrad \ + lookup \ + mask4 \ + mask \ + path3 \ + radialgrad \ + readpixels \ + roundedrect \ + star-nonzero \ + star-oddeven \ + stroke2 \ + stroke \ + vguarc + + +.c.o: + $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $< -o $@ + + + +default: $(PROGRAMS) + + +arc: arc.c eglcommon.o + $(CC) $(CFLAGS) $^ $(LIBS) $(APP_LIB_DEPS) -o $@ + +cap: cap.c eglcommon.o + $(CC) $(CFLAGS) $^ $(LIBS) $(APP_LIB_DEPS) -o $@ + +clear: clear.c eglcommon.o + $(CC) $(CFLAGS) $^ $(LIBS) $(APP_LIB_DEPS) -o $@ + +coord: coord.c eglcommon.o + $(CC) $(CFLAGS) $^ $(LIBS) $(APP_LIB_DEPS) -o $@ + +dash: dash.c eglcommon.o + $(CC) $(CFLAGS) $^ $(LIBS) $(APP_LIB_DEPS) -o $@ + +ellipse: ellipse.c eglcommon.o + $(CC) $(CFLAGS) $^ $(LIBS) $(APP_LIB_DEPS) -o $@ + +filter: filter.c eglcommon.o + $(CC) $(CFLAGS) $^ $(LIBS) $(APP_LIB_DEPS) -o $@ + +gradorigin: gradorigin.c eglcommon.o + $(CC) $(CFLAGS) $^ $(LIBS) $(APP_LIB_DEPS) -o $@ + +image: image.c eglcommon.o + $(CC) $(CFLAGS) $^ $(LIBS) $(APP_LIB_DEPS) -o $@ + +lineto: lineto.c eglcommon.o + $(CC) $(CFLAGS) $^ $(LIBS) $(APP_LIB_DEPS) -o $@ + +lingrad: lingrad.c eglcommon.o + $(CC) $(CFLAGS) $^ $(LIBS) $(APP_LIB_DEPS) -o $@ + +lookup: lookup.c eglcommon.o + $(CC) $(CFLAGS) $^ $(LIBS) $(APP_LIB_DEPS) -o $@ + +mask: mask.c eglcommon.o + $(CC) $(CFLAGS) $^ $(LIBS) $(APP_LIB_DEPS) -o $@ + +mask4: mask4.c eglcommon.o + $(CC) $(CFLAGS) $^ $(LIBS) $(APP_LIB_DEPS) -o $@ + +path3: path3.c eglcommon.o + $(CC) $(CFLAGS) $^ $(LIBS) $(APP_LIB_DEPS) -o $@ + +pattern: pattern.c eglcommon.o + $(CC) $(CFLAGS) $^ $(LIBS) $(APP_LIB_DEPS) -o $@ + +radialgrad: radialgrad.c eglcommon.o + $(CC) $(CFLAGS) $^ $(LIBS) $(APP_LIB_DEPS) -o $@ + +readpixels: readpixels.c eglcommon.o + $(CC) $(CFLAGS) $^ $(LIBS) $(APP_LIB_DEPS) -o $@ + +roundedrect: roundedrect.c eglcommon.o + $(CC) $(CFLAGS) $^ $(LIBS) $(APP_LIB_DEPS) -o $@ + +star-nonzero: star-nonzero.c eglcommon.o + $(CC) $(CFLAGS) $^ $(LIBS) $(APP_LIB_DEPS) -o $@ + +star-oddeven: star-oddeven.c eglcommon.o + $(CC) $(CFLAGS) $^ $(LIBS) $(APP_LIB_DEPS) -o $@ + +stroke: stroke.c eglcommon.o + $(CC) $(CFLAGS) $^ $(LIBS) $(APP_LIB_DEPS) -o $@ + +stroke2: stroke2.c eglcommon.o + $(CC) $(CFLAGS) $^ $(LIBS) $(APP_LIB_DEPS) -o $@ + +vguarc: vguarc.c eglcommon.o + $(CC) $(CFLAGS) $^ $(LIBS) $(APP_LIB_DEPS) -o $@ + + + +eglcommon.o: eglcommon.c $(HEADERS) + $(CC) -c $(CFLAGS) eglcommon.c + + +clean: + rm -f *.o *~ + rm -f *.so + rm -f $(PROGRAMS) diff --git a/progs/openvg/trivial/arc.c b/progs/openvg/trivial/arc.c new file mode 100644 index 0000000000..db686bea6b --- /dev/null +++ b/progs/openvg/trivial/arc.c @@ -0,0 +1,139 @@ +#include "eglcommon.h" + +#include <VG/openvg.h> +#include <math.h> + +const VGfloat clear_color[4] = {1.0, 1.0, 1.0, 1.0}; +const VGfloat color[4] = {1.0, 1.0, 1.0, 0.5}; + +VGPath vgPath; + +static void ellipse(VGPath vgPath, VGfloat rx, VGfloat ry, VGfloat angle) +{ + static const VGubyte cmd[] = + { VG_MOVE_TO_ABS, VG_SCCWARC_TO_REL, VG_SCCWARC_TO_REL, VG_CLOSE_PATH }; + + VGfloat val[12]; + VGfloat c = cos(angle) * rx; + VGfloat s = sin(angle) * rx; + + val[0] = c; + val[1] = s; + val[2] = rx; + val[3] = ry; + val[4] = angle; + val[5] = -2.0f * c; + val[6] = -2.0f * s; + val[7] = rx; + val[8] = ry; + val[9] = angle; + val[10] = 2.0f * c; + val[11] = 2.0f * s; + + vgClearPath(vgPath, VG_PATH_CAPABILITY_ALL); + vgAppendPathData(vgPath, sizeof(cmd), cmd, val); + vgDrawPath(vgPath, VG_FILL_PATH | VG_STROKE_PATH); +} + +static void +init(void) +{ + VGPaint vgPaint; + + vgSetfv(VG_CLEAR_COLOR, 4, clear_color); + vgPath = vgCreatePath(VG_PATH_FORMAT_STANDARD, + VG_PATH_DATATYPE_F, 1.0f, 0.0f, 0, 0, + VG_PATH_CAPABILITY_ALL); + + vgPaint = vgCreatePaint(); + vgSetParameteri(vgPaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR); + vgSetColor(vgPaint, 0x00ff00ff); + vgSetPaint(vgPaint, VG_FILL_PATH); + + vgSeti(VG_RENDERING_QUALITY, VG_RENDERING_QUALITY_NONANTIALIASED); + vgSeti(VG_BLEND_MODE, VG_BLEND_SRC_OVER); + vgSetf(VG_STROKE_LINE_WIDTH, 2.0f); + vgSeti(VG_STROKE_CAP_STYLE, VG_CAP_SQUARE); + vgSeti(VG_STROKE_JOIN_STYLE, VG_JOIN_MITER); + vgSetf(VG_STROKE_MITER_LIMIT, 4.0f); + vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); +} + +/* new window size or exposure */ +static void +reshape(int w, int h) +{ +} + +static void +draw(void) +{ + vgClear(0, 0, window_width(), window_height()); + +#if 0 + vgLoadIdentity(); + vgTranslate(40.0f, 24.0f); + vgScale(0.61804f, 0.61804f); + vgShear(-1.0f, 0.0f); + vgDrawPath(vgPath, VG_FILL_PATH | VG_STROKE_PATH); +#else + + /* row 1, col 1: Identity transform. */ + + vgLoadIdentity(); + vgTranslate(8.0f, 8.0f); + ellipse(vgPath, 4.0f, 4.0f, 0.0f); + + /* row 1, col 2: 10^3 horizontal squeeze. */ + + vgLoadIdentity(); + vgTranslate(24.0f, 8.0f); + vgScale(1.0e-3f, 1.0f); + ellipse(vgPath, 4.0e3f, 4.0f, 0.0f); + + /* row 1, col 3: 10^6 horizontal squeeze. */ + + vgLoadIdentity(); + vgTranslate(40.0f, 8.0f); + vgScale(1.0e-6f, 1.0f); + ellipse(vgPath, 4.0e6f, 4.0f, 0.0f); + + /* row 1, col 4: 10^9 horizontal squeeze. */ + + vgLoadIdentity(); + vgTranslate(56.0f, 8.0f); + vgScale(1.0e-9f, 1.0f); + ellipse(vgPath, 4.0e9f, 4.0f, 0.0f); + + /* row 2, col 1: 10^3 vertical squeeze. */ + + vgLoadIdentity(); + vgTranslate(8.0f, 24.0f); + vgScale(1.0f, 1.0e-3f); + ellipse(vgPath, 4.0f, 4.0e3f, 0.0f); + + /* row 2, col 2: Shear 0. */ + + vgLoadIdentity(); + vgTranslate(24.0f, 24.0f); + vgShear(0.0f, 0.0f); + ellipse(vgPath, 4.0f, 4.0f, 0.0f); + + /* row 2, col 3: Horizontal shear -1. */ + + vgLoadIdentity(); + vgTranslate(40.0f, 24.0f); + vgScale(0.61804f, 0.61804f); + vgShear(-1.0f, 0.0f); + ellipse(vgPath, 10.47213f, 4.0f, 31.717f); +#endif + vgFlush(); +} + + +int main(int argc, char **argv) +{ + set_window_size(64, 64); + return run(argc, argv, init, reshape, + draw, 0); +} diff --git a/progs/openvg/trivial/cap.c b/progs/openvg/trivial/cap.c new file mode 100644 index 0000000000..cd84fe3ac0 --- /dev/null +++ b/progs/openvg/trivial/cap.c @@ -0,0 +1,75 @@ +#include "eglcommon.h" + +#include <VG/openvg.h> + +#include <math.h> +#include <stdlib.h> +#include <stdio.h> + +static void +init(void) +{ + +} + +/* new window size or exposure */ +static void +reshape(int w, int h) +{ +} + +const int subtest = 0; +static void +draw(void) +{ + VGPath line; + VGPaint fillPaint; + VGubyte lineCommands[3] = {VG_MOVE_TO_ABS, VG_LINE_TO_ABS, VG_LINE_TO_ABS}; + VGfloat lineCoords[] = {-2.0f,-1.0f, 0.0f,0.0f, -1.0f, -2.0f}; + VGfloat clearColor[] = {0.0f, 0.0f, 0.0f, 1.0f};/* black color */ + VGfloat fillColor[] = {1.0f, 1.0f, 1.0f, 1.0f};/* white color */ + //VGfloat testRadius = 60.0f; + VGfloat testRadius = 10.0f; + int WINDSIZEX = window_width(); + int WINDSIZEY = window_height(); + + line = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, + 1.0f, 0.0f, 0, 0, VG_PATH_CAPABILITY_ALL); + fillPaint = vgCreatePaint(); + + vgSetf(VG_STROKE_LINE_WIDTH, 1.0f); + //vgSeti(VG_STROKE_CAP_STYLE, VG_CAP_ROUND); + vgSeti(VG_STROKE_CAP_STYLE, VG_CAP_BUTT); + vgSeti(VG_STROKE_JOIN_STYLE, VG_JOIN_ROUND); + //vgSeti(VG_STROKE_JOIN_STYLE, VG_JOIN_BEVEL); + + vgSeti(VG_RENDERING_QUALITY, VG_RENDERING_QUALITY_BETTER); + + vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); + vgLoadIdentity(); + vgTranslate(60, 60); + vgScale(testRadius * 2, testRadius * 2); + + vgAppendPathData(line, 3, lineCommands, lineCoords); + + vgSetfv(VG_CLEAR_COLOR, 4, clearColor); + + vgSetPaint(fillPaint, VG_STROKE_PATH); + + vgSetParameterfv(fillPaint, VG_PAINT_COLOR, 4, fillColor); + vgSetParameteri( fillPaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR); + + vgClear(0, 0, WINDSIZEX, WINDSIZEY); + vgDrawPath(line, VG_STROKE_PATH); + + vgDestroyPath(line); + vgDestroyPaint(fillPaint); +} + + +int main(int argc, char **argv) +{ + set_window_size(100, 100); + return run(argc, argv, init, reshape, + draw, 0); +} diff --git a/progs/openvg/trivial/clear.c b/progs/openvg/trivial/clear.c new file mode 100644 index 0000000000..efb6bf4182 --- /dev/null +++ b/progs/openvg/trivial/clear.c @@ -0,0 +1,42 @@ +#include "eglcommon.h" + +#include <VG/openvg.h> +#include <stdio.h> + +float red_color[4] = {1.0, 0.0, 0.0, 1.0}; +float blue_color[4] = {0.0, 0.0, 1.0, 1.0}; + +static void +init(void) +{ +} + +/* new window size or exposure */ +static void +reshape(int w, int h) +{ + vgLoadIdentity(); +} + +static void +draw(void) +{ + VGint scissor[4] = {100, 100, 25, 25}; + vgSetfv(VG_CLEAR_COLOR, 4, red_color); + vgClear(0, 0, window_width(), window_height()); + + vgSetfv(VG_CLEAR_COLOR, 4, blue_color); + vgClear(50, 50, 50, 50); + + //vgSetiv(VG_SCISSOR_RECTS, 4, scissor); + //vgSeti(VG_SCISSORING, VG_TRUE); + vgCopyPixels(100, 100, 50, 50, 50, 50); + vgClear(150, 150, 50, 50); +} + + +int main(int argc, char **argv) +{ + return run(argc, argv, init, reshape, + draw, 0); +} diff --git a/progs/openvg/trivial/coord.c b/progs/openvg/trivial/coord.c new file mode 100644 index 0000000000..81f7cb6fc9 --- /dev/null +++ b/progs/openvg/trivial/coord.c @@ -0,0 +1,66 @@ +#include "eglcommon.h" + +#include <VG/openvg.h> + +const VGfloat white_color[4] = {1.0, 1.0, 1.0, 1.0}; +const VGfloat color[4] = {0.4, 0.1, 1.0, 1.0}; + +VGPath path; +VGPaint fill; + + +static void +init(void) +{ + /* Absent VG_CLOSE_PATH */ + VGubyte commands[] = {VG_MOVE_TO_ABS, VG_LINE_TO_ABS, VG_LINE_TO_ABS, VG_LINE_TO_ABS, + VG_MOVE_TO_ABS, VG_LINE_TO_ABS, VG_LINE_TO_ABS, VG_LINE_TO_ABS}; + VGfloat clearColor[] = {1.0f, 1.0f, 1.0f, 1.0f};/* white color */ + VGfloat fillColor[] = {1.0f, 0.0f, 0.0f, 1.0f};/* red color */ + VGfloat coords[] = {-16.0f, -16.0f, 0.0f, -16.0f, 0.0f, 0.0f, -16.0f, 0.0f, + 0.0f, 0.0f, 16.0f, 0.0f, 16.0f, 16.0f, 0.0f, 16.0f}; + + vgSetfv(VG_CLEAR_COLOR, 4, clearColor); + vgSeti(VG_RENDERING_QUALITY, VG_RENDERING_QUALITY_NONANTIALIASED); + + vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); + vgLoadIdentity(); + vgTranslate(32.0f, 32.0f); + + path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1.0f, 0.0f, 0, 0, + VG_PATH_CAPABILITY_ALL); + if (path == VG_INVALID_HANDLE) + return; + fill = vgCreatePaint(); + if (fill == VG_INVALID_HANDLE) { + vgDestroyPath(path); + return; + } + vgAppendPathData(path, 8, commands, coords); + vgSetPaint(fill, VG_FILL_PATH); + vgSetParameterfv(fill, VG_PAINT_COLOR, 4, fillColor); + vgSetParameteri(fill, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR); +} + +/* new window size or exposure */ +static void +reshape(int w, int h) +{ +} + +static void +draw(void) +{ + vgClear(0, 0, window_width(), window_height()); + vgDrawPath(path, VG_FILL_PATH); + + vgFlush(); +} + + +int main(int argc, char **argv) +{ + set_window_size(64, 64); + return run(argc, argv, init, reshape, + draw, 0); +} diff --git a/progs/openvg/trivial/dash.c b/progs/openvg/trivial/dash.c new file mode 100644 index 0000000000..2e84ddbd4e --- /dev/null +++ b/progs/openvg/trivial/dash.c @@ -0,0 +1,95 @@ +#include "eglcommon.h" + +#include <VG/openvg.h> +#include <X11/keysym.h> +#include <stdio.h> + +const VGfloat white_color[4] = {1.0, 1.0, 1.0, 1.0}; +const VGfloat color[4] = {0.4, 0.1, 1.0, 1.0}; + +VGPath path; +VGPaint fill; + +VGint cap_style = VG_CAP_BUTT; + +static void +init(void) +{ + static const VGubyte cmds[] = {VG_MOVE_TO_ABS, + VG_LINE_TO_ABS, + VG_LINE_TO_ABS + }; +#if 1 + static const VGfloat coords[] = {100, 100, 150, 100, + 150, 200 + }; +#else + static const VGfloat coords[] = {100, 20, 100, 220, + }; +#endif + VGfloat dash_pattern[2] = { 20.f, 20.f }; + path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1, 0, 0, 0, + VG_PATH_CAPABILITY_APPEND_TO); + vgAppendPathData(path, 3, cmds, coords); + + fill = vgCreatePaint(); + vgSetParameterfv(fill, VG_PAINT_COLOR, 4, color); + vgSetPaint(fill, VG_FILL_PATH); + + vgSetfv(VG_CLEAR_COLOR, 4, white_color); + vgSetf(VG_STROKE_LINE_WIDTH, 20); + vgSeti(VG_STROKE_CAP_STYLE, cap_style); + vgSeti(VG_STROKE_JOIN_STYLE, VG_JOIN_ROUND); + vgSetfv(VG_STROKE_DASH_PATTERN, 2, dash_pattern); + vgSetf(VG_STROKE_DASH_PHASE, 0.0f); +} + +/* new window size or exposure */ +static void +reshape(int w, int h) +{ + vgLoadIdentity(); +} + +static void +draw(void) +{ + vgClear(0, 0, window_width(), window_height()); + vgDrawPath(path, VG_STROKE_PATH); + + vgFlush(); +} + +static int key_press(unsigned key) +{ + switch(key) { + case XK_c: + case XK_C: + ++cap_style; + if (cap_style > VG_CAP_SQUARE) + cap_style = VG_CAP_BUTT; + switch(cap_style) { + case VG_CAP_BUTT: + fprintf(stderr, "Cap style 'butt'\n"); + break; + case VG_CAP_ROUND: + fprintf(stderr, "Cap style 'round'\n"); + break; + case VG_CAP_SQUARE: + fprintf(stderr, "Cap style 'square'\n"); + break; + } + vgSeti(VG_STROKE_CAP_STYLE, cap_style); + break; + default: + break; + } + + return VG_TRUE; +} + +int main(int argc, char **argv) +{ + return run(argc, argv, init, reshape, + draw, key_press); +} diff --git a/progs/openvg/trivial/eglcommon.c b/progs/openvg/trivial/eglcommon.c new file mode 100644 index 0000000000..bacd5685d7 --- /dev/null +++ b/progs/openvg/trivial/eglcommon.c @@ -0,0 +1,288 @@ +#include "eglcommon.h" + + +#include <assert.h> +#include <math.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <X11/Xlib.h> +#include <X11/Xutil.h> +#include <X11/keysym.h> +#include <VG/openvg.h> /* using full OpenGL for now */ +#include <GLES/egl.h> + + +static init_func init = 0; +static draw_func draw = 0; +static reshape_func reshape = 0; +static key_func keyPress = 0; +static VGint width = 300, height = 300; + + +void set_window_size(int w, int h) +{ + width = w; + height = h; +} + +/* + * Create an RGB, double-buffered X window. + * Return the window and context handles. + */ +static void +make_x_window(Display *x_dpy, EGLDisplay egl_dpy, + const char *name, + int x, int y, int width, int height, + Window *winRet, + EGLContext *ctxRet, + EGLSurface *surfRet) +{ + static const EGLint attribs[] = { + EGL_RED_SIZE, 1, + EGL_GREEN_SIZE, 1, + EGL_BLUE_SIZE, 1, + EGL_NONE + }; + + int scrnum; + XSetWindowAttributes attr; + unsigned long mask; + Window root; + Window win; + XVisualInfo *visInfo, visTemplate; + int num_visuals; + EGLContext ctx; + EGLConfig config; + EGLint num_configs; + EGLint vid; + + scrnum = DefaultScreen( x_dpy ); + root = RootWindow( x_dpy, scrnum ); + + if (!eglChooseConfig( egl_dpy, attribs, &config, 1, &num_configs)) { + printf("Error: couldn't get an EGL visual config\n"); + exit(1); + } + + assert(config); + assert(num_configs > 0); + + if (!eglGetConfigAttrib(egl_dpy, config, EGL_NATIVE_VISUAL_ID, &vid)) { + printf("Error: eglGetConfigAttrib() failed\n"); + exit(1); + } + + /* The X window visual must match the EGL config */ + visTemplate.visualid = vid; + visInfo = XGetVisualInfo(x_dpy, VisualIDMask, &visTemplate, &num_visuals); + if (!visInfo) { + printf("Error: couldn't get X visual\n"); + exit(1); + } + + /* window attributes */ + attr.background_pixel = 0; + attr.border_pixel = 0; + attr.colormap = XCreateColormap( x_dpy, root, visInfo->visual, AllocNone); + attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask; + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; + + win = XCreateWindow( x_dpy, root, 0, 0, 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(x_dpy, win, &sizehints); + XSetStandardProperties(x_dpy, win, name, name, + None, (char **)NULL, 0, &sizehints); + } + + eglBindAPI(EGL_OPENVG_API); + + ctx = eglCreateContext(egl_dpy, config, EGL_NO_CONTEXT, NULL ); + if (!ctx) { + printf("Error: eglCreateContext failed\n"); + exit(1); + } + + *surfRet = eglCreateWindowSurface(egl_dpy, config, win, NULL); + + if (!*surfRet) { + printf("Error: eglCreateWindowSurface failed\n"); + exit(1); + } + + XFree(visInfo); + + *winRet = win; + *ctxRet = ctx; +} + +static void +event_loop(Display *dpy, Window win, + EGLDisplay egl_dpy, EGLSurface egl_surf) +{ + while (1) { + int redraw = 0; + XEvent event; + + XNextEvent(dpy, &event); + + switch (event.type) { + case Expose: + redraw = 1; + break; + case ConfigureNotify: + if (reshape) { + width = event.xconfigure.width; + height = event.xconfigure.height; + reshape(event.xconfigure.width, event.xconfigure.height); + } + break; + case KeyPress: + { + char buffer[10]; + int r, code; + code = XLookupKeysym(&event.xkey, 0); + if (!keyPress || !keyPress(code)) { + r = XLookupString(&event.xkey, buffer, sizeof(buffer), + NULL, NULL); + if (buffer[0] == 27) { + /* escape */ + return; + } + } + } + redraw = 1; + break; + default: + ; /*no-op*/ + } + + if (redraw) { + draw(); + eglSwapBuffers(egl_dpy, egl_surf); + } + } +} + +int window_width(void) +{ + return width; +} + +int window_height(void) +{ + return height; +} + +static void +usage(void) +{ + printf("Usage:\n"); + printf(" -display <displayname> set the display to run on\n"); + printf(" -info display OpenGL renderer info\n"); +} + +int run(int argc, char **argv, + init_func init_f, + reshape_func resh_f, + draw_func draw_f, + key_func key_f) +{ + const int winWidth = width, winHeight = height; + Display *x_dpy; + Window win; + EGLSurface egl_surf; + EGLContext egl_ctx; + EGLDisplay egl_dpy; + char *dpyName = NULL; + GLboolean printInfo = GL_FALSE; + EGLint egl_major, egl_minor; + int i; + const char *s; + + init = init_f; + draw = draw_f; + reshape = resh_f; + keyPress = key_f; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-display") == 0) { + dpyName = argv[i+1]; + i++; + } + else if (strcmp(argv[i], "-info") == 0) { + printInfo = GL_TRUE; + } + } + + x_dpy = XOpenDisplay(dpyName); + if (!x_dpy) { + printf("Error: couldn't open display %s\n", + dpyName ? dpyName : getenv("DISPLAY")); + return -1; + } + + egl_dpy = eglGetDisplay(x_dpy); + if (!egl_dpy) { + printf("Error: eglGetDisplay() failed\n"); + return -1; + } + + if (!eglInitialize(egl_dpy, &egl_major, &egl_minor)) { + printf("Error: eglInitialize() failed\n"); + return -1; + } + + s = eglQueryString(egl_dpy, EGL_VERSION); + printf("EGL_VERSION = %s\n", s); + + make_x_window(x_dpy, egl_dpy, + "OpenVG Example", 0, 0, winWidth, winHeight, + &win, &egl_ctx, &egl_surf); + + XMapWindow(x_dpy, win); + if (!eglMakeCurrent(egl_dpy, egl_surf, egl_surf, egl_ctx)) { + printf("Error: eglMakeCurrent() failed\n"); + return -1; + } + + if (printInfo) { + printf("VG_RENDERER = %s\n", (char *) vgGetString(VG_RENDERER)); + printf("VG_VERSION = %s\n", (char *) vgGetString(VG_VERSION)); + printf("VG_VENDOR = %s\n", (char *) vgGetString(VG_VENDOR)); + } + + if (init) + init(); + + /* Set initial projection/viewing transformation. + * We can't be sure we'll get a ConfigureNotify event when the window + * first appears. + */ + if (reshape) + reshape(winWidth, winHeight); + + event_loop(x_dpy, win, egl_dpy, egl_surf); + + eglMakeCurrent(egl_dpy, 0, 0, 0); + eglDestroyContext(egl_dpy, egl_ctx); + eglDestroySurface(egl_dpy, egl_surf); + eglTerminate(egl_dpy); + + + XDestroyWindow(x_dpy, win); + XCloseDisplay(x_dpy); + + return 0; +} + diff --git a/progs/openvg/trivial/eglcommon.h b/progs/openvg/trivial/eglcommon.h new file mode 100644 index 0000000000..958dae9f98 --- /dev/null +++ b/progs/openvg/trivial/eglcommon.h @@ -0,0 +1,20 @@ +#ifndef EGLCOMMON_H +#define EGLCOMMON_H + +typedef void (*init_func)(); +typedef void (*reshape_func)(int, int); +typedef void (*draw_func)(); +typedef int (*key_func)(unsigned key); + + +void set_window_size(int width, int height); +int window_width(void); +int window_height(void); + +int run(int argc, char **argv, + init_func init, + reshape_func resh, + draw_func draw, + key_func key); + +#endif diff --git a/progs/openvg/trivial/ellipse.c b/progs/openvg/trivial/ellipse.c new file mode 100644 index 0000000000..4c7d4904f8 --- /dev/null +++ b/progs/openvg/trivial/ellipse.c @@ -0,0 +1,84 @@ +#include "eglcommon.h" + +#include <VG/openvg.h> + +#include <math.h> +#include <stdlib.h> + +const VGfloat white_color[4] = {1.0, 1.0, 1.0, 1.0}; +const VGfloat color[4] = {0.0, 0.0, 0.0, 1.0}; + +VGPath path; +VGPaint paint; + +static void +init(void) +{ + VGfloat clearColor[] = {1.0f, 1.0f, 1.0f, 1.0f};/* white color */ + VGfloat fillColor[] = {1.0f, 0.0f, 0.0f, 1.0f};/* red color */ + static const VGubyte segments[4] = {VG_MOVE_TO_ABS, + VG_SCCWARC_TO_ABS, + VG_SCCWARC_TO_ABS, + VG_CLOSE_PATH}; + VGfloat data[12]; + const VGfloat cx = 0, cy=29, width=80, height=40; + const VGfloat hw = width * 0.5f; + const VGfloat hh = height * 0.5f; + + data[0] = cx + hw; + data[1] = cy; + data[2] = hw; + data[3] = hh; + data[4] = 0; + data[5] = cx - hw; + data[6] = cy; + data[7] = hw; + data[8] = hh; + data[9] = 0; + data[10] = data[0]; + data[11] = cy; + + vgSetfv(VG_CLEAR_COLOR, 4, clearColor); + vgSeti(VG_RENDERING_QUALITY, VG_RENDERING_QUALITY_NONANTIALIASED); + + + path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, + 1.0f, 0.0f, 0, 0, VG_PATH_CAPABILITY_ALL); + if (path == VG_INVALID_HANDLE) { + return; + } + paint = vgCreatePaint(); + if (paint == VG_INVALID_HANDLE) { + vgDestroyPath(path); + return; + } + + vgAppendPathData(path, 4, segments, data); + vgSetParameterfv(paint, VG_PAINT_COLOR, 4, fillColor); + vgSetParameteri( paint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR); + vgSetPaint(paint, VG_FILL_PATH); +} + +/* new window size or exposure */ +static void +reshape(int w, int h) +{ +} + +static void +draw(void) +{ + vgClear(0, 0, window_width(), window_height()); + vgLoadIdentity(); + vgTranslate(50, 21); + vgDrawPath(path, VG_FILL_PATH); + vgFlush(); +} + + +int main(int argc, char **argv) +{ + set_window_size(100, 100); + return run(argc, argv, init, reshape, + draw, 0); +} diff --git a/progs/openvg/trivial/filter.c b/progs/openvg/trivial/filter.c new file mode 100644 index 0000000000..d96257a933 --- /dev/null +++ b/progs/openvg/trivial/filter.c @@ -0,0 +1,107 @@ +#include "eglcommon.h" + +#include <VG/openvg.h> + +#include <math.h> +#include <stdlib.h> +#include <stdio.h> + +const VGfloat white_color[4] = {1.0, 1.0, 1.0, 1.0}; +const VGfloat color[4] = {1.0, 1.0, 1.0, 0.5}; + +VGImage srcImg; +VGImage dstImg; + +VGPaint fill; + +VGfloat bgCol[4] = {0.906f, 0.914f, 0.761f, 1.0f}; + +static void +init(void) +{ + VGfloat red[4]; + VGfloat grey[4]; + VGfloat orange[4]; + VGfloat blue[4]; + VGfloat black[4]; + VGfloat white[4]; + VGshort transKernel[49] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + + red[0] = 0.6710f; + red[1] = 0.1060f; + red[2] = 0.1330f; + red[3] = 1.0f; + + grey[0] = 0.6347f; + grey[1] = 0.6561f; + grey[2] = 0.6057f; + grey[3] = 1.0f; + + orange[0] = 1.0000f; + orange[1] = 0.8227f; + orange[2] = 0.5057f; + orange[3] = 1.0f; + + blue[0] = 0.0000f; + blue[1] = 0.6908f; + blue[2] = 0.8595f; + blue[3] = 1.0f; + + black[0] = 0; + black[1] = 0; + black[2] = 0; + black[3] = 1.0f; + + white[0] = 1; + white[1] = 1; + white[2] = 1; + white[3] = 1.0f; + + vgSetfv(VG_TILE_FILL_COLOR, 4, blue); + + vgSeti(VG_FILTER_CHANNEL_MASK, 14); + + /* Setup images */ + srcImg = vgCreateImage(VG_sRGBA_8888, 32, 32, + VG_IMAGE_QUALITY_NONANTIALIASED); + dstImg = vgCreateImage(VG_sRGBA_8888, 32, 32, + VG_IMAGE_QUALITY_NONANTIALIASED); + + vgSetfv(VG_CLEAR_COLOR, 4, black); + vgClearImage(srcImg, 0, 0, 32, 32); + vgSetfv(VG_CLEAR_COLOR, 4, red); + vgClearImage(srcImg, 3, 3, 27, 27); + + vgSetfv(VG_CLEAR_COLOR, 4, orange); + vgClearImage(dstImg, 0, 0, 32, 32); + + transKernel[8] = 1; + vgConvolve(dstImg, srcImg, 3, 3, 3, 0, transKernel, + 1, 0, VG_TILE_FILL); +} + +/* new window size or exposure */ +static void +reshape(int w, int h) +{ +} + +static void +draw(void) +{ + vgSetfv(VG_CLEAR_COLOR, 4, bgCol); + vgClear(0, 0, window_width(), window_height()); + vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE); + vgLoadIdentity(); + vgTranslate(10, 10); + vgDrawImage(dstImg); + vgFlush(); +} + + +int main(int argc, char **argv) +{ + set_window_size(64, 64); + return run(argc, argv, init, reshape, + draw, 0); +} diff --git a/progs/openvg/trivial/gradorigin.c b/progs/openvg/trivial/gradorigin.c new file mode 100644 index 0000000000..b376263fe5 --- /dev/null +++ b/progs/openvg/trivial/gradorigin.c @@ -0,0 +1,98 @@ +#include "eglcommon.h" + +#include <VG/openvg.h> + +#include <stdio.h> +#include <string.h> + +static const VGfloat white_color[4] = {1.0, 1.0, 1.0, 1.0}; + +static VGPath path; +static VGPaint fill; + +VGColorRampSpreadMode spread = VG_COLOR_RAMP_SPREAD_PAD; + +static void +init(void) +{ + VGubyte commands[5] = {VG_MOVE_TO_ABS, VG_LINE_TO_ABS, VG_LINE_TO_ABS, VG_LINE_TO_ABS, VG_CLOSE_PATH}; + VGfloat coords[8] = {0.0f,0.0f, 32.0f,0.0f, 32.0f,32.0f, 0.0f,32.0f }; + + VGfloat rampStop[20] = {-0.5f, 1.0f, 1.0f, 1.0f, 1.0f, + 0.25f, 1.0f, 0.0f, 0.0f, 1.0f, + 0.75f, 0.0f, 0.0f, 1.0f, 1.0f, + 1.5f, 0.0f, 0.0f, 0.0f, 0.0f}; + + VGfloat defaultColor[] = {1.0f, 1.0f, 1.0f, 1.0f}; + VGfloat linearGradient[4] = {0.0f, 0.0f, 0.0f, 32.0f}; + + path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, + 1.0f, 0.0f, 0, 0, VG_PATH_CAPABILITY_ALL); + if (path == VG_INVALID_HANDLE) + return; + + fill = vgCreatePaint(); + if (fill == VG_INVALID_HANDLE) { + vgDestroyPath(path); + return; + } + + vgSetfv(VG_CLEAR_COLOR, 4, defaultColor); + vgSeti(VG_RENDERING_QUALITY, VG_RENDERING_QUALITY_NONANTIALIASED); + + vgAppendPathData(path, 5, commands, coords); + + vgSetPaint(fill, VG_FILL_PATH); + vgSetParameteri(fill, VG_PAINT_TYPE, VG_PAINT_TYPE_LINEAR_GRADIENT); + vgSetParameteri(fill, VG_PAINT_COLOR_RAMP_SPREAD_MODE, + VG_COLOR_RAMP_SPREAD_REPEAT); + vgSetParameterfv(fill, VG_PAINT_LINEAR_GRADIENT, 4, linearGradient); + vgSetParameterfv(fill, VG_PAINT_COLOR_RAMP_STOPS, 20, rampStop); +} + +/* new window size or exposure */ +static void +reshape(int w, int h) +{ + vgLoadIdentity(); +} + +static void +draw(void) +{ + vgClear(0, 0, window_width(), window_height()); + + vgDrawPath(path, VG_FILL_PATH); + + vgFlush(); +} + + +int main(int argc, char **argv) +{ + if (argc > 1) { + const char *arg = argv[1]; + if (!strcmp("-pad", arg)) + spread = VG_COLOR_RAMP_SPREAD_PAD; + else if (!strcmp("-repeat", arg)) + spread = VG_COLOR_RAMP_SPREAD_REPEAT; + else if (!strcmp("-reflect", arg)) + spread = VG_COLOR_RAMP_SPREAD_REFLECT; + } + + switch(spread) { + case VG_COLOR_RAMP_SPREAD_PAD: + printf("Using spread mode: pad\n"); + break; + case VG_COLOR_RAMP_SPREAD_REPEAT: + printf("Using spread mode: repeat\n"); + break; + case VG_COLOR_RAMP_SPREAD_REFLECT: + printf("Using spread mode: reflect\n"); + } + + set_window_size(200, 200); + + return run(argc, argv, init, reshape, + draw, 0); +} diff --git a/progs/openvg/trivial/lineto.c b/progs/openvg/trivial/lineto.c new file mode 100644 index 0000000000..94e2981811 --- /dev/null +++ b/progs/openvg/trivial/lineto.c @@ -0,0 +1,56 @@ +#include "eglcommon.h" + +#include <VG/openvg.h> + +const VGfloat white_color[4] = {1.0, 1.0, 1.0, 1.0}; +const VGfloat color[4] = {0.4, 0.1, 1.0, 1.0}; + +VGPath path; +VGPaint fill; + + +static void +init(void) +{ + static const VGubyte sqrCmds[5] = {VG_MOVE_TO_ABS, VG_HLINE_TO_ABS, VG_VLINE_TO_ABS, VG_HLINE_TO_ABS, VG_CLOSE_PATH}; + static const VGfloat sqrCoords[5] = {50.0f, 50.0f, 250.0f, 250.0f, 50.0f}; + path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1, 0, 0, 0, + VG_PATH_CAPABILITY_APPEND_TO); + vgAppendPathData(path, 5, sqrCmds, sqrCoords); + + fill = vgCreatePaint(); + vgSetParameterfv(fill, VG_PAINT_COLOR, 4, color); + vgSetPaint(fill, VG_FILL_PATH); + + vgSetfv(VG_CLEAR_COLOR, 4, white_color); + vgSetf(VG_STROKE_LINE_WIDTH, 10); + vgSeti(VG_STROKE_CAP_STYLE, VG_CAP_BUTT); + vgSeti(VG_STROKE_JOIN_STYLE, VG_JOIN_ROUND); + vgSetf(VG_STROKE_MITER_LIMIT, 4.0f); +} + +/* new window size or exposure */ +static void +reshape(int w, int h) +{ + vgLoadIdentity(); +} + +static void +draw(void) +{ + vgClear(0, 0, window_width(), window_height()); + vgSeti(VG_MATRIX_MODE, VG_MATRIX_STROKE_PAINT_TO_USER); + vgLoadIdentity(); + vgScale(2.25, 2.25); + vgDrawPath(path, VG_STROKE_PATH); + + vgFlush(); +} + + +int main(int argc, char **argv) +{ + return run(argc, argv, init, reshape, + draw, 0); +} diff --git a/progs/openvg/trivial/lingrad.c b/progs/openvg/trivial/lingrad.c new file mode 100644 index 0000000000..bcaad1f101 --- /dev/null +++ b/progs/openvg/trivial/lingrad.c @@ -0,0 +1,87 @@ +#include "eglcommon.h" + +#include <VG/openvg.h> + +#include <stdio.h> +#include <string.h> + +static const VGfloat white_color[4] = {1.0, 1.0, 1.0, 1.0}; + +static VGPath path; +static VGPaint fill; + +VGColorRampSpreadMode spread = VG_COLOR_RAMP_SPREAD_PAD; + +static void +init(void) +{ + static const VGubyte sqrCmds[5] = {VG_MOVE_TO_ABS, VG_HLINE_TO_ABS, VG_VLINE_TO_ABS, VG_HLINE_TO_ABS, VG_CLOSE_PATH}; + static const VGfloat sqrCoords[5] = {0.0f, 0.0f, 400.0f, 400.0f, 0.0f}; + + VGfloat rampStop[] = {0.00f, 1.0f, 1.0f, 1.0f, 1.0f, + 0.33f, 1.0f, 0.0f, 0.0f, 1.0f, + 0.66f, 0.0f, 1.0f, 0.0f, 1.0f, + 1.00f, 0.0f, 0.0f, 1.0f, 1.0f}; + VGfloat linearGradient[4] = {100.0f, 100.0f, 300.0f, 300.0f}; + + path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1, 0, 0, 0, + VG_PATH_CAPABILITY_APPEND_TO); + vgAppendPathData(path, 5, sqrCmds, sqrCoords); + + fill = vgCreatePaint(); + vgSetPaint(fill, VG_FILL_PATH); + + vgSetParameteri(fill, VG_PAINT_TYPE, VG_PAINT_TYPE_LINEAR_GRADIENT); + vgSetParameteri(fill, VG_PAINT_COLOR_RAMP_SPREAD_MODE, spread); + vgSetParameterfv(fill, VG_PAINT_LINEAR_GRADIENT, 4, linearGradient); + vgSetParameterfv(fill, VG_PAINT_COLOR_RAMP_STOPS, 20, rampStop); + + vgSetfv(VG_CLEAR_COLOR, 4, white_color); +} + +/* new window size or exposure */ +static void +reshape(int w, int h) +{ + vgLoadIdentity(); +} + +static void +draw(void) +{ + vgClear(0, 0, window_width(), window_height()); + + vgDrawPath(path, VG_FILL_PATH); + + vgFlush(); +} + + +int main(int argc, char **argv) +{ + if (argc > 1) { + const char *arg = argv[1]; + if (!strcmp("-pad", arg)) + spread = VG_COLOR_RAMP_SPREAD_PAD; + else if (!strcmp("-repeat", arg)) + spread = VG_COLOR_RAMP_SPREAD_REPEAT; + else if (!strcmp("-reflect", arg)) + spread = VG_COLOR_RAMP_SPREAD_REFLECT; + } + + switch(spread) { + case VG_COLOR_RAMP_SPREAD_PAD: + printf("Using spread mode: pad\n"); + break; + case VG_COLOR_RAMP_SPREAD_REPEAT: + printf("Using spread mode: repeat\n"); + break; + case VG_COLOR_RAMP_SPREAD_REFLECT: + printf("Using spread mode: reflect\n"); + } + + set_window_size(400, 400); + + return run(argc, argv, init, reshape, + draw, 0); +} diff --git a/progs/openvg/trivial/lookup.c b/progs/openvg/trivial/lookup.c new file mode 100644 index 0000000000..a103ba4488 --- /dev/null +++ b/progs/openvg/trivial/lookup.c @@ -0,0 +1,71 @@ +#include "eglcommon.h" + +#include <VG/openvg.h> + +#include <math.h> +#include <stdlib.h> +#include <stdio.h> + +const VGfloat white_color[4] = {1.0, 1.0, 1.0, 1.0}; +const VGfloat color[4] = {1.0, 1.0, 1.0, 0.5}; +VGfloat clearColor[] = {1.0f, 0.0f, 0.0f, 1.0f};/* red color */ +VGImage parent; + +VGPaint fill; + +static void +init(void) +{ + VGImage child1, child2; + VGubyte *data; + VGuint LUT[256]; + VGint i; + + data = (VGubyte *)malloc(sizeof(VGubyte)*window_width()*window_height()); + + for (i=0;i<window_width()*window_height();i++) { + data[i] = 0x00; + } + + for (i=0; i<256; i++) { + if ( i == 0 ) + LUT[0] = 0xFFFFFFFF; + else + LUT[i] = 0xFF00FFFF; + } + + parent = vgCreateImage( VG_A_8, 64, 64, VG_IMAGE_QUALITY_NONANTIALIASED ); + + vgImageSubData(parent, data, window_width(), VG_A_8, 0, 0, + window_width(), window_height()); + child1 = vgChildImage(parent, 0, 0, 32, 64); + child2 = vgChildImage(parent, 32, 0, 32, 64); + + vgLookupSingle(child2, child1, LUT, VG_GREEN, VG_FALSE, VG_TRUE); +} + +/* new window size or exposure */ +static void +reshape(int w, int h) +{ +} + +static void +draw(void) +{ + vgSetfv(VG_CLEAR_COLOR, 4, clearColor); + vgClear(0, 0, window_width(), window_height()); + //vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE); + //vgLoadIdentity(); + //vgTranslate(10, 10); + vgDrawImage(parent); + vgFlush(); +} + + +int main(int argc, char **argv) +{ + set_window_size(64, 64); + return run(argc, argv, init, reshape, + draw, 0); +} diff --git a/progs/openvg/trivial/mask.c b/progs/openvg/trivial/mask.c new file mode 100644 index 0000000000..e5c00c5699 --- /dev/null +++ b/progs/openvg/trivial/mask.c @@ -0,0 +1,58 @@ +#include "eglcommon.h" + +#include <VG/openvg.h> + +const VGfloat white_color[4] = {1.0, 1.0, 1.0, 1.0}; +const VGfloat color[4] = {0.4, 0.1, 1.0, 1.0}; + +VGPath path; +VGPaint fill; + + +static void +init(void) +{ + static const VGubyte sqrCmds[5] = {VG_MOVE_TO_ABS, VG_HLINE_TO_ABS, VG_VLINE_TO_ABS, VG_HLINE_TO_ABS, VG_CLOSE_PATH}; + static const VGfloat sqrCoords[5] = {50.0f, 50.0f, 250.0f, 250.0f, 50.0f}; + path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1, 0, 0, 0, + VG_PATH_CAPABILITY_APPEND_TO); + vgAppendPathData(path, 5, sqrCmds, sqrCoords); + + fill = vgCreatePaint(); + vgSetParameterfv(fill, VG_PAINT_COLOR, 4, color); + vgSetPaint(fill, VG_FILL_PATH); + + vgSetfv(VG_CLEAR_COLOR, 4, white_color); + vgSetf(VG_STROKE_LINE_WIDTH, 10); + vgSeti(VG_STROKE_CAP_STYLE, VG_CAP_BUTT); + vgSeti(VG_STROKE_JOIN_STYLE, VG_JOIN_ROUND); + vgSetf(VG_STROKE_MITER_LIMIT, 4.0f); + + vgSeti(VG_MASKING, VG_TRUE); + + vgMask(VG_INVALID_HANDLE, VG_CLEAR_MASK, + 25, 25, 100, 100); +} + +/* new window size or exposure */ +static void +reshape(int w, int h) +{ + vgLoadIdentity(); +} + +static void +draw(void) +{ + vgClear(0, 0, window_width(), window_height()); + vgDrawPath(path, VG_FILL_PATH); + + vgFlush(); +} + + +int main(int argc, char **argv) +{ + return run(argc, argv, init, reshape, + draw, 0); +} diff --git a/progs/openvg/trivial/mask4.c b/progs/openvg/trivial/mask4.c new file mode 100644 index 0000000000..fe6db39648 --- /dev/null +++ b/progs/openvg/trivial/mask4.c @@ -0,0 +1,132 @@ +#include "eglcommon.h" + +#include <VG/openvg.h> +#include <VG/vgu.h> +#include <stdio.h> +#include <math.h> +#include <stdlib.h> + +#include <X11/keysym.h> + +//VGint x_pos = -10, y_pos = -10; +VGint x_pos = 0, y_pos = 4; +VGint img_width = 120, img_height = 120; + +static void RectToPath(VGPath path, VGfloat x, VGfloat y, VGfloat width, VGfloat height) +{ + static const VGubyte segments[5] = {VG_MOVE_TO_ABS, + VG_HLINE_TO_ABS, + VG_VLINE_TO_ABS, + VG_HLINE_TO_ABS, + VG_CLOSE_PATH}; + VGfloat data[5]; + + data[0] = x; + data[1] = y; + data[2] = x + width; + data[3] = y + height; + data[4] = x; + + vgAppendPathData(path, 5, segments, data); +} + +static void +init(void) +{ +} + +/* new window size or exposure */ +static void +reshape(int w, int h) +{ +} + +int key_press(unsigned key) +{ + switch(key) { + case XK_Right: + x_pos +=1; + break; + case XK_Left: + x_pos -=1; + break; + case XK_Up: + y_pos +=1; + break; + case XK_Down: + y_pos -=1; + break; + case 'a': + img_width -= 5; + img_height -= 5; + break; + case 's': + img_width += 5; + img_height += 5; + break; + default: + break; + } + fprintf(stderr, "Posi = %dx%d\n", x_pos, y_pos); + fprintf(stderr, "Size = %dx%d\n", img_width, img_height); + return VG_FALSE; +} + +static void +draw(void) +{ + VGint WINDSIZEX = window_width(); + VGint WINDSIZEY = window_height(); + + VGPaint fill; + VGPath box; + VGfloat color[4] = {1.f, 0.f, 0.f, 1.f}; + VGfloat bgCol[4] = {0.7f, 0.7f, 0.7f, 1.0f}; + VGfloat transCol[4] = {0.f, 0.f, 0.f, 0.f}; + VGImage image = vgCreateImage(VG_sRGBA_8888, img_width, img_height, + VG_IMAGE_QUALITY_NONANTIALIASED); + + /* Background clear */ + fill = vgCreatePaint(); + vgSetParameterfv(fill, VG_PAINT_COLOR, 4, color); + vgSetPaint(fill, VG_FILL_PATH); + + box = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, + 1, 0, 0, 0, VG_PATH_CAPABILITY_ALL); + /* Rectangle to cover completely 16x16 pixel area. */ + RectToPath(box, 0, 0, 64, 64); + + vgSetfv(VG_CLEAR_COLOR, 4, transCol); + vgClearImage(image, 0, 0, img_width, img_height); + vgSetfv(VG_CLEAR_COLOR, 4, color); + vgClearImage(image, 10, 10, 12, 12); + //vgImageSubData(image, pukki_64x64_data, pukki_64x64_stride, + // VG_sRGBA_8888, 0, 0, 32, 32); + vgSeti(VG_MASKING, VG_TRUE); + vgLoadIdentity(); + + vgSetfv(VG_CLEAR_COLOR, 4, bgCol); + vgClear(0, 0, WINDSIZEX, WINDSIZEY); + + + vgMask(image, VG_FILL_MASK, 0, 0, window_width(), window_height()); + vgMask(image, VG_SET_MASK, x_pos, y_pos, 100, 100); + + vgDrawPath(box, VG_FILL_PATH); + + //vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE); + //vgTranslate(-10, -10); + //vgDrawImage(image); + + + vgDestroyPaint(fill); + vgDestroyPath(box); +} + + +int main(int argc, char **argv) +{ + set_window_size(64, 64); + return run(argc, argv, init, reshape, + draw, key_press); +} diff --git a/progs/openvg/trivial/path3.c b/progs/openvg/trivial/path3.c new file mode 100644 index 0000000000..5ce600f65a --- /dev/null +++ b/progs/openvg/trivial/path3.c @@ -0,0 +1,77 @@ +#include "eglcommon.h" + +#include <VG/openvg.h> +#include <VG/vgu.h> +#include <stdio.h> +#include <math.h> +#include <stdlib.h> + +static void +init(void) +{ +} + +/* new window size or exposure */ +static void +reshape(int w, int h) +{ +} + + +static void +draw(void) +{ + VGint WINDSIZEX = window_width(); + VGint WINDSIZEY = window_height(); + VGPath path; + VGPaint paint; + + VGfloat clearColor[] = {1.0f, 1.0f, 1.0f, 0.0f};/* white color */ + VGfloat fillColor[] = {1.0f, 0.0f, 0.0f, 1.0f};/* red color */ + +#if 1 + VGubyte commands[4] = {VG_MOVE_TO_ABS, VG_LCWARC_TO_ABS, VG_SCWARC_TO_ABS, VG_CLOSE_PATH}; +#else + VGubyte commands[4] = {VG_MOVE_TO_ABS, VG_SCCWARC_TO_ABS, VG_LCCWARC_TO_ABS,VG_CLOSE_PATH}; +#endif + VGfloat coords[] = {32.0f, 0.0f, + -32.0f, -32.0f, 0.0f, 64.0f, 32.0f, + -32.0f, -32.0f, 0.0f, 32.0f, 0.0f}; + + + vgSetfv(VG_CLEAR_COLOR, 4, clearColor); + vgClear(0, 0, WINDSIZEX, WINDSIZEY); + vgSeti(VG_RENDERING_QUALITY, VG_RENDERING_QUALITY_NONANTIALIASED); + + vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); + vgLoadIdentity(); + //vgTranslate(32.0f, 32.0f); + + path = vgCreatePath( VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, + 1.0f, 0.0f, 0, 0, VG_PATH_CAPABILITY_ALL ); + if ( path == VG_INVALID_HANDLE ) { + return; + } + paint = vgCreatePaint(); + if ( paint == VG_INVALID_HANDLE ) { + vgDestroyPath(path); + return; + } + + vgAppendPathData(path, 4, commands, coords); + vgSetParameterfv(paint, VG_PAINT_COLOR, 4, fillColor); + vgSetParameteri( paint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR); + vgSetPaint(paint, VG_FILL_PATH); + vgDrawPath(path, VG_FILL_PATH); + + vgDestroyPath(path); + vgDestroyPaint(paint); +} + + +int main(int argc, char **argv) +{ + set_window_size(64, 64); + return run(argc, argv, init, reshape, + draw, 0); +} diff --git a/progs/openvg/trivial/radialgrad.c b/progs/openvg/trivial/radialgrad.c new file mode 100644 index 0000000000..cf3b1d522d --- /dev/null +++ b/progs/openvg/trivial/radialgrad.c @@ -0,0 +1,99 @@ +#include "eglcommon.h" + +#include <VG/openvg.h> + +#include <stdio.h> +#include <string.h> + +static const VGfloat white_color[4] = {1.0, 1.0, 1.0, 1.0}; + +static VGPath path; +static VGPaint fill; + + +VGfloat centeredGradient[5] = {200.0f, 200.0f, 200.0f, 200.0f, 100}; +VGfloat noncenteredGradient[5] = {200.0f, 200.0f, 250.0f, 250.0f, 100}; +VGfloat *radialGradient = centeredGradient; + +VGColorRampSpreadMode spread = VG_COLOR_RAMP_SPREAD_PAD; + +static void +init(void) +{ + static const VGubyte sqrCmds[5] = {VG_MOVE_TO_ABS, VG_HLINE_TO_ABS, VG_VLINE_TO_ABS, VG_HLINE_TO_ABS, VG_CLOSE_PATH}; + static const VGfloat sqrCoords[5] = {0.0f, 0.0f, 400.0f, 400.0f, 0.0f}; + + VGfloat rampStop[] = {0.00f, 1.0f, 1.0f, 1.0f, 1.0f, + 0.33f, 1.0f, 0.0f, 0.0f, 1.0f, + 0.66f, 0.0f, 1.0f, 0.0f, 1.0f, + 1.00f, 0.0f, 0.0f, 1.0f, 1.0f}; + + path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1, 0, 0, 0, + VG_PATH_CAPABILITY_APPEND_TO); + vgAppendPathData(path, 5, sqrCmds, sqrCoords); + + fill = vgCreatePaint(); + vgSetPaint(fill, VG_FILL_PATH); + + vgSetParameteri(fill, VG_PAINT_TYPE, VG_PAINT_TYPE_RADIAL_GRADIENT); + vgSetParameteri(fill, VG_PAINT_COLOR_RAMP_SPREAD_MODE, spread); + vgSetParameterfv(fill, VG_PAINT_RADIAL_GRADIENT, 5, radialGradient); + vgSetParameterfv(fill, VG_PAINT_COLOR_RAMP_STOPS, 20, rampStop); + + vgSetfv(VG_CLEAR_COLOR, 4, white_color); +} + +/* new window size or exposure */ +static void +reshape(int w, int h) +{ + vgLoadIdentity(); +} + +static void +draw(void) +{ + vgClear(0, 0, window_width(), window_height()); + + vgDrawPath(path, VG_FILL_PATH); + + vgFlush(); +} + + +int main(int argc, char **argv) +{ + VGint i; + for (i = 1; i < argc; ++i) { + const char *arg = argv[i]; + if (!strcmp("-pad", arg)) + spread = VG_COLOR_RAMP_SPREAD_PAD; + else if (!strcmp("-repeat", arg)) + spread = VG_COLOR_RAMP_SPREAD_REPEAT; + else if (!strcmp("-reflect", arg)) + spread = VG_COLOR_RAMP_SPREAD_REFLECT; + else if (!strcmp("-center", arg)) { + printf("Centered radial gradient\n"); + radialGradient = centeredGradient; + } else if (!strcmp("-noncenter", arg)) { + printf("Non centered radial gradient\n"); + radialGradient = noncenteredGradient; + } + } + + switch(spread) { + case VG_COLOR_RAMP_SPREAD_PAD: + printf("Using spread mode: pad\n"); + break; + case VG_COLOR_RAMP_SPREAD_REPEAT: + printf("Using spread mode: repeat\n"); + break; + case VG_COLOR_RAMP_SPREAD_REFLECT: + printf("Using spread mode: reflect\n"); + } + + set_window_size(400, 400); + + return run(argc, argv, init, reshape, + draw, 0); +} diff --git a/progs/openvg/trivial/readpixels.c b/progs/openvg/trivial/readpixels.c new file mode 100644 index 0000000000..c8e286db9a --- /dev/null +++ b/progs/openvg/trivial/readpixels.c @@ -0,0 +1,75 @@ +#include "eglcommon.h" + +#include <VG/openvg.h> + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <assert.h> + +float red_color[4] = {1.0, 0.0, 0.0, 1.0}; +float blue_color[4] = {0.0, 0.0, 1.0, 1.0}; +VGint *data; + +static void +init(void) +{ + data = malloc(sizeof(VGint)*2048*2048); +} + +/* new window size or exposure */ +static void +reshape(int w, int h) +{ + vgLoadIdentity(); +} + +static void +draw(void) +{ + static const VGint red_pixel = 255 << 24 | 255 << 16 | 0 << 8 | 0; + static const VGint blue_pixel = 255 << 24 | 0 << 16 | 0 << 8 | 255; + VGint i; + + vgSetfv(VG_CLEAR_COLOR, 4, red_color); + vgClear(0, 0, window_width(), window_height()); + vgFlush(); + + memset(data, 0, window_width() * window_height() * sizeof(VGint)); + + vgReadPixels(data, window_width() * sizeof(VGint), + VG_lARGB_8888, + 0, 0, window_width(), window_height()); + + fprintf(stderr, "Red 0 = 0x%x and at 600 = 0x%x\n", + data[0], data[600]); + for (i = 0; i < window_width() * window_height(); ++i) { + assert(data[i] == red_pixel); + } + + vgSetfv(VG_CLEAR_COLOR, 4, blue_color); + vgClear(50, 50, 50, 50); + vgFlush(); + + memset(data, 0, window_width() * window_height() * sizeof(VGint)); + + vgReadPixels(data, 50 * sizeof(VGint), + VG_lARGB_8888, + 50, 50, 50, 50); + + fprintf(stderr, "Blue 0 = 0x%x and at 100 = 0x%x\n", + data[0], data[100]); + for (i = 0; i < 50 * 50; ++i) { + assert(data[i] == blue_pixel); + } +} + + +int main(int argc, char **argv) +{ + int ret = run(argc, argv, init, reshape, + draw, 0); + + free(data); + return ret; +} diff --git a/progs/openvg/trivial/roundedrect.c b/progs/openvg/trivial/roundedrect.c new file mode 100644 index 0000000000..c80a4ed299 --- /dev/null +++ b/progs/openvg/trivial/roundedrect.c @@ -0,0 +1,67 @@ +#include "eglcommon.h" + +#include <VG/openvg.h> + +const VGfloat white_color[4] = {1.0, 1.0, 1.0, 1.0}; +const VGfloat color[4] = {0.9, 0.1, 0.1, 0.8}; + +VGPath path; +VGPaint fill; + + +static void +init(void) +{ + static const VGubyte sqrCmds[10] = {VG_MOVE_TO_ABS, + VG_LINE_TO_ABS, + VG_CUBIC_TO_ABS, + VG_LINE_TO_ABS, + VG_CUBIC_TO_ABS, + VG_LINE_TO_ABS, + VG_CUBIC_TO_ABS, + VG_LINE_TO_ABS, + VG_CUBIC_TO_ABS, + VG_CLOSE_PATH}; + static const VGfloat sqrCoords[] = { + 45.885571, 62.857143, + 154.11442, 62.857143, + 162.1236, 62.857143, 168.57142, 70.260744, 168.57142, 79.457144, + 168.57142, 123.4, + 168.57142, 132.5964, 162.1236, 140, 154.11442, 140, + 45.885571, 140, + 37.876394, 140, 31.428572, 132.5964, 31.428572, 123.4, + 31.428572, 79.457144, + 31.428572, 70.260744, 37.876394,62.857143, 45.885571,62.857143 + }; + path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1, 0, 0, 0, + VG_PATH_CAPABILITY_APPEND_TO); + vgAppendPathData(path, 10, sqrCmds, sqrCoords); + + fill = vgCreatePaint(); + vgSetParameterfv(fill, VG_PAINT_COLOR, 4, color); + vgSetPaint(fill, VG_FILL_PATH); + + vgSetfv(VG_CLEAR_COLOR, 4, white_color); + vgSetf(VG_STROKE_LINE_WIDTH, 6); +} + +/* new window size or exposure */ +static void +reshape(int w, int h) +{ + vgLoadIdentity(); +} + +static void +draw(void) +{ + vgClear(0, 0, window_width(), window_height()); + vgDrawPath(path, VG_STROKE_PATH); +} + + +int main(int argc, char **argv) +{ + return run(argc, argv, init, reshape, + draw, 0); +} diff --git a/progs/openvg/trivial/star-nonzero.c b/progs/openvg/trivial/star-nonzero.c new file mode 100644 index 0000000000..012fbd3929 --- /dev/null +++ b/progs/openvg/trivial/star-nonzero.c @@ -0,0 +1,55 @@ +#include "eglcommon.h" + +#include <VG/openvg.h> + +const VGfloat white_color[4] = {1.0, 1.0, 1.0, 1.0}; +const VGfloat green_color[4] = {0.0, 1.0, 0.0, 0.8}; + +VGPath path; +VGPaint fill; + + +static void +init(void) +{ + static const VGubyte cmds[6] = {VG_MOVE_TO_ABS, VG_LINE_TO_ABS, VG_LINE_TO_ABS, VG_LINE_TO_ABS, + VG_LINE_TO_ABS, VG_CLOSE_PATH}; + static const VGfloat coords[] = { 0, 200, + 300, 200, + 50, 0, + 150, 300, + 250, 0}; + path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1, 0, 0, 0, + VG_PATH_CAPABILITY_APPEND_TO); + vgAppendPathData(path, 6, cmds, coords); + + fill = vgCreatePaint(); + vgSetParameterfv(fill, VG_PAINT_COLOR, 4, green_color); + vgSetPaint(fill, VG_FILL_PATH); + + vgSetfv(VG_CLEAR_COLOR, 4, white_color); + vgSeti(VG_FILL_RULE, VG_NON_ZERO); +} + +/* new window size or exposure */ +static void +reshape(int w, int h) +{ + vgLoadIdentity(); +} + +static void +draw(void) +{ + vgClear(0, 0, window_width(), window_height()); + vgDrawPath(path, VG_FILL_PATH | VG_STROKE_PATH); + + vgFlush(); +} + + +int main(int argc, char **argv) +{ + return run(argc, argv, init, reshape, + draw, 0); +} diff --git a/progs/openvg/trivial/star-oddeven.c b/progs/openvg/trivial/star-oddeven.c new file mode 100644 index 0000000000..17311cf720 --- /dev/null +++ b/progs/openvg/trivial/star-oddeven.c @@ -0,0 +1,102 @@ +#include "eglcommon.h" + +#include <VG/openvg.h> + +const VGfloat white_color[4] = {1.0, 1.0, 1.0, 1.0}; +const VGfloat green_color[4] = {0.0, 1.0, 0.0, 0.8}; +const VGfloat black_color[4] = {0.0, 0.0, 0.0, 1.0}; + +VGPath path; +VGPaint fill; + + +static void draw_point(VGfloat x, VGfloat y) +{ + + static const VGubyte cmds[] = {VG_MOVE_TO_ABS, VG_LINE_TO_ABS, VG_LINE_TO_ABS, + VG_LINE_TO_ABS, VG_CLOSE_PATH}; + const VGfloat coords[] = { x - 2, y - 2, + x + 2, y - 2, + x + 2, y + 2, + x - 2, y + 2}; + VGPath path; + VGPaint fill; + + path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1, 0, 0, 0, + VG_PATH_CAPABILITY_ALL); + vgAppendPathData(path, 5, cmds, coords); + + fill = vgCreatePaint(); + vgSetParameterfv(fill, VG_PAINT_COLOR, 4, black_color); + vgSetPaint(fill, VG_FILL_PATH); + + vgDrawPath(path, VG_FILL_PATH); + + vgDestroyPath(path); + vgDestroyPaint(fill); +} + +static void draw_marks(VGPath path) +{ + VGfloat point[2], tangent[2]; + int i = 0; + + for (i = 0; i < 1300; i += 50) { + vgPointAlongPath(path, 0, 6, i, + point + 0, point + 1, + tangent + 0, tangent + 1); + draw_point(point[0], point[1]); + } +} + +static void +init(void) +{ + static const VGubyte cmds[6] = {VG_MOVE_TO_ABS, VG_LINE_TO_ABS, VG_LINE_TO_ABS, VG_LINE_TO_ABS, + VG_LINE_TO_ABS, VG_CLOSE_PATH}; + static const VGfloat coords[] = { 0, 200, + 300, 200, + 50, 0, + 150, 300, + 250, 0}; + path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1, 0, 0, 0, + VG_PATH_CAPABILITY_ALL); + vgAppendPathData(path, 6, cmds, coords); + + fill = vgCreatePaint(); + vgSetParameterfv(fill, VG_PAINT_COLOR, 4, green_color); + vgSetPaint(fill, VG_FILL_PATH); + + vgSetfv(VG_CLEAR_COLOR, 4, white_color); +} + +/* new window size or exposure */ +static void +reshape(int w, int h) +{ + vgLoadIdentity(); +} + +static void +draw(void) +{ + VGfloat point[2], tangent[2]; + int i = 0; + + vgClear(0, 0, window_width(), window_height()); + + vgSetPaint(fill, VG_FILL_PATH); + vgDrawPath(path, VG_FILL_PATH); + + draw_marks(path); + + + vgFlush(); +} + + +int main(int argc, char **argv) +{ + return run(argc, argv, init, reshape, + draw, 0); +} diff --git a/progs/openvg/trivial/stroke.c b/progs/openvg/trivial/stroke.c new file mode 100644 index 0000000000..58ae5b7bc8 --- /dev/null +++ b/progs/openvg/trivial/stroke.c @@ -0,0 +1,116 @@ +#include "eglcommon.h" + +#include <VG/openvg.h> +#include <X11/keysym.h> +#include <stdio.h> + +const VGfloat white_color[4] = {1.0, 1.0, 1.0, 1.0}; +const VGfloat color[4] = {0.4, 0.1, 1.0, 1.0}; + +VGPath path; +VGPaint fill; + +VGint cap_style = VG_CAP_BUTT; +VGint join_style = VG_JOIN_MITER; + +static void +init(void) +{ +#if 0 + static const VGubyte cmds[] = {VG_MOVE_TO_ABS, + VG_CUBIC_TO_ABS, + }; + static const VGfloat coords[] = {30, 30, 264, 0, 0, 264, 234, 234 + }; +#else + static const VGubyte cmds[] = {VG_MOVE_TO_ABS, + VG_LINE_TO_ABS, + VG_LINE_TO_ABS + }; + static const VGfloat coords[] = {30, 30, 202, 30, 150, 224 + }; +#endif + VGfloat dash_pattern[2] = { 20.f, 20.f }; + path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1, 0, 0, 0, + VG_PATH_CAPABILITY_APPEND_TO); + vgAppendPathData(path, 3, cmds, coords); + + fill = vgCreatePaint(); + vgSetParameterfv(fill, VG_PAINT_COLOR, 4, color); + vgSetPaint(fill, VG_FILL_PATH); + + vgSetfv(VG_CLEAR_COLOR, 4, white_color); + vgSetf(VG_STROKE_LINE_WIDTH, 20); + vgSeti(VG_STROKE_CAP_STYLE, cap_style); + vgSeti(VG_STROKE_JOIN_STYLE, join_style); + vgSetfv(VG_STROKE_DASH_PATTERN, 2, dash_pattern); + vgSetf(VG_STROKE_DASH_PHASE, 0.0f); +} + +/* new window size or exposure */ +static void +reshape(int w, int h) +{ + vgLoadIdentity(); +} + +static void +draw(void) +{ + vgClear(0, 0, window_width(), window_height()); + vgDrawPath(path, VG_STROKE_PATH); + + vgFlush(); +} + +static int key_press(unsigned key) +{ + switch(key) { + case XK_c: + case XK_C: + ++cap_style; + if (cap_style > VG_CAP_SQUARE) + cap_style = VG_CAP_BUTT; + switch(cap_style) { + case VG_CAP_BUTT: + fprintf(stderr, "Cap style 'butt'\n"); + break; + case VG_CAP_ROUND: + fprintf(stderr, "Cap style 'round'\n"); + break; + case VG_CAP_SQUARE: + fprintf(stderr, "Cap style 'square'\n"); + break; + } + vgSeti(VG_STROKE_CAP_STYLE, cap_style); + break; + case XK_j: + case XK_J: + ++join_style; + if (join_style > VG_JOIN_BEVEL) + join_style = VG_JOIN_MITER; + switch(join_style) { + case VG_JOIN_MITER: + fprintf(stderr, "Join style 'miter'\n"); + break; + case VG_JOIN_ROUND: + fprintf(stderr, "Join style 'round'\n"); + break; + case VG_JOIN_BEVEL: + fprintf(stderr, "Join style 'bevel'\n"); + break; + } + vgSeti(VG_STROKE_JOIN_STYLE, join_style); + break; + default: + break; + } + + return VG_TRUE; +} + +int main(int argc, char **argv) +{ + return run(argc, argv, init, reshape, + draw, key_press); +} diff --git a/progs/openvg/trivial/stroke2.c b/progs/openvg/trivial/stroke2.c new file mode 100644 index 0000000000..ce950c1886 --- /dev/null +++ b/progs/openvg/trivial/stroke2.c @@ -0,0 +1,207 @@ +#include "eglcommon.h" + +#include <VG/openvg.h> +#include <X11/keysym.h> +#include <stdio.h> + +VGPaint stroke; +VGPath target; +VGPath lines; + +VGfloat xform[9]; +VGfloat color1[4]; +VGfloat color2[4]; +VGfloat bgCol[4]; + +static void +init(void) +{ + VGubyte lineCmds[6]; + VGfloat lineCoords[8]; + VGfloat arcCoords[5]; + VGubyte sccCmd[1]; + VGubyte scCmd[1]; + VGubyte lccCmd[1]; + VGubyte lcCmd[1]; + VGubyte moveCmd[1]; + VGfloat moveCoords[2]; + VGint i; + + bgCol[0] = 1.0f; + bgCol[1] = 1.0f; + bgCol[2] = 1.0f; + bgCol[3] = 1.0f; + + vgSetfv(VG_CLEAR_COLOR, 4, bgCol); + vgSeti(VG_RENDERING_QUALITY, VG_RENDERING_QUALITY_NONANTIALIASED); + + stroke = vgCreatePaint(); + /* Red */ + color1[0] = 1.0f; + color1[1] = 0.0f; + color1[2] = 0.0f; + color1[3] = 1.0f; + + /* Orange */ + color2[0] = 1.0000f; + color2[1] = 1.0f; + color2[2] = 0.0f; + color2[3] = 1.0f; + vgSetPaint(stroke, VG_STROKE_PATH); + + vgSeti(VG_STROKE_CAP_STYLE, VG_CAP_SQUARE); + + { + VGfloat temp[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0}; + for (i = 0; i < 9; i++) + { + xform[i] = temp[i]; + } + } + vgGetMatrix(xform); + + target = vgCreatePath(VG_PATH_FORMAT_STANDARD, + VG_PATH_DATATYPE_F, 1, 0, 0, 0, VG_PATH_CAPABILITY_TRANSFORM_TO); + +#if 0 + /* Line path */ + { + VGubyte temp[6] = {VG_MOVE_TO_ABS, VG_VLINE_TO_REL, + VG_MOVE_TO_ABS, VG_VLINE_TO_REL, + VG_HLINE_TO_REL, VG_VLINE_TO_REL}; + for (i = 0; i < 6; i++) + { + lineCmds[i] = temp[i]; + } + } + { + VGfloat temp[8] = {0.5f, 0.8f, -0.6f, 0.28f, 0.6f, -0.4f, 0.44f, 0.4f}; + for (i = 0; i < 8; i++) + { + lineCoords[i] = temp[i] * window_width(); + } + } +#else + { + VGfloat temp[5] = {0.35f, 0.15f, 29, 0.3f, 0.4f}; + for (i = 0; i < 5; i++) + { + arcCoords[i] = temp[i] * window_width(); + } + arcCoords[2] = 29; + } + + { + VGubyte temp[1] = {VG_SCCWARC_TO_ABS}; + for (i = 0; i < 1; i++) + { + sccCmd[i] = temp[i]; + } + } + { + VGubyte temp[1] = {VG_SCWARC_TO_ABS}; + for (i = 0; i < 1; i++) + { + scCmd[i] = temp[i]; + } + } + { + VGubyte temp[1] = {VG_LCCWARC_TO_ABS}; + for (i = 0; i < 1; i++) + { + lccCmd[i] = temp[i]; + } + } + { + VGubyte temp[1] = {VG_LCWARC_TO_ABS}; + for (i = 0; i < 1; i++) + { + lcCmd[i] = temp[i]; + } + } + + { + VGubyte temp[1] = {VG_MOVE_TO_ABS}; + for (i = 0; i < 1; i++) + { + moveCmd[i] = temp[i]; + } + } + { + VGfloat temp[2] = {0.7f, 0.6f}; + for (i = 0; i < 2; i++) + { + moveCoords[i] = temp[i] * window_width(); + } + } +#endif + + lines = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1, + 0, 0, 0, + VG_PATH_CAPABILITY_APPEND_TO| + VG_PATH_CAPABILITY_TRANSFORM_FROM); +#if 0 + vgAppendPathData(lines, 6, lineCmds, lineCoords); +#else + vgAppendPathData(lines, 1, moveCmd, moveCoords); + vgAppendPathData(lines, 1, sccCmd, arcCoords); + vgAppendPathData(lines, 1, moveCmd, moveCoords); + vgAppendPathData(lines, 1, scCmd, arcCoords); + vgAppendPathData(lines, 1, moveCmd, moveCoords); + vgAppendPathData(lines, 1, lccCmd, arcCoords); + vgAppendPathData(lines, 1, moveCmd, moveCoords); + vgAppendPathData(lines, 1, lcCmd, arcCoords); +#endif + + vgLoadIdentity(); + vgTranslate(0.25f * window_width(), 0.25f * window_height()); + vgRotate(30); + vgTranslate(-0.25f * window_width(), -0.25f * window_height()); + vgTransformPath(target, lines);} + +/* new window size or exposure */ +static void +reshape(int w, int h) +{ +} + +static void +draw(void) +{ + vgClear(0, 0, window_width(), window_height()); + vgLoadMatrix(xform); + vgLoadIdentity(); + vgTranslate(0.25f * window_width(), 0.25f * window_height()); + vgRotate(30); + vgTranslate(-0.25f * window_width(), -0.25f * window_height()); + vgSetf(VG_STROKE_LINE_WIDTH, 7); + vgSetParameterfv(stroke, VG_PAINT_COLOR, 4, color1); + vgDrawPath(lines, VG_STROKE_PATH); + + vgLoadMatrix(xform); + vgSetParameterfv(stroke, VG_PAINT_COLOR, 4, color2); + vgSetf(VG_STROKE_LINE_WIDTH, 3); + vgDrawPath(target, VG_STROKE_PATH); +} + +static int key_press(unsigned key) +{ + switch(key) { + case XK_c: + case XK_C: + break; + case XK_j: + case XK_J: + break; + default: + break; + } + + return VG_TRUE; +} + +int main(int argc, char **argv) +{ + return run(argc, argv, init, reshape, + draw, key_press); +} diff --git a/progs/openvg/trivial/vguarc.c b/progs/openvg/trivial/vguarc.c new file mode 100644 index 0000000000..8d971d5c09 --- /dev/null +++ b/progs/openvg/trivial/vguarc.c @@ -0,0 +1,74 @@ +#include "eglcommon.h" + +#include <VG/openvg.h> +#include <VG/vgu.h> + +const VGfloat white_color[4] = {1.0, 1.0, 1.0, 1.0}; +const VGfloat color[4] = {0.4, 0.1, 1.0, 1.0}; + +VGPath path; +VGPaint paint; + + +static void +init(void) +{ + VGfloat clearColor[] = {0.0f, 0.0f, 0.0f, 1.0f};/* black color */ + VGfloat greenColor[] = {0.0f, 1.0f, 0.0f, 1.0f};/* green color */ + VGint arcType = VGU_ARC_OPEN; + VGfloat x, y, w, h, startAngle, angleExtent; + + x = 150; + y = 150; + w = 150; + h = 150; +#if 0 + startAngle = -540.0f; + angleExtent = 270.0f; +#else + startAngle = 270.0f; + angleExtent = 90.0f; +#endif + + paint = vgCreatePaint(); + + vgSetPaint(paint, VG_STROKE_PATH); + vgSetParameterfv(paint, VG_PAINT_COLOR, 4, greenColor); + vgSetParameteri( paint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR); + vgSetf(VG_STROKE_LINE_WIDTH, 6.0f); + vgSeti(VG_RENDERING_QUALITY, VG_RENDERING_QUALITY_NONANTIALIASED); + vgSetfv(VG_CLEAR_COLOR, 4, clearColor); + + path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, + 1.0f, 0.0f, 0, 0, VG_PATH_CAPABILITY_ALL); + + vguArc(path, x, y, w, h, startAngle, angleExtent, arcType); + + vgSeti(VG_STROKE_CAP_STYLE, VG_CAP_BUTT); + vgSeti(VG_STROKE_JOIN_STYLE, VG_JOIN_BEVEL); + vgSetf(VG_STROKE_MITER_LIMIT, 4.0f); +} + +/* new window size or exposure */ +static void +reshape(int w, int h) +{ + vgLoadIdentity(); +} + +static void +draw(void) +{ + vgClear(0, 0, window_width(), window_height()); + vgDrawPath(path, VG_STROKE_PATH); + + vgFlush(); +} + + +int main(int argc, char **argv) +{ + // set_window_size(64, 63); + return run(argc, argv, init, reshape, + draw, 0); +} diff --git a/progs/rbug/.gitignore b/progs/rbug/.gitignore new file mode 100644 index 0000000000..174fe42aa7 --- /dev/null +++ b/progs/rbug/.gitignore @@ -0,0 +1,12 @@ +bin_to_bmp +simple_client +simple_server +shdr_info +shdr_dump +shdr_disable +ctx_info +ctx_rule +tex_dump +tex_info +*.bmp +*.bin diff --git a/progs/rbug/Makefile b/progs/rbug/Makefile new file mode 100644 index 0000000000..fb4e91d1af --- /dev/null +++ b/progs/rbug/Makefile @@ -0,0 +1,48 @@ +# progs/rbug/Makefile + +TOP = ../.. +include $(TOP)/configs/current + +INCLUDES = \ + -I. \ + -I$(TOP)/src/gallium/include \ + -I$(TOP)/src/gallium/auxiliary \ + -I$(TOP)/src/gallium/drivers \ + $(PROG_INCLUDES) + +LINKS = \ + $(GALLIUM_AUXILIARIES) \ + $(PROG_LINKS) + +SOURCES = \ + bin_to_bmp.c \ + simple_client.c \ + simple_server.c \ + shdr_info.c \ + shdr_dump.c \ + shdr_disable.c \ + ctx_info.c \ + ctx_rule.c \ + tex_info.c \ + tex_dump.c + + +OBJECTS = $(SOURCES:.c=.o) + +PROGS = $(OBJECTS:.o=) + +##### TARGETS ##### + +default: $(OBJECTS) $(PROGS) + +clean: + -rm -f $(PROGS) + -rm -f *.o + +##### RULES ##### + +$(OBJECTS): %.o: %.c + $(CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) $(PROG_DEFINES) $< -o $@ + +$(PROGS): %: %.o + $(CC) $(LDFLAGS) $< $(LINKS) -o $@ diff --git a/progs/rbug/README b/progs/rbug/README new file mode 100644 index 0000000000..0eb0a5de9a --- /dev/null +++ b/progs/rbug/README @@ -0,0 +1,39 @@ + REMOTE DEBUGGING CLI APPLICATIONS + + += About = + +This directory contains a Gallium3D remote debugging cli applications. + + += Build Instructions = + +To build, build a normal gallium build and from this directory do the following. + + make + += Usage = + +Make sure that you driver has trace integration, see +src/gallium/driver/trace/README for more information about that. Then from on +the computer that you want to debug do: + + export GALLIUM_RBUG=true + + <launch app> + +From the debugging computer launch apps form this directory. Currently ip +addresses are hardcoded and you need to edit the application, but that will +change in the future. + += Testing = + +The two apps simple_client and simple_server. Are unit testing of the +connection and (de)marsheler. Just run the server first and then the client: + + ./simple_server & + ./simple_client + + +-- +Jakob Bornecrantz <jakob@vmware.com> diff --git a/progs/rbug/bin_to_bmp.c b/progs/rbug/bin_to_bmp.c new file mode 100644 index 0000000000..cdae3486ce --- /dev/null +++ b/progs/rbug/bin_to_bmp.c @@ -0,0 +1,110 @@ +/* + * Copyright 2009 VMware, Inc. + * 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 + * on the rights to use, copy, modify, merge, publish, distribute, sub + * license, 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 (including the next + * paragraph) 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 NON-INFRINGEMENT. IN NO EVENT SHALL + * VMWARE AND/OR THEIR SUPPLIERS 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 "pipe/p_compiler.h" +#include "pipe/p_format.h" +#include "pipe/p_state.h" +#include "util/u_memory.h" +#include "util/u_debug.h" +#include "util/u_network.h" +#include "util/u_tile.h" + +static uint8_t* read(const char *filename, unsigned size); +static void dump(unsigned src_width, unsigned src_height, + unsigned src_stride, enum pipe_format src_format, + uint8_t *data, unsigned src_size); + +int main(int argc, char** argv) +{ + /* change these */ + unsigned width = 64; + unsigned height = 64; + unsigned stride = width * 4; + unsigned size = stride * height; + const char *filename = "mybin.bin"; + enum pipe_format format = PIPE_FORMAT_A8R8G8B8_UNORM; + + dump(width, height, stride, format, read(filename, size), size); + + return 0; +} + +static void dump(unsigned width, unsigned height, + unsigned src_stride, enum pipe_format src_format, + uint8_t *data, unsigned src_size) +{ + struct pipe_format_block src_block; + + enum pipe_format dst_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + struct pipe_format_block dst_block; + unsigned dst_stride; + unsigned dst_size; + float *rgba; + int i; + char filename[512]; + + { + pf_get_block(src_format, &src_block); + assert(src_stride >= pf_get_stride(&src_block, width)); + assert(src_size >= pf_get_2d_size(&src_block, src_stride, width)); + } + { + pf_get_block(dst_format, &dst_block); + dst_stride = pf_get_stride(&dst_block, width); + dst_size = pf_get_2d_size(&dst_block, dst_stride, width); + rgba = MALLOC(dst_size); + } + + util_snprintf(filename, 512, "%s.bmp", pf_name(src_format)); + + if (pf_is_compressed(src_format)) { + debug_printf("skipping: %s\n", filename); + return; + } + + debug_printf("saving: %s\n", filename); + + for (i = 0; i < height; i++) { + pipe_tile_raw_to_rgba(src_format, data + src_stride * i, + width, 1, + &rgba[width*4*i], dst_stride); + } + + debug_dump_float_rgba_bmp(filename, width, height, rgba, width); + + FREE(rgba); +} + +static uint8_t* read(const char *filename, unsigned size) +{ + uint8_t *data; + FILE *file = fopen(filename, "rb"); + + data = MALLOC(size); + + fread(data, 1, size, file); + fclose(file); + + return data; +} diff --git a/progs/rbug/ctx_info.c b/progs/rbug/ctx_info.c new file mode 100644 index 0000000000..d72c326719 --- /dev/null +++ b/progs/rbug/ctx_info.c @@ -0,0 +1,80 @@ +/* + * Copyright 2009 VMware, Inc. + * 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 + * on the rights to use, copy, modify, merge, publish, distribute, sub + * license, 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 (including the next + * paragraph) 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 NON-INFRINGEMENT. IN NO EVENT SHALL + * VMWARE AND/OR THEIR SUPPLIERS 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 "pipe/p_compiler.h" +#include "pipe/p_format.h" +#include "util/u_memory.h" +#include "util/u_debug.h" +#include "util/u_network.h" + +#include "rbug/rbug.h" + +static void talk() +{ + int c = u_socket_connect("localhost", 13370); + struct rbug_connection *con = rbug_from_socket(c); + struct rbug_header *header; + struct rbug_proto_context_list_reply *list; + struct rbug_proto_context_info_reply *info; + int i; + + assert(c >= 0); + assert(con); + debug_printf("Connection get!\n"); + + debug_printf("Sending get contexts\n"); + rbug_send_context_list(con, NULL); + + debug_printf("Waiting for contexts\n"); + header = rbug_get_message(con, NULL); + assert(header->opcode == RBUG_OP_CONTEXT_LIST_REPLY); + list = (struct rbug_proto_context_list_reply *)header; + + debug_printf("Got contexts:\n"); + for (i = 0; i < list->contexts_len; i++) { +#if 0 + rbug_send_contexts_info(con, list->contexts[i], NULL); + + header = rbug_get_message(con, NULL); + assert(header->opcode == RBUG_OP_CONTEXT_INFO_REPLY); + info = (struct rbug_proto_context_info_reply *)header; +#else + (void)info; + header = NULL; +#endif + + debug_printf("%llu\n", + (unsigned long long)list->contexts[i]); + rbug_free_header(header); + } + + rbug_free_header(&list->header); + rbug_disconnect(con); +} + +int main(int argc, char** argv) +{ + talk(); + return 0; +} diff --git a/progs/rbug/ctx_rule.c b/progs/rbug/ctx_rule.c new file mode 100644 index 0000000000..e38b7b4e9b --- /dev/null +++ b/progs/rbug/ctx_rule.c @@ -0,0 +1,86 @@ +/* + * Copyright 2009 VMware, Inc. + * 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 + * on the rights to use, copy, modify, merge, publish, distribute, sub + * license, 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 (including the next + * paragraph) 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 NON-INFRINGEMENT. IN NO EVENT SHALL + * VMWARE AND/OR THEIR SUPPLIERS 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 "pipe/p_compiler.h" +#include "pipe/p_format.h" +#include "util/u_memory.h" +#include "util/u_debug.h" +#include "util/u_network.h" + +#include "rbug/rbug.h" + +static void talk(rbug_context_t ctx, rbug_shader_t shdr) +{ + int c = u_socket_connect("localhost", 13370); + struct rbug_connection *con; + struct rbug_header *header; + + if (c < 0) + c = u_socket_connect("localhost", 13370); + + con = rbug_from_socket(c); + assert(c >= 0); + assert(con); + debug_printf("Connection get!\n"); + + rbug_send_context_draw_rule(con, ctx, 0, shdr, 0, 0, RBUG_BLOCK_AFTER, NULL); + + rbug_send_ping(con, NULL); + + debug_printf("Sent waiting for reply\n"); + header = rbug_get_message(con, NULL); + + if (header->opcode != RBUG_OP_PING_REPLY) + debug_printf("Error\n"); + else + debug_printf("Ok!\n"); + + rbug_free_header(header); + rbug_disconnect(con); +} + +static void print_usage() +{ + printf("Usage ctx_rule <context> <fragment>\n"); + exit(-1); +} + +int main(int argc, char** argv) +{ + long ctx; + long shdr; + + if (argc < 3) + print_usage(); + + ctx = atol(argv[1]); + shdr = atol(argv[2]); + + if (ctx <= 0 && ctx <= 0) + print_usage(); + + talk((uint64_t)ctx, (uint64_t)shdr); + + return 0; +} diff --git a/progs/rbug/shdr_disable.c b/progs/rbug/shdr_disable.c new file mode 100644 index 0000000000..e6b12073d8 --- /dev/null +++ b/progs/rbug/shdr_disable.c @@ -0,0 +1,82 @@ +/* + * Copyright 2009 VMware, Inc. + * 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 + * on the rights to use, copy, modify, merge, publish, distribute, sub + * license, 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 (including the next + * paragraph) 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 NON-INFRINGEMENT. IN NO EVENT SHALL + * VMWARE AND/OR THEIR SUPPLIERS 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 "pipe/p_compiler.h" +#include "pipe/p_format.h" +#include "util/u_memory.h" +#include "util/u_debug.h" +#include "util/u_network.h" + +#include "rbug/rbug.h" + +static void talk(rbug_context_t ctx, rbug_shader_t shdr) +{ + int c = u_socket_connect("localhost", 13370); + struct rbug_connection *con = rbug_from_socket(c); + struct rbug_header *header; + + assert(c >= 0); + assert(con); + debug_printf("Connection get!\n"); + + rbug_send_shader_disable(con, ctx, shdr, true, NULL); + + rbug_send_ping(con, NULL); + + debug_printf("Sent waiting for reply\n"); + header = rbug_get_message(con, NULL); + + if (header->opcode != RBUG_OP_PING_REPLY) + debug_printf("Error\n"); + else + debug_printf("Ok!\n"); + + rbug_free_header(header); + rbug_disconnect(con); +} + +static void print_usage() +{ + printf("Usage shdr_disable <context> <shader>\n"); + exit(-1); +} + +int main(int argc, char** argv) +{ + long ctx; + long shdr; + + if (argc < 3) + print_usage(); + + ctx = atol(argv[1]); + shdr = atol(argv[2]); + + if (ctx <= 0 && ctx <= 0) + print_usage(); + + talk((uint64_t)ctx, (uint64_t)shdr); + + return 0; +} diff --git a/progs/rbug/shdr_dump.c b/progs/rbug/shdr_dump.c new file mode 100644 index 0000000000..8f9d758d51 --- /dev/null +++ b/progs/rbug/shdr_dump.c @@ -0,0 +1,115 @@ +/* + * Copyright 2009 VMware, Inc. + * 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 + * on the rights to use, copy, modify, merge, publish, distribute, sub + * license, 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 (including the next + * paragraph) 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 NON-INFRINGEMENT. IN NO EVENT SHALL + * VMWARE AND/OR THEIR SUPPLIERS 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 "pipe/p_compiler.h" +#include "pipe/p_format.h" +#include "util/u_memory.h" +#include "util/u_debug.h" +#include "util/u_network.h" + +#include "rbug/rbug.h" + +#include "tgsi/tgsi_dump.h" + +static void shader_info(struct rbug_connection *con, rbug_context_t ctx) +{ + struct rbug_header *header; + struct rbug_proto_shader_list_reply *list; + struct rbug_proto_shader_info_reply *info; + int i; + + debug_printf("Sending get shaders to %llu\n", (unsigned long long)ctx); + rbug_send_shader_list(con, ctx, NULL); + + debug_printf("Waiting for shaders from %llu\n", (unsigned long long)ctx); + header = rbug_get_message(con, NULL); + assert(header->opcode == RBUG_OP_SHADER_LIST_REPLY); + list = (struct rbug_proto_shader_list_reply *)header; + + debug_printf("Got shaders:\n"); + for (i = 0; i < list->shaders_len; i++) { + rbug_send_shader_info(con, ctx, list->shaders[i], NULL); + + header = rbug_get_message(con, NULL); + assert(header->opcode == RBUG_OP_SHADER_INFO_REPLY); + info = (struct rbug_proto_shader_info_reply *)header; + + debug_printf("#####################################################\n"); + debug_printf("ctx: %llu shdr: %llu disabled %u\n", + (unsigned long long)ctx, + (unsigned long long)list->shaders[i], + info->disabled); + + /* just to be sure */ + assert(sizeof(struct tgsi_token) == 4); + + debug_printf("-----------------------------------------------------\n"); + tgsi_dump((struct tgsi_token *)info->original, 0); + + if (info->replaced_len > 0) { + debug_printf("-----------------------------------------------------\n"); + tgsi_dump((struct tgsi_token *)info->replaced, 0); + } + + rbug_free_header(header); + } + + debug_printf("#####################################################\n"); + rbug_free_header(&list->header); +} + +static void talk() +{ + int c = u_socket_connect("localhost", 13370); + struct rbug_connection *con = rbug_from_socket(c); + struct rbug_header *header; + struct rbug_proto_context_list_reply *list; + int i; + + assert(c >= 0); + assert(con); + debug_printf("Connection get!\n"); + + debug_printf("Sending get contexts\n"); + rbug_send_context_list(con, NULL); + + debug_printf("Waiting for contexts\n"); + header = rbug_get_message(con, NULL); + assert(header->opcode == RBUG_OP_CONTEXT_LIST_REPLY); + list = (struct rbug_proto_context_list_reply *)header; + + debug_printf("Got contexts:\n"); + for (i = 0; i < list->contexts_len; i++) { + shader_info(con, list->contexts[i]); + } + + rbug_free_header(&list->header); + rbug_disconnect(con); +} + +int main(int argc, char** argv) +{ + talk(); + return 0; +} diff --git a/progs/rbug/shdr_info.c b/progs/rbug/shdr_info.c new file mode 100644 index 0000000000..b6864e988e --- /dev/null +++ b/progs/rbug/shdr_info.c @@ -0,0 +1,98 @@ +/* + * Copyright 2009 VMware, Inc. + * 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 + * on the rights to use, copy, modify, merge, publish, distribute, sub + * license, 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 (including the next + * paragraph) 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 NON-INFRINGEMENT. IN NO EVENT SHALL + * VMWARE AND/OR THEIR SUPPLIERS 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 "pipe/p_compiler.h" +#include "pipe/p_format.h" +#include "util/u_memory.h" +#include "util/u_debug.h" +#include "util/u_network.h" + +#include "rbug/rbug.h" + +static void shader_info(struct rbug_connection *con, rbug_context_t ctx) +{ + struct rbug_header *header; + struct rbug_proto_shader_list_reply *list; + struct rbug_proto_shader_info_reply *info; + int i; + + rbug_send_shader_list(con, ctx, NULL); + + header = rbug_get_message(con, NULL); + assert(header->opcode == RBUG_OP_SHADER_LIST_REPLY); + list = (struct rbug_proto_shader_list_reply *)header; + + debug_printf(" context | shader | disabled |\n"); + for (i = 0; i < list->shaders_len; i++) { + rbug_send_shader_info(con, ctx, list->shaders[i], NULL); + + header = rbug_get_message(con, NULL); + assert(header->opcode == RBUG_OP_SHADER_INFO_REPLY); + info = (struct rbug_proto_shader_info_reply *)header; + + debug_printf("% 15llu |% 15llu |% 15u |\n", + (unsigned long long)ctx, + (unsigned long long)list->shaders[i], + (unsigned)info->disabled); + + rbug_free_header(header); + } + + rbug_free_header(&list->header); +} + +static void talk() +{ + int c = u_socket_connect("localhost", 13370); + struct rbug_connection *con = rbug_from_socket(c); + struct rbug_header *header; + struct rbug_proto_context_list_reply *list; + int i; + + assert(c >= 0); + assert(con); + debug_printf("Connection get!\n"); + + debug_printf("Sending get contexts\n"); + rbug_send_context_list(con, NULL); + + debug_printf("Waiting for contexts\n"); + header = rbug_get_message(con, NULL); + assert(header->opcode == RBUG_OP_CONTEXT_LIST_REPLY); + list = (struct rbug_proto_context_list_reply *)header; + + debug_printf("Got contexts:\n"); + for (i = 0; i < list->contexts_len; i++) { + shader_info(con, list->contexts[i]); + } + + rbug_free_header(&list->header); + rbug_disconnect(con); +} + +int main(int argc, char** argv) +{ + talk(); + return 0; +} diff --git a/progs/rbug/simple_client.c b/progs/rbug/simple_client.c new file mode 100644 index 0000000000..38929fa796 --- /dev/null +++ b/progs/rbug/simple_client.c @@ -0,0 +1,64 @@ +/* + * Copyright 2009 VMware, Inc. + * 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 + * on the rights to use, copy, modify, merge, publish, distribute, sub + * license, 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 (including the next + * paragraph) 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 NON-INFRINGEMENT. IN NO EVENT SHALL + * VMWARE AND/OR THEIR SUPPLIERS 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 "pipe/p_compiler.h" +#include "util/u_memory.h" +#include "util/u_debug.h" +#include "util/u_network.h" + +#include "rbug/rbug.h" + +static void talk() +{ + int c = u_socket_connect("localhost", 13370); + struct rbug_connection *con = rbug_from_socket(c); + struct rbug_header *header; + struct rbug_proto_texture_list_reply *list; + int i; + + assert(c >= 0); + assert(con); + debug_printf("Connection get!\n"); + + debug_printf("Sending get textures\n"); + rbug_send_texture_list(con, NULL); + + debug_printf("Waiting for textures\n"); + header = rbug_get_message(con, NULL); + assert(header->opcode == RBUG_OP_TEXTURE_LIST_REPLY); + list = (struct rbug_proto_texture_list_reply *)header; + + debug_printf("Got textures:\n"); + for (i = 0; i < list->textures_len; i++) + debug_printf("\ttex %llu\n", (unsigned long long)list->textures[i]); + + rbug_free_header(header); + rbug_disconnect(con); +} + +int main(int argc, char** argv) +{ + talk(); + return 0; +} diff --git a/progs/rbug/simple_server.c b/progs/rbug/simple_server.c new file mode 100644 index 0000000000..04380c3310 --- /dev/null +++ b/progs/rbug/simple_server.c @@ -0,0 +1,62 @@ +/* + * Copyright 2009 VMware, Inc. + * 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 + * on the rights to use, copy, modify, merge, publish, distribute, sub + * license, 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 (including the next + * paragraph) 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 NON-INFRINGEMENT. IN NO EVENT SHALL + * VMWARE AND/OR THEIR SUPPLIERS 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 "pipe/p_compiler.h" +#include "util/u_memory.h" +#include "util/u_debug.h" +#include "util/u_network.h" + +#include "rbug/rbug.h" + +static void wait() +{ + int s = u_socket_listen_on_port(13370); + int c = u_socket_accept(s); + struct rbug_connection *con = rbug_from_socket(c); + struct rbug_header *header; + rbug_texture_t texs[2]; + uint32_t serial; + texs[0] = 1337; + texs[1] = 7331; + + assert(s >= 0); + assert(c >= 0); + assert(con); + debug_printf("Connection get!\n"); + + debug_printf("Waiting for get textures\n"); + header = rbug_get_message(con, &serial); + assert(header); + assert(header->opcode == RBUG_OP_TEXTURE_LIST); + rbug_free_header(header); + + rbug_send_texture_list_reply(con, serial, texs, 2, NULL); + rbug_disconnect(con); +} + +int main(int argc, char** argv) +{ + wait(); + return 0; +} diff --git a/progs/rbug/tex_dump.c b/progs/rbug/tex_dump.c new file mode 100644 index 0000000000..f9e06ee994 --- /dev/null +++ b/progs/rbug/tex_dump.c @@ -0,0 +1,127 @@ +/* + * Copyright 2009 VMware, Inc. + * 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 + * on the rights to use, copy, modify, merge, publish, distribute, sub + * license, 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 (including the next + * paragraph) 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 NON-INFRINGEMENT. IN NO EVENT SHALL + * VMWARE AND/OR THEIR SUPPLIERS 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 "pipe/p_compiler.h" +#include "pipe/p_format.h" +#include "pipe/p_state.h" +#include "util/u_memory.h" +#include "util/u_debug.h" +#include "util/u_network.h" +#include "util/u_tile.h" +#include "rbug/rbug.h" + +static void dump(rbug_texture_t tex, + struct rbug_proto_texture_info_reply *info, + struct rbug_proto_texture_read_reply *read, + int mip) +{ + enum pipe_format format = info->format; + uint8_t *data = read->data; + unsigned width = info->width[mip]; + unsigned height = info->height[mip]; + unsigned dst_stride = width * 4 * 4; + unsigned src_stride = read->stride; + float *rgba = MALLOC(dst_stride * height); + int i; + char filename[512]; + + util_snprintf(filename, 512, "%llu_%s_%u.bmp", + (unsigned long long)tex, pf_name(info->format), mip); + + if (pf_is_compressed(info->format)) { + debug_printf("skipping: %s\n", filename); + return; + } + + debug_printf("saving: %s\n", filename); + + for (i = 0; i < height; i++) { + pipe_tile_raw_to_rgba(format, data + src_stride * i, + width, 1, + &rgba[width*4*i], dst_stride); + } + + debug_dump_float_rgba_bmp(filename, width, height, rgba, width); + + FREE(rgba); +} + +static void talk() +{ + int c = u_socket_connect("localhost", 13370); + struct rbug_connection *con = rbug_from_socket(c); + struct rbug_header *header; + struct rbug_header *header2; + struct rbug_proto_texture_list_reply *list; + struct rbug_proto_texture_info_reply *info; + struct rbug_proto_texture_read_reply *read; + int i, j; + + assert(c >= 0); + assert(con); + debug_printf("Connection get!\n"); + + debug_printf("Sending get textures\n"); + rbug_send_texture_list(con, NULL); + + debug_printf("Waiting for textures\n"); + header = rbug_get_message(con, NULL); + assert(header->opcode == RBUG_OP_TEXTURE_LIST_REPLY); + list = (struct rbug_proto_texture_list_reply *)header; + + debug_printf("Got textures:\n"); + for (i = 0; i < list->textures_len; i++) { + rbug_send_texture_info(con, list->textures[i], NULL); + + header = rbug_get_message(con, NULL); + assert(header->opcode == RBUG_OP_TEXTURE_INFO_REPLY); + info = (struct rbug_proto_texture_info_reply *)header; + + for (j = 0; j <= info->last_level; j++) { + rbug_send_texture_read(con, list->textures[i], + 0, j, 0, + 0, 0, info->width[j], info->height[j], + NULL); + + header2 = rbug_get_message(con, NULL); + assert(header2->opcode == RBUG_OP_TEXTURE_READ_REPLY); + read = (struct rbug_proto_texture_read_reply *)header2; + + dump(list->textures[i], info, read, j); + + rbug_free_header(header2); + } + + rbug_free_header(header); + + } + rbug_free_header(&list->header); + rbug_disconnect(con); +} + +int main(int argc, char** argv) +{ + talk(); + return 0; +} diff --git a/progs/rbug/tex_info.c b/progs/rbug/tex_info.c new file mode 100644 index 0000000000..4a21bae359 --- /dev/null +++ b/progs/rbug/tex_info.c @@ -0,0 +1,78 @@ +/* + * Copyright 2009 VMware, Inc. + * 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 + * on the rights to use, copy, modify, merge, publish, distribute, sub + * license, 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 (including the next + * paragraph) 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 NON-INFRINGEMENT. IN NO EVENT SHALL + * VMWARE AND/OR THEIR SUPPLIERS 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 "pipe/p_compiler.h" +#include "pipe/p_format.h" +#include "util/u_memory.h" +#include "util/u_debug.h" +#include "util/u_network.h" + +#include "rbug/rbug.h" + +static void talk() +{ + int c = u_socket_connect("localhost", 13370); + struct rbug_connection *con = rbug_from_socket(c); + struct rbug_header *header; + struct rbug_proto_texture_list_reply *list; + struct rbug_proto_texture_info_reply *info; + int i; + + assert(c >= 0); + assert(con); + debug_printf("Connection get!\n"); + + debug_printf("Sending get textures\n"); + rbug_send_texture_list(con, NULL); + + debug_printf("Waiting for textures\n"); + header = rbug_get_message(con, NULL); + assert(header->opcode == RBUG_OP_TEXTURE_LIST_REPLY); + list = (struct rbug_proto_texture_list_reply *)header; + + debug_printf("Got textures:\n"); + for (i = 0; i < list->textures_len; i++) { + rbug_send_texture_info(con, list->textures[i], NULL); + + header = rbug_get_message(con, NULL); + assert(header->opcode == RBUG_OP_TEXTURE_INFO_REPLY); + info = (struct rbug_proto_texture_info_reply *)header; + + debug_printf("%llu %s %u x %u x %u, block(%ux%u %u), last_level: %u, nr_samples: %u, usage: %u\n", + (unsigned long long)list->textures[i], pf_name(info->format), + info->width[0], info->height[0], info->depth[0], + info->blockw, info->blockh, info->blocksize, + info->last_level, info->nr_samples, info->tex_usage); + rbug_free_header(header); + } + + rbug_free_header(&list->header); + rbug_disconnect(con); +} + +int main(int argc, char** argv) +{ + talk(); + return 0; +} diff --git a/progs/samples/prim.c b/progs/samples/prim.c index f47c60faef..c04750725f 100644 --- a/progs/samples/prim.c +++ b/progs/samples/prim.c @@ -466,25 +466,22 @@ static void Draw(void) } else { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); } -#if 01 + Viewport(0, 0); Point(); Viewport(0, 1); Lines(); Viewport(0, 2); LineStrip(); Viewport(0, 3); LineLoop(); Viewport(1, 0); Bitmap(); - Viewport(1, 1); TriangleFan(); Viewport(1, 2); Triangles(); Viewport(1, 3); TriangleStrip(); Viewport(2, 0); Rect(); -#endif Viewport(2, 1); PolygonFunc(); -#if 01 Viewport(2, 2); Quads(); Viewport(2, 3); QuadStrip(); -#endif + glFlush(); if (doubleBuffer) { diff --git a/progs/slang/vstest.c b/progs/slang/vstest.c index 5108d15742..472ea9b62e 100644 --- a/progs/slang/vstest.c +++ b/progs/slang/vstest.c @@ -128,29 +128,29 @@ static void va_render () { case C: glColorPointer (4, GL_FLOAT, 0, att->data); - glEnable (GL_COLOR_ARRAY); + glEnableClientState (GL_COLOR_ARRAY); break; case S: glSecondaryColorPointerEXT (4, GL_FLOAT, 0, att->data); - glEnable (GL_SECONDARY_COLOR_ARRAY_EXT); + glEnableClientState (GL_SECONDARY_COLOR_ARRAY_EXT); break; case N: glNormalPointer (GL_FLOAT, 0, att->data); - glEnable (GL_NORMAL_ARRAY); + glEnableClientState (GL_NORMAL_ARRAY); break; case V: glVertexPointer (4, GL_FLOAT, 0, att->data); - glEnable (GL_VERTEX_ARRAY); + glEnableClientState (GL_VERTEX_ARRAY); break; case T: assert (att->index >= 0 && att->index < 8); glClientActiveTextureARB (GL_TEXTURE0_ARB + att->index); glTexCoordPointer (4, GL_FLOAT, 0, att->data); - glEnable (GL_TEXTURE_COORD_ARRAY); + glEnableClientState (GL_TEXTURE_COORD_ARRAY); break; case F: glFogCoordPointerEXT (GL_FLOAT, 0, att->data); - glEnable (GL_FOG_COORDINATE_ARRAY_EXT); + glEnableClientState (GL_FOG_COORDINATE_ARRAY_EXT); break; case A: assert (att->index > 0 && att->index < 16); @@ -169,23 +169,23 @@ static void va_render () switch (att->dispatch) { case C: - glDisable (GL_COLOR_ARRAY); + glDisableClientState (GL_COLOR_ARRAY); break; case S: - glDisable (GL_SECONDARY_COLOR_ARRAY_EXT); + glDisableClientState (GL_SECONDARY_COLOR_ARRAY_EXT); break; case N: - glDisable (GL_NORMAL_ARRAY); + glDisableClientState (GL_NORMAL_ARRAY); break; case V: - glDisable (GL_VERTEX_ARRAY); + glDisableClientState (GL_VERTEX_ARRAY); break; case T: glClientActiveTextureARB (GL_TEXTURE0_ARB + att->index); - glDisable (GL_TEXTURE_COORD_ARRAY); + glDisableClientState (GL_TEXTURE_COORD_ARRAY); break; case F: - glDisable (GL_FOG_COORDINATE_ARRAY_EXT); + glDisableClientState (GL_FOG_COORDINATE_ARRAY_EXT); break; case A: glDisableVertexAttribArrayARB (att->index); diff --git a/progs/tests/Makefile b/progs/tests/Makefile index b58d7b25e4..4d9b4e8388 100644 --- a/progs/tests/Makefile +++ b/progs/tests/Makefile @@ -17,6 +17,7 @@ SOURCES = \ arbfptest1.c \ arbfptexture.c \ arbfptrig.c \ + arbgpuprog.c \ arbnpot.c \ arbnpot-mipmap.c \ arbvptest1.c \ @@ -48,7 +49,8 @@ SOURCES = \ fptest1.c \ fptexture.c \ getprocaddress.c \ - glutfx \ + getteximage.c \ + glutfx.c \ interleave.c \ invert.c \ jkrahntest.c \ @@ -66,6 +68,8 @@ SOURCES = \ no_s3tc.c \ packedpixels.c \ pbo.c \ + persp_hint.c \ + prim.c \ prog_parameter.c \ quads.c \ random.c \ diff --git a/progs/tests/SConscript b/progs/tests/SConscript index a4b5a45573..bb6a1d2b8a 100644 --- a/progs/tests/SConscript +++ b/progs/tests/SConscript @@ -72,6 +72,7 @@ progs = [ 'fogcoord', 'fptest1', 'fptexture', + 'getteximage', 'glutfx', 'interleave', 'invert', @@ -91,6 +92,7 @@ progs = [ 'no_s3tc', 'packedpixels', 'pbo', + 'persp_hint', 'prog_parameter', 'quads', 'random', diff --git a/progs/tests/arbgpuprog.c b/progs/tests/arbgpuprog.c new file mode 100644 index 0000000000..23aa899d96 --- /dev/null +++ b/progs/tests/arbgpuprog.c @@ -0,0 +1,230 @@ +/** + * Just compile ARB vert/frag program from named file(s). + */ + +#include <assert.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <GL/glut.h> + + +static GLuint FragProg; +static GLuint VertProg; +static GLint Win; + +static PFNGLPROGRAMLOCALPARAMETER4FVARBPROC glProgramLocalParameter4fvARB_func; +static PFNGLPROGRAMLOCALPARAMETER4DARBPROC glProgramLocalParameter4dARB_func; +static PFNGLGETPROGRAMLOCALPARAMETERDVARBPROC glGetProgramLocalParameterdvARB_func; +static PFNGLGENPROGRAMSARBPROC glGenProgramsARB_func; +static PFNGLPROGRAMSTRINGARBPROC glProgramStringARB_func; +static PFNGLBINDPROGRAMARBPROC glBindProgramARB_func; +static PFNGLISPROGRAMARBPROC glIsProgramARB_func; +static PFNGLDELETEPROGRAMSARBPROC glDeleteProgramsARB_func; + + +static void Redisplay( void ) +{ + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + glutSwapBuffers(); + exit(0); +} + + +static void Reshape( int width, int 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.0, 0.0, -15.0 ); +} + + +static void Key( unsigned char key, int x, int y ) +{ + (void) x; + (void) y; + switch (key) { + case 27: + glDeleteProgramsARB_func(1, &VertProg); + glDeleteProgramsARB_func(1, &FragProg); + glutDestroyWindow(Win); + exit(0); + break; + } + glutPostRedisplay(); +} + + +/* A helper for finding errors in program strings */ +static int FindLine( const char *program, int position ) +{ + int i, line = 1; + for (i = 0; i < position; i++) { + if (program[i] == '\n') + line++; + } + return line; +} + + +static void Init( const char *vertProgFile, + const char *fragProgFile ) +{ + GLint errorPos; + char buf[10*1000]; + + if (!glutExtensionSupported("GL_ARB_vertex_program")) { + printf("Sorry, this demo requires GL_ARB_vertex_program\n"); + exit(1); + } + if (!glutExtensionSupported("GL_ARB_fragment_program")) { + printf("Sorry, this demo requires GL_ARB_fragment_program\n"); + exit(1); + } + + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + + /* + * Get extension function pointers. + */ + glProgramLocalParameter4fvARB_func = (PFNGLPROGRAMLOCALPARAMETER4FVARBPROC) glutGetProcAddress("glProgramLocalParameter4fvARB"); + assert(glProgramLocalParameter4fvARB_func); + + glProgramLocalParameter4dARB_func = (PFNGLPROGRAMLOCALPARAMETER4DARBPROC) glutGetProcAddress("glProgramLocalParameter4dARB"); + assert(glProgramLocalParameter4dARB_func); + + glGetProgramLocalParameterdvARB_func = (PFNGLGETPROGRAMLOCALPARAMETERDVARBPROC) glutGetProcAddress("glGetProgramLocalParameterdvARB"); + assert(glGetProgramLocalParameterdvARB_func); + + glGenProgramsARB_func = (PFNGLGENPROGRAMSARBPROC) glutGetProcAddress("glGenProgramsARB"); + assert(glGenProgramsARB_func); + + glProgramStringARB_func = (PFNGLPROGRAMSTRINGARBPROC) glutGetProcAddress("glProgramStringARB"); + assert(glProgramStringARB_func); + + glBindProgramARB_func = (PFNGLBINDPROGRAMARBPROC) glutGetProcAddress("glBindProgramARB"); + assert(glBindProgramARB_func); + + glIsProgramARB_func = (PFNGLISPROGRAMARBPROC) glutGetProcAddress("glIsProgramARB"); + assert(glIsProgramARB_func); + + glDeleteProgramsARB_func = (PFNGLDELETEPROGRAMSARBPROC) glutGetProcAddress("glDeleteProgramsARB"); + assert(glDeleteProgramsARB_func); + + /* + * Vertex program + */ + if (vertProgFile) { + FILE *f; + int len; + + glGenProgramsARB_func(1, &VertProg); + assert(VertProg > 0); + glBindProgramARB_func(GL_VERTEX_PROGRAM_ARB, VertProg); + + f = fopen(vertProgFile, "r"); + if (!f) { + printf("Unable to open %s\n", fragProgFile); + exit(1); + } + + len = fread(buf, 1, 10*1000,f); + glProgramStringARB_func(GL_VERTEX_PROGRAM_ARB, + GL_PROGRAM_FORMAT_ASCII_ARB, + len, + (const GLubyte *) buf); + + glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorPos); + if (glGetError() != GL_NO_ERROR || errorPos != -1) { + int l = FindLine(buf, errorPos); + printf("Vertex Program Error (pos=%d line=%d): %s\n", errorPos, l, + (char *) glGetString(GL_PROGRAM_ERROR_STRING_ARB)); + exit(0); + } + else { + glEnable(GL_VERTEX_PROGRAM_ARB); + printf("Vertex Program OK\n"); + } + } + + /* + * Fragment program + */ + if (fragProgFile) { + FILE *f; + int len; + + glGenProgramsARB_func(1, &FragProg); + assert(FragProg > 0); + glBindProgramARB_func(GL_FRAGMENT_PROGRAM_ARB, FragProg); + + f = fopen(fragProgFile, "r"); + if (!f) { + printf("Unable to open %s\n", fragProgFile); + exit(1); + } + + len = fread(buf, 1, 10*1000,f); + glProgramStringARB_func(GL_FRAGMENT_PROGRAM_ARB, + GL_PROGRAM_FORMAT_ASCII_ARB, + len, + (const GLubyte *) buf); + + glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorPos); + if (glGetError() != GL_NO_ERROR || errorPos != -1) { + int l = FindLine(buf, errorPos); + printf("Fragment Program Error (pos=%d line=%d): %s\n", errorPos, l, + (char *) glGetString(GL_PROGRAM_ERROR_STRING_ARB)); + exit(0); + } + else { + glEnable(GL_FRAGMENT_PROGRAM_ARB); + printf("Fragment Program OK\n"); + } + } +} + + +int main( int argc, char *argv[] ) +{ + const char *vertProgFile = NULL, *fragProgFile = NULL; + int i; + + glutInit( &argc, argv ); + glutInitWindowPosition( 0, 0 ); + glutInitWindowSize( 200, 200 ); + glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ); + Win = glutCreateWindow(argv[0]); + glutReshapeFunc( Reshape ); + glutKeyboardFunc( Key ); + glutDisplayFunc( Redisplay ); + + if (argc == 1) { + printf("arbgpuprog:\n"); + printf(" Compile GL_ARB_vertex/fragment_programs, report any errors.\n"); + printf("Usage:\n"); + printf(" arbgpuprog [--vp vertprogfile] [--fp fragprogfile]\n"); + exit(1); + } + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "--vp") == 0) { + vertProgFile = argv[i+1]; + i++; + } + else if (strcmp(argv[i], "--fp") == 0) { + fragProgFile = argv[i+1]; + i++; + } + } + + Init(vertProgFile, fragProgFile); + + glutMainLoop(); + return 0; +} diff --git a/progs/tests/bufferobj.c b/progs/tests/bufferobj.c index 1d97b060ef..d4ca270016 100644 --- a/progs/tests/bufferobj.c +++ b/progs/tests/bufferobj.c @@ -1,5 +1,6 @@ /* * Test GL_ARB_vertex_buffer_object + * Also test GL_ARB_vertex_array_object if supported * * Brian Paul * 16 Sep 2003 @@ -9,6 +10,7 @@ #include <assert.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <math.h> #include <GL/glew.h> #include <GL/glut.h> @@ -17,6 +19,7 @@ struct object { + GLuint ArrayObjectID; /** GL_ARB_vertex_array_object */ GLuint VertexBufferID; GLuint ColorBufferID; GLuint ElementsBufferID; @@ -35,6 +38,7 @@ static GLuint Win; static GLfloat Xrot = 0, Yrot = 0, Zrot = 0; static GLboolean Anim = GL_TRUE; +static GLboolean Have_ARB_vertex_array_object = GL_FALSE; static void CheckError(int line) @@ -48,34 +52,54 @@ static void CheckError(int line) static void DrawObject( const struct object *obj ) { - glBindBufferARB(GL_ARRAY_BUFFER_ARB, obj->VertexBufferID); - glVertexPointer(3, GL_FLOAT, obj->VertexStride, (void *) obj->VertexOffset); - glEnable(GL_VERTEX_ARRAY); + if (Have_ARB_vertex_array_object && obj->ArrayObjectID) { + glBindVertexArray(obj->ArrayObjectID); + + if (obj->NumElements > 0) { + /* indexed arrays */ + glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, obj->ElementsBufferID); + glDrawElements(GL_LINE_LOOP, obj->NumElements, GL_UNSIGNED_INT, NULL); + } + else { + /* non-indexed arrays */ + glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0); + glDrawArrays(GL_LINE_LOOP, 0, obj->NumVerts); + } + + glBindVertexArray(0); + } + else { + /* no vertex array objects, must set vertex/color pointers per draw */ + + glBindBufferARB(GL_ARRAY_BUFFER_ARB, obj->VertexBufferID); + glVertexPointer(3, GL_FLOAT, obj->VertexStride, (void *) obj->VertexOffset); + glEnableClientState(GL_VERTEX_ARRAY); - /* test push/pop attrib */ - /* XXX this leads to a segfault with NVIDIA's 53.36 driver */ + /* test push/pop attrib */ + /* XXX this leads to a segfault with NVIDIA's 53.36 driver */ #if 0 - if (1) - { - glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT); - /*glVertexPointer(3, GL_FLOAT, 0, (void *) (obj->VertexOffset + 10000));*/ - glBindBufferARB(GL_ARRAY_BUFFER_ARB, 999999); - glPopClientAttrib(); - } + if (1) + { + glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT); + /*glVertexPointer(3, GL_FLOAT, 0, (void *) (obj->VertexOffset + 10000));*/ + glBindBufferARB(GL_ARRAY_BUFFER_ARB, 999999); + glPopClientAttrib(); + } #endif - glBindBufferARB(GL_ARRAY_BUFFER_ARB, obj->ColorBufferID); - glColorPointer(3, GL_FLOAT, obj->ColorStride, (void *) obj->ColorOffset); - glEnable(GL_COLOR_ARRAY); - - if (obj->NumElements > 0) { - /* indexed arrays */ - glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, obj->ElementsBufferID); - glDrawElements(GL_LINE_LOOP, obj->NumElements, GL_UNSIGNED_INT, NULL); - } - else { - /* non-indexed arrays */ - glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0); - glDrawArrays(GL_LINE_LOOP, 0, obj->NumVerts); + glBindBufferARB(GL_ARRAY_BUFFER_ARB, obj->ColorBufferID); + glColorPointer(3, GL_FLOAT, obj->ColorStride, (void *) obj->ColorOffset); + glEnableClientState(GL_COLOR_ARRAY); + + if (obj->NumElements > 0) { + /* indexed arrays */ + glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, obj->ElementsBufferID); + glDrawElements(GL_LINE_LOOP, obj->NumElements, GL_UNSIGNED_INT, NULL); + } + else { + /* non-indexed arrays */ + glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0); + glDrawArrays(GL_LINE_LOOP, 0, obj->NumVerts); + } } } @@ -187,6 +211,28 @@ static void SpecialKey( int key, int x, int y ) } +/** + * If GL_ARB_vertex_array_object is supported, create an array object + * and set all the per-array state. + */ +static void +CreateVertexArrayObject(struct object *obj) +{ + glGenVertexArrays(1, &obj->ArrayObjectID); + glBindVertexArray(obj->ArrayObjectID); + + glBindBufferARB(GL_ARRAY_BUFFER_ARB, obj->VertexBufferID); + glVertexPointer(3, GL_FLOAT, obj->VertexStride, (void *) obj->VertexOffset); + glEnableClientState(GL_VERTEX_ARRAY); + + glBindBufferARB(GL_ARRAY_BUFFER_ARB, obj->ColorBufferID); + glColorPointer(3, GL_FLOAT, obj->ColorStride, (void *) obj->ColorOffset); + glEnableClientState(GL_COLOR_ARRAY); + + glBindVertexArray(0); +} + + /* * Non-interleaved position/color data. */ @@ -262,6 +308,10 @@ static void MakeObject1(struct object *obj) glGetBufferParameterivARB(GL_ARRAY_BUFFER_ARB, GL_BUFFER_MAPPED_ARB, &i); assert(!i); + + if (Have_ARB_vertex_array_object) { + CreateVertexArrayObject(obj); + } } @@ -297,6 +347,10 @@ static void MakeObject2(struct object *obj) obj->NumElements = 0; glUnmapBufferARB(GL_ARRAY_BUFFER_ARB); + + if (Have_ARB_vertex_array_object) { + CreateVertexArrayObject(obj); + } } @@ -347,6 +401,10 @@ static void MakeObject3(struct object *obj) i[3] = 3; glUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB); obj->NumElements = 4; + + if (Have_ARB_vertex_array_object) { + CreateVertexArrayObject(obj); + } } @@ -387,6 +445,10 @@ static void MakeObject4(struct object *obj) /* Setup a buffer of indices to test the ELEMENTS path */ obj->ElementsBufferID = 0; obj->NumElements = 0; + + if (Have_ARB_vertex_array_object) { + CreateVertexArrayObject(obj); + } } @@ -399,6 +461,13 @@ static void Init( void ) } printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + Have_ARB_vertex_array_object = + glutExtensionSupported("GL_ARB_vertex_array_object"); + + printf("Using GL_ARB_vertex_array_object: %s\n", + (Have_ARB_vertex_array_object ? "yes" : "no")); + + /* Test buffer object deletion */ if (1) { static GLubyte data[1000]; @@ -413,6 +482,7 @@ static void Init( void ) assert(!glIsBufferARB(id)); } + memset(Objects, 0, sizeof(Objects)); MakeObject1(Objects + 0); MakeObject2(Objects + 1); MakeObject3(Objects + 2); diff --git a/progs/tests/floattex.c b/progs/tests/floattex.c index ad14cacdcb..39302ce3af 100644 --- a/progs/tests/floattex.c +++ b/progs/tests/floattex.c @@ -33,7 +33,7 @@ static const char *VertShaderText = "} \n"; static struct uniform_info Uniforms[] = { - { "tex1", 1, GL_INT, { 0, 0, 0, 0 }, -1 }, + { "tex1", 1, GL_SAMPLER_2D, { 0, 0, 0, 0 }, -1 }, END_OF_UNIFORMS }; @@ -189,7 +189,7 @@ CreateProgram(void) glUseProgram_func(program); - InitUniforms(program, Uniforms); + SetUniformValues(program, Uniforms); return program; } diff --git a/progs/tests/getprocaddress.c b/progs/tests/getprocaddress.c index ca66025d2d..a09ea58e1d 100644 --- a/progs/tests/getprocaddress.c +++ b/progs/tests/getprocaddress.c @@ -39,13 +39,2600 @@ typedef void (*generic_func)(); #define EQUAL(X, Y) (fabs((X) - (Y)) < 0.001) -/** +/* This macro simplifies the task of querying an extension function + * pointer and checking to see whether it resolved. + */ +#define DECLARE_GLFUNC_PTR(name,type) \ + type name = (type) glXGetProcAddressARB((const GLubyte *) "gl" #name) + +/******************************************************************** + * Generic helper functions used by the test functions. + */ + +static void CheckGLError(int line, const char *file, const char *function) +{ + int errorCode; + glFinish(); + errorCode = glGetError(); + if (errorCode == GL_NO_ERROR) return; + while (errorCode != GL_NO_ERROR) { + fprintf(stderr, "OpenGL error 0x%x (%s) at line %d of file %s in function %s()\n", + errorCode, + errorCode == GL_INVALID_VALUE? "GL_INVALID_VALUE": + errorCode == GL_INVALID_ENUM? "GL_INVALID_ENUM": + errorCode == GL_INVALID_OPERATION? "GL_INVALID_OPERATION": + errorCode == GL_STACK_OVERFLOW? "GL_STACK_OVERFLOW": + errorCode == GL_STACK_UNDERFLOW? "GL_STACK_UNDERFLOW": + errorCode == GL_OUT_OF_MEMORY? "GL_OUT_OF_MEMORY": + "unknown", + line, file, function); + errorCode = glGetError(); + } + fflush(stderr); +} + +static GLboolean +compare_bytes(const char *errorLabel, GLuint expectedSize, + const GLubyte *expectedData, GLuint actualSize, const GLubyte *actualData) +{ + int i; + + if (expectedSize == actualSize && + memcmp(expectedData, actualData, actualSize) == 0) { + /* All is well */ + return GL_TRUE; + } + + /* Trouble; we don't match. Print out why. */ + fprintf(stderr, "%s: actual data is not as expected\n", errorLabel); + for (i = 0; i <= 1; i++) { + const GLubyte *ptr; + int size; + char *label; + int j; + + switch(i) { + case 0: + label = "expected"; + size = expectedSize; + ptr = expectedData; + break; + case 1: + label = " actual"; + size = actualSize; + ptr = actualData; + break; + } + + fprintf(stderr, " %s: size %d: {", label, size); + for (j = 0; j < size; j++) { + fprintf(stderr, "%s0x%02x", j > 0 ? ", " : "", ptr[j]); + } + fprintf(stderr, "}\n"); + } + + /* We fail if the data is unexpected. */ + return GL_FALSE; +} + + +static GLboolean +compare_ints(const char *errorLabel, GLuint expectedSize, + const GLint *expectedData, GLuint actualSize, const GLint *actualData) +{ + int i; + + if (expectedSize == actualSize && + memcmp(expectedData, actualData, actualSize*sizeof(*expectedData)) == 0) { + /* All is well */ + return GL_TRUE; + } + + /* Trouble; we don't match. Print out why. */ + fprintf(stderr, "%s: actual data is not as expected\n", errorLabel); + for (i = 0; i <= 1; i++) { + const GLint *ptr; + int size; + char *label; + int j; + + switch(i) { + case 0: + label = "expected"; + size = expectedSize; + ptr = expectedData; + break; + case 1: + label = " actual"; + size = actualSize; + ptr = actualData; + break; + } + + fprintf(stderr, " %s: size %d: {", label, size); + for (j = 0; j < size; j++) { + fprintf(stderr, "%s%d", j > 0 ? ", " : "", ptr[j]); + } + fprintf(stderr, "}\n"); + } + + /* We fail if the data is unexpected. */ + return GL_FALSE; +} + +#define MAX_CONVERTED_VALUES 4 +static GLboolean +compare_shorts_to_ints(const char *errorLabel, GLuint expectedSize, + const GLshort *expectedData, GLuint actualSize, const GLint *actualData) +{ + int i; + GLint convertedValues[MAX_CONVERTED_VALUES]; + + if (expectedSize > MAX_CONVERTED_VALUES) { + fprintf(stderr, "%s: too much data [need %d values, have %d values]\n", + errorLabel, expectedSize, MAX_CONVERTED_VALUES); + return GL_FALSE; + } + + for (i = 0; i < expectedSize; i++) { + convertedValues[i] = (GLint) expectedData[i]; + } + + return compare_ints(errorLabel, expectedSize, convertedValues, + actualSize, actualData); +} + +static GLboolean +compare_floats(const char *errorLabel, GLuint expectedSize, + const GLfloat *expectedData, GLuint actualSize, const GLfloat *actualData) +{ + int i; + + if (expectedSize == actualSize && + memcmp(expectedData, actualData, actualSize*sizeof(*expectedData)) == 0) { + /* All is well */ + return GL_TRUE; + } + + /* Trouble; we don't match. Print out why. */ + fprintf(stderr, "%s: actual data is not as expected\n", errorLabel); + for (i = 0; i <= 1; i++) { + const GLfloat *ptr; + int size; + char *label; + int j; + + switch(i) { + case 0: + label = "expected"; + size = expectedSize; + ptr = expectedData; + break; + case 1: + label = " actual"; + size = actualSize; + ptr = actualData; + break; + } + + fprintf(stderr, " %s: size %d: {", label, size); + for (j = 0; j < size; j++) { + fprintf(stderr, "%s%f", j > 0 ? ", " : "", ptr[j]); + } + fprintf(stderr, "}\n"); + } + + /* We fail if the data is unexpected. */ + return GL_FALSE; +} + +static GLboolean +compare_doubles(const char *errorLabel, GLuint expectedSize, + const GLdouble *expectedData, GLuint actualSize, const GLdouble *actualData) +{ + int i; + + if (expectedSize == actualSize || + memcmp(expectedData, actualData, actualSize*sizeof(*expectedData)) == 0) { + /* All is well */ + return GL_TRUE; + } + + /* Trouble; we don't match. Print out why. */ + fprintf(stderr, "%s: actual data is not as expected\n", errorLabel); + for (i = 0; i <= 1; i++) { + const GLdouble *ptr; + int size; + char *label; + int j; + + switch(i) { + case 0: + label = "expected"; + size = expectedSize; + ptr = expectedData; + break; + case 1: + label = " actual"; + size = actualSize; + ptr = actualData; + break; + } + + fprintf(stderr, " %s: size %d: {", label, size); + for (j = 0; j < size; j++) { + fprintf(stderr, "%s%f", j > 0 ? ", " : "", ptr[j]); + } + fprintf(stderr, "}\n"); + } + + /* We fail if the data is unexpected. */ + return GL_FALSE; +} + +/******************************************************************** + * Functions to assist with GL_ARB_texture_compressiong testing + */ + +static GLboolean +check_texture_format_supported(GLenum format) +{ + GLint numFormats; + GLint *formats; + register int i; + + glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB, &numFormats); + formats = malloc(numFormats * sizeof(GLint)); + if (formats == NULL) { + fprintf(stderr, "check_texture_format_supported: could not allocate memory for %d GLints\n", + numFormats); + return GL_FALSE; + } + + memset(formats, 0, numFormats * sizeof(GLint)); + glGetIntegerv(GL_COMPRESSED_TEXTURE_FORMATS_ARB, formats); + + for (i = 0; i < numFormats; i++) { + if (formats[i] == format) { + free(formats); + return GL_TRUE; + } + } + + /* We didn't find the format we were looking for. Give an error. */ +#define FORMAT_NAME(x) (\ + x == GL_COMPRESSED_RGB_FXT1_3DFX ? "GL_COMPRESSED_RGB_FXT1_3DFX" : \ + x == GL_COMPRESSED_RGBA_FXT1_3DFX ? "GL_COMPRESSED_RGBA_FXT1_3DFX" : \ + x == GL_COMPRESSED_RGB_S3TC_DXT1_EXT ? "GL_COMPRESSED_RGB_S3TC_DXT1_EXT" : \ + x == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT ? "GL_COMPRESSED_RGBA_S3TC_DXT1_EXT" : \ + x == GL_COMPRESSED_RGBA_S3TC_DXT3_EXT ? "GL_COMPRESSED_RGBA_S3TC_DXT3_EXT" : \ + x == GL_COMPRESSED_RGBA_S3TC_DXT5_EXT ? "GL_COMPRESSED_RGBA_S3TC_DXT5_EXT" : \ + x == GL_RGB_S3TC ? "GL_RGB_S3TC" : \ + x == GL_RGB4_S3TC ? "GL_RGB4_S3TC" : \ + x == GL_RGBA_S3TC ? "GL_RGBA_S3TC" : \ + x == GL_RGBA4_S3TC ? "GL_RGBA4_S3TC" : \ + "unknown") + fprintf(stderr, "check_texture_format_supported: unsupported format 0x%04x [%s]\n", + format, FORMAT_NAME(format)); + fprintf(stderr, "supported formats:"); + for (i = 0; i < numFormats; i++) { + fprintf(stderr, " 0x%04x [%s]", formats[i], FORMAT_NAME(formats[i])); + } + fprintf(stderr, "\n"); + return GL_FALSE; +} + +/* This helper function compresses an RGBA texture and compares it + * against the expected compressed data. It returns GL_TRUE if all + * went as expected, or GL_FALSE in the case of error. + */ +static GLboolean +check_texture_compression(const char *message, GLenum dimension, + GLint width, GLint height, GLint depth, const GLubyte *texture, + int expectedCompressedSize, const GLubyte *expectedCompressedData) +{ + /* These are the data we query about the texture. */ + GLint isCompressed; + GLenum compressedFormat; + GLint compressedSize; + GLubyte *compressedData; + + /* We need this function pointer to operate. */ + DECLARE_GLFUNC_PTR(GetCompressedTexImageARB, PFNGLGETCOMPRESSEDTEXIMAGEARBPROC); + if (GetCompressedTexImageARB == NULL) { + fprintf(stderr, + "%s: could not query GetCompressedTexImageARB function pointer\n", + message); + return GL_FALSE; + } + + /* Verify that we actually have the GL_COMPRESSED_RGBA_S3TC_DXT3_EXT format available. */ + if (!check_texture_format_supported(GL_COMPRESSED_RGBA_S3TC_DXT3_EXT)) { + return GL_FALSE; + } + + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + /* Set up the base image, requesting that the GL library compress it. */ + switch(dimension) { + case GL_TEXTURE_1D: + glTexImage1D(GL_TEXTURE_1D, 0, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, + width, 0, + GL_RGBA, GL_UNSIGNED_BYTE, texture); + break; + case GL_TEXTURE_2D: + glTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, + width, height, 0, + GL_RGBA, GL_UNSIGNED_BYTE, texture); + break; + case GL_TEXTURE_3D: + glTexImage3D(GL_TEXTURE_3D, 0, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, + width, height, depth, 0, + GL_RGBA, GL_UNSIGNED_BYTE, texture); + break; + default: + fprintf(stderr, "%s: unknown dimension 0x%04x.\n", message, dimension); + return GL_FALSE; + } + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* Make sure the texture is compressed, and pull it out if it is. */ + glGetTexLevelParameteriv(dimension, 0, GL_TEXTURE_COMPRESSED_ARB, + &isCompressed); + if (!isCompressed) { + fprintf(stderr, "%s: could not compress GL_COMPRESSED_RGBA_S3TC_DXT3_EXT texture\n", + message); + return GL_FALSE; + } + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + glGetTexLevelParameteriv(dimension, 0, GL_TEXTURE_INTERNAL_FORMAT, + (GLint *)&compressedFormat); + if (compressedFormat != GL_COMPRESSED_RGBA_S3TC_DXT3_EXT) { + fprintf(stderr, "%s: got internal format 0x%04x, expected GL_COMPRESSED_RGBA_S3TC_DXT3_EXT [0x%04x]\n", + __FUNCTION__, compressedFormat, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT); + return GL_FALSE; + } + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + glGetTexLevelParameteriv(dimension, 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE_ARB, &compressedSize); + compressedData = malloc(compressedSize); + if (compressedData == NULL) { + fprintf(stderr, "%s: could not malloc %d bytes for compressed texture\n", + message, compressedSize); + return GL_FALSE; + } + memset(compressedData, 0, compressedSize); + (*GetCompressedTexImageARB)(dimension, 0, compressedData); + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* Compare it to the expected compressed data. The compare_bytes() + * call will print out diagnostics in the case of failure. + */ + if (!compare_bytes(message, + expectedCompressedSize, expectedCompressedData, + compressedSize, compressedData)) { + + free(compressedData); + return GL_FALSE; + } + + /* All done. Free our allocated data and return success. */ + free(compressedData); + return GL_TRUE; +} + +/* We'll use one function to exercise 1D, 2D, and 3D textures. */ + +/* The test function for compressed 3D texture images requires several + * different function pointers that have to be queried. This function + * gets all the function pointers it needs itself, and so is suitable for + * use to test any and all of the incorporated functions. + */ + +static GLboolean +exercise_CompressedTextures(GLenum dimension) +{ + /* Set up a basic (uncompressed) texture. We're doing a blue/yellow + * checkerboard. The 8x4/32-pixel board is well-suited to S3TC + * compression, which works on 4x4 blocks of pixels. + */ +#define B 0,0,255,255 +#define Y 255,255,0,255 +#define TEXTURE_WIDTH 16 +#define TEXTURE_HEIGHT 4 +#define TEXTURE_DEPTH 1 + static GLubyte texture[TEXTURE_WIDTH*TEXTURE_HEIGHT*TEXTURE_DEPTH*4] = { + B, B, Y, Y, B, B, Y, Y, B, B, Y, Y, B, B, Y, Y, + B, B, Y, Y, B, B, Y, Y, B, B, Y, Y, B, B, Y, Y, + Y, Y, B, B, Y, Y, B, B, Y, Y, B, B, Y, Y, B, B, + Y, Y, B, B, Y, Y, B, B, Y, Y, B, B, Y, Y, B, B, + }; +#undef B +#undef Y + GLubyte uncompressedTexture[TEXTURE_WIDTH*TEXTURE_HEIGHT*TEXTURE_DEPTH*4]; + + /* We'll use this as a texture subimage. */ +#define R 255,0,0,255 +#define G 0,255,0,255 +#define SUBTEXTURE_WIDTH 4 +#define SUBTEXTURE_HEIGHT 4 +#define SUBTEXTURE_DEPTH 1 + static GLubyte subtexture[SUBTEXTURE_WIDTH*SUBTEXTURE_HEIGHT*SUBTEXTURE_DEPTH*4] = { + G, G, R, R, + G, G, R, R, + R, R, G, G, + R, R, G, G, + }; +#undef R +#undef G + + /* These are the expected compressed textures. (In the case of + * a failed comparison, the test program will print out the + * actual compressed data in a format that can be directly used + * here, if desired.) The brave of heart can calculate the compression + * themselves based on the formulae described at: + * http://en.wikipedia.org/wiki/S3_Texture_Compression + * In a nutshell, each group of 16 bytes encodes a 4x4 texture block. + * The first eight bytes of each group are 4-bit alpha values + * for each of the 16 pixels in the texture block. + * The next four bytes in each group are LSB-first RGB565 colors; the + * first two bytes are identified as the color C0, and the next two + * are the color C1. (Two more colors C2 and C3 will be calculated + * from these, but do not appear in the compression data.) The + * last 4 bytes of the group are sixteen 2-bit indices that, for + * each of the 16 pixels in the texture block, select one of the + * colors C0, C1, C2, or C3. + * + * For example, our blue/yellow checkerboard is made up of + * four identical 4x4 blocks. Each of those blocks will + * be encoded as: eight bytes of 0xff (16 alpha values, each 0xf), + * C0 as the RGB565 color yellow (0xffe0), encoded LSB-first; + * C1 as the RGB565 color blue (0x001f), encoded LSB-first; + * and 4 bytes of 16 2-bit color indices reflecting the + * choice of color for each of the 16 pixels: + * 00, 00, 01, 01, = 0x05 + * 00, 00, 01, 01, = 0x05 + * 01, 01, 00, 00, = 0x50 + * 01, 01, 00, 00, = 0x50 + */ + static GLubyte compressedTexture[] = { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xe0, 0xff, 0x1f, 0x00, 0x05, 0x05, 0x50, 0x50, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xe0, 0xff, 0x1f, 0x00, 0x05, 0x05, 0x50, 0x50, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xe0, 0xff, 0x1f, 0x00, 0x05, 0x05, 0x50, 0x50, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xe0, 0xff, 0x1f, 0x00, 0x05, 0x05, 0x50, 0x50 + }; + + /* The similar calculations for the 4x4 subtexture are left + * as an exercise for the reader. + */ + static GLubyte compressedSubTexture[] = { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x00, 0xf8, 0xe0, 0x07, 0x05, 0x05, 0x50, 0x50, + }; + + /* The combined texture replaces the initial blue/yellow + * block with the green/red block. (I'd wanted to do + * the more interesting exercise of putting the + * green/red block in the middle of the blue/yellow + * texture, which is a non-trivial replacement, but + * the attempt produces GL_INVALID_OPERATION, showing + * that you can only replace whole blocks of + * subimages with S3TC.) The combined texture looks + * like: + * G G R R B B Y Y B B Y Y B B Y Y + * G G R R B B Y Y B B Y Y B B Y Y + * R R G G Y Y B B Y Y B B Y Y B B + * R R G G Y Y B B Y Y B B Y Y B B + * which encodes just like the green/red block followed + * by 3 copies of the yellow/blue block. + */ + static GLubyte compressedCombinedTexture[] = { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x00, 0xf8, 0xe0, 0x07, 0x05, 0x05, 0x50, 0x50, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xe0, 0xff, 0x1f, 0x00, 0x05, 0x05, 0x50, 0x50, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xe0, 0xff, 0x1f, 0x00, 0x05, 0x05, 0x50, 0x50, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xe0, 0xff, 0x1f, 0x00, 0x05, 0x05, 0x50, 0x50 + }; + + /* These are the data we query about the texture. */ + GLint queryIsCompressed; + GLenum queryCompressedFormat; + GLint queryCompressedSize; + GLubyte queryCompressedData[sizeof(compressedTexture)]; + + /* Query the function pointers we need. We actually won't need most + * of these (the "dimension" parameter dictates whether we're testing + * 1D, 2D, or 3D textures), but we'll have them all ready just in case. + */ + DECLARE_GLFUNC_PTR(GetCompressedTexImageARB, PFNGLGETCOMPRESSEDTEXIMAGEARBPROC); + DECLARE_GLFUNC_PTR(CompressedTexImage3DARB, PFNGLCOMPRESSEDTEXIMAGE3DARBPROC); + DECLARE_GLFUNC_PTR(CompressedTexSubImage3DARB, PFNGLCOMPRESSEDTEXSUBIMAGE3DARBPROC); + DECLARE_GLFUNC_PTR(CompressedTexImage2DARB, PFNGLCOMPRESSEDTEXIMAGE2DARBPROC); + DECLARE_GLFUNC_PTR(CompressedTexSubImage2DARB, PFNGLCOMPRESSEDTEXSUBIMAGE2DARBPROC); + DECLARE_GLFUNC_PTR(CompressedTexImage1DARB, PFNGLCOMPRESSEDTEXIMAGE1DARBPROC); + DECLARE_GLFUNC_PTR(CompressedTexSubImage1DARB, PFNGLCOMPRESSEDTEXSUBIMAGE1DARBPROC); + + /* If the necessary functions are missing, we can't continue */ + if (GetCompressedTexImageARB == NULL) { + fprintf(stderr, "%s: GetCompressedTexImageARB function is missing\n", + __FUNCTION__); + return GL_FALSE; + } + switch (dimension) { + case GL_TEXTURE_1D: + if (CompressedTexImage1DARB == NULL || CompressedTexSubImage1DARB == NULL) { + fprintf(stderr, "%s: 1D compressed texture functions are missing\n", + __FUNCTION__); + return GL_FALSE; + }; + break; + case GL_TEXTURE_2D: + if (CompressedTexImage2DARB == NULL || CompressedTexSubImage2DARB == NULL) { + fprintf(stderr, "%s: 2D compressed texture functions are missing\n", + __FUNCTION__); + return GL_FALSE; + }; + break; + case GL_TEXTURE_3D: + if (CompressedTexImage3DARB == NULL || CompressedTexSubImage3DARB == NULL) { + fprintf(stderr, "%s: 3D compressed texture functions are missing\n", + __FUNCTION__); + return GL_FALSE; + }; + break; + default: + fprintf(stderr, "%s: unknown texture dimension 0x%04x passed.\n", + __FUNCTION__, dimension); + return GL_FALSE; + } + + /* Check the compression of our base texture image. */ + if (!check_texture_compression("texture compression", dimension, + TEXTURE_WIDTH, TEXTURE_HEIGHT, TEXTURE_DEPTH, texture, + sizeof(compressedTexture), compressedTexture)) { + + /* Something's wrong with texture compression. The function + * above will have printed an appropriate error. + */ + return GL_FALSE; + } + + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* Do the same for our texture subimage */ + if (!check_texture_compression("subtexture compression", dimension, + SUBTEXTURE_WIDTH, SUBTEXTURE_HEIGHT, SUBTEXTURE_DEPTH, subtexture, + sizeof(compressedSubTexture), compressedSubTexture)) { + + /* Something's wrong with texture compression. The function + * above will have printed an appropriate error. + */ + return GL_FALSE; + } + + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* Send the base compressed texture down to the hardware. */ + switch(dimension) { + case GL_TEXTURE_3D: + (*CompressedTexImage3DARB)(GL_TEXTURE_3D, 0, + GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, + TEXTURE_WIDTH, TEXTURE_HEIGHT, TEXTURE_DEPTH, 0, + sizeof(compressedTexture), compressedTexture); + break; + + case GL_TEXTURE_2D: + (*CompressedTexImage2DARB)(GL_TEXTURE_2D, 0, + GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, + TEXTURE_WIDTH, TEXTURE_HEIGHT, 0, + sizeof(compressedTexture), compressedTexture); + break; + + case GL_TEXTURE_1D: + (*CompressedTexImage1DARB)(GL_TEXTURE_1D, 0, + GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, + TEXTURE_WIDTH, 0, + sizeof(compressedTexture), compressedTexture); + break; + } + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* For grins, query it to make sure it is as expected. */ + glGetTexLevelParameteriv(dimension, 0, GL_TEXTURE_COMPRESSED_ARB, + &queryIsCompressed); + if (!queryIsCompressed) { + fprintf(stderr, "%s: compressed texture did not come back as compressed\n", + __FUNCTION__); + return GL_FALSE; + } + glGetTexLevelParameteriv(dimension, 0, GL_TEXTURE_INTERNAL_FORMAT, + (GLint *)&queryCompressedFormat); + if (queryCompressedFormat != GL_COMPRESSED_RGBA_S3TC_DXT3_EXT) { + fprintf(stderr, "%s: got internal format 0x%04x, expected GL_COMPRESSED_RGBA_S3TC_DXT3_EXT [0x%04x]\n", + __FUNCTION__, queryCompressedFormat, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT); + return GL_FALSE; + } + glGetTexLevelParameteriv(dimension, 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE_ARB, + &queryCompressedSize); + if (queryCompressedSize != sizeof(compressedTexture)) { + fprintf(stderr, "%s: compressed 3D texture changed size: expected %d, actual %d\n", + __FUNCTION__, sizeof(compressedTexture), queryCompressedSize); + return GL_FALSE; + } + (*GetCompressedTexImageARB)(dimension, 0, queryCompressedData); + if (!compare_bytes( + "exercise_CompressedTextures:doublechecking compressed texture", + sizeof(compressedTexture), compressedTexture, + queryCompressedSize, queryCompressedData)) { + return GL_FALSE; + } + + /* Now apply the texture subimage. The current implementation of + * S3TC requires that subimages be only applied to whole blocks. + */ + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + switch(dimension) { + case GL_TEXTURE_3D: + (*CompressedTexSubImage3DARB)(GL_TEXTURE_3D, 0, + 0, 0, 0, /* offsets */ + SUBTEXTURE_WIDTH, SUBTEXTURE_HEIGHT, SUBTEXTURE_DEPTH, + GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, + sizeof(compressedSubTexture), compressedSubTexture); + break; + case GL_TEXTURE_2D: + (*CompressedTexSubImage2DARB)(GL_TEXTURE_2D, 0, + 0, 0, /* offsets */ + SUBTEXTURE_WIDTH, SUBTEXTURE_HEIGHT, + GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, + sizeof(compressedSubTexture), compressedSubTexture); + break; + case GL_TEXTURE_1D: + (*CompressedTexSubImage2DARB)(GL_TEXTURE_2D, 0, + 0, 0, /* offsets */ + SUBTEXTURE_WIDTH, SUBTEXTURE_HEIGHT, + GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, + sizeof(compressedSubTexture), compressedSubTexture); + break; + } + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* Query the compressed texture back now, and see that it + * is as expected. + */ + (*GetCompressedTexImageARB)(dimension, 0, queryCompressedData); + if (!compare_bytes("exercise_CompressedTextures:combined texture", + sizeof(compressedCombinedTexture), compressedCombinedTexture, + queryCompressedSize, queryCompressedData)) { + return GL_FALSE; + } + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* Just for the exercise, uncompress the texture and pull it out. + * We don't check it because the compression is lossy, so it won't + * compare exactly to the source texture; we just + * want to exercise the code paths that convert it. + */ + glGetTexImage(dimension, 0, GL_RGBA, GL_UNSIGNED_BYTE, uncompressedTexture); + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* If we survived this far, we pass. */ + return GL_TRUE; +} + +/************************************************************************** + * Functions to assist with GL_EXT_framebuffer_object and + * GL_EXT_framebuffer_blit testing. + */ + +#define FB_STATUS_NAME(x) (\ + x == GL_FRAMEBUFFER_COMPLETE_EXT ? "GL_FRAMEBUFFER_COMPLETE_EXT" : \ + x == GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT ? "GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT" : \ + x == GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT ? "GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT" : \ + x == GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT ? "GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT" : \ + x == GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT ? "GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT" : \ + x == GL_FRAMEBUFFER_UNSUPPORTED_EXT ? "GL_FRAMEBUFFER_UNSUPPORTED_EXT" : \ + x == GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT ? "GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT" : \ + x == GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT ? "GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT" : \ + x == GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT ? "GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT" : \ + "unknown") + +static GLboolean +exercise_framebuffer(void) +{ + GLuint framebufferID = 0; + GLuint renderbufferID = 0; + + /* Dimensions of the framebuffer and renderbuffers are arbitrary. + * Since they won't be shown on-screen, we can use whatever we want. + */ + const GLint Width = 100; + const GLint Height = 100; + + /* Every function we use will be referenced through function pointers. + * This will allow this test program to run on OpenGL implementations + * that *don't* implement these extensions (though the implementation + * used to compile them must have up-to-date header files). + */ + DECLARE_GLFUNC_PTR(GenFramebuffersEXT, PFNGLGENFRAMEBUFFERSEXTPROC); + DECLARE_GLFUNC_PTR(IsFramebufferEXT, PFNGLISFRAMEBUFFEREXTPROC); + DECLARE_GLFUNC_PTR(DeleteFramebuffersEXT, PFNGLDELETEFRAMEBUFFERSEXTPROC); + DECLARE_GLFUNC_PTR(BindFramebufferEXT, PFNGLBINDFRAMEBUFFEREXTPROC); + DECLARE_GLFUNC_PTR(GenRenderbuffersEXT, PFNGLGENRENDERBUFFERSEXTPROC); + DECLARE_GLFUNC_PTR(IsRenderbufferEXT, PFNGLISRENDERBUFFEREXTPROC); + DECLARE_GLFUNC_PTR(DeleteRenderbuffersEXT, PFNGLDELETERENDERBUFFERSEXTPROC); + DECLARE_GLFUNC_PTR(BindRenderbufferEXT, PFNGLBINDRENDERBUFFEREXTPROC); + DECLARE_GLFUNC_PTR(FramebufferRenderbufferEXT, PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC); + DECLARE_GLFUNC_PTR(RenderbufferStorageEXT, PFNGLRENDERBUFFERSTORAGEEXTPROC); + DECLARE_GLFUNC_PTR(CheckFramebufferStatusEXT, PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC); + + /* The BlitFramebuffer function comes from a different extension. + * It's possible for an implementation to implement all the above, + * but not BlitFramebuffer; so it's okay if this one comes back + * NULL, as we can still test the rest. + */ + DECLARE_GLFUNC_PTR(BlitFramebufferEXT, PFNGLBLITFRAMEBUFFEREXTPROC); + + /* We cannot test unless we have all the function pointers. */ + if ( + GenFramebuffersEXT == NULL || + IsFramebufferEXT == NULL || + DeleteFramebuffersEXT == NULL || + BindFramebufferEXT == NULL || + GenRenderbuffersEXT == NULL || + IsRenderbufferEXT == NULL || + DeleteRenderbuffersEXT == NULL || + BindRenderbufferEXT == NULL || + FramebufferRenderbufferEXT == NULL || + RenderbufferStorageEXT == NULL || + CheckFramebufferStatusEXT == NULL + ) { + fprintf(stderr, "%s: could not locate all framebuffer functions\n", + __FUNCTION__); + return GL_FALSE; + } + + /* Generate a framebuffer for us to play with. */ + (*GenFramebuffersEXT)(1, &framebufferID); + if (framebufferID == 0) { + fprintf(stderr, "%s: failed to generate a frame buffer ID.\n", + __FUNCTION__); + return GL_FALSE; + } + /* The generated name is not a framebuffer object until bound. */ + (*BindFramebufferEXT)(GL_FRAMEBUFFER_EXT, framebufferID); + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + if (!(*IsFramebufferEXT)(framebufferID)) { + fprintf(stderr, "%s: generated a frame buffer ID 0x%x that wasn't a framebuffer\n", + __FUNCTION__, framebufferID); + (*BindFramebufferEXT)(GL_FRAMEBUFFER_EXT, 0); + (*DeleteFramebuffersEXT)(1, &framebufferID); + return GL_FALSE; + } + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + { + GLint queriedFramebufferID; + glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &queriedFramebufferID); + if (queriedFramebufferID != framebufferID) { + fprintf(stderr, "%s: bound frame buffer 0x%x, but queried 0x%x\n", + __FUNCTION__, framebufferID, queriedFramebufferID); + (*BindFramebufferEXT)(GL_FRAMEBUFFER_EXT, 0); + (*DeleteFramebuffersEXT)(1, &framebufferID); + return GL_FALSE; + } + } + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* Create a color buffer to attach to the frame buffer object, so + * we can actually operate on it. We go through the same basic checks + * with the renderbuffer that we do with the framebuffer. + */ + (*GenRenderbuffersEXT)(1, &renderbufferID); + if (renderbufferID == 0) { + fprintf(stderr, "%s: could not generate a renderbuffer ID\n", + __FUNCTION__); + (*BindFramebufferEXT)(GL_FRAMEBUFFER_EXT, 0); + (*DeleteFramebuffersEXT)(1, &framebufferID); + return GL_FALSE; + } + (*BindRenderbufferEXT)(GL_RENDERBUFFER_EXT, renderbufferID); + if (!(*IsRenderbufferEXT)(renderbufferID)) { + fprintf(stderr, "%s: generated renderbuffer 0x%x is not a renderbuffer\n", + __FUNCTION__, renderbufferID); + (*BindRenderbufferEXT)(GL_RENDERBUFFER_EXT, 0); + (*DeleteRenderbuffersEXT)(1, &renderbufferID); + (*BindFramebufferEXT)(GL_FRAMEBUFFER_EXT, 0); + (*DeleteFramebuffersEXT)(1, &framebufferID); + return GL_FALSE; + } + { + GLint queriedRenderbufferID = 0; + glGetIntegerv(GL_RENDERBUFFER_BINDING_EXT, &queriedRenderbufferID); + if (renderbufferID != queriedRenderbufferID) { + fprintf(stderr, "%s: bound renderbuffer 0x%x, but got 0x%x\n", + __FUNCTION__, renderbufferID, queriedRenderbufferID); + (*BindRenderbufferEXT)(GL_RENDERBUFFER_EXT, 0); + (*DeleteRenderbuffersEXT)(1, &renderbufferID); + (*BindFramebufferEXT)(GL_FRAMEBUFFER_EXT, 0); + (*DeleteFramebuffersEXT)(1, &framebufferID); + return GL_FALSE; + } + } + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* Add the renderbuffer as a color attachment to the current + * framebuffer (which is our generated framebuffer). + */ + (*FramebufferRenderbufferEXT)(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, + GL_RENDERBUFFER_EXT, renderbufferID); + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* The renderbuffer will need some dimensions and storage space. */ + (*RenderbufferStorageEXT)(GL_RENDERBUFFER_EXT, GL_RGB, Width, Height); + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* That should be everything we need. If we set up to draw and to + * read from our color attachment, we should be "framebuffer complete", + * meaning the framebuffer is ready to go. + */ + glDrawBuffer(GL_COLOR_ATTACHMENT1_EXT); + glReadBuffer(GL_COLOR_ATTACHMENT1_EXT); + { + GLenum status = (*CheckFramebufferStatusEXT)(GL_FRAMEBUFFER_EXT); + if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { + fprintf(stderr, "%s: framebuffer not complete; status = %s [0x%x]\n", + __FUNCTION__, FB_STATUS_NAME(status), status); + glReadBuffer(0); + glDrawBuffer(0); + (*BindRenderbufferEXT)(GL_RENDERBUFFER_EXT, 0); + (*DeleteRenderbuffersEXT)(1, &renderbufferID); + (*BindFramebufferEXT)(GL_FRAMEBUFFER_EXT, 0); + (*DeleteFramebuffersEXT)(1, &framebufferID); + return GL_FALSE; + } + } + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* Define the contents of the frame buffer */ + glClearColor(0.5, 0.5, 0.5, 0.0); + glClear(GL_COLOR_BUFFER_BIT); + + /* If the GL_EXT_framebuffer_blit is supported, attempt a framebuffer + * blit from (5,5)-(10,10) to (90,90)-(95,95). This is *not* an + * error if framebuffer_blit is *not* supported (as we can still + * effectively test the other functions). + */ + if (BlitFramebufferEXT != NULL) { + (*BlitFramebufferEXT)(5, 5, 10, 10, 90, 90, 95, 95, + GL_COLOR_BUFFER_BIT, GL_NEAREST); + } + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* We could now test to see whether the framebuffer had the desired + * contents. As this is just a touch test, we'll leave that for now. + * Clean up and go home. + */ + glReadBuffer(0); + glDrawBuffer(0); + (*BindRenderbufferEXT)(GL_RENDERBUFFER_EXT, 0); + (*DeleteRenderbuffersEXT)(1, &renderbufferID); + (*BindFramebufferEXT)(GL_FRAMEBUFFER_EXT, 0); + (*DeleteFramebuffersEXT)(1, &framebufferID); + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + return GL_TRUE; +} + +/************************************************************************** + * Functions to assist with GL_ARB_shader_objects testing. + */ + +static void +print_info_log(const char *message, GLhandleARB object) +{ + DECLARE_GLFUNC_PTR(GetObjectParameterivARB, PFNGLGETOBJECTPARAMETERIVARBPROC); + DECLARE_GLFUNC_PTR(GetInfoLogARB, PFNGLGETINFOLOGARBPROC); + int logLength, queryLength; + char *log; + + if (GetObjectParameterivARB == NULL) { + fprintf(stderr, "%s: could not get GetObjectParameterivARB address\n", + message); + return; + } + if (GetInfoLogARB == NULL) { + fprintf(stderr, "%s: could not get GetInfoLogARB address\n", + message); + return; + } + + (*GetObjectParameterivARB)(object, GL_OBJECT_INFO_LOG_LENGTH_ARB, + &logLength); + if (logLength == 0) { + fprintf(stderr, "%s: info log length is 0\n", message); + return; + } + log = malloc(logLength); + if (log == NULL) { + fprintf(stderr, "%s: could not malloc %d bytes for info log\n", + message, logLength); + } + else { + (*GetInfoLogARB)(object, logLength, &queryLength, log); + fprintf(stderr, "%s: info log says '%s'\n", + message, log); + } + free(log); +} + +static GLboolean +exercise_uniform_start(const char *fragmentShaderText, const char *uniformName, + GLhandleARB *returnProgram, GLint *returnUniformLocation) +{ + DECLARE_GLFUNC_PTR(CreateShaderObjectARB, PFNGLCREATESHADEROBJECTARBPROC); + DECLARE_GLFUNC_PTR(ShaderSourceARB, PFNGLSHADERSOURCEARBPROC); + DECLARE_GLFUNC_PTR(CompileShaderARB, PFNGLCOMPILESHADERARBPROC); + DECLARE_GLFUNC_PTR(CreateProgramObjectARB, PFNGLCREATEPROGRAMOBJECTARBPROC); + DECLARE_GLFUNC_PTR(AttachObjectARB, PFNGLATTACHOBJECTARBPROC); + DECLARE_GLFUNC_PTR(LinkProgramARB, PFNGLLINKPROGRAMARBPROC); + DECLARE_GLFUNC_PTR(UseProgramObjectARB, PFNGLUSEPROGRAMOBJECTARBPROC); + DECLARE_GLFUNC_PTR(ValidateProgramARB, PFNGLVALIDATEPROGRAMARBPROC); + DECLARE_GLFUNC_PTR(GetUniformLocationARB, PFNGLGETUNIFORMLOCATIONARBPROC); + DECLARE_GLFUNC_PTR(DeleteObjectARB, PFNGLDELETEOBJECTARBPROC); + DECLARE_GLFUNC_PTR(GetObjectParameterivARB, PFNGLGETOBJECTPARAMETERIVARBPROC); + GLhandleARB fs, program; + GLint uniformLocation; + GLint shaderCompiled, programValidated; + + if (CreateShaderObjectARB == NULL || + ShaderSourceARB == NULL || + CompileShaderARB == NULL || + CreateProgramObjectARB == NULL || + AttachObjectARB == NULL || + LinkProgramARB == NULL || + UseProgramObjectARB == NULL || + ValidateProgramARB == NULL || + GetUniformLocationARB == NULL || + DeleteObjectARB == NULL || + GetObjectParameterivARB == NULL || + 0) { + return GL_FALSE; + } + + /* Create the trivial fragment shader and program. For safety + * we'll check to make sure they compile and link correctly. + */ + fs = (*CreateShaderObjectARB)(GL_FRAGMENT_SHADER_ARB); + (*ShaderSourceARB)(fs, 1, &fragmentShaderText, NULL); + (*CompileShaderARB)(fs); + (*GetObjectParameterivARB)(fs, GL_OBJECT_COMPILE_STATUS_ARB, + &shaderCompiled); + if (!shaderCompiled) { + print_info_log("shader did not compile", fs); + (*DeleteObjectARB)(fs); + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + return GL_FALSE; + } + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + program = (*CreateProgramObjectARB)(); + (*AttachObjectARB)(program, fs); + (*LinkProgramARB)(program); + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* Make sure we're going to run successfully */ + (*ValidateProgramARB)(program); + (*GetObjectParameterivARB)(program, GL_OBJECT_VALIDATE_STATUS_ARB, + &programValidated); + if (!programValidated) {; + print_info_log("program did not validate", program); + (*DeleteObjectARB)(program); + (*DeleteObjectARB)(fs); + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + return GL_FALSE; + } + + /* Put the program in place. We're not allowed to assign to uniform + * variables used by the program until the program is put into use. + */ + (*UseProgramObjectARB)(program); + + /* Once the shader is in place, we're free to delete it; this + * won't affect the copy that's part of the program. + */ + (*DeleteObjectARB)(fs); + + /* Find the location index of the uniform variable we declared; + * the caller will ned that to set the value. + */ + uniformLocation = (*GetUniformLocationARB)(program, uniformName); + if (uniformLocation == -1) { + fprintf(stderr, "%s: could not determine uniform location\n", + __FUNCTION__); + (*DeleteObjectARB)(program); + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + return GL_FALSE; + } + + /* All done with what we're supposed to do - return the program + * handle and the uniform location to the caller. + */ + *returnProgram = program; + *returnUniformLocation = uniformLocation; + return GL_TRUE; +} + +static void +exercise_uniform_end(GLhandleARB program) +{ + DECLARE_GLFUNC_PTR(UseProgramObjectARB, PFNGLUSEPROGRAMOBJECTARBPROC); + DECLARE_GLFUNC_PTR(DeleteObjectARB, PFNGLDELETEOBJECTARBPROC); + if (UseProgramObjectARB == NULL || DeleteObjectARB == NULL) { + return; + } + + /* Turn off our program by setting the special value 0, and + * then delete the program object. + */ + (*UseProgramObjectARB)(0); + (*DeleteObjectARB)(program); + CheckGLError(__LINE__, __FILE__, __FUNCTION__); +} + +/************************************************************************** + * Exercises for fences + */ +static GLboolean +exercise_fences(void) +{ + DECLARE_GLFUNC_PTR(DeleteFencesNV, PFNGLDELETEFENCESNVPROC); + DECLARE_GLFUNC_PTR(FinishFenceNV, PFNGLFINISHFENCENVPROC); + DECLARE_GLFUNC_PTR(GenFencesNV, PFNGLGENFENCESNVPROC); + DECLARE_GLFUNC_PTR(GetFenceivNV, PFNGLGETFENCEIVNVPROC); + DECLARE_GLFUNC_PTR(IsFenceNV, PFNGLISFENCENVPROC); + DECLARE_GLFUNC_PTR(SetFenceNV, PFNGLSETFENCENVPROC); + DECLARE_GLFUNC_PTR(TestFenceNV, PFNGLTESTFENCENVPROC); + GLuint fence; + GLint fenceStatus, fenceCondition; + int count; + + /* Make sure we have all the function pointers we need. */ + if (GenFencesNV == NULL || + SetFenceNV == NULL || + IsFenceNV == NULL || + GetFenceivNV == NULL || + TestFenceNV == NULL || + FinishFenceNV == NULL || + DeleteFencesNV == NULL) { + fprintf(stderr, "%s: don't have all the fence functions\n", + __FUNCTION__); + return GL_FALSE; + } + + /* Create and set a simple fence. */ + (*GenFencesNV)(1, &fence); + (*SetFenceNV)(fence, GL_ALL_COMPLETED_NV); + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* Make sure it reads as a fence. */ + if (!(*IsFenceNV)(fence)) { + fprintf(stderr, "%s: set fence is not a fence\n", __FUNCTION__); + (*DeleteFencesNV)(1, &fence); + return GL_FALSE; + } + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* Try to read back its current status and condition. */ + (*GetFenceivNV)(fence, GL_FENCE_CONDITION_NV, &fenceCondition); + if (fenceCondition != GL_ALL_COMPLETED_NV) { + fprintf(stderr, "%s: expected fence condition 0x%x, got 0x%x\n", + __FUNCTION__, GL_ALL_COMPLETED_NV, fenceCondition); + (*DeleteFencesNV)(1, &fence); + return GL_FALSE; + } + (*GetFenceivNV)(fence, GL_FENCE_STATUS_NV, &fenceStatus); + if (fenceStatus != GL_TRUE && fenceStatus != GL_FALSE) { + fprintf(stderr,"%s: fence status should be GL_TRUE or GL_FALSE, got 0x%x\n", + __FUNCTION__, fenceStatus); + (*DeleteFencesNV)(1, &fence); + return GL_FALSE; + } + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* Set the fence again, query its status, and wait for it to finish + * two different ways: once by looping on TestFence(), and a + * second time by a simple call to FinishFence(); + */ + (*SetFenceNV)(fence, GL_ALL_COMPLETED_NV); + glFlush(); + count = 1; + while (!(*TestFenceNV)(fence)) { + count++; + if (count == 0) { + break; + } + } + if (count == 0) { + fprintf(stderr, "%s: fence never returned true\n", __FUNCTION__); + (*DeleteFencesNV)(1, &fence); + return GL_FALSE; + } + (*SetFenceNV)(fence, GL_ALL_COMPLETED_NV); + (*FinishFenceNV)(fence); + if ((*TestFenceNV)(fence) != GL_TRUE) { + fprintf(stderr, "%s: finished fence does not have status GL_TRUE\n", + __FUNCTION__); + (*DeleteFencesNV)(1, &fence); + return GL_FALSE; + } + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* All done. Delete the fence and return. */ + (*DeleteFencesNV)(1, &fence); + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + return GL_TRUE; +} + +/************************************************************************** + * Exercises for buffer objects + */ +enum Map_Buffer_Usage{ Use_Map_Buffer, Use_Map_Buffer_Range}; +static GLboolean +exercise_buffer_objects(enum Map_Buffer_Usage usage) +{ +#define BUFFER_DATA_SIZE 1024 + GLuint bufferID; + GLint bufferMapped; + static GLubyte data[BUFFER_DATA_SIZE] = {0}; + float *dataPtr; + + /* Get the function pointers we need. These are from + * GL_ARB_vertex_buffer_object and are required in all + * cases. + */ + DECLARE_GLFUNC_PTR(GenBuffersARB, PFNGLGENBUFFERSARBPROC); + DECLARE_GLFUNC_PTR(BindBufferARB, PFNGLBINDBUFFERARBPROC); + DECLARE_GLFUNC_PTR(BufferDataARB, PFNGLBUFFERDATAARBPROC); + DECLARE_GLFUNC_PTR(MapBufferARB, PFNGLMAPBUFFERARBPROC); + DECLARE_GLFUNC_PTR(UnmapBufferARB, PFNGLUNMAPBUFFERARBPROC); + DECLARE_GLFUNC_PTR(DeleteBuffersARB, PFNGLDELETEBUFFERSARBPROC); + DECLARE_GLFUNC_PTR(GetBufferParameterivARB, PFNGLGETBUFFERPARAMETERIVARBPROC); + + /* These are from GL_ARB_map_buffer_range, and are optional + * unless we're given Use_Map_Buffer_Range. Note that they do *not* + * have the standard "ARB" suffixes; this is because the extension + * was introduced *after* a superset was standardized in OpenGL 3.0. + * (The extension really only exists to allow the functionality on + * devices that cannot implement a full OpenGL 3.0 driver.) + */ + DECLARE_GLFUNC_PTR(FlushMappedBufferRange, PFNGLFLUSHMAPPEDBUFFERRANGEPROC); + DECLARE_GLFUNC_PTR(MapBufferRange, PFNGLMAPBUFFERRANGEPROC); + + /* This is from APPLE_flush_buffer_range, and is optional even if + * we're given Use_Map_Buffer_Range. Test it before using it. + */ + DECLARE_GLFUNC_PTR(BufferParameteriAPPLE, PFNGLBUFFERPARAMETERIAPPLEPROC); + + /* Make sure we have all the function pointers we need. */ + if (GenBuffersARB == NULL || + BindBufferARB == NULL || + BufferDataARB == NULL || + MapBufferARB == NULL || + UnmapBufferARB == NULL || + DeleteBuffersARB == NULL || + GetBufferParameterivARB == NULL) { + fprintf(stderr, "%s: missing basic MapBuffer functions\n", __FUNCTION__); + return GL_FALSE; + } + if (usage == Use_Map_Buffer_Range) { + if (FlushMappedBufferRange == NULL || MapBufferRange == NULL) { + fprintf(stderr, "%s: missing MapBufferRange functions\n", __FUNCTION__); + return GL_FALSE; + } + } + + /* Create and define a buffer */ + (*GenBuffersARB)(1, &bufferID); + (*BindBufferARB)(GL_ARRAY_BUFFER_ARB, bufferID); + (*BufferDataARB)(GL_ARRAY_BUFFER_ARB, BUFFER_DATA_SIZE, data, + GL_DYNAMIC_DRAW_ARB); + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* If we're using MapBufferRange, and if the BufferParameteriAPPLE + * function is present, use it before mapping. This particular + * use is a no-op, intended just to exercise the entry point. + */ + if (usage == Use_Map_Buffer_Range && BufferParameteriAPPLE != NULL) { + (*BufferParameteriAPPLE)(GL_ARRAY_BUFFER_ARB, + GL_BUFFER_SERIALIZED_MODIFY_APPLE, GL_TRUE); + } + + /* Map it, and make sure it's mapped. */ + switch(usage) { + case Use_Map_Buffer: + dataPtr = (float *) (*MapBufferARB)( + GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); + break; + case Use_Map_Buffer_Range: + dataPtr = (float *)(*MapBufferRange)(GL_ARRAY_BUFFER_ARB, + 4, 16, GL_MAP_WRITE_BIT | GL_MAP_FLUSH_EXPLICIT_BIT); + break; + } + if (dataPtr == NULL) { + fprintf(stderr, "%s: %s returned NULL\n", __FUNCTION__, + usage == Use_Map_Buffer ? "MapBuffer" : "MapBufferRange"); + (*BindBufferARB)(GL_ARRAY_BUFFER_ARB, 0); + (*DeleteBuffersARB)(1, &bufferID); + return GL_FALSE; + } + (*GetBufferParameterivARB)(GL_ARRAY_BUFFER_ARB, GL_BUFFER_MAPPED_ARB, + &bufferMapped); + if (!bufferMapped) { + fprintf(stderr, "%s: buffer should be mapped but isn't\n", __FUNCTION__); + (*BindBufferARB)(GL_ARRAY_BUFFER_ARB, 0); + (*DeleteBuffersARB)(1, &bufferID); + return GL_FALSE; + } + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* Write something to it, just to make sure we don't segfault. */ + *dataPtr = 1.5; + + /* Unmap to show we're finished with the buffer. Note that if we're + * using MapBufferRange, we first have to flush the range we modified. + */ + if (usage == Use_Map_Buffer_Range) { + (*FlushMappedBufferRange)(GL_ARRAY_BUFFER_ARB, 4, 16); + } + if (!(*UnmapBufferARB)(GL_ARRAY_BUFFER_ARB)) { + fprintf(stderr, "%s: UnmapBuffer failed\n", __FUNCTION__); + (*BindBufferARB)(GL_ARRAY_BUFFER_ARB, 0); + (*DeleteBuffersARB)(1, &bufferID); + return GL_FALSE; + } + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* All done. */ + (*BindBufferARB)(GL_ARRAY_BUFFER_ARB, 0); + (*DeleteBuffersARB)(1, &bufferID); + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + return GL_TRUE; + +#undef BUFFER_DATA_SIZE +} + +/************************************************************************** + * Exercises for occlusion query + */ +static GLboolean +exercise_occlusion_query(void) +{ + GLuint queryObject; + GLint queryReady; + GLuint querySampleCount; + GLint queryCurrent; + GLint queryCounterBits; + + /* Get the function pointers we need. These are from + * GL_ARB_vertex_buffer_object and are required in all + * cases. + */ + DECLARE_GLFUNC_PTR(GenQueriesARB, PFNGLGENQUERIESARBPROC); + DECLARE_GLFUNC_PTR(BeginQueryARB, PFNGLBEGINQUERYARBPROC); + DECLARE_GLFUNC_PTR(GetQueryivARB, PFNGLGETQUERYIVARBPROC); + DECLARE_GLFUNC_PTR(EndQueryARB, PFNGLENDQUERYARBPROC); + DECLARE_GLFUNC_PTR(IsQueryARB, PFNGLISQUERYARBPROC); + DECLARE_GLFUNC_PTR(GetQueryObjectivARB, PFNGLGETQUERYOBJECTIVARBPROC); + DECLARE_GLFUNC_PTR(GetQueryObjectuivARB, PFNGLGETQUERYOBJECTUIVARBPROC); + DECLARE_GLFUNC_PTR(DeleteQueriesARB, PFNGLDELETEQUERIESARBPROC); + + /* Make sure we have all the function pointers we need. */ + if (GenQueriesARB == NULL || + BeginQueryARB == NULL || + GetQueryivARB == NULL || + EndQueryARB == NULL || + IsQueryARB == NULL || + GetQueryObjectivARB == NULL || + GetQueryObjectuivARB == NULL || + DeleteQueriesARB == NULL) { + fprintf(stderr, "%s: don't have all the Query functions\n", __FUNCTION__); + return GL_FALSE; + } + + /* Create a query object, and start a query. */ + (*GenQueriesARB)(1, &queryObject); + (*BeginQueryARB)(GL_SAMPLES_PASSED_ARB, queryObject); + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* While we're in the query, check the functions that are supposed + * to return which query we're in and how many bits of resolution + * we get. + */ + (*GetQueryivARB)(GL_SAMPLES_PASSED_ARB, GL_CURRENT_QUERY_ARB, &queryCurrent); + if (queryCurrent != queryObject) { + fprintf(stderr, "%s: current query 0x%x != set query 0x%x\n", + __FUNCTION__, queryCurrent, queryObject); + (*EndQueryARB)(GL_SAMPLES_PASSED_ARB); + (*DeleteQueriesARB)(1, &queryObject); + return GL_FALSE; + } + (*GetQueryivARB)(GL_SAMPLES_PASSED_ARB, GL_QUERY_COUNTER_BITS_ARB, + &queryCounterBits); + if (queryCounterBits < 1) { + fprintf(stderr, "%s: query counter bits is too small (%d)\n", + __FUNCTION__, queryCounterBits); + (*EndQueryARB)(GL_SAMPLES_PASSED_ARB); + (*DeleteQueriesARB)(1, &queryObject); + return GL_FALSE; + } + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* Finish up the query. Since we didn't draw anything, the result + * should be 0 passed samples. + */ + (*EndQueryARB)(GL_SAMPLES_PASSED_ARB); + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* Routine existence test */ + if (!(*IsQueryARB)(queryObject)) { + fprintf(stderr, "%s: query object 0x%x fails existence test\n", + __FUNCTION__, queryObject); + (*DeleteQueriesARB)(1, &queryObject); + return GL_FALSE; + } + + /* Loop until the query is ready, then get back the result. We use + * the signed query for the boolean value of whether the result is + * available, but the unsigned query to actually pull the result; + * this is just to test both entrypoints, but in a real query you may + * need the extra bit of resolution. + */ + queryReady = GL_FALSE; + do { + (*GetQueryObjectivARB)(queryObject, GL_QUERY_RESULT_AVAILABLE_ARB, + &queryReady); + } while (!queryReady); + (*GetQueryObjectuivARB)(queryObject, GL_QUERY_RESULT_ARB, &querySampleCount); + (*DeleteQueriesARB)(1, &queryObject); + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* If sample count isn't 0, something's funny. */ + if (querySampleCount > 0) { + fprintf(stderr, "%s: expected query result of 0, got %ud\n", + __FUNCTION__, querySampleCount); + return GL_FALSE; + } + + /* Here, all is well. */ + return GL_TRUE; +} + +/************************************************************************** * The following functions are used to check that the named OpenGL function * actually does what it's supposed to do. - * The naming of these functions is signficant. The getprocaddress.py script + * The naming of these functions is significant. The getprocaddress.py script * scans this file and extracts these function names. */ +static GLboolean +test_WeightPointerARB(generic_func func) +{ + /* Assume we have at least 2 vertex units (or this extension makes + * no sense), and establish a set of 2-element vector weights. + * We use floats that can be represented exactly in binary + * floating point formats so we can compare correctly later. + * We also make sure the 0th entry matches the default weights, + * so we can restore the default easily. + */ +#define USE_VERTEX_UNITS 2 +#define USE_WEIGHT_INDEX 3 + static GLfloat weights[] = { + 1.0, 0.0, + 0.875, 0.125, + 0.75, 0.25, + 0.625, 0.375, + 0.5, 0.5, + 0.375, 0.625, + 0.25, 0.75, + 0.125, 0.875, + 0.0, 1.0, + }; + GLint numVertexUnits; + GLfloat *currentWeights; + int i; + int errorCount = 0; + + PFNGLWEIGHTPOINTERARBPROC WeightPointerARB = (PFNGLWEIGHTPOINTERARBPROC) func; + + /* Make sure we have at least two vertex units */ + glGetIntegerv(GL_MAX_VERTEX_UNITS_ARB, &numVertexUnits); + if (numVertexUnits < USE_VERTEX_UNITS) { + fprintf(stderr, "%s: need %d vertex units, got %d\n", + __FUNCTION__, USE_VERTEX_UNITS, numVertexUnits); + return GL_FALSE; + } + + /* Make sure we allocate enough room to query all the current weights */ + currentWeights = (GLfloat *)malloc(numVertexUnits * sizeof(GLfloat)); + if (currentWeights == NULL) { + fprintf(stderr, "%s: couldn't allocate room for %d floats\n", + __FUNCTION__, numVertexUnits); + return GL_FALSE; + } + + /* Set up the pointer, enable the state, and try to send down a + * weight vector (we'll arbitrarily send index 2). + */ + (*WeightPointerARB)(USE_VERTEX_UNITS, GL_FLOAT, 0, weights); + glEnableClientState(GL_WEIGHT_ARRAY_ARB); + glArrayElement(USE_WEIGHT_INDEX); + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* Verify that it changed the current state. */ + glGetFloatv(GL_CURRENT_WEIGHT_ARB, currentWeights); + for (i = 0; i < numVertexUnits; i++) { + if (i < USE_VERTEX_UNITS) { + /* This is one of the units we explicitly set. */ + if (currentWeights[i] != weights[USE_VERTEX_UNITS*USE_WEIGHT_INDEX + i]) { + fprintf(stderr, "%s: current weight at index %d is %f, should be %f\n", + __FUNCTION__, i, currentWeights[i], + weights[USE_VERTEX_UNITS*USE_WEIGHT_INDEX + i]); + errorCount++; + } + } + else { + /* All other weights should be 0. */ + if (currentWeights[i] != 0.0) { + fprintf(stderr, "%s: current weight at index %d is %f, should be %f\n", + __FUNCTION__, i, 0.0, + weights[USE_VERTEX_UNITS*USE_WEIGHT_INDEX + i]); + errorCount++; + } + } + } + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* Restore the old state. We know the default set of weights is in + * index 0. + */ + glArrayElement(0); + glDisableClientState(GL_WEIGHT_ARRAY_ARB); + (*WeightPointerARB)(0, GL_FLOAT, 0, NULL); + free(currentWeights); + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* We're fine if we didn't get any mismatches. */ + if (errorCount == 0) { + return GL_TRUE; + } + else { + return GL_FALSE; + } +} + +/* Wrappers on the exercise_occlusion_query function */ +static GLboolean +test_GenQueriesARB(generic_func func) +{ + (void) func; + return exercise_occlusion_query(); +} +static GLboolean +test_BeginQueryARB(generic_func func) +{ + (void) func; + return exercise_occlusion_query(); +} +static GLboolean +test_GetQueryivARB(generic_func func) +{ + (void) func; + return exercise_occlusion_query(); +} +static GLboolean +test_EndQueryARB(generic_func func) +{ + (void) func; + return exercise_occlusion_query(); +} +static GLboolean +test_IsQueryARB(generic_func func) +{ + (void) func; + return exercise_occlusion_query(); +} +static GLboolean +test_GetQueryObjectivARB(generic_func func) +{ + (void) func; + return exercise_occlusion_query(); +} +static GLboolean +test_GetQueryObjectuivARB(generic_func func) +{ + (void) func; + return exercise_occlusion_query(); +} +static GLboolean +test_DeleteQueriesARB(generic_func func) +{ + (void) func; + return exercise_occlusion_query(); +} + +/* Wrappers on the exercise_buffer_objects() function */ +static GLboolean +test_GenBuffersARB(generic_func func) +{ + (void) func; + return exercise_buffer_objects(Use_Map_Buffer); +} +static GLboolean +test_BindBufferARB(generic_func func) +{ + (void) func; + return exercise_buffer_objects(Use_Map_Buffer); +} +static GLboolean +test_BufferDataARB(generic_func func) +{ + (void) func; + return exercise_buffer_objects(Use_Map_Buffer); +} +static GLboolean +test_MapBufferARB(generic_func func) +{ + (void) func; + return exercise_buffer_objects(Use_Map_Buffer); +} +static GLboolean +test_UnmapBufferARB(generic_func func) +{ + (void) func; + return exercise_buffer_objects(Use_Map_Buffer); +} +static GLboolean +test_DeleteBuffersARB(generic_func func) +{ + (void) func; + return exercise_buffer_objects(Use_Map_Buffer); +} +static GLboolean +test_GetBufferParameterivARB(generic_func func) +{ + (void) func; + return exercise_buffer_objects(Use_Map_Buffer); +} +static GLboolean +test_FlushMappedBufferRange(generic_func func) +{ + (void) func; + return exercise_buffer_objects(Use_Map_Buffer_Range); +} +static GLboolean +test_MapBufferRange(generic_func func) +{ + (void) func; + return exercise_buffer_objects(Use_Map_Buffer_Range); +} +static GLboolean +test_BufferParameteriAPPLE(generic_func func) +{ + (void) func; + return exercise_buffer_objects(Use_Map_Buffer_Range); +} + +/* Wrappers on the exercise_framebuffer() function */ +static GLboolean +test_BindFramebufferEXT(generic_func func) +{ + (void) func; + return exercise_framebuffer(); +} +static GLboolean +test_BindRenderbufferEXT(generic_func func) +{ + (void) func; + return exercise_framebuffer(); +} +static GLboolean +test_CheckFramebufferStatusEXT(generic_func func) +{ + (void) func; + return exercise_framebuffer(); +} +static GLboolean +test_DeleteFramebuffersEXT(generic_func func) +{ + (void) func; + return exercise_framebuffer(); +} +static GLboolean +test_DeleteRenderbuffersEXT(generic_func func) +{ + (void) func; + return exercise_framebuffer(); +} +static GLboolean +test_FramebufferRenderbufferEXT(generic_func func) +{ + (void) func; + return exercise_framebuffer(); +} +static GLboolean +test_GenFramebuffersEXT(generic_func func) +{ + (void) func; + return exercise_framebuffer(); +} +static GLboolean +test_GenRenderbuffersEXT(generic_func func) +{ + (void) func; + return exercise_framebuffer(); +} +static GLboolean +test_IsFramebufferEXT(generic_func func) +{ + (void) func; + return exercise_framebuffer(); +} +static GLboolean +test_IsRenderbufferEXT(generic_func func) +{ + (void) func; + return exercise_framebuffer(); +} +static GLboolean +test_RenderbufferStorageEXT(generic_func func) +{ + (void) func; + return exercise_framebuffer(); +} +static GLboolean +test_BlitFramebufferEXT(generic_func func) +{ + (void) func; + return exercise_framebuffer(); +} + +/* These are wrappers on the exercise_CompressedTextures function. + * Unfortunately, we cannot test the 1D counterparts, because the + * texture compressions available all support 2D and higher only. + */ +static GLboolean +test_CompressedTexImage2DARB(generic_func func) +{ + (void) func; + return exercise_CompressedTextures(GL_TEXTURE_2D); +} +static GLboolean +test_CompressedTexSubImage2DARB(generic_func func) +{ + (void) func; + return exercise_CompressedTextures(GL_TEXTURE_2D); +} +static GLboolean +test_CompressedTexImage3DARB(generic_func func) +{ + (void) func; + return exercise_CompressedTextures(GL_TEXTURE_3D); +} +static GLboolean +test_CompressedTexSubImage3DARB(generic_func func) +{ + (void) func; + return exercise_CompressedTextures(GL_TEXTURE_3D); +} +static GLboolean +test_GetCompressedTexImageARB(generic_func func) +{ + (void) func; + return exercise_CompressedTextures(GL_TEXTURE_3D); +} + +/* Wrappers on exercise_fences(). */ +static GLboolean +test_DeleteFencesNV(generic_func func) +{ + (void) func; + return exercise_fences(); +} +static GLboolean +test_GenFencesNV(generic_func func) +{ + (void) func; + return exercise_fences(); +} +static GLboolean +test_SetFenceNV(generic_func func) +{ + (void) func; + return exercise_fences(); +} +static GLboolean +test_TestFenceNV(generic_func func) +{ + (void) func; + return exercise_fences(); +} +static GLboolean +test_FinishFenceNV(generic_func func) +{ + (void) func; + return exercise_fences(); +} +static GLboolean +test_GetFenceivNV(generic_func func) +{ + (void) func; + return exercise_fences(); +} +static GLboolean +test_IsFenceNV(generic_func func) +{ + (void) func; + return exercise_fences(); +} + +/* A bunch of glUniform*() tests */ +static GLboolean +test_Uniform1iv(generic_func func) +{ + PFNGLUNIFORM1IVARBPROC Uniform1ivARB = (PFNGLUNIFORM1IVARBPROC) func; + DECLARE_GLFUNC_PTR(GetUniformivARB, PFNGLGETUNIFORMIVARBPROC); + + /* This is a trivial fragment shader that sets the color of the + * fragment to the uniform value passed in. + */ + static const char *fragmentShaderText = + "uniform int uniformColor;" + "void main() {gl_FragColor.r = uniformColor;}"; + static const char *uniformName = "uniformColor"; + + GLhandleARB program; + GLint uniformLocation; + const GLint uniform[1] = {1}; + GLint queriedUniform[1]; + + if (GetUniformivARB == NULL) { + return GL_FALSE; + } + + /* Call a helper function to compile up the shader and give + * us back the validated program and uniform location. + * If it fails, something's wrong and we can't continue. + */ + if (!exercise_uniform_start(fragmentShaderText, uniformName, + &program, &uniformLocation)) { + return GL_FALSE; + } + + /* Set the value of the program uniform. Note that you must + * use a compatible type. Our uniform above is an integer + * so we must set it using integer versions + * of the Uniform* functions. The "1" means we're setting + * one vector's worth of information. + */ + (*Uniform1ivARB)(uniformLocation, 1, uniform); + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* Query it back */ + (*GetUniformivARB)(program, uniformLocation, queriedUniform); + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* Clean up before we check to see whether it came back unscathed */ + exercise_uniform_end(program); + + /* Now check to see whether the uniform came back as expected. This + * will return GL_TRUE if all is well, or GL_FALSE if the comparison failed. + */ + return compare_ints(__FUNCTION__, 1, uniform, 1, queriedUniform); +} + +static GLboolean +test_Uniform1i(generic_func func) +{ + PFNGLUNIFORM1IARBPROC Uniform1iARB = (PFNGLUNIFORM1IARBPROC) func; + DECLARE_GLFUNC_PTR(GetUniformivARB, PFNGLGETUNIFORMIVARBPROC); + + /* This is a trivial fragment shader that sets the color of the + * fragment to the uniform value passed in. + */ + static const char *fragmentShaderText = + "uniform int uniformColor;" + "void main() {gl_FragColor.r = uniformColor;}"; + static const char *uniformName = "uniformColor"; + + GLhandleARB program; + GLint uniformLocation; + const GLint uniform[1] = {1}; + GLint queriedUniform[4]; + + if (GetUniformivARB == NULL) { + return GL_FALSE; + } + + /* Call a helper function to compile up the shader and give + * us back the validated program and uniform location. + * If it fails, something's wrong and we can't continue. + */ + if (!exercise_uniform_start(fragmentShaderText, uniformName, + &program, &uniformLocation)) { + return GL_FALSE; + } + + /* Set the value of the program uniform. Note that you must + * use a compatible type. Our uniform above is an integer + * so we must set it using integer versions + * of the Uniform* functions. + */ + (*Uniform1iARB)(uniformLocation, uniform[0]); + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* Query it back */ + (*GetUniformivARB)(program, uniformLocation, queriedUniform); + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* Clean up before we check to see whether it came back unscathed */ + exercise_uniform_end(program); + + /* Now check to see whether the uniform came back as expected. This + * will return GL_TRUE if all is well, or GL_FALSE if the comparison failed. + */ + return compare_ints(__FUNCTION__, 1, uniform, 1, queriedUniform); +} + +static GLboolean +test_Uniform1fv(generic_func func) +{ + PFNGLUNIFORM1FVARBPROC Uniform1fvARB = (PFNGLUNIFORM1FVARBPROC) func; + DECLARE_GLFUNC_PTR(GetUniformfvARB, PFNGLGETUNIFORMFVARBPROC); + + /* This is a trivial fragment shader that sets the color of the + * fragment to the uniform value passed in. + */ + static const char *fragmentShaderText = + "uniform float uniformColor;" + "void main() {gl_FragColor.r = uniformColor;}"; + static const char *uniformName = "uniformColor"; + + GLhandleARB program; + GLint uniformLocation; + const GLfloat uniform[1] = {1.1}; + GLfloat queriedUniform[1]; + + if (GetUniformfvARB == NULL) { + return GL_FALSE; + } + + /* Call a helper function to compile up the shader and give + * us back the validated program and uniform location. + * If it fails, something's wrong and we can't continue. + */ + if (!exercise_uniform_start(fragmentShaderText, uniformName, + &program, &uniformLocation)) { + return GL_FALSE; + } + + /* Set the value of the program uniform. Note that you must + * use a compatible type. Our uniform above is a float + * so we must set it using float versions + * of the Uniform* functions. The "1" means we're setting + * one vector's worth of information. + */ + (*Uniform1fvARB)(uniformLocation, 1, uniform); + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* Query it back */ + (*GetUniformfvARB)(program, uniformLocation, queriedUniform); + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* Clean up before we check to see whether it came back unscathed */ + exercise_uniform_end(program); + + /* Now check to see whether the uniform came back as expected. This + * will return GL_TRUE if all is well, or GL_FALSE if the comparison failed. + */ + return compare_floats(__FUNCTION__, 1, uniform, 1, queriedUniform); +} + +static GLboolean +test_Uniform1f(generic_func func) +{ + PFNGLUNIFORM1FARBPROC Uniform1fARB = (PFNGLUNIFORM1FARBPROC) func; + DECLARE_GLFUNC_PTR(GetUniformfvARB, PFNGLGETUNIFORMFVARBPROC); + + /* This is a trivial fragment shader that sets the color of the + * fragment to the uniform value passed in. + */ + static const char *fragmentShaderText = + "uniform float uniformColor;" + "void main() {gl_FragColor.r = uniformColor;}"; + static const char *uniformName = "uniformColor"; + + GLhandleARB program; + GLint uniformLocation; + const GLfloat uniform[1] = {1.1}; + GLfloat queriedUniform[1]; + + if (GetUniformfvARB == NULL) { + return GL_FALSE; + } + + /* Call a helper function to compile up the shader and give + * us back the validated program and uniform location. + * If it fails, something's wrong and we can't continue. + */ + if (!exercise_uniform_start(fragmentShaderText, uniformName, + &program, &uniformLocation)) { + return GL_FALSE; + } + + /* Set the value of the program uniform. Note that you must + * use a compatible type. Our uniform above is a float + * so we must set it using float versions + * of the Uniform* functions. + */ + (*Uniform1fARB)(uniformLocation, uniform[0]); + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* Query it back */ + (*GetUniformfvARB)(program, uniformLocation, queriedUniform); + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* Clean up before we check to see whether it came back unscathed */ + exercise_uniform_end(program); + + /* Now check to see whether the uniform came back as expected. This + * will return GL_TRUE if all is well, or GL_FALSE if the comparison failed. + */ + return compare_floats(__FUNCTION__, 1, uniform, 1, queriedUniform); +} + +static GLboolean +test_Uniform2iv(generic_func func) +{ + PFNGLUNIFORM2IVARBPROC Uniform2ivARB = (PFNGLUNIFORM2IVARBPROC) func; + DECLARE_GLFUNC_PTR(GetUniformivARB, PFNGLGETUNIFORMIVARBPROC); + + /* This is a trivial fragment shader that sets the color of the + * fragment to the uniform value passed in. + */ + static const char *fragmentShaderText = + "uniform ivec2 uniformColor;" + "void main() {gl_FragColor.rg = uniformColor;}"; + static const char *uniformName = "uniformColor"; + + GLhandleARB program; + GLint uniformLocation; + const GLint uniform[2] = {1,2}; + GLint queriedUniform[2]; + + if (GetUniformivARB == NULL) { + return GL_FALSE; + } + + /* Call a helper function to compile up the shader and give + * us back the validated program and uniform location. + * If it fails, something's wrong and we can't continue. + */ + if (!exercise_uniform_start(fragmentShaderText, uniformName, + &program, &uniformLocation)) { + return GL_FALSE; + } + + /* Set the value of the program uniform. Note that you must + * use a compatible type. Our uniform above is an integer + * vector 2 (ivec2), so we must set it using integer versions + * of the Uniform* functions. The "1" means we're setting + * one vector's worth of information. + */ + (*Uniform2ivARB)(uniformLocation, 1, uniform); + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* Query it back */ + (*GetUniformivARB)(program, uniformLocation, queriedUniform); + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* Clean up before we check to see whether it came back unscathed */ + exercise_uniform_end(program); + + /* Now check to see whether the uniform came back as expected. This + * will return GL_TRUE if all is well, or GL_FALSE if the comparison failed. + */ + return compare_ints(__FUNCTION__, 2, uniform, 2, queriedUniform); +} + +static GLboolean +test_Uniform2i(generic_func func) +{ + PFNGLUNIFORM2IARBPROC Uniform2iARB = (PFNGLUNIFORM2IARBPROC) func; + DECLARE_GLFUNC_PTR(GetUniformivARB, PFNGLGETUNIFORMIVARBPROC); + + /* This is a trivial fragment shader that sets the color of the + * fragment to the uniform value passed in. + */ + static const char *fragmentShaderText = + "uniform ivec2 uniformColor;" + "void main() {gl_FragColor.rg = uniformColor;}"; + static const char *uniformName = "uniformColor"; + + GLhandleARB program; + GLint uniformLocation; + const GLint uniform[2] = {1,2}; + GLint queriedUniform[4]; + + if (GetUniformivARB == NULL) { + return GL_FALSE; + } + + /* Call a helper function to compile up the shader and give + * us back the validated program and uniform location. + * If it fails, something's wrong and we can't continue. + */ + if (!exercise_uniform_start(fragmentShaderText, uniformName, + &program, &uniformLocation)) { + return GL_FALSE; + } + + /* Set the value of the program uniform. Note that you must + * use a compatible type. Our uniform above is an integer + * vector 2 (ivec2), so we must set it using integer versions + * of the Uniform* functions. + */ + (*Uniform2iARB)(uniformLocation, uniform[0], uniform[1]); + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* Query it back */ + (*GetUniformivARB)(program, uniformLocation, queriedUniform); + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* Clean up before we check to see whether it came back unscathed */ + exercise_uniform_end(program); + + /* Now check to see whether the uniform came back as expected. This + * will return GL_TRUE if all is well, or GL_FALSE if the comparison failed. + */ + return compare_ints(__FUNCTION__, 2, uniform, 2, queriedUniform); +} + +static GLboolean +test_Uniform2fv(generic_func func) +{ + PFNGLUNIFORM2FVARBPROC Uniform2fvARB = (PFNGLUNIFORM2FVARBPROC) func; + DECLARE_GLFUNC_PTR(GetUniformfvARB, PFNGLGETUNIFORMFVARBPROC); + + /* This is a trivial fragment shader that sets the color of the + * fragment to the uniform value passed in. + */ + static const char *fragmentShaderText = + "uniform vec2 uniformColor;" + "void main() {gl_FragColor.rg = uniformColor;}"; + static const char *uniformName = "uniformColor"; + + GLhandleARB program; + GLint uniformLocation; + const GLfloat uniform[2] = {1.1,2.2}; + GLfloat queriedUniform[2]; + + if (GetUniformfvARB == NULL) { + return GL_FALSE; + } + + /* Call a helper function to compile up the shader and give + * us back the validated program and uniform location. + * If it fails, something's wrong and we can't continue. + */ + if (!exercise_uniform_start(fragmentShaderText, uniformName, + &program, &uniformLocation)) { + return GL_FALSE; + } + + /* Set the value of the program uniform. Note that you must + * use a compatible type. Our uniform above is a float + * vector 2 (vec2), so we must set it using float versions + * of the Uniform* functions. The "1" means we're setting + * one vector's worth of information. + */ + (*Uniform2fvARB)(uniformLocation, 1, uniform); + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* Query it back */ + (*GetUniformfvARB)(program, uniformLocation, queriedUniform); + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* Clean up before we check to see whether it came back unscathed */ + exercise_uniform_end(program); + + /* Now check to see whether the uniform came back as expected. This + * will return GL_TRUE if all is well, or GL_FALSE if the comparison failed. + */ + return compare_floats(__FUNCTION__, 2, uniform, 2, queriedUniform); +} + +static GLboolean +test_Uniform2f(generic_func func) +{ + PFNGLUNIFORM2FARBPROC Uniform2fARB = (PFNGLUNIFORM2FARBPROC) func; + DECLARE_GLFUNC_PTR(GetUniformfvARB, PFNGLGETUNIFORMFVARBPROC); + + /* This is a trivial fragment shader that sets the color of the + * fragment to the uniform value passed in. + */ + static const char *fragmentShaderText = + "uniform vec2 uniformColor;" + "void main() {gl_FragColor.rg = uniformColor;}"; + static const char *uniformName = "uniformColor"; + + GLhandleARB program; + GLint uniformLocation; + const GLfloat uniform[2] = {1.1,2.2}; + GLfloat queriedUniform[2]; + + if (GetUniformfvARB == NULL) { + return GL_FALSE; + } + + /* Call a helper function to compile up the shader and give + * us back the validated program and uniform location. + * If it fails, something's wrong and we can't continue. + */ + if (!exercise_uniform_start(fragmentShaderText, uniformName, + &program, &uniformLocation)) { + return GL_FALSE; + } + + /* Set the value of the program uniform. Note that you must + * use a compatible type. Our uniform above is a float + * vector 2 (vec2), so we must set it using float versions + * of the Uniform* functions. + */ + (*Uniform2fARB)(uniformLocation, uniform[0], uniform[1]); + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* Query it back */ + (*GetUniformfvARB)(program, uniformLocation, queriedUniform); + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* Clean up before we check to see whether it came back unscathed */ + exercise_uniform_end(program); + + /* Now check to see whether the uniform came back as expected. This + * will return GL_TRUE if all is well, or GL_FALSE if the comparison failed. + */ + return compare_floats(__FUNCTION__, 2, uniform, 2, queriedUniform); +} + +static GLboolean +test_Uniform3iv(generic_func func) +{ + PFNGLUNIFORM3IVARBPROC Uniform3ivARB = (PFNGLUNIFORM3IVARBPROC) func; + DECLARE_GLFUNC_PTR(GetUniformivARB, PFNGLGETUNIFORMIVARBPROC); + + /* This is a trivial fragment shader that sets the color of the + * fragment to the uniform value passed in. + */ + static const char *fragmentShaderText = + "uniform ivec3 uniformColor;" + "void main() {gl_FragColor.rgb = uniformColor;}"; + static const char *uniformName = "uniformColor"; + + GLhandleARB program; + GLint uniformLocation; + const GLint uniform[3] = {1,2,3}; + GLint queriedUniform[3]; + + if (GetUniformivARB == NULL) { + return GL_FALSE; + } + + /* Call a helper function to compile up the shader and give + * us back the validated program and uniform location. + * If it fails, something's wrong and we can't continue. + */ + if (!exercise_uniform_start(fragmentShaderText, uniformName, + &program, &uniformLocation)) { + return GL_FALSE; + } + + /* Set the value of the program uniform. Note that you must + * use a compatible type. Our uniform above is an integer + * vector 3 (ivec3), so we must set it using integer versions + * of the Uniform* functions. The "1" means we're setting + * one vector's worth of information. + */ + (*Uniform3ivARB)(uniformLocation, 1, uniform); + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* Query it back */ + (*GetUniformivARB)(program, uniformLocation, queriedUniform); + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* Clean up before we check to see whether it came back unscathed */ + exercise_uniform_end(program); + + /* Now check to see whether the uniform came back as expected. This + * will return GL_TRUE if all is well, or GL_FALSE if the comparison failed. + */ + return compare_ints(__FUNCTION__, 3, uniform, 3, queriedUniform); +} + +static GLboolean +test_Uniform3i(generic_func func) +{ + PFNGLUNIFORM3IARBPROC Uniform3iARB = (PFNGLUNIFORM3IARBPROC) func; + DECLARE_GLFUNC_PTR(GetUniformivARB, PFNGLGETUNIFORMIVARBPROC); + + /* This is a trivial fragment shader that sets the color of the + * fragment to the uniform value passed in. + */ + static const char *fragmentShaderText = + "uniform ivec3 uniformColor;" + "void main() {gl_FragColor.rgb = uniformColor;}"; + static const char *uniformName = "uniformColor"; + + GLhandleARB program; + GLint uniformLocation; + const GLint uniform[3] = {1,2,3}; + GLint queriedUniform[4]; + + if (GetUniformivARB == NULL) { + return GL_FALSE; + } + + /* Call a helper function to compile up the shader and give + * us back the validated program and uniform location. + * If it fails, something's wrong and we can't continue. + */ + if (!exercise_uniform_start(fragmentShaderText, uniformName, + &program, &uniformLocation)) { + return GL_FALSE; + } + + /* Set the value of the program uniform. Note that you must + * use a compatible type. Our uniform above is an integer + * vector 3 (ivec3), so we must set it using integer versions + * of the Uniform* functions. + */ + (*Uniform3iARB)(uniformLocation, uniform[0], uniform[1], uniform[2]); + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* Query it back */ + (*GetUniformivARB)(program, uniformLocation, queriedUniform); + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* Clean up before we check to see whether it came back unscathed */ + exercise_uniform_end(program); + + /* Now check to see whether the uniform came back as expected. This + * will return GL_TRUE if all is well, or GL_FALSE if the comparison failed. + */ + return compare_ints(__FUNCTION__, 3, uniform, 3, queriedUniform); +} + +static GLboolean +test_Uniform3fv(generic_func func) +{ + PFNGLUNIFORM3FVARBPROC Uniform3fvARB = (PFNGLUNIFORM3FVARBPROC) func; + DECLARE_GLFUNC_PTR(GetUniformfvARB, PFNGLGETUNIFORMFVARBPROC); + + /* This is a trivial fragment shader that sets the color of the + * fragment to the uniform value passed in. + */ + static const char *fragmentShaderText = + "uniform vec3 uniformColor;" + "void main() {gl_FragColor.rgb = uniformColor;}"; + static const char *uniformName = "uniformColor"; + + GLhandleARB program; + GLint uniformLocation; + const GLfloat uniform[3] = {1.1,2.2,3.3}; + GLfloat queriedUniform[3]; + + if (GetUniformfvARB == NULL) { + return GL_FALSE; + } + + /* Call a helper function to compile up the shader and give + * us back the validated program and uniform location. + * If it fails, something's wrong and we can't continue. + */ + if (!exercise_uniform_start(fragmentShaderText, uniformName, + &program, &uniformLocation)) { + return GL_FALSE; + } + + /* Set the value of the program uniform. Note that you must + * use a compatible type. Our uniform above is a float + * vector 3 (vec3), so we must set it using float versions + * of the Uniform* functions. The "1" means we're setting + * one vector's worth of information. + */ + (*Uniform3fvARB)(uniformLocation, 1, uniform); + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* Query it back */ + (*GetUniformfvARB)(program, uniformLocation, queriedUniform); + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* Clean up before we check to see whether it came back unscathed */ + exercise_uniform_end(program); + + /* Now check to see whether the uniform came back as expected. This + * will return GL_TRUE if all is well, or GL_FALSE if the comparison failed. + */ + return compare_floats(__FUNCTION__, 3, uniform, 3, queriedUniform); +} + +static GLboolean +test_Uniform3f(generic_func func) +{ + PFNGLUNIFORM3FARBPROC Uniform3fARB = (PFNGLUNIFORM3FARBPROC) func; + DECLARE_GLFUNC_PTR(GetUniformfvARB, PFNGLGETUNIFORMFVARBPROC); + + /* This is a trivial fragment shader that sets the color of the + * fragment to the uniform value passed in. + */ + static const char *fragmentShaderText = + "uniform vec3 uniformColor;" + "void main() {gl_FragColor.rgb = uniformColor;}"; + static const char *uniformName = "uniformColor"; + + GLhandleARB program; + GLint uniformLocation; + const GLfloat uniform[3] = {1.1,2.2,3.3}; + GLfloat queriedUniform[3]; + + if (GetUniformfvARB == NULL) { + return GL_FALSE; + } + + /* Call a helper function to compile up the shader and give + * us back the validated program and uniform location. + * If it fails, something's wrong and we can't continue. + */ + if (!exercise_uniform_start(fragmentShaderText, uniformName, + &program, &uniformLocation)) { + return GL_FALSE; + } + + /* Set the value of the program uniform. Note that you must + * use a compatible type. Our uniform above is a float + * vector 3 (vec3), so we must set it using float versions + * of the Uniform* functions. + */ + (*Uniform3fARB)(uniformLocation, uniform[0], uniform[1], uniform[2]); + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* Query it back */ + (*GetUniformfvARB)(program, uniformLocation, queriedUniform); + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* Clean up before we check to see whether it came back unscathed */ + exercise_uniform_end(program); + + /* Now check to see whether the uniform came back as expected. This + * will return GL_TRUE if all is well, or GL_FALSE if the comparison failed. + */ + return compare_floats(__FUNCTION__, 3, uniform, 3, queriedUniform); +} + +static GLboolean +test_Uniform4iv(generic_func func) +{ + PFNGLUNIFORM4IVARBPROC Uniform4ivARB = (PFNGLUNIFORM4IVARBPROC) func; + DECLARE_GLFUNC_PTR(GetUniformivARB, PFNGLGETUNIFORMIVARBPROC); + + /* This is a trivial fragment shader that sets the color of the + * fragment to the uniform value passed in. + */ + static const char *fragmentShaderText = + "uniform ivec4 uniformColor; void main() {gl_FragColor = uniformColor;}"; + static const char *uniformName = "uniformColor"; + + GLhandleARB program; + GLint uniformLocation; + const GLint uniform[4] = {1,2,3,4}; + GLint queriedUniform[4]; + + if (GetUniformivARB == NULL) { + return GL_FALSE; + } + + /* Call a helper function to compile up the shader and give + * us back the validated program and uniform location. + * If it fails, something's wrong and we can't continue. + */ + if (!exercise_uniform_start(fragmentShaderText, uniformName, + &program, &uniformLocation)) { + return GL_FALSE; + } + + /* Set the value of the program uniform. Note that you must + * use a compatible type. Our uniform above is an integer + * vector (ivec4), so we must set it using integer versions + * of the Uniform* functions. The "1" means we're setting + * one vector's worth of information. + */ + (*Uniform4ivARB)(uniformLocation, 1, uniform); + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* Query it back */ + (*GetUniformivARB)(program, uniformLocation, queriedUniform); + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* Clean up before we check to see whether it came back unscathed */ + exercise_uniform_end(program); + + /* Now check to see whether the uniform came back as expected. This + * will return GL_TRUE if all is well, or GL_FALSE if the comparison failed. + */ + return compare_ints(__FUNCTION__, 4, uniform, 4, queriedUniform); +} + +static GLboolean +test_Uniform4i(generic_func func) +{ + PFNGLUNIFORM4IARBPROC Uniform4iARB = (PFNGLUNIFORM4IARBPROC) func; + DECLARE_GLFUNC_PTR(GetUniformivARB, PFNGLGETUNIFORMIVARBPROC); + + /* This is a trivial fragment shader that sets the color of the + * fragment to the uniform value passed in. + */ + static const char *fragmentShaderText = + "uniform ivec4 uniformColor; void main() {gl_FragColor = uniformColor;}"; + static const char *uniformName = "uniformColor"; + + GLhandleARB program; + GLint uniformLocation; + const GLint uniform[4] = {1,2,3,4}; + GLint queriedUniform[4]; + + if (GetUniformivARB == NULL) { + return GL_FALSE; + } + + /* Call a helper function to compile up the shader and give + * us back the validated program and uniform location. + * If it fails, something's wrong and we can't continue. + */ + if (!exercise_uniform_start(fragmentShaderText, uniformName, + &program, &uniformLocation)) { + return GL_FALSE; + } + + /* Set the value of the program uniform. Note that you must + * use a compatible type. Our uniform above is an integer + * vector (ivec4), so we must set it using integer versions + * of the Uniform* functions. + */ + (*Uniform4iARB)(uniformLocation, uniform[0], uniform[1], uniform[2], + uniform[3]); + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* Query it back */ + (*GetUniformivARB)(program, uniformLocation, queriedUniform); + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* Clean up before we check to see whether it came back unscathed */ + exercise_uniform_end(program); + + /* Now check to see whether the uniform came back as expected. This + * will return GL_TRUE if all is well, or GL_FALSE if the comparison failed. + */ + return compare_ints(__FUNCTION__, 4, uniform, 4, queriedUniform); +} + +static GLboolean +test_Uniform4fv(generic_func func) +{ + PFNGLUNIFORM4FVARBPROC Uniform4fvARB = (PFNGLUNIFORM4FVARBPROC) func; + DECLARE_GLFUNC_PTR(GetUniformfvARB, PFNGLGETUNIFORMFVARBPROC); + + /* This is a trivial fragment shader that sets the color of the + * fragment to the uniform value passed in. + */ + static const char *fragmentShaderText = + "uniform vec4 uniformColor; void main() {gl_FragColor = uniformColor;}"; + static const char *uniformName = "uniformColor"; + + GLhandleARB program; + GLint uniformLocation; + const GLfloat uniform[4] = {1.1,2.2,3.3,4.4}; + GLfloat queriedUniform[4]; + + if (GetUniformfvARB == NULL) { + return GL_FALSE; + } + + /* Call a helper function to compile up the shader and give + * us back the validated program and uniform location. + * If it fails, something's wrong and we can't continue. + */ + if (!exercise_uniform_start(fragmentShaderText, uniformName, + &program, &uniformLocation)) { + return GL_FALSE; + } + + /* Set the value of the program uniform. Note that you must + * use a compatible type. Our uniform above is a float + * vector (vec4), so we must set it using float versions + * of the Uniform* functions. The "1" means we're setting + * one vector's worth of information. + */ + (*Uniform4fvARB)(uniformLocation, 1, uniform); + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* Query it back */ + (*GetUniformfvARB)(program, uniformLocation, queriedUniform); + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* Clean up before we check to see whether it came back unscathed */ + exercise_uniform_end(program); + + /* Now check to see whether the uniform came back as expected. This + * will return GL_TRUE if all is well, or GL_FALSE if the comparison failed. + */ + return compare_floats(__FUNCTION__, 4, uniform, 4, queriedUniform); +} + +static GLboolean +test_Uniform4f(generic_func func) +{ + PFNGLUNIFORM4FARBPROC Uniform4fARB = (PFNGLUNIFORM4FARBPROC) func; + DECLARE_GLFUNC_PTR(GetUniformfvARB, PFNGLGETUNIFORMFVARBPROC); + + /* This is a trivial fragment shader that sets the color of the + * fragment to the uniform value passed in. + */ + static const char *fragmentShaderText = + "uniform vec4 uniformColor; void main() {gl_FragColor = uniformColor;}"; + static const char *uniformName = "uniformColor"; + + GLhandleARB program; + GLint uniformLocation; + const GLfloat uniform[4] = {1.1,2.2,3.3,4.4}; + GLfloat queriedUniform[4]; + + if (GetUniformfvARB == NULL) { + return GL_FALSE; + } + + /* Call a helper function to compile up the shader and give + * us back the validated program and uniform location. + * If it fails, something's wrong and we can't continue. + */ + if (!exercise_uniform_start(fragmentShaderText, uniformName, + &program, &uniformLocation)) { + return GL_FALSE; + } + + /* Set the value of the program uniform. Note that you must + * use a compatible type. Our uniform above is an integer + * vector (ivec4), so we must set it using integer versions + * of the Uniform* functions. + */ + (*Uniform4fARB)(uniformLocation, uniform[0], uniform[1], uniform[2], + uniform[3]); + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* Query it back */ + (*GetUniformfvARB)(program, uniformLocation, queriedUniform); + CheckGLError(__LINE__, __FILE__, __FUNCTION__); + + /* Clean up before we check to see whether it came back unscathed */ + exercise_uniform_end(program); + + /* Now check to see whether the uniform came back as expected. This + * will return GL_TRUE if all is well, or GL_FALSE if the comparison failed. + */ + return compare_floats(__FUNCTION__, 4, uniform, 4, queriedUniform); +} static GLboolean test_ActiveTextureARB(generic_func func) @@ -107,6 +2694,40 @@ test_VertexAttrib1fvARB(generic_func func) } static GLboolean +test_VertexAttrib1dvARB(generic_func func) +{ + PFNGLVERTEXATTRIB1DVARBPROC vertexAttrib1dvARB = (PFNGLVERTEXATTRIB1DVARBPROC) func; + PFNGLGETVERTEXATTRIBDVARBPROC getVertexAttribdvARB = (PFNGLGETVERTEXATTRIBDVARBPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribdvARB"); + + const GLdouble v[1] = {25.0}; + const GLdouble def[1] = {0}; + GLdouble res[4]; + GLboolean pass; + (*vertexAttrib1dvARB)(6, v); + (*getVertexAttribdvARB)(6, GL_CURRENT_VERTEX_ATTRIB_ARB, res); + pass = (res[0] == 25.0 && res[1] == 0.0 && res[2] == 0.0 && res[3] == 1.0); + (*vertexAttrib1dvARB)(6, def); + return pass; +} + +static GLboolean +test_VertexAttrib1svARB(generic_func func) +{ + PFNGLVERTEXATTRIB1SVARBPROC vertexAttrib1svARB = (PFNGLVERTEXATTRIB1SVARBPROC) func; + PFNGLGETVERTEXATTRIBIVARBPROC getVertexAttribivARB = (PFNGLGETVERTEXATTRIBIVARBPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribivARB"); + + const GLshort v[1] = {25.0}; + const GLshort def[1] = {0}; + GLint res[4]; + GLboolean pass; + (*vertexAttrib1svARB)(6, v); + (*getVertexAttribivARB)(6, GL_CURRENT_VERTEX_ATTRIB_ARB, res); + pass = (res[0] == 25 && res[1] == 0 && res[2] == 0 && res[3] == 1); + (*vertexAttrib1svARB)(6, def); + return pass; +} + +static GLboolean test_VertexAttrib4NubvARB(generic_func func) { PFNGLVERTEXATTRIB4NUBVARBPROC vertexAttrib4NubvARB = (PFNGLVERTEXATTRIB4NUBVARBPROC) func; @@ -177,7 +2798,6 @@ test_VertexAttrib4NsvARB(generic_func func) return pass; } - static GLboolean test_VertexAttrib4NusvARB(generic_func func) { @@ -195,42 +2815,110 @@ test_VertexAttrib4NusvARB(generic_func func) return pass; } +static GLboolean +test_VertexAttrib1sNV(generic_func func) +{ + PFNGLVERTEXATTRIB1SNVPROC vertexAttrib1sNV = (PFNGLVERTEXATTRIB1SNVPROC) func; + PFNGLGETVERTEXATTRIBIVNVPROC getVertexAttribivNV = (PFNGLGETVERTEXATTRIBIVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribivNV"); + + const GLshort v[4] = {2, 0, 0, 1}; + const GLshort def[4] = {0, 0, 0, 1}; + GLint res[4]; + (*vertexAttrib1sNV)(6, v[0]); + (*getVertexAttribivNV)(6, GL_CURRENT_ATTRIB_NV, res); + (*vertexAttrib1sNV)(6, def[0]); + return compare_shorts_to_ints(__FUNCTION__, 4, v, 4, res); +} static GLboolean -test_VertexAttrib4ubNV(generic_func func) +test_VertexAttrib1fNV(generic_func func) { - PFNGLVERTEXATTRIB4UBNVPROC vertexAttrib4ubNV = (PFNGLVERTEXATTRIB4UBNVPROC) func; + PFNGLVERTEXATTRIB1FNVPROC vertexAttrib1fNV = (PFNGLVERTEXATTRIB1FNVPROC) func; PFNGLGETVERTEXATTRIBFVNVPROC getVertexAttribfvNV = (PFNGLGETVERTEXATTRIBFVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvNV"); - const GLubyte v[4] = {255, 0, 255, 0}; - const GLubyte def[4] = {0, 0, 0, 255}; + const GLfloat v[4] = {2.5, 0.0, 0.0, 1.0}; + const GLfloat def[4] = {0, 0, 0, 1}; GLfloat res[4]; - GLboolean pass; - (*vertexAttrib4ubNV)(6, v[0], v[1], v[2], v[3]); + (*vertexAttrib1fNV)(6, v[0]); (*getVertexAttribfvNV)(6, GL_CURRENT_ATTRIB_NV, res); - pass = (res[0] == 1.0 && res[1] == 0.0 && res[2] == 1.0 && res[3] == 0.0); - (*vertexAttrib4ubNV)(6, def[0], def[1], def[2], def[3]); - return pass; + (*vertexAttrib1fNV)(6, def[0]); + return compare_floats(__FUNCTION__, 4, v, 4, res); } +static GLboolean +test_VertexAttrib1dNV(generic_func func) +{ + PFNGLVERTEXATTRIB1DNVPROC vertexAttrib1dNV = (PFNGLVERTEXATTRIB1DNVPROC) func; + PFNGLGETVERTEXATTRIBDVNVPROC getVertexAttribdvNV = (PFNGLGETVERTEXATTRIBDVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribdvNV"); + + const GLdouble v[4] = {2.5, 0.0, 0.0, 1.0}; + const GLdouble def[4] = {0, 0, 0, 1}; + GLdouble res[4]; + (*vertexAttrib1dNV)(6, v[0]); + (*getVertexAttribdvNV)(6, GL_CURRENT_ATTRIB_NV, res); + (*vertexAttrib1dNV)(6, def[0]); + return compare_doubles(__FUNCTION__, 4, v, 4, res); +} static GLboolean test_VertexAttrib2sNV(generic_func func) { PFNGLVERTEXATTRIB2SNVPROC vertexAttrib2sNV = (PFNGLVERTEXATTRIB2SNVPROC) func; + PFNGLGETVERTEXATTRIBIVNVPROC getVertexAttribivNV = (PFNGLGETVERTEXATTRIBIVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribivNV"); + + const GLshort v[4] = {2, 4, 0, 1}; + const GLshort def[4] = {0, 0, 0, 1}; + GLint res[4]; + (*vertexAttrib2sNV)(6, v[0], v[1]); + (*getVertexAttribivNV)(6, GL_CURRENT_ATTRIB_NV, res); + (*vertexAttrib2sNV)(6, def[0], def[1]); + return compare_shorts_to_ints(__FUNCTION__, 4, v, 4, res); +} + +static GLboolean +test_VertexAttrib2fNV(generic_func func) +{ + PFNGLVERTEXATTRIB2FNVPROC vertexAttrib2fNV = (PFNGLVERTEXATTRIB2FNVPROC) func; PFNGLGETVERTEXATTRIBFVNVPROC getVertexAttribfvNV = (PFNGLGETVERTEXATTRIBFVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvNV"); - const GLshort v[2] = {2, -4,}; - const GLshort def[2] = {0, 0}; + const GLfloat v[4] = {2.5, 4.25, 0.0, 1.0}; + const GLfloat def[4] = {0, 0, 0, 1}; GLfloat res[4]; - GLboolean pass; - (*vertexAttrib2sNV)(6, v[0], v[1]); + (*vertexAttrib2fNV)(6, v[0], v[1]); (*getVertexAttribfvNV)(6, GL_CURRENT_ATTRIB_NV, res); - pass = (EQUAL(res[0], 2) && EQUAL(res[1], -4) && EQUAL(res[2], 0) && res[3] == 1.0); - (*vertexAttrib2sNV)(6, def[0], def[1]); - return pass; + (*vertexAttrib2fNV)(6, def[0], def[1]); + return compare_floats(__FUNCTION__, 4, v, 4, res); +} + +static GLboolean +test_VertexAttrib2dNV(generic_func func) +{ + PFNGLVERTEXATTRIB2DNVPROC vertexAttrib2dNV = (PFNGLVERTEXATTRIB2DNVPROC) func; + PFNGLGETVERTEXATTRIBDVNVPROC getVertexAttribdvNV = (PFNGLGETVERTEXATTRIBDVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribdvNV"); + + const GLdouble v[4] = {2.5, 4.25, 0.0, 1.0}; + const GLdouble def[4] = {0, 0, 0, 1}; + GLdouble res[4]; + (*vertexAttrib2dNV)(6, v[0], v[1]); + (*getVertexAttribdvNV)(6, GL_CURRENT_ATTRIB_NV, res); + (*vertexAttrib2dNV)(6, def[0], def[1]); + return compare_doubles(__FUNCTION__, 4, v, 4, res); } +static GLboolean +test_VertexAttrib3sNV(generic_func func) +{ + PFNGLVERTEXATTRIB3SNVPROC vertexAttrib3sNV = (PFNGLVERTEXATTRIB3SNVPROC) func; + PFNGLGETVERTEXATTRIBIVNVPROC getVertexAttribivNV = (PFNGLGETVERTEXATTRIBIVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribivNV"); + + const GLshort v[4] = {2, 4, 7, 1}; + const GLshort def[4] = {0, 0, 0, 1}; + GLint res[4]; + (*vertexAttrib3sNV)(6, v[0], v[1], v[2]); + (*getVertexAttribivNV)(6, GL_CURRENT_ATTRIB_NV, res); + (*vertexAttrib3sNV)(6, def[0], def[1], def[2]); + return compare_shorts_to_ints(__FUNCTION__, 4, v, 4, res); +} static GLboolean test_VertexAttrib3fNV(generic_func func) @@ -238,35 +2926,467 @@ test_VertexAttrib3fNV(generic_func func) PFNGLVERTEXATTRIB3FNVPROC vertexAttrib3fNV = (PFNGLVERTEXATTRIB3FNVPROC) func; PFNGLGETVERTEXATTRIBFVNVPROC getVertexAttribfvNV = (PFNGLGETVERTEXATTRIBFVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvNV"); - const GLfloat v[3] = {0.2, 0.4, 0.8}; - const GLfloat def[3] = {0, 0, 0}; + const GLfloat v[4] = {2.5, 4.25, 7.125, 1.0}; + const GLfloat def[4] = {0, 0, 0, 1}; GLfloat res[4]; - GLboolean pass; (*vertexAttrib3fNV)(6, v[0], v[1], v[2]); (*getVertexAttribfvNV)(6, GL_CURRENT_ATTRIB_NV, res); - pass = (EQUAL(res[0], 0.2) && EQUAL(res[1], 0.4) && EQUAL(res[2], 0.8) && res[3] == 1.0); (*vertexAttrib3fNV)(6, def[0], def[1], def[2]); - return pass; + return compare_floats(__FUNCTION__, 4, v, 4, res); } +static GLboolean +test_VertexAttrib3dNV(generic_func func) +{ + PFNGLVERTEXATTRIB3DNVPROC vertexAttrib3dNV = (PFNGLVERTEXATTRIB3DNVPROC) func; + PFNGLGETVERTEXATTRIBDVNVPROC getVertexAttribdvNV = (PFNGLGETVERTEXATTRIBDVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribdvNV"); + + const GLdouble v[4] = {2.5, 4.25, 7.125, 1.0}; + const GLdouble def[4] = {0, 0, 0, 1}; + GLdouble res[4]; + (*vertexAttrib3dNV)(6, v[0], v[1], v[2]); + (*getVertexAttribdvNV)(6, GL_CURRENT_ATTRIB_NV, res); + (*vertexAttrib3dNV)(6, def[0], def[1], def[2]); + return compare_doubles(__FUNCTION__, 4, v, 4, res); +} + +static GLboolean +test_VertexAttrib4sNV(generic_func func) +{ + PFNGLVERTEXATTRIB4SNVPROC vertexAttrib4sNV = (PFNGLVERTEXATTRIB4SNVPROC) func; + PFNGLGETVERTEXATTRIBIVNVPROC getVertexAttribivNV = (PFNGLGETVERTEXATTRIBIVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribivNV"); + + const GLshort v[4] = {2, 4, 7, 5}; + const GLshort def[4] = {0, 0, 0, 1}; + GLint res[4]; + (*vertexAttrib4sNV)(6, v[0], v[1], v[2], v[3]); + (*getVertexAttribivNV)(6, GL_CURRENT_ATTRIB_NV, res); + (*vertexAttrib4sNV)(6, def[0], def[1], def[2], def[3]); + return compare_shorts_to_ints(__FUNCTION__, 4, v, 4, res); +} + +static GLboolean +test_VertexAttrib4fNV(generic_func func) +{ + PFNGLVERTEXATTRIB4FNVPROC vertexAttrib4fNV = (PFNGLVERTEXATTRIB4FNVPROC) func; + PFNGLGETVERTEXATTRIBFVNVPROC getVertexAttribfvNV = (PFNGLGETVERTEXATTRIBFVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvNV"); + + const GLfloat v[4] = {2.5, 4.25, 7.125, 5.0625}; + const GLfloat def[4] = {0, 0, 0, 1}; + GLfloat res[4]; + (*vertexAttrib4fNV)(6, v[0], v[1], v[2], v[3]); + (*getVertexAttribfvNV)(6, GL_CURRENT_ATTRIB_NV, res); + (*vertexAttrib4fNV)(6, def[0], def[1], def[2], def[3]); + return compare_floats(__FUNCTION__, 4, v, 4, res); +} + +static GLboolean +test_VertexAttrib4dNV(generic_func func) +{ + PFNGLVERTEXATTRIB4DNVPROC vertexAttrib4dNV = (PFNGLVERTEXATTRIB4DNVPROC) func; + PFNGLGETVERTEXATTRIBDVNVPROC getVertexAttribdvNV = (PFNGLGETVERTEXATTRIBDVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribdvNV"); + + const GLdouble v[4] = {2.5, 4.25, 7.125, 5.0625}; + const GLdouble def[4] = {0, 0, 0, 1}; + GLdouble res[4]; + (*vertexAttrib4dNV)(6, v[0], v[1], v[2], v[3]); + (*getVertexAttribdvNV)(6, GL_CURRENT_ATTRIB_NV, res); + (*vertexAttrib4dNV)(6, def[0], def[1], def[2], def[3]); + return compare_doubles(__FUNCTION__, 4, v, 4, res); +} + +static GLboolean +test_VertexAttrib4ubNV(generic_func func) +{ + PFNGLVERTEXATTRIB4UBNVPROC vertexAttrib4ubNV = (PFNGLVERTEXATTRIB4UBNVPROC) func; + PFNGLGETVERTEXATTRIBFVNVPROC getVertexAttribfvNV = (PFNGLGETVERTEXATTRIBFVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvNV"); + + const GLubyte v[4] = {255, 0, 255, 0}; + const GLubyte def[4] = {0, 0, 0, 255}; + GLfloat res[4]; + /* There's no byte-value query; so we use the float-value query. + * Bytes are interpreted as steps between 0 and 1, so the + * expected float values will be 0.0 for byte value 0 and 1.0 for + * byte value 255. + */ + GLfloat expectedResults[4] = {1.0, 0.0, 1.0, 0.0}; + (*vertexAttrib4ubNV)(6, v[0], v[1], v[2], v[3]); + (*getVertexAttribfvNV)(6, GL_CURRENT_ATTRIB_NV, res); + (*vertexAttrib4ubNV)(6, def[0], def[1], def[2], def[3]); + return compare_floats(__FUNCTION__, 4, expectedResults, 4, res); +} + +static GLboolean +test_VertexAttrib1fvNV(generic_func func) +{ + PFNGLVERTEXATTRIB1FVNVPROC vertexAttrib1fvNV = (PFNGLVERTEXATTRIB1FVNVPROC) func; + PFNGLGETVERTEXATTRIBFVNVPROC getVertexAttribfvNV = (PFNGLGETVERTEXATTRIBFVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvNV"); + + const GLfloat v[4] = {2.5, 0.0, 0.0, 1.0}; + const GLfloat def[4] = {0, 0, 0, 1}; + GLfloat res[4]; + (*vertexAttrib1fvNV)(6, v); + (*getVertexAttribfvNV)(6, GL_CURRENT_ATTRIB_NV, res); + (*vertexAttrib1fvNV)(6, def); + return compare_floats(__FUNCTION__, 4, v, 4, res); +} + +static GLboolean +test_VertexAttrib1dvNV(generic_func func) +{ + PFNGLVERTEXATTRIB1DVNVPROC vertexAttrib1dvNV = (PFNGLVERTEXATTRIB1DVNVPROC) func; + PFNGLGETVERTEXATTRIBDVNVPROC getVertexAttribdvNV = (PFNGLGETVERTEXATTRIBDVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribdvNV"); + + const GLdouble v[4] = {2.5, 0.0, 0.0, 1.0}; + const GLdouble def[4] = {0, 0, 0, 1}; + GLdouble res[4]; + (*vertexAttrib1dvNV)(6, v); + (*getVertexAttribdvNV)(6, GL_CURRENT_ATTRIB_NV, res); + (*vertexAttrib1dvNV)(6, def); + return compare_doubles(__FUNCTION__, 4, v, 4, res); +} + +static GLboolean +test_VertexAttrib2svNV(generic_func func) +{ + PFNGLVERTEXATTRIB2SVNVPROC vertexAttrib2svNV = (PFNGLVERTEXATTRIB2SVNVPROC) func; + PFNGLGETVERTEXATTRIBIVNVPROC getVertexAttribivNV = (PFNGLGETVERTEXATTRIBIVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribivNV"); + + const GLshort v[4] = {2, 4, 0, 1}; + const GLshort def[4] = {0, 0, 0, 1}; + GLint res[4]; + (*vertexAttrib2svNV)(6, v); + (*getVertexAttribivNV)(6, GL_CURRENT_ATTRIB_NV, res); + (*vertexAttrib2svNV)(6, def); + return compare_shorts_to_ints(__FUNCTION__, 4, v, 4, res); +} + +static GLboolean +test_VertexAttrib2fvNV(generic_func func) +{ + PFNGLVERTEXATTRIB2FVNVPROC vertexAttrib2fvNV = (PFNGLVERTEXATTRIB2FVNVPROC) func; + PFNGLGETVERTEXATTRIBFVNVPROC getVertexAttribfvNV = (PFNGLGETVERTEXATTRIBFVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvNV"); + + const GLfloat v[4] = {2.5, 4.25, 0.0, 1.0}; + const GLfloat def[4] = {0, 0, 0, 1}; + GLfloat res[4]; + (*vertexAttrib2fvNV)(6, v); + (*getVertexAttribfvNV)(6, GL_CURRENT_ATTRIB_NV, res); + (*vertexAttrib2fvNV)(6, def); + return compare_floats(__FUNCTION__, 4, v, 4, res); +} + +static GLboolean +test_VertexAttrib2dvNV(generic_func func) +{ + PFNGLVERTEXATTRIB2DVNVPROC vertexAttrib2dvNV = (PFNGLVERTEXATTRIB2DVNVPROC) func; + PFNGLGETVERTEXATTRIBDVNVPROC getVertexAttribdvNV = (PFNGLGETVERTEXATTRIBDVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribdvNV"); + + const GLdouble v[4] = {2.5, 4.25, 0.0, 1.0}; + const GLdouble def[4] = {0, 0, 0, 1}; + GLdouble res[4]; + (*vertexAttrib2dvNV)(6, v); + (*getVertexAttribdvNV)(6, GL_CURRENT_ATTRIB_NV, res); + (*vertexAttrib2dvNV)(6, def); + return compare_doubles(__FUNCTION__, 4, v, 4, res); +} + +static GLboolean +test_VertexAttrib3svNV(generic_func func) +{ + PFNGLVERTEXATTRIB3SVNVPROC vertexAttrib3svNV = (PFNGLVERTEXATTRIB3SVNVPROC) func; + PFNGLGETVERTEXATTRIBIVNVPROC getVertexAttribivNV = (PFNGLGETVERTEXATTRIBIVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribivNV"); + + const GLshort v[4] = {2, 4, 7, 1}; + const GLshort def[4] = {0, 0, 0, 1}; + GLint res[4]; + (*vertexAttrib3svNV)(6, v); + (*getVertexAttribivNV)(6, GL_CURRENT_ATTRIB_NV, res); + (*vertexAttrib3svNV)(6, def); + return compare_shorts_to_ints(__FUNCTION__, 4, v, 4, res); +} + +static GLboolean +test_VertexAttrib3fvNV(generic_func func) +{ + PFNGLVERTEXATTRIB3FVNVPROC vertexAttrib3fvNV = (PFNGLVERTEXATTRIB3FVNVPROC) func; + PFNGLGETVERTEXATTRIBFVNVPROC getVertexAttribfvNV = (PFNGLGETVERTEXATTRIBFVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvNV"); + + const GLfloat v[4] = {2.5, 4.25, 7.125, 1.0}; + const GLfloat def[4] = {0, 0, 0, 1}; + GLfloat res[4]; + (*vertexAttrib3fvNV)(6, v); + (*getVertexAttribfvNV)(6, GL_CURRENT_ATTRIB_NV, res); + (*vertexAttrib3fvNV)(6, def); + return compare_floats(__FUNCTION__, 4, v, 4, res); +} + +static GLboolean +test_VertexAttrib3dvNV(generic_func func) +{ + PFNGLVERTEXATTRIB3DVNVPROC vertexAttrib3dvNV = (PFNGLVERTEXATTRIB3DVNVPROC) func; + PFNGLGETVERTEXATTRIBDVNVPROC getVertexAttribdvNV = (PFNGLGETVERTEXATTRIBDVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribdvNV"); + + const GLdouble v[4] = {2.5, 4.25, 7.125, 1.0}; + const GLdouble def[4] = {0, 0, 0, 1}; + GLdouble res[4]; + (*vertexAttrib3dvNV)(6, v); + (*getVertexAttribdvNV)(6, GL_CURRENT_ATTRIB_NV, res); + (*vertexAttrib3dvNV)(6, def); + return compare_doubles(__FUNCTION__, 4, v, 4, res); +} + +static GLboolean +test_VertexAttrib4svNV(generic_func func) +{ + PFNGLVERTEXATTRIB4SVNVPROC vertexAttrib4svNV = (PFNGLVERTEXATTRIB4SVNVPROC) func; + PFNGLGETVERTEXATTRIBIVNVPROC getVertexAttribivNV = (PFNGLGETVERTEXATTRIBIVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribivNV"); + + const GLshort v[4] = {2, 4, 7, 5}; + const GLshort def[4] = {0, 0, 0, 1}; + GLint res[4]; + (*vertexAttrib4svNV)(6, v); + (*getVertexAttribivNV)(6, GL_CURRENT_ATTRIB_NV, res); + (*vertexAttrib4svNV)(6, def); + return compare_shorts_to_ints(__FUNCTION__, 4, v, 4, res); +} + +static GLboolean +test_VertexAttrib4fvNV(generic_func func) +{ + PFNGLVERTEXATTRIB4FVNVPROC vertexAttrib4fvNV = (PFNGLVERTEXATTRIB4FVNVPROC) func; + PFNGLGETVERTEXATTRIBFVNVPROC getVertexAttribfvNV = (PFNGLGETVERTEXATTRIBFVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvNV"); + + const GLfloat v[4] = {2.5, 4.25, 7.125, 5.0625}; + const GLfloat def[4] = {0, 0, 0, 1}; + GLfloat res[4]; + (*vertexAttrib4fvNV)(6, v); + (*getVertexAttribfvNV)(6, GL_CURRENT_ATTRIB_NV, res); + (*vertexAttrib4fvNV)(6, def); + return compare_floats(__FUNCTION__, 4, v, 4, res); +} static GLboolean test_VertexAttrib4dvNV(generic_func func) { PFNGLVERTEXATTRIB4DVNVPROC vertexAttrib4dvNV = (PFNGLVERTEXATTRIB4DVNVPROC) func; + PFNGLGETVERTEXATTRIBDVNVPROC getVertexAttribdvNV = (PFNGLGETVERTEXATTRIBDVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribdvNV"); + + const GLdouble v[4] = {2.5, 4.25, 7.125, 5.0625}; + const GLdouble def[4] = {0, 0, 0, 1}; + GLdouble res[4]; + (*vertexAttrib4dvNV)(6, v); + (*getVertexAttribdvNV)(6, GL_CURRENT_ATTRIB_NV, res); + (*vertexAttrib4dvNV)(6, def); + return compare_doubles(__FUNCTION__, 4, v, 4, res); +} + +static GLboolean +test_VertexAttrib4ubvNV(generic_func func) +{ + PFNGLVERTEXATTRIB4UBVNVPROC vertexAttrib4ubvNV = (PFNGLVERTEXATTRIB4UBVNVPROC) func; + PFNGLGETVERTEXATTRIBFVNVPROC getVertexAttribfvNV = (PFNGLGETVERTEXATTRIBFVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvNV"); + + const GLubyte v[4] = {255, 0, 255, 0}; + const GLubyte def[4] = {0, 0, 0, 255}; + GLfloat res[4]; + /* There's no byte-value query; so we use the float-value query. + * Bytes are interpreted as steps between 0 and 1, so the + * expected float values will be 0.0 for byte value 0 and 1.0 for + * byte value 255. + */ + GLfloat expectedResults[4] = {1.0, 0.0, 1.0, 0.0}; + (*vertexAttrib4ubvNV)(6, v); + (*getVertexAttribfvNV)(6, GL_CURRENT_ATTRIB_NV, res); + (*vertexAttrib4ubvNV)(6, def); + return compare_floats(__FUNCTION__, 4, expectedResults, 4, res); +} + +static GLboolean +test_VertexAttribs1fvNV(generic_func func) +{ + PFNGLVERTEXATTRIBS1FVNVPROC vertexAttribs1fvNV = (PFNGLVERTEXATTRIBS1FVNVPROC) func; PFNGLGETVERTEXATTRIBFVNVPROC getVertexAttribfvNV = (PFNGLGETVERTEXATTRIBFVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvNV"); - const GLdouble v[4] = {0.2, 0.4, 0.8, 1.2}; + const GLfloat v[4] = {2.5, 0.0, 0.0, 1.0}; + const GLfloat def[4] = {0, 0, 0, 1}; + GLfloat res[4]; + (*vertexAttribs1fvNV)(6, 1, v); + (*getVertexAttribfvNV)(6, GL_CURRENT_ATTRIB_NV, res); + (*vertexAttribs1fvNV)(6, 1, def); + return compare_floats(__FUNCTION__, 4, v, 4, res); +} + +static GLboolean +test_VertexAttribs1dvNV(generic_func func) +{ + PFNGLVERTEXATTRIBS1DVNVPROC vertexAttribs1dvNV = (PFNGLVERTEXATTRIBS1DVNVPROC) func; + PFNGLGETVERTEXATTRIBDVNVPROC getVertexAttribdvNV = (PFNGLGETVERTEXATTRIBDVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribdvNV"); + + const GLdouble v[4] = {2.5, 0.0, 0.0, 1.0}; const GLdouble def[4] = {0, 0, 0, 1}; + GLdouble res[4]; + (*vertexAttribs1dvNV)(6, 1, v); + (*getVertexAttribdvNV)(6, GL_CURRENT_ATTRIB_NV, res); + (*vertexAttribs1dvNV)(6, 1, def); + return compare_doubles(__FUNCTION__, 4, v, 4, res); +} + +static GLboolean +test_VertexAttribs2svNV(generic_func func) +{ + PFNGLVERTEXATTRIBS2SVNVPROC vertexAttribs2svNV = (PFNGLVERTEXATTRIBS2SVNVPROC) func; + PFNGLGETVERTEXATTRIBIVNVPROC getVertexAttribivNV = (PFNGLGETVERTEXATTRIBIVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribivNV"); + + const GLshort v[4] = {2, 4, 0, 1}; + const GLshort def[4] = {0, 0, 0, 1}; + GLint res[4]; + (*vertexAttribs2svNV)(6, 1, v); + (*getVertexAttribivNV)(6, GL_CURRENT_ATTRIB_NV, res); + (*vertexAttribs2svNV)(6, 1, def); + return compare_shorts_to_ints(__FUNCTION__, 4, v, 4, res); +} + +static GLboolean +test_VertexAttribs2fvNV(generic_func func) +{ + PFNGLVERTEXATTRIBS2FVNVPROC vertexAttribs2fvNV = (PFNGLVERTEXATTRIBS2FVNVPROC) func; + PFNGLGETVERTEXATTRIBFVNVPROC getVertexAttribfvNV = (PFNGLGETVERTEXATTRIBFVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvNV"); + + const GLfloat v[4] = {2.5, 4.25, 0.0, 1.0}; + const GLfloat def[4] = {0, 0, 0, 1}; GLfloat res[4]; - GLboolean pass; - (*vertexAttrib4dvNV)(6, v); + (*vertexAttribs2fvNV)(6, 1, v); (*getVertexAttribfvNV)(6, GL_CURRENT_ATTRIB_NV, res); - pass = (EQUAL(res[0], 0.2) && EQUAL(res[1], 0.4) && EQUAL(res[2], 0.8) && EQUAL(res[3], 1.2)); - (*vertexAttrib4dvNV)(6, def); - return pass; + (*vertexAttribs2fvNV)(6, 1, def); + return compare_floats(__FUNCTION__, 4, v, 4, res); +} + +static GLboolean +test_VertexAttribs2dvNV(generic_func func) +{ + PFNGLVERTEXATTRIBS2DVNVPROC vertexAttribs2dvNV = (PFNGLVERTEXATTRIBS2DVNVPROC) func; + PFNGLGETVERTEXATTRIBDVNVPROC getVertexAttribdvNV = (PFNGLGETVERTEXATTRIBDVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribdvNV"); + + const GLdouble v[4] = {2.5, 4.25, 0.0, 1.0}; + const GLdouble def[4] = {0, 0, 0, 1}; + GLdouble res[4]; + (*vertexAttribs2dvNV)(6, 1, v); + (*getVertexAttribdvNV)(6, GL_CURRENT_ATTRIB_NV, res); + (*vertexAttribs2dvNV)(6, 1, def); + return compare_doubles(__FUNCTION__, 4, v, 4, res); } +static GLboolean +test_VertexAttribs3svNV(generic_func func) +{ + PFNGLVERTEXATTRIBS3SVNVPROC vertexAttribs3svNV = (PFNGLVERTEXATTRIBS3SVNVPROC) func; + PFNGLGETVERTEXATTRIBIVNVPROC getVertexAttribivNV = (PFNGLGETVERTEXATTRIBIVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribivNV"); + + const GLshort v[4] = {2, 4, 7, 1}; + const GLshort def[4] = {0, 0, 0, 1}; + GLint res[4]; + (*vertexAttribs3svNV)(6, 1, v); + (*getVertexAttribivNV)(6, GL_CURRENT_ATTRIB_NV, res); + (*vertexAttribs3svNV)(6, 1, def); + return compare_shorts_to_ints(__FUNCTION__, 4, v, 4, res); +} + +static GLboolean +test_VertexAttribs3fvNV(generic_func func) +{ + PFNGLVERTEXATTRIBS3FVNVPROC vertexAttribs3fvNV = (PFNGLVERTEXATTRIBS3FVNVPROC) func; + PFNGLGETVERTEXATTRIBFVNVPROC getVertexAttribfvNV = (PFNGLGETVERTEXATTRIBFVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvNV"); + + const GLfloat v[4] = {2.5, 4.25, 7.125, 1.0}; + const GLfloat def[4] = {0, 0, 0, 1}; + GLfloat res[4]; + (*vertexAttribs3fvNV)(6, 1, v); + (*getVertexAttribfvNV)(6, GL_CURRENT_ATTRIB_NV, res); + (*vertexAttribs3fvNV)(6, 1, def); + return compare_floats(__FUNCTION__, 4, v, 4, res); +} + +static GLboolean +test_VertexAttribs3dvNV(generic_func func) +{ + PFNGLVERTEXATTRIBS3DVNVPROC vertexAttribs3dvNV = (PFNGLVERTEXATTRIBS3DVNVPROC) func; + PFNGLGETVERTEXATTRIBDVNVPROC getVertexAttribdvNV = (PFNGLGETVERTEXATTRIBDVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribdvNV"); + + const GLdouble v[4] = {2.5, 4.25, 7.125, 1.0}; + const GLdouble def[4] = {0, 0, 0, 1}; + GLdouble res[4]; + (*vertexAttribs3dvNV)(6, 1, v); + (*getVertexAttribdvNV)(6, GL_CURRENT_ATTRIB_NV, res); + (*vertexAttribs3dvNV)(6, 1, def); + return compare_doubles(__FUNCTION__, 4, v, 4, res); +} + +static GLboolean +test_VertexAttribs4svNV(generic_func func) +{ + PFNGLVERTEXATTRIBS4SVNVPROC vertexAttribs4svNV = (PFNGLVERTEXATTRIBS4SVNVPROC) func; + PFNGLGETVERTEXATTRIBIVNVPROC getVertexAttribivNV = (PFNGLGETVERTEXATTRIBIVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribivNV"); + + const GLshort v[4] = {2, 4, 7, 5}; + const GLshort def[4] = {0, 0, 0, 1}; + GLint res[4]; + (*vertexAttribs4svNV)(6, 1, v); + (*getVertexAttribivNV)(6, GL_CURRENT_ATTRIB_NV, res); + (*vertexAttribs4svNV)(6, 1, def); + return compare_shorts_to_ints(__FUNCTION__, 4, v, 4, res); +} + +static GLboolean +test_VertexAttribs4fvNV(generic_func func) +{ + PFNGLVERTEXATTRIBS4FVNVPROC vertexAttribs4fvNV = (PFNGLVERTEXATTRIBS4FVNVPROC) func; + PFNGLGETVERTEXATTRIBFVNVPROC getVertexAttribfvNV = (PFNGLGETVERTEXATTRIBFVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvNV"); + + const GLfloat v[4] = {2.5, 4.25, 7.125, 5.0625}; + const GLfloat def[4] = {0, 0, 0, 1}; + GLfloat res[4]; + (*vertexAttribs4fvNV)(6, 1, v); + (*getVertexAttribfvNV)(6, GL_CURRENT_ATTRIB_NV, res); + (*vertexAttribs4fvNV)(6, 1, def); + return compare_floats(__FUNCTION__, 4, v, 4, res); +} + +static GLboolean +test_VertexAttribs4dvNV(generic_func func) +{ + PFNGLVERTEXATTRIBS4DVNVPROC vertexAttribs4dvNV = (PFNGLVERTEXATTRIBS4DVNVPROC) func; + PFNGLGETVERTEXATTRIBDVNVPROC getVertexAttribdvNV = (PFNGLGETVERTEXATTRIBDVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribdvNV"); + + const GLdouble v[4] = {2.5, 4.25, 7.125, 5.0625}; + const GLdouble def[4] = {0, 0, 0, 1}; + GLdouble res[4]; + (*vertexAttribs4dvNV)(6, 1, v); + (*getVertexAttribdvNV)(6, GL_CURRENT_ATTRIB_NV, res); + (*vertexAttribs4dvNV)(6, 1, def); + return compare_doubles(__FUNCTION__, 4, v, 4, res); +} + +static GLboolean +test_VertexAttribs4ubvNV(generic_func func) +{ + PFNGLVERTEXATTRIBS4UBVNVPROC vertexAttribs4ubvNV = (PFNGLVERTEXATTRIBS4UBVNVPROC) func; + PFNGLGETVERTEXATTRIBFVNVPROC getVertexAttribfvNV = (PFNGLGETVERTEXATTRIBFVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvNV"); + + const GLubyte v[4] = {255, 0, 255, 0}; + const GLubyte def[4] = {0, 0, 0, 255}; + GLfloat res[4]; + /* There's no byte-value query; so we use the float-value query. + * Bytes are interpreted as steps between 0 and 1, so the + * expected float values will be 0.0 for byte value 0 and 1.0 for + * byte value 255. + */ + GLfloat expectedResults[4] = {1.0, 0.0, 1.0, 0.0}; + (*vertexAttribs4ubvNV)(6, 1, v); + (*getVertexAttribfvNV)(6, GL_CURRENT_ATTRIB_NV, res); + (*vertexAttribs4ubvNV)(6, 1, def); + return compare_floats(__FUNCTION__, 4, expectedResults, 4, res); +} static GLboolean test_StencilFuncSeparateATI(generic_func func) @@ -387,17 +3507,32 @@ extension_supported(const char *haystack, const char *needle) } -static void +/* Run all the known extension function tests, if the extension is supported. + * Return a count of how many failed. + */ +static int check_functions( const char *extensions ) { struct name_test_pair *entry; - int failures = 0, passes = 0; - int totalFail = 0, totalPass = 0; + int failures = 0, passes = 0, untested = 0; + int totalFail = 0, totalPass = 0, totalUntested = 0, totalUnsupported = 0; int doTests; - + const char *version = (const char *) glGetString(GL_VERSION); + + /* The functions list will have "real" entries (consisting of + * a GL function name and a pointer to an exercise function for + * that GL function), and "group" entries (indicated as + * such by having a "-" as the first character of the name). + * "Group" names always start with the "-" character, and can + * be numeric (e.g. "-1.0", "-2.1"), indicating that a particular + * OpenGL version is required for the following functions; or can be + * an extension name (e.g. "-GL_ARB_multitexture") that means + * that the named extension is required for the following functions. + */ for (entry = functions; entry->name; entry++) { + /* Check if this is a group indicator */ if (entry->name[0] == '-') { - const char *version = (const char *) glGetString(GL_VERSION); + /* A group indicator; check if it's an OpenGL version group */ if (entry->name[1] == '1') { /* check GL version 1.x */ if (version[0] == '1' && @@ -419,14 +3554,27 @@ check_functions( const char *extensions ) /* check if the named extension is available */ doTests = extension_supported(extensions, entry->name+1); } + + /* doTests is now set if we're starting an OpenGL version + * group, and the running OpenGL version is at least the + * version required; or if we're starting an OpenGL extension + * group, and the extension is supported. + */ if (doTests) printf("Testing %s functions\n", entry->name + 1); - totalFail += failures; - totalPass += passes; + + /* Each time we hit a title function, reset the function + * counts. + */ failures = 0; passes = 0; + untested = 0; } else if (doTests) { + /* Here, we know we're trying to exercise a function for + * a supported extension. See whether we have a test for + * it, and try to run it. + */ generic_func funcPtr = (generic_func) glXGetProcAddressARB((const GLubyte *) entry->name); if (funcPtr) { if (entry->test) { @@ -436,21 +3584,36 @@ check_functions( const char *extensions ) if (b) { printf(" Pass\n"); passes++; + totalPass++; } else { printf(" FAIL!!!\n"); failures++; + totalFail++; } } else { - passes++; + untested++; + totalUntested++; } } else { printf(" glXGetProcAddress(%s) failed!\n", entry->name); failures++; + totalFail++; } } + else { + /* Here, we have a function that belongs to a group that + * is known to be unsupported. + */ + totalUnsupported++; + } + + /* Make sure a poor test case doesn't leave any lingering + * OpenGL errors. + */ + CheckGLError(__LINE__, __FILE__, __FUNCTION__); if (doTests && (!(entry+1)->name || (entry+1)->name[0] == '-')) { if (failures > 0) { @@ -459,18 +3622,29 @@ check_functions( const char *extensions ) if (passes > 0) { printf(" %d passed.\n", passes); } + if (untested > 0) { + printf(" %d untested.\n", untested); + } } } - totalFail += failures; - totalPass += passes; printf("-----------------------------\n"); - printf("Total: %d pass %d fail\n", totalPass, totalFail); + printf("Total: %d pass %d fail %d untested %d unsupported %d total\n", + totalPass, totalFail, totalUntested, totalUnsupported, + totalPass + totalFail + totalUntested + totalUnsupported); + + return totalFail; } +/* Return an error code */ +#define ERROR_NONE 0 +#define ERROR_NO_VISUAL 1 +#define ERROR_NO_CONTEXT 2 +#define ERROR_NO_MAKECURRENT 3 +#define ERROR_FAILED 4 -static void +static int print_screen_info(Display *dpy, int scrnum, Bool allowDirect) { Window win; @@ -496,6 +3670,7 @@ print_screen_info(Display *dpy, int scrnum, Bool allowDirect) GLXContext ctx; XVisualInfo *visinfo; int width = 100, height = 100; + int failures; root = RootWindow(dpy, scrnum); @@ -504,7 +3679,7 @@ print_screen_info(Display *dpy, int scrnum, Bool allowDirect) visinfo = glXChooseVisual(dpy, scrnum, attribDouble); if (!visinfo) { fprintf(stderr, "Error: couldn't find RGB GLX visual\n"); - return; + return ERROR_NO_VISUAL; } } @@ -521,26 +3696,29 @@ print_screen_info(Display *dpy, int scrnum, Bool allowDirect) if (!ctx) { fprintf(stderr, "Error: glXCreateContext failed\n"); XDestroyWindow(dpy, win); - return; + return ERROR_NO_CONTEXT; } - if (glXMakeCurrent(dpy, win, ctx)) { - check_functions( (const char *) glGetString(GL_EXTENSIONS) ); - } - else { + if (!glXMakeCurrent(dpy, win, ctx)) { fprintf(stderr, "Error: glXMakeCurrent failed\n"); + glXDestroyContext(dpy, ctx); + XDestroyWindow(dpy, win); + return ERROR_NO_MAKECURRENT; } + failures = check_functions( (const char *) glGetString(GL_EXTENSIONS) ); glXDestroyContext(dpy, ctx); XDestroyWindow(dpy, win); -} + return (failures == 0 ? ERROR_NONE : ERROR_FAILED); +} int main(int argc, char *argv[]) { char *displayName = NULL; Display *dpy; + int returnCode; dpy = XOpenDisplay(displayName); if (!dpy) { @@ -548,9 +3726,9 @@ main(int argc, char *argv[]) return -1; } - print_screen_info(dpy, 0, GL_TRUE); + returnCode = print_screen_info(dpy, 0, GL_TRUE); XCloseDisplay(dpy); - return 0; + return returnCode; } diff --git a/progs/tests/getprocaddress.py b/progs/tests/getprocaddress.py index 8adfc51bd6..699195bd48 100644 --- a/progs/tests/getprocaddress.py +++ b/progs/tests/getprocaddress.py @@ -52,7 +52,7 @@ static struct name_test_pair functions[] = {""" prev_category = None - for f in api.functionIterateByOffset(): + for f in api.functionIterateByCategory(): [category, num] = api.get_category_for_name( f.name ) if category != prev_category: print ' { "-%s", NULL},' % category diff --git a/progs/tests/getteximage.c b/progs/tests/getteximage.c new file mode 100644 index 0000000000..71f29b4ac8 --- /dev/null +++ b/progs/tests/getteximage.c @@ -0,0 +1,253 @@ +/** + * Test glGetTexImage() + * Brian Paul + * 9 June 2009 + */ + + +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <GL/glew.h> +#include <GL/glut.h> + +static int Win; + + +static void +TestGetTexImage(GLboolean npot) +{ + GLuint iter; + GLubyte *data = (GLubyte *) malloc(1024 * 1024 * 4); + GLubyte *data2 = (GLubyte *) malloc(1024 * 1024 * 4); + + glEnable(GL_TEXTURE_2D); + + printf("glTexImage2D + glGetTexImage:\n"); + + for (iter = 0; iter < 8; iter++) { + GLint p = (iter % 8) + 3; + GLint w = npot ? (p * 20) : (1 << p); + GLint h = npot ? (p * 10) : (1 << p); + GLuint i; + GLint level = 0; + + printf(" Testing %d x %d tex image\n", w, h); + + /* fill data */ + for (i = 0; i < w * h * 4; i++) { + data[i] = i & 0xff; + data2[i] = 0; + } + + glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, w, h, 0, + GL_RGBA, GL_UNSIGNED_BYTE, data); + + glBegin(GL_POINTS); + glVertex2f(0, 0); + glEnd(); + + /* get */ + glGetTexImage(GL_TEXTURE_2D, level, GL_RGBA, GL_UNSIGNED_BYTE, data2); + + /* compare */ + for (i = 0; i < w * h * 4; i++) { + if (data2[i] != data[i]) { + printf("glTexImage + glGetTexImage failure!\n"); + printf("Expected value %d, found %d\n", data[i], data2[i]); + abort(); + } + } + } + + printf("Passed\n"); + glDisable(GL_TEXTURE_2D); + free(data); + free(data2); +} + + +static GLboolean +ColorsEqual(const GLubyte ref[4], const GLubyte act[4]) +{ + if (abs((int) ref[0] - (int) act[0]) > 1 || + abs((int) ref[1] - (int) act[1]) > 1 || + abs((int) ref[2] - (int) act[2]) > 1 || + abs((int) ref[3] - (int) act[3]) > 1) { + printf("expected %d %d %d %d\n", ref[0], ref[1], ref[2], ref[3]); + printf("found %d %d %d %d\n", act[0], act[1], act[2], act[3]); + return GL_FALSE; + } + return GL_TRUE; +} + + +static void +TestGetTexImageRTT(GLboolean npot) +{ + GLuint iter; + + printf("Render to texture + glGetTexImage:\n"); + + for (iter = 0; iter < 8; iter++) { + + GLuint fb, tex; + GLint w, h; + GLint level = 0; + + if (npot) { + w = 200 + iter * 40; + h = 200 + iter * 12; + } + else { + w = 4 << iter; + h = 4 << iter; + } + + glGenTextures(1, &tex); + glGenFramebuffersEXT(1, &fb); + + glBindTexture(GL_TEXTURE_2D, tex); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, + GL_RGBA, GL_UNSIGNED_BYTE, NULL); + + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb); + glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, + GL_TEXTURE_2D, tex, level); + + glViewport(0, 0, w, h); + + printf(" Testing %d x %d tex image\n", w, h); + { + static const GLubyte blue[4] = {0, 0, 255, 255}; + GLubyte color[4]; + GLubyte *data2 = (GLubyte *) malloc(w * h * 4); + GLuint i; + + /* random clear color */ + for (i = 0; i < 4; i++) { + color[i] = rand() % 256; + } + + glClearColor(color[0] / 255.0, + color[1] / 255.0, + color[2] / 255.0, + color[3] / 255.0); + + glClear(GL_COLOR_BUFFER_BIT); + + /* draw polygon over top half, in blue */ + glColor4ubv(blue); + glRectf(0, 0.5, 1.0, 1.0); + + /* get */ + glGetTexImage(GL_TEXTURE_2D, level, GL_RGBA, GL_UNSIGNED_BYTE, data2); + + /* compare */ + for (i = 0; i < w * h; i += 4) { + if (i < w * h / 2) { + /* lower half */ + if (!ColorsEqual(color, data2 + i * 4)) { + printf("Render to texture failure (expected clear color)!\n"); + abort(); + } + } + else { + /* upper half */ + if (!ColorsEqual(blue, data2 + i * 4)) { + printf("Render to texture failure (expected blue)!\n"); + abort(); + } + } + } + + free(data2); + } + + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); + glDeleteFramebuffersEXT(1, &fb); + glDeleteTextures(1, &tex); + + } + + printf("Passed\n"); +} + + + + +static void +Draw(void) +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + TestGetTexImage(GL_FALSE); + if (glutExtensionSupported("GL_ARB_texture_non_power_of_two")) + TestGetTexImage(GL_TRUE); + + if (glutExtensionSupported("GL_EXT_framebuffer_object") || + glutExtensionSupported("GL_ARB_framebuffer_object")) { + TestGetTexImageRTT(GL_FALSE); + if (glutExtensionSupported("GL_ARB_texture_non_power_of_two")) + TestGetTexImageRTT(GL_TRUE); + } + + glutDestroyWindow(Win); + exit(0); + + glutSwapBuffers(); +} + + +static void +Reshape(int width, int height) +{ + glViewport(0, 0, width, height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(0, 1, 0, 1, -1, 1); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0.0, 0.0, 0.0); +} + + +static void +Key(unsigned char key, int x, int y) +{ + (void) x; + (void) y; + switch (key) { + case 27: + glutDestroyWindow(Win); + exit(0); + break; + } + glutPostRedisplay(); +} + + +static void +Init(void) +{ +} + + +int +main(int argc, char *argv[]) +{ + glutInit(&argc, argv); + glutInitWindowPosition(0, 0); + glutInitWindowSize(400, 400); + glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); + Win = glutCreateWindow(argv[0]); + glewInit(); + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutDisplayFunc(Draw); + Init(); + glutMainLoop(); + return 0; +} diff --git a/progs/tests/mapbufrange.c b/progs/tests/mapbufrange.c index 0021bb2607..76e02dd406 100644 --- a/progs/tests/mapbufrange.c +++ b/progs/tests/mapbufrange.c @@ -98,10 +98,10 @@ Draw(void) { glBindBufferARB(GL_ARRAY_BUFFER_ARB, BufferID); glVertexPointer(3, GL_FLOAT, 24, 0); - glEnable(GL_VERTEX_ARRAY); + glEnableClientState(GL_VERTEX_ARRAY); glColorPointer(3, GL_FLOAT, 24, (void*) 12); - glEnable(GL_COLOR_ARRAY); + glEnableClientState(GL_COLOR_ARRAY); glDrawArrays(GL_QUADS, 0, NumRects * 4); diff --git a/progs/tests/mapvbo.c b/progs/tests/mapvbo.c index c392e76835..52a22a5e79 100644 --- a/progs/tests/mapvbo.c +++ b/progs/tests/mapvbo.c @@ -54,10 +54,10 @@ Draw(void) glBindBufferARB(GL_ARRAY_BUFFER_ARB, BufferID); glVertexPointer(3, GL_FLOAT, 24, 0); - glEnable(GL_VERTEX_ARRAY); + glEnableClientState(GL_VERTEX_ARRAY); glColorPointer(3, GL_FLOAT, 24, (void*) 12); - glEnable(GL_COLOR_ARRAY); + glEnableClientState(GL_COLOR_ARRAY); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); diff --git a/progs/tests/persp_hint.c b/progs/tests/persp_hint.c new file mode 100644 index 0000000000..27140d1f56 --- /dev/null +++ b/progs/tests/persp_hint.c @@ -0,0 +1,149 @@ +/* + * Test the GL_PERSPECTIVE_CORRECTION_HINT setting and its effect on + * color interpolation. + * + * Press 'i' to toggle between GL_NICEST/GL_FASTEST/GL_DONT_CARE. + * + * Depending on the driver, the hint may make a difference, or not. + */ + + +#include <stdlib.h> +#include <stdio.h> +#include <GL/glut.h> + + +static GLenum PerspHint = GL_DONT_CARE; + + +static void +init(void) +{ + GLubyte image[256][256][4]; + GLuint i, j; + for (i = 0; i < 256; i++) { + for (j = 0; j < 256; j++) { + image[i][j][0] = j; + image[i][j][1] = j; + image[i][j][2] = j; + image[i][j][3] = 255; + } + } + glTexImage2D(GL_TEXTURE_2D, 0, 4, 256, 256, 0, + GL_RGBA, GL_UNSIGNED_BYTE, image); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); + + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); +} + + +static void +display(void) +{ + switch (PerspHint) { + case GL_NICEST: + printf("hint = GL_NICEST\n"); + break; + case GL_FASTEST: + printf("hint = GL_FASTEST\n"); + break; + case GL_DONT_CARE: + printf("hint = GL_DONT_CARE\n"); + break; + default: + ; + } + + glClear(GL_COLOR_BUFFER_BIT); + +#if 1 + glBegin(GL_QUADS); + /* exercise perspective interpolation */ + glColor3f(0.0, 0.0, 0.0); glVertex3f(-1.0, -1.0, -1.0); + glColor3f(0.0, 0.0, 0.0); glVertex3f(-1.0, 1.0, -1.0); + glColor3f(0.0, 1.0, 0.0); glVertex3f( 7.0, 1.0, -7.0); + glColor3f(0.0, 1.0, 0.0); glVertex3f( 7.0, -1.0, -7.0); + + /* stripe of linear interpolation */ + glColor3f(0.0, 0.0, 0.0); glVertex3f(-1.0, -0.1, -1.001); + glColor3f(0.0, 0.0, 0.0); glVertex3f(-1.0, 0.1, -1.001); + glColor3f(0.0, 1.0, 0.0); glVertex3f( 1.0, 0.1, -1.001); + glColor3f(0.0, 1.0, 0.0); glVertex3f( 1.0, -0.1, -1.001); + glEnd(); +#else + glEnable(GL_TEXTURE_2D); + glBegin(GL_QUADS); + glTexCoord2f(0.0, 0.0); glVertex3f(-1.0, 0.0, -1.0); + glTexCoord2f(0.0, 1.0); glVertex3f(-1.0, 1.0, -1.0); + glTexCoord2f(1.0, 1.0); glVertex3f( 5.0, 1.0, -7.0); + glTexCoord2f(1.0, 0.0); glVertex3f( 5.0, 0.0, -7.0); + + glTexCoord2f(0.0, 0.0); glVertex3f(-1.0, -1.0, -1.001); + glTexCoord2f(0.0, 1.0); glVertex3f(-1.0, 0.0, -1.001); + glTexCoord2f(1.0, 1.0); glVertex3f( 1.0, 0.0, -1.001); + glTexCoord2f(1.0, 0.0); glVertex3f( 1.0, -1.0, -1.001); + glEnd(); +#endif + + glFlush(); +} + + +static void +reshape(int w, int h) +{ + glViewport(0, 0, w, h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(90.0, (GLfloat) w / h, 1.0, 300.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + + +static void +key(unsigned char k, int x, int y) +{ + switch (k) { + case 27: /* Escape */ + exit(0); + break; + case 'i': + if (PerspHint == GL_FASTEST) + PerspHint = GL_NICEST; + else if (PerspHint == GL_NICEST) + PerspHint = GL_DONT_CARE; + else + PerspHint = GL_FASTEST; + glHint(GL_PERSPECTIVE_CORRECTION_HINT, PerspHint); + break; + default: + return; + } + glutPostRedisplay(); +} + + +int +main(int argc, char** argv) +{ + glutInit(&argc, argv); + glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); + glutInitWindowSize (500, 500); + glutCreateWindow (argv[0]); + glutReshapeFunc (reshape); + glutDisplayFunc(display); + glutKeyboardFunc(key); + + printf("Main quad: perspective projection\n"); + printf("Middle stripe: linear interpolation\n"); + printf("Press 'i' to toggle interpolation hint\n"); + init(); + + glutMainLoop(); + return 0; +} diff --git a/progs/tests/prim.c b/progs/tests/prim.c new file mode 100644 index 0000000000..3e006e823d --- /dev/null +++ b/progs/tests/prim.c @@ -0,0 +1,559 @@ +#define GL_GLEXT_PROTOTYPES +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <GL/glut.h> + + +#define PIXEL_CENTER(x) ((long)(x) + 0.5) + +#define GAP 10 +#define ROWS 3 +#define COLS 4 + +#define OPENGL_WIDTH 48 +#define OPENGL_HEIGHT 13 + + +GLenum provoking = GL_LAST_VERTEX_CONVENTION_EXT; +GLenum rgb, doubleBuffer, windType; +GLint windW, windH; + +GLenum mode1, mode2; +GLint boxW, boxH; +GLubyte OpenGL_bits[] = { + 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, + 0x7f, 0xfb, 0xff, 0xff, 0xff, 0x01, + 0x7f, 0xfb, 0xff, 0xff, 0xff, 0x01, + 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, + 0x3e, 0x8f, 0xb7, 0xf9, 0xfc, 0x01, + 0x63, 0xdb, 0xb0, 0x8d, 0x0d, 0x00, + 0x63, 0xdb, 0xb7, 0x8d, 0x0d, 0x00, + 0x63, 0xdb, 0xb6, 0x8d, 0x0d, 0x00, + 0x63, 0x8f, 0xf3, 0xcc, 0x0d, 0x00, + 0x63, 0x00, 0x00, 0x0c, 0x4c, 0x0a, + 0x63, 0x00, 0x00, 0x0c, 0x4c, 0x0e, + 0x63, 0x00, 0x00, 0x8c, 0xed, 0x0e, + 0x3e, 0x00, 0x00, 0xf8, 0x0c, 0x00, +}; + + +#include "tkmap.c" + +static void Init(void) +{ + + mode1 = GL_TRUE; + mode2 = GL_TRUE; +} + +static void Reshape(int width, int height) +{ + + windW = (GLint)width; + windH = (GLint)height; +} + +static void RotateColorMask(void) +{ + static GLint rotation = 0; + + rotation = (rotation + 1) & 0x3; + switch (rotation) { + case 0: + glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); + glIndexMask( 0xff ); + break; + case 1: + glColorMask(GL_FALSE, GL_TRUE, GL_TRUE, GL_TRUE); + glIndexMask(0xFE); + break; + case 2: + glColorMask(GL_TRUE, GL_FALSE, GL_TRUE, GL_TRUE); + glIndexMask(0xFD); + break; + case 3: + glColorMask(GL_TRUE, GL_TRUE, GL_FALSE, GL_TRUE); + glIndexMask(0xFB); + break; + } +} + +static void Key(unsigned char key, int x, int y) +{ + + switch (key) { + case 27: + exit(1); + case '1': + mode1 = !mode1; + break; + case '2': + mode2 = !mode2; + break; + case '3': + RotateColorMask(); + break; + case 'p': + if (provoking == GL_FIRST_VERTEX_CONVENTION_EXT) { + printf("provoke last\n"); + provoking = GL_LAST_VERTEX_CONVENTION_EXT; + } + else { + printf("provoke first\n"); + provoking = GL_FIRST_VERTEX_CONVENTION_EXT; + } + glProvokingVertexEXT(provoking); + break; + default: + return; + } + + glutPostRedisplay(); +} + +static void Viewport(GLint row, GLint column) +{ + GLint x, y; + + boxW = (windW - (COLS + 1) * GAP) / COLS; + boxH = (windH - (ROWS + 1) * GAP) / ROWS; + + x = GAP + column * (boxW + GAP); + y = GAP + row * (boxH + GAP); + + glViewport(x, y, boxW, boxH); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-boxW/2, boxW/2, -boxH/2, boxH/2, 0.0, 1.0); + glMatrixMode(GL_MODELVIEW); + + glEnable(GL_SCISSOR_TEST); + glScissor(x, y, boxW, boxH); +} + +static void Point(void) +{ + GLint i; + + glBegin(GL_POINTS); + SetColor(COLOR_WHITE); + glVertex2i(0, 0); + for (i = 1; i < 8; i++) { + GLint j = i * 2; + SetColor(COLOR_BLACK+i); + glVertex2i(-j, -j); + glVertex2i(-j, 0); + glVertex2i(-j, j); + glVertex2i(0, j); + glVertex2i(j, j); + glVertex2i(j, 0); + glVertex2i(j, -j); + glVertex2i(0, -j); + } + glEnd(); +} + +static void Lines(void) +{ + GLint i; + + glPushMatrix(); + + glTranslatef(-12, 0, 0); + for (i = 1; i < 8; i++) { + glBegin(GL_LINES); + SetColor(COLOR_BLACK+i); + glVertex2i(-boxW/4, -boxH/4); + SetColor(COLOR_BLACK+i+1); + glVertex2i(boxW/4, boxH/4); + glEnd(); + glTranslatef(4, 0, 0); + } + + glPopMatrix(); + + glBegin(GL_LINES); + glVertex2i(0, 0); + glEnd(); +} + +static void LineStrip(void) +{ + + glBegin(GL_LINE_STRIP); + SetColor(COLOR_RED); + glVertex2f(PIXEL_CENTER(-boxW/4), PIXEL_CENTER(-boxH/4)); + SetColor(COLOR_GREEN); + glVertex2f(PIXEL_CENTER(-boxW/4), PIXEL_CENTER(boxH/4)); + SetColor(COLOR_BLUE); + glVertex2f(PIXEL_CENTER(boxW/4), PIXEL_CENTER(boxH/4)); + SetColor(COLOR_WHITE); + glVertex2f(PIXEL_CENTER(boxW/4), PIXEL_CENTER(-boxH/4)); + glEnd(); + + glBegin(GL_LINE_STRIP); + glVertex2i(0, 0); + glEnd(); +} + +static void LineLoop(void) +{ + + glBegin(GL_LINE_LOOP); + SetColor(COLOR_RED); + glVertex2f(PIXEL_CENTER(-boxW/4), PIXEL_CENTER(-boxH/4)); + SetColor(COLOR_GREEN); + glVertex2f(PIXEL_CENTER(-boxW/4), PIXEL_CENTER(boxH/4)); + SetColor(COLOR_BLUE); + glVertex2f(PIXEL_CENTER(boxW/4), PIXEL_CENTER(boxH/4)); + SetColor(COLOR_WHITE); + glVertex2f(PIXEL_CENTER(boxW/4), PIXEL_CENTER(-boxH/4)); + glEnd(); + + glEnable(GL_LOGIC_OP); + glLogicOp(GL_XOR); + + glEnable(GL_BLEND); + glBlendFunc(GL_ONE, GL_ONE); + + SetColor(COLOR_MAGENTA); + glBegin(GL_LINE_LOOP); + glVertex2f(PIXEL_CENTER(-boxW/8), PIXEL_CENTER(-boxH/8)); + glVertex2f(PIXEL_CENTER(-boxW/8), PIXEL_CENTER(boxH/8)); + glEnd(); + glBegin(GL_LINE_LOOP); + glVertex2f(PIXEL_CENTER(-boxW/8), PIXEL_CENTER(boxH/8+5)); + glVertex2f(PIXEL_CENTER(boxW/8), PIXEL_CENTER(boxH/8+5)); + glEnd(); + glDisable(GL_LOGIC_OP); + glDisable(GL_BLEND); + + SetColor(COLOR_GREEN); + glBegin(GL_POINTS); + glVertex2i(0, 0); + glEnd(); + + glBegin(GL_LINE_LOOP); + glVertex2i(0, 0); + glEnd(); +} + +static void Bitmap(void) +{ + + glBegin(GL_LINES); + SetColor(COLOR_GREEN); + glVertex2i(-boxW/2, 0); + glVertex2i(boxW/2, 0); + glVertex2i(0, -boxH/2); + glVertex2i(0, boxH/2); + SetColor(COLOR_RED); + glVertex2i(0, -3); + glVertex2i(0, -3+OPENGL_HEIGHT); + SetColor(COLOR_BLUE); + glVertex2i(0, -3); + glVertex2i(OPENGL_WIDTH, -3); + glEnd(); + + SetColor(COLOR_GREEN); + + glPixelStorei(GL_UNPACK_LSB_FIRST, GL_TRUE); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + + glRasterPos2i(0, 0); + glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, 0, 3, 0.0, 0.0, OpenGL_bits); +} + +static void Triangles(void) +{ + + glBegin(GL_TRIANGLES); + SetColor(COLOR_GREEN); + glVertex2i(-boxW/4, -boxH/4); + SetColor(COLOR_RED); + glVertex2i(-boxW/8, -boxH/16); + SetColor(COLOR_BLUE); + glVertex2i(boxW/8, -boxH/16); + + SetColor(COLOR_GREEN); + glVertex2i(-boxW/4, boxH/4); + SetColor(COLOR_RED); + glVertex2i(-boxW/8, boxH/16); + SetColor(COLOR_BLUE); + glVertex2i(boxW/8, boxH/16); + glEnd(); + + glBegin(GL_TRIANGLES); + glVertex2i(0, 0); + glVertex2i(-100, 100); + glEnd(); +} + +static void TriangleStrip(void) +{ + + glBegin(GL_TRIANGLE_STRIP); + SetColor(COLOR_GREEN); + glVertex2i(-boxW/4, -boxH/4); + SetColor(COLOR_RED); + glVertex2i(-boxW/4, boxH/4); + SetColor(COLOR_BLUE); + glVertex2i(0, -boxH/4); + SetColor(COLOR_WHITE); + glVertex2i(0, boxH/4); + SetColor(COLOR_CYAN); + glVertex2i(boxW/4, -boxH/4); + SetColor(COLOR_YELLOW); + glVertex2i(boxW/4, boxH/4); + glEnd(); + + glBegin(GL_TRIANGLE_STRIP); + glVertex2i(0, 0); + glVertex2i(-100, 100); + glEnd(); +} + +static void TriangleFan(void) +{ + GLint vx[8][2]; + GLint x0, y0, x1, y1, x2, y2, x3, y3; + GLint i; + + y0 = -boxH/4; + y1 = y0 + boxH/2/3; + y2 = y1 + boxH/2/3; + y3 = boxH/4; + x0 = -boxW/4; + x1 = x0 + boxW/2/3; + x2 = x1 + boxW/2/3; + x3 = boxW/4; + + vx[0][0] = x0; vx[0][1] = y1; + vx[1][0] = x0; vx[1][1] = y2; + vx[2][0] = x1; vx[2][1] = y3; + vx[3][0] = x2; vx[3][1] = y3; + vx[4][0] = x3; vx[4][1] = y2; + vx[5][0] = x3; vx[5][1] = y1; + vx[6][0] = x2; vx[6][1] = y0; + vx[7][0] = x1; vx[7][1] = y0; + + glBegin(GL_TRIANGLE_FAN); + SetColor(COLOR_WHITE); + glVertex2i(0, 0); + for (i = 0; i < 8; i++) { + SetColor(COLOR_WHITE-i); + glVertex2iv(vx[i]); + } + glEnd(); + + glBegin(GL_TRIANGLE_FAN); + glVertex2i(0, 0); + glVertex2i(-100, 100); + glEnd(); +} + +static void Rect(void) +{ + + SetColor(COLOR_GREEN); + glRecti(-boxW/4, -boxH/4, boxW/4, boxH/4); +} + +static void PolygonFunc(void) +{ + GLint vx[8][2]; + GLint x0, y0, x1, y1, x2, y2, x3, y3; + GLint i; + + y0 = -boxH/4; + y1 = y0 + boxH/2/3; + y2 = y1 + boxH/2/3; + y3 = boxH/4; + x0 = -boxW/4; + x1 = x0 + boxW/2/3; + x2 = x1 + boxW/2/3; + x3 = boxW/4; + + vx[0][0] = x0; vx[0][1] = y1; + vx[1][0] = x0; vx[1][1] = y2; + vx[2][0] = x1; vx[2][1] = y3; + vx[3][0] = x2; vx[3][1] = y3; + vx[4][0] = x3; vx[4][1] = y2; + vx[5][0] = x3; vx[5][1] = y1; + vx[6][0] = x2; vx[6][1] = y0; + vx[7][0] = x1; vx[7][1] = y0; + + glBegin(GL_POLYGON); + for (i = 0; i < 8; i++) { + SetColor(COLOR_WHITE-i); + glVertex2iv(vx[i]); + } + glEnd(); + + glBegin(GL_POLYGON); + glVertex2i(0, 0); + glVertex2i(100, 100); + glEnd(); +} + +static void Quads(void) +{ + + glBegin(GL_QUADS); + SetColor(COLOR_GREEN); + glVertex2i(-boxW/4, -boxH/4); + SetColor(COLOR_RED); + glVertex2i(-boxW/8, -boxH/16); + SetColor(COLOR_BLUE); + glVertex2i(boxW/8, -boxH/16); + SetColor(COLOR_WHITE); + glVertex2i(boxW/4, -boxH/4); + + SetColor(COLOR_GREEN); + glVertex2i(-boxW/4, boxH/4); + SetColor(COLOR_RED); + glVertex2i(-boxW/8, boxH/16); + SetColor(COLOR_BLUE); + glVertex2i(boxW/8, boxH/16); + SetColor(COLOR_WHITE); + glVertex2i(boxW/4, boxH/4); + glEnd(); + + glBegin(GL_QUADS); + glVertex2i(0, 0); + glVertex2i(100, 100); + glVertex2i(-100, 100); + glEnd(); +} + +static void QuadStrip(void) +{ + + glBegin(GL_QUAD_STRIP); + SetColor(COLOR_GREEN); + glVertex2i(-boxW/4, -boxH/4); + SetColor(COLOR_RED); + glVertex2i(-boxW/4, boxH/4); + SetColor(COLOR_BLUE); + glVertex2i(0, -boxH/4); + SetColor(COLOR_WHITE); + glVertex2i(0, boxH/4); + SetColor(COLOR_CYAN); + glVertex2i(boxW/4, -boxH/4); + SetColor(COLOR_YELLOW); + glVertex2i(boxW/4, boxH/4); + glEnd(); + + glBegin(GL_QUAD_STRIP); + glVertex2i(0, 0); + glVertex2i(100, 100); + glVertex2i(-100, 100); + glEnd(); +} + +static void Draw(void) +{ + + glViewport(0, 0, windW, windH); + glDisable(GL_SCISSOR_TEST); + + glPushAttrib(GL_COLOR_BUFFER_BIT); + + glColorMask(1, 1, 1, 1); + glIndexMask(~0); + + glClearColor(0.0, 0.0, 0.0, 0.0); + glClear(GL_COLOR_BUFFER_BIT); + + glPopAttrib(); + + if (mode1) { + glShadeModel(GL_SMOOTH); + } else { + glShadeModel(GL_FLAT); + } + + if (mode2) { + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + } else { + glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + } + + Viewport(0, 0); Point(); + Viewport(0, 1); Lines(); + Viewport(0, 2); LineStrip(); + Viewport(0, 3); LineLoop(); + + Viewport(1, 0); Bitmap(); + Viewport(1, 1); TriangleFan(); + Viewport(1, 2); Triangles(); + Viewport(1, 3); TriangleStrip(); + + Viewport(2, 0); Rect(); + Viewport(2, 1); PolygonFunc(); + Viewport(2, 2); Quads(); + Viewport(2, 3); QuadStrip(); + + glFlush(); + + if (doubleBuffer) { + glutSwapBuffers(); + } +} + +static GLenum Args(int argc, char **argv) +{ + GLint i; + + rgb = GL_TRUE; + doubleBuffer = GL_FALSE; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-ci") == 0) { + rgb = GL_FALSE; + } else if (strcmp(argv[i], "-rgb") == 0) { + rgb = GL_TRUE; + } else if (strcmp(argv[i], "-sb") == 0) { + doubleBuffer = GL_FALSE; + } else if (strcmp(argv[i], "-db") == 0) { + doubleBuffer = GL_TRUE; + } else { + printf("%s (Bad option).\n", argv[i]); + return GL_FALSE; + } + } + return GL_TRUE; +} + +int main(int argc, char **argv) +{ + glutInit(&argc, argv); + + if (Args(argc, argv) == GL_FALSE) { + exit(1); + } + + windW = 600; + windH = 300; + glutInitWindowPosition(0, 0); glutInitWindowSize( windW, windH); + + windType = (rgb) ? GLUT_RGB : GLUT_INDEX; + windType |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; + glutInitDisplayMode(windType); + + if (glutCreateWindow("Primitive Test") == GL_FALSE) { + exit(1); + } + + InitMap(); + + Init(); + + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutDisplayFunc(Draw); + glutMainLoop(); + return 0; +} diff --git a/progs/tests/texcompsub.c b/progs/tests/texcompsub.c index 79a5f958a1..50106bf1e2 100644 --- a/progs/tests/texcompsub.c +++ b/progs/tests/texcompsub.c @@ -6,6 +6,7 @@ #include <assert.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <GL/glew.h> #include <GL/glut.h> @@ -31,6 +32,8 @@ CheckError(int line) static void LoadCompressedImage(void) { + unsigned char ImgDataTemp[ImgSize / 4]; + unsigned i; const GLenum filter = GL_LINEAR; glTexImage2D(Target, 0, CompFormat, ImgWidth, ImgHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); @@ -40,11 +43,24 @@ LoadCompressedImage(void) 0, 0, /* pos */ ImgWidth, ImgHeight / 2, CompFormat, ImgSize / 2, ImgData + ImgSize / 2); - /* top half */ + + /* top left */ + for (i = 0; i < ImgHeight / 8; i++) { + memcpy(&ImgDataTemp[i * ImgWidth], &ImgData[i * 2 * ImgWidth], ImgWidth); + } glCompressedTexSubImage2DARB(Target, 0, 0, ImgHeight / 2, /* pos */ - ImgWidth, ImgHeight / 2, - CompFormat, ImgSize / 2, ImgData); + ImgWidth / 2, ImgHeight / 2, + CompFormat, ImgSize / 4, ImgDataTemp); + + /* top right */ + for (i = 0; i < ImgHeight / 8; i++) { + memcpy(&ImgDataTemp[i * ImgWidth], &ImgData[i * 2 * ImgWidth + ImgWidth], ImgWidth); + } + glCompressedTexSubImage2DARB(Target, 0, + ImgWidth / 2, ImgHeight / 2, /* pos */ + ImgWidth / 2, ImgHeight / 2, + CompFormat, ImgSize / 4, ImgDataTemp); glTexParameteri(Target, GL_TEXTURE_MIN_FILTER, filter); glTexParameteri(Target, GL_TEXTURE_MAG_FILTER, filter); diff --git a/progs/tests/tkmap.c b/progs/tests/tkmap.c new file mode 100644 index 0000000000..3ded79caca --- /dev/null +++ b/progs/tests/tkmap.c @@ -0,0 +1,71 @@ + +enum { + COLOR_BLACK = 0, + COLOR_RED, + COLOR_GREEN, + COLOR_YELLOW, + COLOR_BLUE, + COLOR_MAGENTA, + COLOR_CYAN, + COLOR_WHITE +}; + +static float RGBMap[9][3] = { + {0, 0, 0}, + {1, 0, 0}, + {0, 1, 0}, + {1, 1, 0}, + {0, 0, 1}, + {1, 0, 1}, + {0, 1, 1}, + {1, 1, 1}, + {0.5, 0.5, 0.5} +}; + +static void SetColor(int c) +{ + if (glutGet(GLUT_WINDOW_RGBA)) + glColor3fv(RGBMap[c]); + else + glIndexf(c); +} + +static void InitMap(void) +{ + int i; + + if (rgb) + return; + + for (i = 0; i < 9; i++) + glutSetColor(i, RGBMap[i][0], RGBMap[i][1], RGBMap[i][2]); +} + +static void SetFogRamp(int density, int startIndex) +{ + int fogValues, colorValues; + int i, j, k; + float intensity; + + fogValues = 1 << density; + colorValues = 1 << startIndex; + for (i = 0; i < colorValues; i++) { + for (j = 0; j < fogValues; j++) { + k = i * fogValues + j; + intensity = (i * fogValues + j * colorValues) / 255.0; + glutSetColor(k, intensity, intensity, intensity); + } + } +} + +static void SetGreyRamp(void) +{ + int i; + float intensity; + + for (i = 0; i < 255; i++) { + intensity = i / 255.0; + glutSetColor(i, intensity, intensity, intensity); + } +} + diff --git a/progs/trivial/.gitignore b/progs/trivial/.gitignore index 348431478d..4d6e405c50 100644 --- a/progs/trivial/.gitignore +++ b/progs/trivial/.gitignore @@ -26,6 +26,7 @@ fs-tri line line-clip line-cull +line-flat line-smooth line-stipple-wide line-userclip @@ -145,6 +146,7 @@ tristrip-flat vbo-drawarrays vbo-drawelements vbo-drawrange +vbo-noninterleaved vp-array vp-array-int vp-clip @@ -154,6 +156,7 @@ vp-tri-cb vp-tri-cb-pos vp-tri-cb-tex vp-tri-imm +vp-tri-invariant vp-tri-swap vp-tri-tex vp-unfilled diff --git a/progs/util/extfuncs.h b/progs/util/extfuncs.h index 0469e2f2c4..2bb57030a8 100644 --- a/progs/util/extfuncs.h +++ b/progs/util/extfuncs.h @@ -137,7 +137,6 @@ static PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC glRenderbufferStorageMultisample_ static PFNGLFRAMEBUFFERTEXTURELAYERPROC glFramebufferTextureLayer_func = NULL; - static void GetExtensionFuncs(void) { diff --git a/progs/util/shaderutil.c b/progs/util/shaderutil.c index 13b68d90e0..489e71cc30 100644 --- a/progs/util/shaderutil.c +++ b/progs/util/shaderutil.c @@ -9,21 +9,12 @@ #include <assert.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <GL/glew.h> #include <GL/glut.h> #include "shaderutil.h" -static void -Init(void) -{ - static GLboolean firstCall = GL_TRUE; - if (firstCall) { - firstCall = GL_FALSE; - } -} - - GLboolean ShadersSupported(void) { @@ -47,8 +38,6 @@ CompileShaderText(GLenum shaderType, const char *text) GLuint shader; GLint stat; - Init(); - shader = glCreateShader(shaderType); glShaderSource(shader, 1, (const GLchar **) &text, NULL); glCompileShader(shader); @@ -79,9 +68,6 @@ CompileShaderFile(GLenum shaderType, const char *filename) GLuint shader; FILE *f; - Init(); - - f = fopen(filename, "r"); if (!f) { fprintf(stderr, "Unable to open shader file %s\n", filename); @@ -136,7 +122,7 @@ LinkShaders(GLuint vertShader, GLuint fragShader) void -InitUniforms(GLuint program, struct uniform_info uniforms[]) +SetUniformValues(GLuint program, struct uniform_info uniforms[]) { GLuint i; @@ -144,28 +130,133 @@ InitUniforms(GLuint program, struct uniform_info uniforms[]) uniforms[i].location = glGetUniformLocation(program, uniforms[i].name); - printf("Uniform %s location: %d\n", uniforms[i].name, - uniforms[i].location); - - switch (uniforms[i].size) { - case 1: - if (uniforms[i].type == GL_INT) - glUniform1i(uniforms[i].location, - (GLint) uniforms[i].value[0]); - else - glUniform1fv(uniforms[i].location, 1, uniforms[i].value); + switch (uniforms[i].type) { + case GL_INT: + case GL_SAMPLER_1D: + case GL_SAMPLER_2D: + case GL_SAMPLER_3D: + case GL_SAMPLER_CUBE: + case GL_SAMPLER_2D_RECT_ARB: + glUniform1i(uniforms[i].location, + (GLint) uniforms[i].value[0]); + break; + case GL_FLOAT: + glUniform1fv(uniforms[i].location, 1, uniforms[i].value); break; - case 2: + case GL_FLOAT_VEC2: glUniform2fv(uniforms[i].location, 1, uniforms[i].value); break; - case 3: + case GL_FLOAT_VEC3: glUniform3fv(uniforms[i].location, 1, uniforms[i].value); break; - case 4: + case GL_FLOAT_VEC4: glUniform4fv(uniforms[i].location, 1, uniforms[i].value); break; default: - abort(); + if (strncmp(uniforms[i].name, "gl_", 3) == 0) { + /* built-in uniform: ignore */ + } + else { + fprintf(stderr, + "Unexpected uniform data type in SetUniformValues\n"); + abort(); + } } } } + + +/** Get list of uniforms used in the program */ +GLuint +GetUniforms(GLuint program, struct uniform_info uniforms[]) +{ + GLint n, max, i; + + glGetProgramiv(program, GL_ACTIVE_UNIFORMS, &n); + glGetProgramiv(program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &max); + + for (i = 0; i < n; i++) { + GLint size, len; + GLenum type; + char name[100]; + + glGetActiveUniform(program, i, 100, &len, &size, &type, name); + + uniforms[i].name = strdup(name); + uniforms[i].size = size; + uniforms[i].type = type; + uniforms[i].location = glGetUniformLocation(program, name); + } + + uniforms[i].name = NULL; /* end of list */ + + return n; +} + + +void +PrintUniforms(const struct uniform_info uniforms[]) +{ + GLint i; + + printf("Uniforms:\n"); + + for (i = 0; uniforms[i].name; i++) { + printf(" %d: %s size=%d type=0x%x loc=%d value=%g, %g, %g, %g\n", + i, + uniforms[i].name, + uniforms[i].size, + uniforms[i].type, + uniforms[i].location, + uniforms[i].value[0], + uniforms[i].value[1], + uniforms[i].value[2], + uniforms[i].value[3]); + } +} + + +/** Get list of attribs used in the program */ +GLuint +GetAttribs(GLuint program, struct attrib_info attribs[]) +{ + GLint n, max, i; + + glGetProgramiv(program, GL_ACTIVE_ATTRIBUTES, &n); + glGetProgramiv(program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &max); + + for (i = 0; i < n; i++) { + GLint size, len; + GLenum type; + char name[100]; + + glGetActiveAttrib(program, i, 100, &len, &size, &type, name); + + attribs[i].name = strdup(name); + attribs[i].size = size; + attribs[i].type = type; + attribs[i].location = glGetAttribLocation(program, name); + } + + attribs[i].name = NULL; /* end of list */ + + return n; +} + + +void +PrintAttribs(const struct attrib_info attribs[]) +{ + GLint i; + + printf("Attribs:\n"); + + for (i = 0; attribs[i].name; i++) { + printf(" %d: %s size=%d type=0x%x loc=%d\n", + i, + attribs[i].name, + attribs[i].size, + attribs[i].type, + attribs[i].location); + } +} diff --git a/progs/util/shaderutil.h b/progs/util/shaderutil.h index cfb8c1f3b0..0a6be02675 100644 --- a/progs/util/shaderutil.h +++ b/progs/util/shaderutil.h @@ -6,8 +6,8 @@ struct uniform_info { const char *name; - GLuint size; - GLenum type; /**< GL_FLOAT or GL_INT */ + GLuint size; /**< number of value[] elements: 1, 2, 3 or 4 */ + GLenum type; /**< GL_FLOAT, GL_FLOAT_VEC4, GL_INT, etc */ GLfloat value[4]; GLint location; /**< filled in by InitUniforms() */ }; @@ -15,6 +15,15 @@ struct uniform_info #define END_OF_UNIFORMS { NULL, 0, GL_NONE, { 0, 0, 0, 0 }, -1 } +struct attrib_info +{ + const char *name; + GLuint size; /**< number of value[] elements: 1, 2, 3 or 4 */ + GLenum type; /**< GL_FLOAT, GL_FLOAT_VEC4, GL_INT, etc */ + GLint location; +}; + + extern GLboolean ShadersSupported(void); @@ -28,7 +37,18 @@ extern GLuint LinkShaders(GLuint vertShader, GLuint fragShader); extern void -InitUniforms(GLuint program, struct uniform_info uniforms[]); +SetUniformValues(GLuint program, struct uniform_info uniforms[]); + +extern GLuint +GetUniforms(GLuint program, struct uniform_info uniforms[]); + +extern void +PrintUniforms(const struct uniform_info uniforms[]); +extern GLuint +GetAttribs(GLuint program, struct attrib_info attribs[]); + +extern void +PrintAttribs(const struct attrib_info attribs[]); #endif /* SHADER_UTIL_H */ diff --git a/progs/vp/arl-static.txt b/progs/vp/arl-static.txt index aea87b79a4..83aebf689e 100644 --- a/progs/vp/arl-static.txt +++ b/progs/vp/arl-static.txt @@ -1,5 +1,5 @@ !!ARBvp1.0 -PARAM arr[5] = { {.0,.1,.2,.3}, {.4,.5,.6,.7}, {.8,.9,.10,.1}, {.12,.3,.4,.14}, {.5,.8,.1,.9}, {.2,0,.4,.1}, {.6,.1,.8,.9}}; +PARAM arr[7] = { {.0,.1,.2,.3}, {.4,.5,.6,.7}, {.8,.9,.10,.1}, {.12,.3,.4,.14}, {.5,.8,.1,.9}, {.2,0,.4,.1}, {.6,.1,.8,.9}}; ADDRESS addr; ARL addr.x, {3}.x; MOV result.color, arr[addr.x]; diff --git a/progs/vp/arl-unused.txt b/progs/vp/arl-unused.txt index 7bdbb8e86c..c2afe3c092 100644 --- a/progs/vp/arl-unused.txt +++ b/progs/vp/arl-unused.txt @@ -1,5 +1,5 @@ !!ARBvp1.0 -PARAM arr[5] = { {.0,.1,.2,.3}, {.4,.5,.6,.7}, {.8,.9,.10,.1}, {.12,.3,.4,.14}, {.5,.8,.1,.9}, {.2,0,.4,.1}, {.6,.1,.8,.9}}; +PARAM arr[7] = { {.0,.1,.2,.3}, {.4,.5,.6,.7}, {.8,.9,.10,.1}, {.12,.3,.4,.14}, {.5,.8,.1,.9}, {.2,0,.4,.1}, {.6,.1,.8,.9}}; ADDRESS addr; ARL addr.x, {3}.x; # not actually used MOV result.color, arr[3]; diff --git a/progs/xdemos/Makefile b/progs/xdemos/Makefile index 6581df8039..53e1c54ef3 100644 --- a/progs/xdemos/Makefile +++ b/progs/xdemos/Makefile @@ -26,6 +26,7 @@ PROGS = \ glxsnoop \ glxswapcontrol \ manywin \ + multictx \ offset \ overlay \ pbinfo \ diff --git a/progs/xdemos/glxgears.c b/progs/xdemos/glxgears.c index bc84ee3dbd..088f25a357 100644 --- a/progs/xdemos/glxgears.c +++ b/progs/xdemos/glxgears.c @@ -23,10 +23,7 @@ * This is a port of the infamous "gears" demo to straight GLX (i.e. no GLUT) * Port by Brian Paul 23 March 2001 * - * Command line options: - * -info print GL implementation information - * -stereo use stereo enabled GLX visual - * + * See usage() below for command line options. */ @@ -45,10 +42,6 @@ typedef int (*PFNGLXGETSWAPINTERVALMESAPROC)(void); #endif -static int is_glx_extension_supported(Display *dpy, const char *query); - -static void query_vsync(Display *dpy); - #define BENCHMARK #ifdef BENCHMARK @@ -572,7 +565,7 @@ make_window( Display *dpy, const char *name, /** * Determine whether or not a GLX extension is supported. */ -int +static int is_glx_extension_supported(Display *dpy, const char *query) { const int scrnum = DefaultScreen(dpy); @@ -592,7 +585,7 @@ is_glx_extension_supported(Display *dpy, const char *query) /** * Attempt to determine whether or not the display is synched to vblank. */ -void +static void query_vsync(Display *dpy) { int interval = 0; diff --git a/progs/xdemos/glxswapcontrol.c b/progs/xdemos/glxswapcontrol.c index 8cdd560207..cd60d460a0 100644 --- a/progs/xdemos/glxswapcontrol.c +++ b/progs/xdemos/glxswapcontrol.c @@ -303,13 +303,13 @@ draw(void) glDisable(GL_LIGHTING); glShadeModel(GL_SMOOTH); - glEnable( GL_VERTEX_ARRAY ); - glEnable( GL_COLOR_ARRAY ); + glEnableClientState( GL_VERTEX_ARRAY ); + glEnableClientState( GL_COLOR_ARRAY ); glVertexPointer( 3, GL_FLOAT, 0, vert ); glColorPointer( 3, GL_FLOAT, 0, col ); glDrawArrays( GL_POLYGON, 0, 4 ); - glDisable( GL_COLOR_ARRAY ); - glDisable( GL_VERTEX_ARRAY ); + glDisableClientState( GL_COLOR_ARRAY ); + glDisableClientState( GL_VERTEX_ARRAY ); glMatrixMode(GL_PROJECTION); glLoadIdentity(); diff --git a/progs/xdemos/multictx.c b/progs/xdemos/multictx.c new file mode 100644 index 0000000000..75255b2860 --- /dev/null +++ b/progs/xdemos/multictx.c @@ -0,0 +1,585 @@ +/* + * Copyright (C) 2009 VMware, Inc. 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. + */ + +/* + * Test rendering with two contexts into one window. + * Setup different rendering state for each context to check that + * context switching is handled properly. + * + * Brian Paul + * 6 Aug 2009 + */ + + +#include <math.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <sys/time.h> +#include <unistd.h> +#include <X11/Xlib.h> +#include <X11/keysym.h> +#include <GL/gl.h> +#include <GL/glx.h> + + + +#ifndef M_PI +#define M_PI 3.14159265 +#endif + + +/** Event handler results: */ +#define NOP 0 +#define EXIT 1 +#define DRAW 2 + +static GLfloat view_rotx = 0.0, view_roty = 210.0, view_rotz = 0.0; +static GLint gear1, gear2; +static GLfloat angle = 0.0; + +static GLboolean animate = GL_TRUE; /* Animation */ + + +static double +current_time(void) +{ + struct timeval tv; +#ifdef __VMS + (void) gettimeofday(&tv, NULL ); +#else + struct timezone tz; + (void) gettimeofday(&tv, &tz); +#endif + return (double) tv.tv_sec + tv.tv_usec / 1000000.0; +} + + +/* + * + * Draw a gear wheel. You'll probably want to call this function when + * building a display list since we do a lot of trig here. + * + * Input: inner_radius - radius of hole at center + * outer_radius - radius at center of teeth + * width - width of gear + * teeth - number of teeth + * tooth_depth - depth of tooth + */ +static void +gear(GLfloat inner_radius, GLfloat outer_radius, GLfloat width, + GLint teeth, GLfloat tooth_depth) +{ + GLint i; + GLfloat r0, r1, r2; + GLfloat angle, da; + GLfloat u, v, len; + + r0 = inner_radius; + r1 = outer_radius - tooth_depth / 2.0; + r2 = outer_radius + tooth_depth / 2.0; + + da = 2.0 * M_PI / teeth / 4.0; + + glShadeModel(GL_FLAT); + + glNormal3f(0.0, 0.0, 1.0); + + /* draw front face */ + glBegin(GL_QUAD_STRIP); + for (i = 0; i <= teeth; i++) { + angle = i * 2.0 * M_PI / teeth; + glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5); + glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5); + if (i < teeth) { + glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5); + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), + width * 0.5); + } + } + glEnd(); + + /* draw front sides of teeth */ + glBegin(GL_QUADS); + da = 2.0 * M_PI / teeth / 4.0; + for (i = 0; i < teeth; i++) { + angle = i * 2.0 * M_PI / teeth; + + glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5); + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5); + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), + width * 0.5); + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), + width * 0.5); + } + glEnd(); + + glNormal3f(0.0, 0.0, -1.0); + + /* draw back face */ + glBegin(GL_QUAD_STRIP); + for (i = 0; i <= teeth; i++) { + angle = i * 2.0 * M_PI / teeth; + glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5); + glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5); + if (i < teeth) { + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), + -width * 0.5); + glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5); + } + } + glEnd(); + + /* draw back sides of teeth */ + glBegin(GL_QUADS); + da = 2.0 * M_PI / teeth / 4.0; + for (i = 0; i < teeth; i++) { + angle = i * 2.0 * M_PI / teeth; + + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), + -width * 0.5); + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), + -width * 0.5); + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5); + glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5); + } + glEnd(); + + /* draw outward faces of teeth */ + glBegin(GL_QUAD_STRIP); + for (i = 0; i < teeth; i++) { + angle = i * 2.0 * M_PI / teeth; + + glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5); + glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5); + u = r2 * cos(angle + da) - r1 * cos(angle); + v = r2 * sin(angle + da) - r1 * sin(angle); + len = sqrt(u * u + v * v); + u /= len; + v /= len; + glNormal3f(v, -u, 0.0); + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5); + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5); + glNormal3f(cos(angle), sin(angle), 0.0); + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), + width * 0.5); + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), + -width * 0.5); + u = r1 * cos(angle + 3 * da) - r2 * cos(angle + 2 * da); + v = r1 * sin(angle + 3 * da) - r2 * sin(angle + 2 * da); + glNormal3f(v, -u, 0.0); + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), + width * 0.5); + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), + -width * 0.5); + glNormal3f(cos(angle), sin(angle), 0.0); + } + + glVertex3f(r1 * cos(0), r1 * sin(0), width * 0.5); + glVertex3f(r1 * cos(0), r1 * sin(0), -width * 0.5); + + glEnd(); + + glShadeModel(GL_SMOOTH); + + /* draw inside radius cylinder */ + glBegin(GL_QUAD_STRIP); + for (i = 0; i <= teeth; i++) { + angle = i * 2.0 * M_PI / teeth; + glNormal3f(-cos(angle), -sin(angle), 0.0); + glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5); + glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5); + } + glEnd(); +} + + +static void +draw(int ctx) +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glPushMatrix(); + glRotatef(view_rotx, 1.0, 0.0, 0.0); + glRotatef(view_roty + angle, 0.0, 1.0, 0.0); + glRotatef(view_rotz, 0.0, 0.0, 1.0); + + if (ctx == 0) { + glDisable(GL_CULL_FACE); + glPushMatrix(); + glRotatef(angle, 0.0, 0.0, 1.0); + glCallList(gear1); + glPopMatrix(); + /* This should not effect the other context's rendering */ + glEnable(GL_CULL_FACE); + glCullFace(GL_FRONT_AND_BACK); + } + else { + glPushMatrix(); + glRotatef(-2.0 * angle - 9.0, 0.0, 0.0, 1.0); + glCallList(gear2); + glPopMatrix(); + } + + glPopMatrix(); + + /* this flush is important since we'll be switching contexts next */ + glFlush(); +} + + + +static void +draw_frame(Display *dpy, Window win, GLXContext ctx1, GLXContext ctx2) +{ + static double tRot0 = -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; + } + + glXMakeCurrent(dpy, (GLXDrawable) win, ctx1); + draw(0); + + glXMakeCurrent(dpy, (GLXDrawable) win, ctx2); + draw(1); + + glXSwapBuffers(dpy, win); +} + + +/* new window size or exposure */ +static void +reshape(Display *dpy, Window win, + GLXContext ctx1, GLXContext ctx2, int width, int height) +{ + int i; + + width /= 2; + + /* loop: left half of window, right half of window */ + for (i = 0; i < 2; i++) { + if (i == 0) + glXMakeCurrent(dpy, win, ctx1); + else + glXMakeCurrent(dpy, win, ctx2); + + glViewport(width * i, 0, width, height); + glScissor(width * i, 0, width, height); + + { + GLfloat h = (GLfloat) height / (GLfloat) width; + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-1.0, 1.0, -h, h, 5.0, 60.0); + } + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0.0, 0.0, -30.0); + } +} + + + +static void +init(Display *dpy, Window win, GLXContext ctx1, GLXContext ctx2) +{ + static GLfloat pos[4] = { 5.0, 5.0, 10.0, 0.0 }; + static GLfloat red[4] = { 0.8, 0.1, 0.0, 1.0 }; + static GLfloat green[4] = { 0.0, 0.8, 0.2, 0.5 }; + /*static GLfloat blue[4] = { 0.2, 0.2, 1.0, 1.0 };*/ + + /* first ctx */ + { + static GLuint stipple[32] = { + 0x00ff00ff, 0x00ff00ff, 0x00ff00ff, 0x00ff00ff, + 0x00ff00ff, 0x00ff00ff, 0x00ff00ff, 0x00ff00ff, + + 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00, + 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00, + + 0x00ff00ff, 0x00ff00ff, 0x00ff00ff, 0x00ff00ff, + 0x00ff00ff, 0x00ff00ff, 0x00ff00ff, 0x00ff00ff, + + 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00, + 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00 + }; + + glXMakeCurrent(dpy, win, ctx1); + + glLightfv(GL_LIGHT0, GL_POSITION, pos); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glEnable(GL_DEPTH_TEST); + + gear1 = glGenLists(1); + glNewList(gear1, GL_COMPILE); + glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red); + gear(1.0, 4.0, 1.0, 20, 0.7); + glEndList(); + + glEnable(GL_NORMALIZE); + glEnable(GL_SCISSOR_TEST); + glClearColor(0.4, 0.4, 0.4, 1.0); + + glPolygonStipple((GLubyte *) stipple); + glEnable(GL_POLYGON_STIPPLE); + } + + /* second ctx */ + { + glXMakeCurrent(dpy, win, ctx2); + + glLightfv(GL_LIGHT0, GL_POSITION, pos); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glEnable(GL_DEPTH_TEST); + + gear2 = glGenLists(1); + glNewList(gear2, GL_COMPILE); + glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green); + gear(1.5, 3.0, 1.5, 16, 0.7); + glEndList(); + + glEnable(GL_NORMALIZE); + glEnable(GL_SCISSOR_TEST); + glClearColor(0.6, 0.6, 0.6, 1.0); + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + } +} + + +/** + * Create an RGB, double-buffered window. + * Return the window and two context handles. + */ +static void +make_window_and_contexts( Display *dpy, const char *name, + int x, int y, int width, int height, + Window *winRet, + GLXContext *ctxRet1, + GLXContext *ctxRet2) +{ + 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; + XSetWindowAttributes attr; + unsigned long mask; + Window root; + Window win; + XVisualInfo *visinfo; + + scrnum = DefaultScreen( dpy ); + root = RootWindow( dpy, scrnum ); + + visinfo = glXChooseVisual( dpy, scrnum, attribs ); + if (!visinfo) { + printf("Error: couldn't get an RGB, Double-buffered visual\n"); + exit(1); + } + + /* 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); + } + + *winRet = win; + *ctxRet1 = glXCreateContext( dpy, visinfo, NULL, True ); + *ctxRet2 = glXCreateContext( dpy, visinfo, NULL, True ); + + if (!*ctxRet1 || !*ctxRet2) { + printf("Error: glXCreateContext failed\n"); + exit(1); + } + + XFree(visinfo); +} + + +/** + * Handle one X event. + * \return NOP, EXIT or DRAW + */ +static int +handle_event(Display *dpy, Window win, GLXContext ctx1, GLXContext ctx2, + XEvent *event) +{ + (void) dpy; + (void) win; + + switch (event->type) { + case Expose: + return DRAW; + case ConfigureNotify: + reshape(dpy, win, ctx1, ctx2, + 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, GLXContext ctx1, GLXContext ctx2) +{ + while (1) { + int op; + while (!animate || XPending(dpy) > 0) { + XEvent event; + XNextEvent(dpy, &event); + op = handle_event(dpy, win, ctx1, ctx2, &event); + if (op == EXIT) + return; + else if (op == DRAW) + break; + } + + draw_frame(dpy, win, ctx1, ctx2); + } +} + + +int +main(int argc, char *argv[]) +{ + unsigned int winWidth = 800, winHeight = 400; + int x = 0, y = 0; + Display *dpy; + Window win; + GLXContext ctx1, ctx2; + char *dpyName = NULL; + GLboolean printInfo = GL_FALSE; + int i; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-display") == 0) { + dpyName = argv[i+1]; + i++; + } + else { + return 1; + } + } + + dpy = XOpenDisplay(dpyName); + if (!dpy) { + printf("Error: couldn't open display %s\n", + dpyName ? dpyName : getenv("DISPLAY")); + return -1; + } + + make_window_and_contexts(dpy, "multictx", x, y, winWidth, winHeight, + &win, &ctx1, &ctx2); + XMapWindow(dpy, win); + + if (printInfo) { + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); + printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); + printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS)); + } + + init(dpy, win, ctx1, ctx2); + + /* Set initial projection/viewing transformation. + * We can't be sure we'll get a ConfigureNotify event when the window + * first appears. + */ + reshape(dpy, win, ctx1, ctx2, winWidth, winHeight); + + event_loop(dpy, win, ctx1, ctx2); + + glDeleteLists(gear1, 1); + glDeleteLists(gear2, 1); + glXDestroyContext(dpy, ctx1); + glXDestroyContext(dpy, ctx2); + XDestroyWindow(dpy, win); + XCloseDisplay(dpy); + + return 0; +} |