diff options
Diffstat (limited to 'progs')
189 files changed, 3867 insertions, 9160 deletions
diff --git a/progs/SConscript b/progs/SConscript index aa6640cf7a..d84e0a8220 100644 --- a/progs/SConscript +++ b/progs/SConscript @@ -24,6 +24,7 @@ if progs_env['platform'] == 'windows': if progs_env['platform'] == 'windows': progs_env.Prepend(LIBS = ['glu32', 'opengl32']) else: + progs_env.Tool('x11') progs_env.Prepend(LIBS = ['GLU', 'GL']) # Glut @@ -55,5 +56,4 @@ SConscript([ 'fp/SConscript', 'wgl/SConscript', 'perf/SConscript', - 'gallium/unit/SConscript', ]) diff --git a/progs/demos/dissolve.c b/progs/demos/dissolve.c index 0b8df1bb66..8ab5242d91 100644 --- a/progs/demos/dissolve.c +++ b/progs/demos/dissolve.c @@ -1,5 +1,5 @@ /** - * Dissolve between two images using randomized stencil buffer + * Dissolve between two images using randomized/patterned stencil buffer * and varying stencil ref. * * Brian Paul @@ -9,6 +9,7 @@ #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <math.h> #include <GL/glut.h> #include "readtex.h" @@ -28,6 +29,8 @@ static GLfloat ScaleX[2], ScaleY[2]; static GLubyte StencilRef = 0; +static int Mode = 0; + static void Idle(void) @@ -38,13 +41,114 @@ Idle(void) static void -RandomizeStencilBuffer(void) +FillRandomPixels(GLubyte *b) { - GLubyte *b = malloc(WinWidth * WinHeight); int i; for (i = 0; i < WinWidth * WinHeight; i++) { b[i] = rand() & 0xff; } +} + + +static void +FillRandomRects(GLubyte *b) +{ + int i; + + memset(b, 0, WinWidth * WinHeight); + + for (i = 0; i < 256; i++) { + int x = rand() % WinWidth; + int y = rand() % WinHeight; + int w = rand() % 60; + int h = rand() % 60; + int ix, iy; + + if (x + w > WinWidth) + w = WinWidth - x; + if (y + h > WinHeight) + h = WinHeight - y; + + for (iy = 0; iy < h; iy++) { + for (ix = 0; ix < w; ix++) { + int p = (y + iy) * WinWidth + x + ix; + b[p] = i; + } + } + } +} + + +static void +FillWipe(GLubyte *b) +{ + int iy, ix; + + memset(b, 0, WinWidth * WinHeight); + + for (iy = 0; iy < WinHeight; iy++) { + for (ix = 0; ix < WinWidth; ix++) { + int p = iy * WinWidth + ix; + b[p] = 2 * ix + iy / 2; + } + } +} + + +static void +FillMoire(GLubyte *b) +{ + int iy, ix; + + memset(b, 0, WinWidth * WinHeight); + + for (iy = 0; iy < WinHeight; iy++) { + for (ix = 0; ix < WinWidth; ix++) { + int p = iy * WinWidth + ix; + b[p] = (ix / 2) * (ix / 2) - (iy / 2) * (iy / 2); + } + } +} + + +static void +FillWaves(GLubyte *b) +{ + int iy, ix; + + memset(b, 0, WinWidth * WinHeight); + + for (iy = 0; iy < WinHeight; iy++) { + for (ix = 0; ix < WinWidth; ix++) { + int p = iy * WinWidth + ix; + float x = 8.0 * 3.1415 * ix / (float) WinWidth; + b[p] = (int) (25.0 * sin(x) ) - iy*2; + } + } +} + + +typedef void (*FillFunc)(GLubyte *b); + + +static FillFunc Funcs[] = { + FillRandomPixels, + FillRandomRects, + FillWipe, + FillMoire, + FillWaves +}; + +#define NUM_MODES (sizeof(Funcs) / sizeof(Funcs[0])) + + + +static void +InitStencilBuffer(void) +{ + GLubyte *b = malloc(WinWidth * WinHeight); + + Funcs[Mode](b); glStencilFunc(GL_ALWAYS, 0, ~0); glPixelZoom(1.0, 1.0); @@ -54,7 +158,6 @@ RandomizeStencilBuffer(void) } - static void Draw(void) { @@ -85,7 +188,7 @@ Reshape(int width, int height) glLoadIdentity(); glTranslatef(0.0, 0.0, -15.0); - RandomizeStencilBuffer(); + InitStencilBuffer(); ScaleX[0] = (float) width / ImgWidth[0]; ScaleY[0] = (float) height / ImgHeight[0]; @@ -102,12 +205,26 @@ Key(unsigned char key, int x, int y) (void) y; switch (key) { case 'a': + case ' ': Anim = !Anim; if (Anim) glutIdleFunc(Idle); else glutIdleFunc(NULL); break; + case 'i': + InitStencilBuffer(); + break; + case '-': + StencilRef--; + break; + case '+': + StencilRef++; + break; + case 'm': + Mode = (Mode + 1) % NUM_MODES; + InitStencilBuffer(); + break; case 27: glutDestroyWindow(Win); exit(0); @@ -143,8 +260,8 @@ Init(void) int main(int argc, char *argv[]) { - glutInit(&argc, argv); glutInitWindowSize(WinWidth, WinHeight); + glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_STENCIL); Win = glutCreateWindow(argv[0]); glutReshapeFunc(Reshape); @@ -153,6 +270,14 @@ main(int argc, char *argv[]) if (Anim) glutIdleFunc(Idle); Init(); + + printf("Keys:\n"); + printf(" a/SPACE toggle animation\n"); + printf(" +/- single step\n"); + printf(" i re-init pattern\n"); + printf(" m change pattern/dissolve mode\n"); + printf(" ESC exit\n"); + glutMainLoop(); return 0; } diff --git a/progs/demos/stex3d.c b/progs/demos/stex3d.c index c0bbea0960..de18480c25 100644 --- a/progs/demos/stex3d.c +++ b/progs/demos/stex3d.c @@ -36,6 +36,7 @@ static int tex_width=64, tex_height=64, tex_depth=64; static float angx=0, angy=0, angz=0; static int texgen = 2, animate = 1, smooth = 1, wireframe = 0; static int CurTexture = NOISE_TEXTURE, CurObject = TORUS; +static GLenum Filter = GL_LINEAR; static void @@ -298,8 +299,6 @@ create3Dtexture(void) printf("setting up 3d texture...\n"); glBindTexture(GL_TEXTURE_3D, NOISE_TEXTURE); - glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_REPEAT); @@ -406,6 +405,9 @@ drawScene(void) glDisable(GL_TEXTURE_GEN_R); } + glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, Filter); + glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, Filter); + glCallList(CurObject); glPopMatrix(); @@ -505,6 +507,12 @@ KeyHandler(unsigned char key, int x, int y) else CurObject = TORUS; break; + case 'f': + if (Filter == GL_LINEAR) + Filter = GL_NEAREST; + else + Filter = GL_LINEAR; + break; case 'i': if (CurTexture == NOISE_TEXTURE) CurTexture = GRADIENT_TEXTURE; @@ -513,6 +521,7 @@ KeyHandler(unsigned char key, int x, int y) glBindTexture(GL_TEXTURE_3D, CurTexture); break; case 'a': + case ' ': animate = !animate; if (animate) glutIdleFunc(Idle); @@ -559,8 +568,6 @@ create3Dgradient(void) glBindTexture(GL_TEXTURE_3D, GRADIENT_TEXTURE); - glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_REPEAT); diff --git a/progs/egl/Makefile b/progs/egl/Makefile deleted file mode 100644 index 25de6e1f70..0000000000 --- a/progs/egl/Makefile +++ /dev/null @@ -1,70 +0,0 @@ -# progs/egl/Makefile - -TOP = ../.. -include $(TOP)/configs/current - - -INCLUDE_DIRS = -I$(TOP)/include - -HEADERS = $(TOP)/include/GLES/egl.h -LIB_DEP = $(TOP)/$(LIB_DIR)/libEGL.so - -LIBS = -L$(TOP)/$(LIB_DIR) -lEGL -lGL - -PROGRAMS = \ - demo1 \ - demo2 \ - demo3 \ - egltri \ - eglinfo \ - eglgears \ - eglscreen \ - peglgears \ - xeglgears \ - xeglthreads \ - xegl_tri - - -.c.o: - $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $< -o $@ - - - -default: $(PROGRAMS) - -demo1: demo1.o $(HEADERS) $(LIB_DEP) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB) - -demo2: demo2.o $(HEADERS) $(LIB_DEP) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB) - -demo3: demo3.o $(HEADERS) $(LIB_DEP) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB) - -egltri: egltri.o $(HEADERS) $(LIB_DEP) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB) - -eglinfo: eglinfo.o $(HEADERS) $(LIB_DEP) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) - -eglgears: eglgears.o $(HEADERS) $(LIB_DEP) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB) -lm - -eglscreen: eglscreen.o $(HEADERS) $(LIB_DEP) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB) - -peglgears: peglgears.o $(HEADERS) $(LIB_DEP) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB) -lm - -xeglgears: xeglgears.o $(HEADERS) $(LIB_DEP) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lm -L$(libdir) -lX11 - -xeglthreads: xeglthreads.o $(HEADERS) $(LIB_DEP) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lm -L$(libdir) -lX11 - -xegl_tri: xegl_tri.o $(HEADERS) $(LIB_DEP) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lm -L$(libdir) -lX11 - -clean: - -rm -f *.o *~ - -rm -f $(PROGRAMS) diff --git a/progs/egl/egltri.c b/progs/egl/egltri.c deleted file mode 100644 index 006e06eb03..0000000000 --- a/progs/egl/egltri.c +++ /dev/null @@ -1,264 +0,0 @@ -/* - * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. - * Copyright (C) 2008 Brian Paul All Rights Reserved. - * Copyright (C) 2008 Jakob Bornecrantz 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. - */ - -/* - * This program is based on eglgears and xegl_tri. - * Remixed by Jakob Bornecrantz - * - * No command line options. - * Program runs for 5 seconds then exits, outputing framerate to console - */ - -#define EGL_EGLEXT_PROTOTYPES - -#include <assert.h> -#include <math.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <GL/gl.h> -#include <EGL/egl.h> -#include <EGL/eglext.h> - -#define MAX_CONFIGS 10 -#define MAX_MODES 100 - - -/* XXX this probably isn't very portable */ - -#include <sys/time.h> -#include <unistd.h> - -/* return current time (in seconds) */ -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; -} - - -static GLfloat view_rotx = 0.0, view_roty = 0.0, view_rotz = 0.0; - -static void draw() -{ - static const GLfloat verts[3][2] = { - { -1, -1 }, - { 1, -1 }, - { 0, 1 } - }; - static const GLfloat colors[3][3] = { - { 1, 0, 0 }, - { 0, 1, 0 }, - { 0, 0, 1 } - }; - - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - glPushMatrix(); - glRotatef(view_rotx, 1, 0, 0); - glRotatef(view_roty, 0, 1, 0); - glRotatef(view_rotz, 0, 0, 1); - - { - 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); - } - - glPopMatrix(); -} - -static void init() -{ - glClearColor(0.4, 0.4, 0.4, 0.0); -} - -/* new window size or exposure */ -static void reshape(int width, int height) -{ - GLfloat ar = (GLfloat) width / (GLfloat) height; - - 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, -10.0); -} - -static void run(EGLDisplay dpy, EGLSurface surf, int ttr) -{ - double st = current_time(); - double ct = st; - int frames = 0; - GLfloat seconds, fps; - - while (ct - st < ttr) - { - ct = current_time(); - - draw(); - - eglSwapBuffers(dpy, surf); - - frames++; - } - - seconds = ct - st; - fps = frames / seconds; - printf("%d frames in %3.1f seconds = %6.3f FPS\n", frames, seconds, fps); -} - -int main(int argc, char *argv[]) -{ - int maj, min; - EGLContext ctx; - EGLSurface screen_surf; - EGLConfig configs[MAX_CONFIGS]; - EGLint numConfigs, i; - EGLBoolean b; - EGLDisplay d; - EGLint screenAttribs[10]; - EGLModeMESA mode[MAX_MODES]; - EGLScreenMESA screen; - EGLint count, chosenMode = 0; - GLboolean printInfo = GL_FALSE; - EGLint width = 0, height = 0; - - /* parse cmd line args */ - for (i = 1; i < argc; i++) - { - if (strcmp(argv[i], "-info") == 0) - { - printInfo = GL_TRUE; - } - else - printf("Warning: unknown parameter: %s\n", argv[i]); - } - - /* DBR : Create EGL context/surface etc */ - d = eglGetDisplay(EGL_DEFAULT_DISPLAY); - assert(d); - - if (!eglInitialize(d, &maj, &min)) { - printf("egltri: eglInitialize failed\n"); - exit(1); - } - - printf("egltri: EGL version = %d.%d\n", maj, min); - printf("egltri: EGL_VENDOR = %s\n", eglQueryString(d, EGL_VENDOR)); - - /* XXX use ChooseConfig */ - eglGetConfigs(d, configs, MAX_CONFIGS, &numConfigs); - eglGetScreensMESA(d, &screen, 1, &count); - - if (!eglGetModesMESA(d, screen, mode, MAX_MODES, &count) || count == 0) { - printf("egltri: eglGetModesMESA failed!\n"); - return 0; - } - - /* Print list of modes, and find the one to use */ - printf("egltri: Found %d modes:\n", count); - for (i = 0; i < count; i++) { - EGLint w, h; - eglGetModeAttribMESA(d, mode[i], EGL_WIDTH, &w); - eglGetModeAttribMESA(d, mode[i], EGL_HEIGHT, &h); - printf("%3d: %d x %d\n", i, w, h); - if (w > width && h > height) { - width = w; - height = h; - chosenMode = i; - } - } - printf("egltri: Using screen mode/size %d: %d x %d\n", chosenMode, width, height); - - eglBindAPI(EGL_OPENGL_API); - ctx = eglCreateContext(d, configs[0], EGL_NO_CONTEXT, NULL); - if (ctx == EGL_NO_CONTEXT) { - printf("egltri: failed to create context\n"); - return 0; - } - - /* build up screenAttribs array */ - i = 0; - screenAttribs[i++] = EGL_WIDTH; - screenAttribs[i++] = width; - screenAttribs[i++] = EGL_HEIGHT; - screenAttribs[i++] = height; - screenAttribs[i++] = EGL_NONE; - - screen_surf = eglCreateScreenSurfaceMESA(d, configs[0], screenAttribs); - if (screen_surf == EGL_NO_SURFACE) { - printf("egltri: failed to create screen surface\n"); - return 0; - } - - b = eglShowScreenSurfaceMESA(d, screen, screen_surf, mode[chosenMode]); - if (!b) { - printf("egltri: show surface failed\n"); - return 0; - } - - b = eglMakeCurrent(d, screen_surf, screen_surf, ctx); - if (!b) { - printf("egltri: make current failed\n"); - return 0; - } - - 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(); - reshape(width, height); - - glDrawBuffer( GL_BACK ); - - run(d, screen_surf, 5.0); - - eglDestroySurface(d, screen_surf); - eglDestroyContext(d, ctx); - eglTerminate(d); - - return 0; -} diff --git a/progs/egl/eglut/Makefile b/progs/egl/eglut/Makefile new file mode 100644 index 0000000000..f5cafa7010 --- /dev/null +++ b/progs/egl/eglut/Makefile @@ -0,0 +1,35 @@ +# progs/egl/eglut + +TOP = ../../.. +include $(TOP)/configs/current + +INCLUDES = \ + -I$(TOP)/include + +SOURCES = $(wildcard *.c) + +EGLUT_X11_OBJECTS = eglut.o eglut_x11.o +EGLUT_SCREEN_OBJECTS = eglut.o eglut_screen.o + +default: depend libeglut-x11.a libeglut-screen.a + +libeglut-x11.a: $(EGLUT_X11_OBJECTS) + $(MKLIB) -o eglut-x11 -static $(EGLUT_X11_OBJECTS) + +libeglut-screen.a: $(EGLUT_SCREEN_OBJECTS) + $(MKLIB) -o eglut-screen -static $(EGLUT_SCREEN_OBJECTS) + +.c.o: + $(CC) -c -o $@ $< $(INCLUDES) $(DEFINES) $(CFLAGS) + +depend: $(SOURCES) + @rm -f depend + @touch depend + @$(MKDEP) $(MKDEP_OPTIONS) $(INCLUDES) $(SOURCES) \ + > /dev/null 2>/dev/null + +clean: + rm -f *.o *.a + rm -f depend depend.bak + +sinclude depend diff --git a/progs/egl/eglut/eglut.c b/progs/egl/eglut/eglut.c new file mode 100644 index 0000000000..b9b5e6e5a8 --- /dev/null +++ b/progs/egl/eglut/eglut.c @@ -0,0 +1,346 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <stdarg.h> +#include <sys/time.h> + +#include "EGL/egl.h" +#include "EGL/eglext.h" + +#include "eglutint.h" + +static struct eglut_state _eglut_state = { + .api_mask = EGLUT_OPENGL_ES1_BIT, + .window_width = 300, + .window_height = 300, + .verbose = 0, + .num_windows = 0, +}; + +struct eglut_state *_eglut = &_eglut_state; + +void +_eglutFatal(char *format, ...) +{ + va_list args; + + va_start(args, format); + + fprintf(stderr, "EGLUT: "); + vfprintf(stderr, format, args); + va_end(args); + putc('\n', stderr); + + exit(1); +} + +/* return current time (in milliseconds) */ +int +_eglutNow(void) +{ + struct timeval tv; +#ifdef __VMS + (void) gettimeofday(&tv, NULL ); +#else + struct timezone tz; + (void) gettimeofday(&tv, &tz); +#endif + return tv.tv_sec * 1000 + tv.tv_usec / 1000; +} + +static void +_eglutDestroyWindow(struct eglut_window *win) +{ + if (_eglut->surface_type != EGL_PBUFFER_BIT && + _eglut->surface_type != EGL_SCREEN_BIT_MESA) + eglDestroySurface(_eglut->dpy, win->surface); + + _eglutNativeFiniWindow(win); + + eglDestroyContext(_eglut->dpy, win->context); +} + +static EGLConfig +_eglutChooseConfig(void) +{ + EGLConfig config; + EGLint config_attribs[32]; + EGLint renderable_type, num_configs, i; + + i = 0; + config_attribs[i++] = EGL_RED_SIZE; + config_attribs[i++] = 1; + config_attribs[i++] = EGL_GREEN_SIZE; + config_attribs[i++] = 1; + config_attribs[i++] = EGL_BLUE_SIZE; + config_attribs[i++] = 1; + config_attribs[i++] = EGL_DEPTH_SIZE; + config_attribs[i++] = 1; + + config_attribs[i++] = EGL_SURFACE_TYPE; + config_attribs[i++] = _eglut->surface_type; + + config_attribs[i++] = EGL_RENDERABLE_TYPE; + renderable_type = 0x0; + if (_eglut->api_mask & EGLUT_OPENGL_BIT) + renderable_type |= EGL_OPENGL_BIT; + if (_eglut->api_mask & (EGLUT_OPENGL_ES1_BIT | EGLUT_OPENGL_ES2_BIT)) + renderable_type |= EGL_OPENGL_ES_BIT; + if (_eglut->api_mask & EGLUT_OPENVG_BIT) + renderable_type |= EGL_OPENVG_BIT; + config_attribs[i++] = renderable_type; + + config_attribs[i] = EGL_NONE; + + if (!eglChooseConfig(_eglut->dpy, + config_attribs, &config, 1, &num_configs) || !num_configs) + _eglutFatal("failed to choose a config"); + + return config; +} + +static struct eglut_window * +_eglutCreateWindow(const char *title, int x, int y, int w, int h) +{ + struct eglut_window *win; + EGLint context_attribs[4]; + EGLint api, i; + + win = calloc(1, sizeof(*win)); + if (!win) + _eglutFatal("failed to allocate window"); + + win->config = _eglutChooseConfig(); + + i = 0; + context_attribs[i] = EGL_NONE; + + /* multiple APIs? */ + + api = EGL_OPENGL_ES_API; + if (_eglut->api_mask & EGLUT_OPENGL_BIT) { + api = EGL_OPENGL_API; + } + else if (_eglut->api_mask & EGLUT_OPENVG_BIT) { + api = EGL_OPENVG_API; + } + else if (_eglut->api_mask & EGLUT_OPENGL_ES2_BIT) { + context_attribs[i++] = EGL_CONTEXT_CLIENT_VERSION; + context_attribs[i++] = 2; + } + + context_attribs[i] = EGL_NONE; + + eglBindAPI(api); + win->context = eglCreateContext(_eglut->dpy, + win->config, EGL_NO_CONTEXT, context_attribs); + if (!win->context) + _eglutFatal("failed to create context"); + + _eglutNativeInitWindow(win, title, x, y, w, h); + switch (_eglut->surface_type) { + case EGL_WINDOW_BIT: + win->surface = eglCreateWindowSurface(_eglut->dpy, + win->config, win->native.u.window, NULL); + break; + case EGL_PIXMAP_BIT: + win->surface = eglCreatePixmapSurface(_eglut->dpy, + win->config, win->native.u.pixmap, NULL); + break; + case EGL_PBUFFER_BIT: + case EGL_SCREEN_BIT_MESA: + win->surface = win->native.u.surface; + break; + default: + break; + } + if (win->surface == EGL_NO_SURFACE) + _eglutFatal("failed to create surface"); + + return win; +} + +void +eglutInitAPIMask(int mask) +{ + _eglut->api_mask = mask; +} + +void +eglutInitWindowSize(int width, int height) +{ + _eglut->window_width = width; + _eglut->window_height = height; +} + +void +eglutInit(int argc, char **argv) +{ + int i; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-display") == 0) + _eglut->display_name = argv[++i]; + else if (strcmp(argv[i], "-info") == 0) { + _eglut->verbose = 1; + } + } + + _eglutNativeInitDisplay(); + _eglut->dpy = eglGetDisplay(_eglut->native_dpy); + + if (!eglInitialize(_eglut->dpy, &_eglut->major, &_eglut->minor)) + _eglutFatal("failed to initialize EGL display"); + + _eglut->init_time = _eglutNow(); + + printf("EGL_VERSION = %s\n", eglQueryString(_eglut->dpy, EGL_VERSION)); + if (_eglut->verbose) { + printf("EGL_VENDOR = %s\n", eglQueryString(_eglut->dpy, EGL_VENDOR)); + printf("EGL_EXTENSIONS = %s\n", + eglQueryString(_eglut->dpy, EGL_EXTENSIONS)); + printf("EGL_CLIENT_APIS = %s\n", + eglQueryString(_eglut->dpy, EGL_CLIENT_APIS)); + } +} + +int +eglutGet(int state) +{ + int val; + + switch (state) { + case EGLUT_ELAPSED_TIME: + val = _eglutNow() - _eglut->init_time; + break; + default: + val = -1; + break; + } + + return val; +} + +void +eglutIdleFunc(EGLUTidleCB func) +{ + _eglut->idle_cb = func; +} + +void +eglutPostRedisplay(void) +{ + _eglut->redisplay = 1; +} + +void +eglutMainLoop(void) +{ + struct eglut_window *win = _eglut->current; + + if (!win) + _eglutFatal("no window is created\n"); + + if (win->reshape_cb) + win->reshape_cb(win->native.width, win->native.height); + + _eglutNativeEventLoop(); +} + +static void +_eglutFini(void) +{ + eglTerminate(_eglut->dpy); + _eglutNativeFiniDisplay(); +} + +void +eglutDestroyWindow(int win) +{ + struct eglut_window *window = _eglut->current; + + if (window->index != win) + return; + + /* XXX it causes some bug in st/egl KMS backend */ + if ( _eglut->surface_type != EGL_SCREEN_BIT_MESA) + eglMakeCurrent(_eglut->dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + + _eglutDestroyWindow(_eglut->current); +} + +static void +_eglutDefaultKeyboard(unsigned char key) +{ + if (key == 27) { + if (_eglut->current) + eglutDestroyWindow(_eglut->current->index); + _eglutFini(); + + exit(0); + } +} + +int +eglutCreateWindow(const char *title) +{ + struct eglut_window *win; + + win = _eglutCreateWindow(title, 0, 0, + _eglut->window_width, _eglut->window_height); + + win->index = _eglut->num_windows++; + win->reshape_cb = NULL; + win->display_cb = NULL; + win->keyboard_cb = _eglutDefaultKeyboard; + win->special_cb = NULL; + + if (!eglMakeCurrent(_eglut->dpy, win->surface, win->surface, win->context)) + _eglutFatal("failed to make window current"); + _eglut->current = win; + + return win->index; +} + +int +eglutGetWindowWidth(void) +{ + struct eglut_window *win = _eglut->current; + return win->native.width; +} + +int +eglutGetWindowHeight(void) +{ + struct eglut_window *win = _eglut->current; + return win->native.height; +} + +void +eglutDisplayFunc(EGLUTdisplayCB func) +{ + struct eglut_window *win = _eglut->current; + win->display_cb = func; + +} + +void +eglutReshapeFunc(EGLUTreshapeCB func) +{ + struct eglut_window *win = _eglut->current; + win->reshape_cb = func; +} + +void +eglutKeyboardFunc(EGLUTkeyboardCB func) +{ + struct eglut_window *win = _eglut->current; + win->keyboard_cb = func; +} + +void +eglutSpecialFunc(EGLUTspecialCB func) +{ + struct eglut_window *win = _eglut->current; + win->special_cb = func; +} diff --git a/progs/egl/eglut/eglut.h b/progs/egl/eglut/eglut.h new file mode 100644 index 0000000000..07df4ba9f7 --- /dev/null +++ b/progs/egl/eglut/eglut.h @@ -0,0 +1,68 @@ +#ifndef EGLUT_H +#define EGLUT_H + +/* used by eglutInitAPIMask */ +enum { + EGLUT_OPENGL_BIT = 0x1, + EGLUT_OPENGL_ES1_BIT = 0x2, + EGLUT_OPENGL_ES2_BIT = 0x4, + EGLUT_OPENVG_BIT = 0x8 +}; + +/* used by EGLUTspecialCB */ +enum { + /* function keys */ + EGLUT_KEY_F1, + EGLUT_KEY_F2, + EGLUT_KEY_F3, + EGLUT_KEY_F4, + EGLUT_KEY_F5, + EGLUT_KEY_F6, + EGLUT_KEY_F7, + EGLUT_KEY_F8, + EGLUT_KEY_F9, + EGLUT_KEY_F10, + EGLUT_KEY_F11, + EGLUT_KEY_F12, + + /* directional keys */ + EGLUT_KEY_LEFT, + EGLUT_KEY_UP, + EGLUT_KEY_RIGHT, + EGLUT_KEY_DOWN, +}; + +/* used by eglutGet */ +enum { + EGLUT_ELAPSED_TIME +}; + +typedef void (*EGLUTidleCB)(void); +typedef void (*EGLUTreshapeCB)(int, int); +typedef void (*EGLUTdisplayCB)(void); +typedef void (*EGLUTkeyboardCB)(unsigned char); +typedef void (*EGLUTspecialCB)(int); + +void eglutInitAPIMask(int mask); +void eglutInitWindowSize(int width, int height); +void eglutInit(int argc, char **argv); + +int eglutGet(int state); + +void eglutIdleFunc(EGLUTidleCB func); +void eglutPostRedisplay(void); + +void eglutMainLoop(void); + +int eglutCreateWindow(const char *title); +void eglutDestroyWindow(int win); + +int eglutGetWindowWidth(void); +int eglutGetWindowHeight(void); + +void eglutDisplayFunc(EGLUTdisplayCB func); +void eglutReshapeFunc(EGLUTreshapeCB func); +void eglutKeyboardFunc(EGLUTkeyboardCB func); +void eglutSpecialFunc(EGLUTspecialCB func); + +#endif /* EGLUT_H */ diff --git a/progs/egl/eglut/eglut_screen.c b/progs/egl/eglut/eglut_screen.c new file mode 100644 index 0000000000..50549e4bcf --- /dev/null +++ b/progs/egl/eglut/eglut_screen.c @@ -0,0 +1,154 @@ +#include <stdio.h> +#include <string.h> +#include <sys/time.h> + +#define EGL_EGLEXT_PROTOTYPES +#include "EGL/egl.h" +#include "EGL/eglext.h" + +#include "eglutint.h" + +#define MAX_MODES 100 + +static EGLScreenMESA kms_screen; +static EGLModeMESA kms_mode; +static EGLint kms_width, kms_height; + +void +_eglutNativeInitDisplay(void) +{ + _eglut->native_dpy = EGL_DEFAULT_DISPLAY; + _eglut->surface_type = EGL_SCREEN_BIT_MESA; +} + +void +_eglutNativeFiniDisplay(void) +{ + kms_screen = 0; + kms_mode = 0; + kms_width = 0; + kms_height = 0; +} + +static void +init_kms(void) +{ + EGLModeMESA modes[MAX_MODES]; + EGLint num_screens, num_modes; + EGLint width, height, best_mode; + EGLint i; + + if (!eglGetScreensMESA(_eglut->dpy, &kms_screen, 1, &num_screens) || + !num_screens) + _eglutFatal("eglGetScreensMESA failed\n"); + + if (!eglGetModesMESA(_eglut->dpy, kms_screen, + modes, MAX_MODES, &num_modes) || !num_modes) + _eglutFatal("eglGetModesMESA failed!\n"); + + printf("Found %d modes:\n", num_modes); + + best_mode = 0; + width = 0; + height = 0; + for (i = 0; i < num_modes; i++) { + EGLint w, h; + eglGetModeAttribMESA(_eglut->dpy, modes[i], EGL_WIDTH, &w); + eglGetModeAttribMESA(_eglut->dpy, modes[i], EGL_HEIGHT, &h); + printf("%3d: %d x %d\n", i, w, h); + if (w > width && h > height) { + width = w; + height = h; + best_mode = i; + } + } + + printf("Will use screen size: %d x %d\n", width, height); + + kms_mode = modes[best_mode]; + kms_width = width; + kms_height = height; +} + +void +_eglutNativeInitWindow(struct eglut_window *win, const char *title, + int x, int y, int w, int h) +{ + EGLint surf_attribs[16]; + EGLint i; + const char *exts; + + exts = eglQueryString(_eglut->dpy, EGL_EXTENSIONS); + if (!exts || !strstr(exts, "EGL_MESA_screen_surface")) + _eglutFatal("EGL_MESA_screen_surface is not supported\n"); + + init_kms(); + + i = 0; + surf_attribs[i++] = EGL_WIDTH; + surf_attribs[i++] = kms_width; + surf_attribs[i++] = EGL_HEIGHT; + surf_attribs[i++] = kms_height; + surf_attribs[i++] = EGL_NONE; + + /* create surface */ + win->native.u.surface = eglCreateScreenSurfaceMESA(_eglut->dpy, + win->config, surf_attribs); + if (win->native.u.surface == EGL_NO_SURFACE) + _eglutFatal("eglCreateScreenSurfaceMESA failed\n"); + + if (!eglShowScreenSurfaceMESA(_eglut->dpy, kms_screen, + win->native.u.surface, kms_mode)) + _eglutFatal("eglShowScreenSurfaceMESA failed\n"); + + win->native.width = kms_width; + win->native.height = kms_height; +} + +void +_eglutNativeFiniWindow(struct eglut_window *win) +{ + eglShowScreenSurfaceMESA(_eglut->dpy, + kms_screen, EGL_NO_SURFACE, 0); + eglDestroySurface(_eglut->dpy, win->native.u.surface); +} + +void +_eglutNativeEventLoop(void) +{ + int start = _eglutNow(); + int frames = 0; + + _eglut->redisplay = 1; + + while (1) { + struct eglut_window *win = _eglut->current; + int now = _eglutNow(); + + if (now - start > 5000) { + double elapsed = (double) (now - start) / 1000.0; + + printf("%d frames in %3.1f seconds = %6.3f FPS\n", + frames, elapsed, frames / elapsed); + + start = now; + frames = 0; + + /* send escape */ + if (win->keyboard_cb) + win->keyboard_cb(27); + } + + if (_eglut->idle_cb) + _eglut->idle_cb(); + + if (_eglut->redisplay) { + _eglut->redisplay = 0; + + if (win->display_cb) + win->display_cb(); + eglSwapBuffers(_eglut->dpy, win->surface); + frames++; + } + } +} diff --git a/progs/egl/eglut/eglut_x11.c b/progs/egl/eglut/eglut_x11.c new file mode 100644 index 0000000000..f3b2280374 --- /dev/null +++ b/progs/egl/eglut/eglut_x11.c @@ -0,0 +1,220 @@ +#include <X11/Xlib.h> +#include <X11/Xutil.h> +#include <X11/keysym.h> + +#include "eglutint.h" + +void +_eglutNativeInitDisplay(void) +{ + _eglut->native_dpy = XOpenDisplay(_eglut->display_name); + if (!_eglut->native_dpy) + _eglutFatal("failed to initialize native display"); + + _eglut->surface_type = EGL_WINDOW_BIT; +} + +void +_eglutNativeFiniDisplay(void) +{ + XCloseDisplay(_eglut->native_dpy); +} + +void +_eglutNativeInitWindow(struct eglut_window *win, const char *title, + int x, int y, int w, int h) +{ + XVisualInfo *visInfo, visTemplate; + int num_visuals; + Window root, xwin; + XSetWindowAttributes attr; + unsigned long mask; + EGLint vid; + + if (!eglGetConfigAttrib(_eglut->dpy, + win->config, EGL_NATIVE_VISUAL_ID, &vid)) + _eglutFatal("failed to get visual id"); + + /* The X window visual must match the EGL config */ + visTemplate.visualid = vid; + visInfo = XGetVisualInfo(_eglut->native_dpy, + VisualIDMask, &visTemplate, &num_visuals); + if (!visInfo) + _eglutFatal("failed to get an visual of id 0x%x", vid); + + root = RootWindow(_eglut->native_dpy, DefaultScreen(_eglut->native_dpy)); + + /* window attributes */ + attr.background_pixel = 0; + attr.border_pixel = 0; + attr.colormap = XCreateColormap(_eglut->native_dpy, + root, visInfo->visual, AllocNone); + attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask; + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; + + xwin = XCreateWindow(_eglut->native_dpy, root, x, y, w, h, + 0, visInfo->depth, InputOutput, visInfo->visual, mask, &attr); + if (!xwin) + _eglutFatal("failed to create a window"); + + XFree(visInfo); + + /* set hints and properties */ + { + XSizeHints sizehints; + sizehints.x = x; + sizehints.y = y; + sizehints.width = w; + sizehints.height = h; + sizehints.flags = USSize | USPosition; + XSetNormalHints(_eglut->native_dpy, xwin, &sizehints); + XSetStandardProperties(_eglut->native_dpy, xwin, + title, title, None, (char **) NULL, 0, &sizehints); + } + + XMapWindow(_eglut->native_dpy, xwin); + + win->native.u.window = xwin; + win->native.width = w; + win->native.height = h; +} + +void +_eglutNativeFiniWindow(struct eglut_window *win) +{ + XDestroyWindow(_eglut->native_dpy, win->native.u.window); +} + +static int +lookup_keysym(KeySym sym) +{ + int special; + + switch (sym) { + case XK_F1: + special = EGLUT_KEY_F1; + break; + case XK_F2: + special = EGLUT_KEY_F2; + break; + case XK_F3: + special = EGLUT_KEY_F3; + break; + case XK_F4: + special = EGLUT_KEY_F4; + break; + case XK_F5: + special = EGLUT_KEY_F5; + break; + case XK_F6: + special = EGLUT_KEY_F6; + break; + case XK_F7: + special = EGLUT_KEY_F7; + break; + case XK_F8: + special = EGLUT_KEY_F8; + break; + case XK_F9: + special = EGLUT_KEY_F9; + break; + case XK_F10: + special = EGLUT_KEY_F10; + break; + case XK_F11: + special = EGLUT_KEY_F11; + break; + case XK_F12: + special = EGLUT_KEY_F12; + break; + case XK_KP_Left: + case XK_Left: + special = EGLUT_KEY_LEFT; + break; + case XK_KP_Up: + case XK_Up: + special = EGLUT_KEY_UP; + break; + case XK_KP_Right: + case XK_Right: + special = EGLUT_KEY_RIGHT; + break; + case XK_KP_Down: + case XK_Down: + special = EGLUT_KEY_DOWN; + break; + default: + special = -1; + break; + } + + return special; +} + +static void +next_event(struct eglut_window *win) +{ + int redraw = 0; + XEvent event; + + if (!XPending(_eglut->native_dpy)) { + if (_eglut->idle_cb) + _eglut->idle_cb(); + return; + } + + XNextEvent(_eglut->native_dpy, &event); + + switch (event.type) { + case Expose: + redraw = 1; + break; + case ConfigureNotify: + win->native.width = event.xconfigure.width; + win->native.height = event.xconfigure.height; + if (win->reshape_cb) + win->reshape_cb(win->native.width, win->native.height); + break; + case KeyPress: + { + char buffer[1]; + KeySym sym; + int r; + + r = XLookupString(&event.xkey, + buffer, sizeof(buffer), &sym, NULL); + if (r && win->keyboard_cb) { + win->keyboard_cb(buffer[0]); + } + else if (!r && win->special_cb) { + r = lookup_keysym(sym); + if (r >= 0) + win->special_cb(r); + } + } + redraw = 1; + break; + default: + ; /*no-op*/ + } + + _eglut->redisplay = redraw; +} + +void +_eglutNativeEventLoop(void) +{ + while (1) { + struct eglut_window *win = _eglut->current; + + next_event(win); + + if (_eglut->redisplay) { + _eglut->redisplay = 0; + + if (win->display_cb) + win->display_cb(); + eglSwapBuffers(_eglut->dpy, win->surface); + } + } +} diff --git a/progs/egl/eglut/eglutint.h b/progs/egl/eglut/eglutint.h new file mode 100644 index 0000000000..54d329f328 --- /dev/null +++ b/progs/egl/eglut/eglutint.h @@ -0,0 +1,78 @@ +#ifndef _EGLUTINT_H_ +#define _EGLUTINT_H_ + +#include "EGL/egl.h" +#include "eglut.h" + +struct eglut_window { + EGLConfig config; + EGLContext context; + + /* initialized by native display */ + struct { + union { + EGLNativeWindowType window; + EGLNativePixmapType pixmap; + EGLSurface surface; /* pbuffer or screen surface */ + } u; + int width, height; + } native; + + EGLSurface surface; + + int index; + + EGLUTreshapeCB reshape_cb; + EGLUTdisplayCB display_cb; + EGLUTkeyboardCB keyboard_cb; + EGLUTspecialCB special_cb; +}; + +struct eglut_state { + int api_mask; + int window_width, window_height; + const char *display_name; + int verbose; + int init_time; + + EGLUTidleCB idle_cb; + + int num_windows; + + /* initialized by native display */ + EGLNativeDisplayType native_dpy; + EGLint surface_type; + + EGLDisplay dpy; + EGLint major, minor; + + struct eglut_window *current; + + int redisplay; +}; + +extern struct eglut_state *_eglut; + +void +_eglutFatal(char *format, ...); + +int +_eglutNow(void); + +void +_eglutNativeInitDisplay(void); + +void +_eglutNativeFiniDisplay(void); + +void +_eglutNativeInitWindow(struct eglut_window *win, const char *title, + int x, int y, int w, int h); + +void +_eglutNativeFiniWindow(struct eglut_window *win); + +void +_eglutNativeEventLoop(void); + +#endif /* _EGLUTINT_H_ */ diff --git a/progs/egl/.gitignore b/progs/egl/opengl/.gitignore index 7a13d4686a..49c3a511f3 100644 --- a/progs/egl/.gitignore +++ b/progs/egl/opengl/.gitignore @@ -1,12 +1,13 @@ demo1 demo2 demo3 -eglgears +eglgears_x11 +eglgears_screen eglinfo eglscreen -egltri +egltri_x11 +egltri_screen peglgears xeglbindtex xeglgears xeglthreads -xegl_tri diff --git a/progs/egl/opengl/Makefile b/progs/egl/opengl/Makefile new file mode 100644 index 0000000000..9a91df9906 --- /dev/null +++ b/progs/egl/opengl/Makefile @@ -0,0 +1,83 @@ +# progs/egl/Makefile + +TOP = ../../.. +include $(TOP)/configs/current + + +INCLUDE_DIRS = -I$(TOP)/include + +HEADERS = $(TOP)/include/GLES/egl.h +LIB_DEP = $(TOP)/$(LIB_DIR)/libEGL.so + +LIBS = -L$(TOP)/$(LIB_DIR) -lEGL -lGL -lm + +EGLUT_DIR = $(TOP)/progs/egl/eglut + +EGLUT_DEMOS = \ + eglgears \ + egltri + +EGLUT_X11_DEMOS := $(addsuffix _x11,$(EGLUT_DEMOS)) +EGLUT_SCREEN_DEMOS := $(addsuffix _screen,$(EGLUT_DEMOS)) + +PROGRAMS = \ + demo1 \ + demo2 \ + demo3 \ + eglinfo \ + eglscreen \ + peglgears \ + xeglgears \ + xeglthreads + + +.c.o: + $(CC) -c $(INCLUDE_DIRS) -I$(EGLUT_DIR) $(CFLAGS) $< -o $@ + + + +default: $(PROGRAMS) $(EGLUT_X11_DEMOS) $(EGLUT_SCREEN_DEMOS) + +demo1: demo1.o $(HEADERS) $(LIB_DEP) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB) + +demo2: demo2.o $(HEADERS) $(LIB_DEP) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB) + +demo3: demo3.o $(HEADERS) $(LIB_DEP) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB) + +eglinfo: eglinfo.o $(HEADERS) $(LIB_DEP) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) + +eglscreen: eglscreen.o $(HEADERS) $(LIB_DEP) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB) + +peglgears: peglgears.o $(HEADERS) $(LIB_DEP) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB) -lm + +xeglgears: xeglgears.o $(HEADERS) $(LIB_DEP) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lm $(X11_LIBS) + +xeglthreads: xeglthreads.o $(HEADERS) $(LIB_DEP) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lpthread -lm $(X11_LIBS) + +$(EGLUT_DIR)/libeglut-x11.a $(EGLUT_DIR)/libeglut-screen.a: + @$(MAKE) -C $(EGLUT_DIR) + +# define the rules for EGLUT demos +define eglut-demo-rule +$(1)_x11 $(1)_screen: $(1)_%: $(1).o $(EGLUT_DIR)/libeglut-%.a $(LIB_DEP) +endef +$(foreach demo, $(EGLUT_DEMOS), $(eval $(call eglut-demo-rule,$(demo)))) + +# build EGLUT demos +$(EGLUT_X11_DEMOS): + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -L$(EGLUT_DIR) -leglut-$* $(LIBS) -lX11 +$(EGLUT_SCREEN_DEMOS): + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -L$(EGLUT_DIR) -leglut-$* $(LIBS) + +clean: + -rm -f *.o *~ + -rm -f $(PROGRAMS) $(EGLUT_X11_DEMOS) $(EGLUT_SCREEN_DEMOS) + @$(MAKE) -C $(EGLUT_DIR) clean diff --git a/progs/egl/demo1.c b/progs/egl/opengl/demo1.c index d892734ee5..d892734ee5 100644 --- a/progs/egl/demo1.c +++ b/progs/egl/opengl/demo1.c diff --git a/progs/egl/demo2.c b/progs/egl/opengl/demo2.c index b9e92f62ac..b9e92f62ac 100644 --- a/progs/egl/demo2.c +++ b/progs/egl/opengl/demo2.c diff --git a/progs/egl/demo3.c b/progs/egl/opengl/demo3.c index 64b9ee652c..64b9ee652c 100644 --- a/progs/egl/demo3.c +++ b/progs/egl/opengl/demo3.c diff --git a/progs/egl/eglgears.c b/progs/egl/opengl/eglgears.c index 63490953ae..28da9c0ac7 100644 --- a/progs/egl/eglgears.c +++ b/progs/egl/opengl/eglgears.c @@ -27,78 +27,16 @@ * Program runs for 5 seconds then exits, outputing framerate to console */ -#define EGL_EGLEXT_PROTOTYPES - -#include <assert.h> #include <math.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> #include <GL/gl.h> #include <EGL/egl.h> -#include <EGL/eglext.h> - -#define MAX_CONFIGS 10 -#define MAX_MODES 100 - -#define BENCHMARK - -#ifdef BENCHMARK - -/* XXX this probably isn't very portable */ - -#include <sys/time.h> -#include <unistd.h> - -/* return current time (in seconds) */ -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; -} - -#else /*BENCHMARK*/ - -/* dummy */ -static double -current_time(void) -{ - /* update this function for other platforms! */ - static double t = 0.0; - static int warn = 1; - if (warn) { - fprintf(stderr, "Warning: current_time() not implemented!!\n"); - warn = 0; - } - return t += 1.0; -} - -#endif /*BENCHMARK*/ - - -#ifndef M_PI -#define M_PI 3.14159265 -#endif +#include "eglut.h" static GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0; static GLint gear1, gear2, gear3; static GLfloat angle = 0.0; -#if 0 -static GLfloat eyesep = 5.0; /* Eye separation. */ -static GLfloat fix_point = 40.0; /* Fixation point distance. */ -static GLfloat left, right, asp; /* Stereo frustum params. */ -#endif - - /* * * Draw a gear wheel. You'll probably want to call this function when @@ -270,6 +208,22 @@ draw(void) } +static void +idle(void) +{ + static double t0 = -1.; + double dt, t = eglutGet(EGLUT_ELAPSED_TIME) / 1000.0; + if (t0 < 0.0) + t0 = t; + dt = t - t0; + t0 = t; + + angle += 70.0 * dt; /* 70 degrees per second */ + angle = fmod(angle, 360.0); /* prevents eventual overflow */ + + eglutPostRedisplay(); +} + /* new window size or exposure */ static void reshape(int width, int height) @@ -325,158 +279,23 @@ init(void) glEnable(GL_NORMALIZE); } - - - -static void run_gears(EGLDisplay dpy, EGLSurface surf, int ttr) -{ - double st = current_time(); - double ct = st; - int frames = 0; - GLfloat seconds, fps; - - while (ct - st < ttr) - { - double tt = current_time(); - double dt = tt - ct; - ct = tt; - - /* advance rotation for next frame */ - angle += 70.0 * dt; /* 70 degrees per second */ - if (angle > 3600.0) - angle -= 3600.0; - - draw(); - - eglSwapBuffers(dpy, surf); - - - frames++; - } - - seconds = ct - st; - fps = frames / seconds; - printf("%d frames in %3.1f seconds = %6.3f FPS\n", frames, seconds, fps); - -} - - int main(int argc, char *argv[]) { - int maj, min; - EGLContext ctx; - EGLSurface screen_surf; - EGLConfig configs[MAX_CONFIGS]; - EGLint numConfigs, i; - EGLBoolean b; - EGLDisplay d; - EGLint screenAttribs[10]; - EGLModeMESA mode[MAX_MODES]; - EGLScreenMESA screen; - EGLint count; - EGLint chosenMode = 0; - GLboolean printInfo = GL_FALSE; - EGLint width = 0, height = 0; - - /* parse cmd line args */ - for (i = 1; i < argc; i++) - { - if (strcmp(argv[i], "-info") == 0) - { - printInfo = GL_TRUE; - } - else - printf("Warning: unknown parameter: %s\n", argv[i]); - } - - /* DBR : Create EGL context/surface etc */ - d = eglGetDisplay(EGL_DEFAULT_DISPLAY); - assert(d); - - if (!eglInitialize(d, &maj, &min)) { - printf("eglgears: eglInitialize failed\n"); - exit(1); - } - - printf("eglgears: EGL version = %d.%d\n", maj, min); - printf("eglgears: EGL_VENDOR = %s\n", eglQueryString(d, EGL_VENDOR)); - - /* XXX use ChooseConfig */ - eglGetConfigs(d, configs, MAX_CONFIGS, &numConfigs); - eglGetScreensMESA(d, &screen, 1, &count); - - if (!eglGetModesMESA(d, screen, mode, MAX_MODES, &count) || count == 0) { - printf("eglgears: eglGetModesMESA failed!\n"); - return 0; - } - - /* Print list of modes, and find the one to use */ - printf("eglgears: Found %d modes:\n", count); - for (i = 0; i < count; i++) { - EGLint w, h; - eglGetModeAttribMESA(d, mode[i], EGL_WIDTH, &w); - eglGetModeAttribMESA(d, mode[i], EGL_HEIGHT, &h); - printf("%3d: %d x %d\n", i, w, h); - if (w > width && h > height) { - width = w; - height = h; - chosenMode = i; - } - } - printf("eglgears: Using screen mode/size %d: %d x %d\n", chosenMode, width, height); - - eglBindAPI(EGL_OPENGL_API); - ctx = eglCreateContext(d, configs[0], EGL_NO_CONTEXT, NULL); - if (ctx == EGL_NO_CONTEXT) { - printf("eglgears: failed to create context\n"); - return 0; - } - - /* build up screenAttribs array */ - i = 0; - screenAttribs[i++] = EGL_WIDTH; - screenAttribs[i++] = width; - screenAttribs[i++] = EGL_HEIGHT; - screenAttribs[i++] = height; - screenAttribs[i++] = EGL_NONE; - - screen_surf = eglCreateScreenSurfaceMESA(d, configs[0], screenAttribs); - if (screen_surf == EGL_NO_SURFACE) { - printf("eglgears: failed to create screen surface\n"); - return 0; - } - - b = eglShowScreenSurfaceMESA(d, screen, screen_surf, mode[chosenMode]); - if (!b) { - printf("eglgears: show surface failed\n"); - return 0; - } - - b = eglMakeCurrent(d, screen_surf, screen_surf, ctx); - if (!b) { - printf("eglgears: make current failed\n"); - return 0; - } - - 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(); - reshape(width, height); + eglutInitWindowSize(300, 300); + eglutInitAPIMask(EGLUT_OPENGL_BIT); + eglutInit(argc, argv); - glDrawBuffer( GL_BACK ); + eglutCreateWindow("eglgears"); - run_gears(d, screen_surf, 5.0); - - eglDestroySurface(d, screen_surf); - eglDestroyContext(d, ctx); - eglTerminate(d); + eglutIdleFunc(idle); + eglutReshapeFunc(reshape); + eglutDisplayFunc(draw); + + init(); + glDrawBuffer(GL_BACK); - return 0; + eglutMainLoop(); + + return 0; } diff --git a/progs/egl/eglinfo.c b/progs/egl/opengl/eglinfo.c index 961fd9ccc7..961fd9ccc7 100644 --- a/progs/egl/eglinfo.c +++ b/progs/egl/opengl/eglinfo.c diff --git a/progs/egl/eglscreen.c b/progs/egl/opengl/eglscreen.c index 520f76ea03..520f76ea03 100644 --- a/progs/egl/eglscreen.c +++ b/progs/egl/opengl/eglscreen.c diff --git a/progs/es1/screen/tri.c b/progs/egl/opengl/egltri.c index bab9499944..fb1dde3529 100644 --- a/progs/es1/screen/tri.c +++ b/progs/egl/opengl/egltri.c @@ -1,21 +1,16 @@ /* - * Copyright (C) 2009 Chia-I Wu <olv@0xlab.org> - * - * Based on egltri by - * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. * Copyright (C) 2008 Brian Paul All Rights Reserved. - * Copyright (C) 2008 Jakob Bornecrantz 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 @@ -24,45 +19,36 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <GLES/gl.h> -#include "winsys.h" +/* + * Draw a triangle with X/EGL. + * Brian Paul + * 3 June 2008 + */ -static GLfloat view_rotx = 0.0, view_roty = 0.0, view_rotz = 0.0; -static void tri_init() -{ - glClearColor(0.4, 0.4, 0.4, 0.0); -} +#include <math.h> +#include <stdlib.h> +#include <string.h> +#include <GL/gl.h> -static void tri_reshape(int width, int height) -{ - GLfloat ar = (GLfloat) width / (GLfloat) height; +#include "eglut.h" - glViewport(0, 0, (GLint) width, (GLint) height); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glFrustumf(-ar, ar, -1, 1, 5.0, 60.0); +static GLfloat view_rotx = 0.0, view_roty = 0.0, view_rotz = 0.0; - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glTranslatef(0.0, 0.0, -10.0); -} -static void tri_draw(void *data) +static void +draw(void) { static const GLfloat verts[3][2] = { { -1, -1 }, { 1, -1 }, { 0, 1 } }; - static const GLfloat colors[3][4] = { - { 1, 0, 0, 1 }, - { 0, 1, 0, 1 }, - { 0, 0, 1, 1 } + static const GLfloat colors[3][3] = { + { 1, 0, 0 }, + { 0, 1, 0 }, + { 0, 0, 1 } }; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -74,7 +60,7 @@ static void tri_draw(void *data) { glVertexPointer(2, GL_FLOAT, 0, verts); - glColorPointer(4, GL_FLOAT, 0, colors); + glColorPointer(3, GL_FLOAT, 0, colors); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_COLOR_ARRAY); @@ -87,43 +73,69 @@ static void tri_draw(void *data) glPopMatrix(); } -static void tri_run(void) + +/* new window size or exposure */ +static void +reshape(int width, int height) +{ + GLfloat ar = (GLfloat) width / (GLfloat) height; + + 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, -10.0); +} + + +static void +init(void) { - winsysRun(3.0, tri_draw, NULL); + glClearColor(0.4, 0.4, 0.4, 0.0); } -int main(int argc, char *argv[]) + +static void +special_key(int special) { - EGLint width, height; - GLboolean printInfo = GL_FALSE; - int i; - - /* parse cmd line args */ - for (i = 1; i < argc; i++) { - if (strcmp(argv[i], "-info") == 0) { - printInfo = GL_TRUE; - } - else { - printf("Warning: unknown parameter: %s\n", argv[i]); - } + switch (special) { + case EGLUT_KEY_LEFT: + view_roty += 5.0; + break; + case EGLUT_KEY_RIGHT: + view_roty -= 5.0; + break; + case EGLUT_KEY_UP: + view_rotx += 5.0; + break; + case EGLUT_KEY_DOWN: + view_rotx -= 5.0; + break; + default: + break; } +} - if (!winsysInitScreen()) - exit(1); - winsysQueryScreenSize(&width, &height); +int +main(int argc, char *argv[]) +{ + eglutInitWindowSize(300, 300); + eglutInitAPIMask(EGLUT_OPENGL_BIT); + eglutInit(argc, argv); - 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)); - } + eglutCreateWindow("egltri"); + + eglutReshapeFunc(reshape); + eglutDisplayFunc(draw); + eglutSpecialFunc(special_key); - tri_init(); - tri_reshape(width, height); - tri_run(); + init(); - winsysFiniScreen(); + eglutMainLoop(); return 0; } diff --git a/progs/egl/peglgears.c b/progs/egl/opengl/peglgears.c index 212d1acf69..212d1acf69 100644 --- a/progs/egl/peglgears.c +++ b/progs/egl/opengl/peglgears.c diff --git a/progs/egl/xeglgears.c b/progs/egl/opengl/xeglgears.c index a6a977d9ff..a6a977d9ff 100644 --- a/progs/egl/xeglgears.c +++ b/progs/egl/opengl/xeglgears.c diff --git a/progs/egl/xeglthreads.c b/progs/egl/opengl/xeglthreads.c index 5787faecb9..5787faecb9 100644 --- a/progs/egl/xeglthreads.c +++ b/progs/egl/opengl/xeglthreads.c diff --git a/progs/egl/opengles1/.gitignore b/progs/egl/opengles1/.gitignore new file mode 100644 index 0000000000..135e3deb35 --- /dev/null +++ b/progs/egl/opengles1/.gitignore @@ -0,0 +1,15 @@ +bindtex +drawtex_x11 +drawtex_screen +es1_info +gears_x11 +gears_screen +msaa +pbuffer +render_tex +texture_from_pixmap +torus_x11 +torus_screen +tri_x11 +tri_screen +two_win diff --git a/progs/egl/opengles1/Makefile b/progs/egl/opengles1/Makefile new file mode 100644 index 0000000000..554cff9e6b --- /dev/null +++ b/progs/egl/opengles1/Makefile @@ -0,0 +1,102 @@ +# progs/egl/opengles1/Makefile + +TOP = ../../.. +include $(TOP)/configs/current + + +INCLUDE_DIRS = \ + -I$(TOP)/include \ + +HEADERS = $(TOP)/include/GLES/egl.h + + +ES1_LIB_DEPS = \ + $(TOP)/$(LIB_DIR)/libEGL.so \ + $(TOP)/$(LIB_DIR)/libGLESv1_CM.so + + +ES1_LIBS = \ + -L$(TOP)/$(LIB_DIR) -lEGL \ + -L$(TOP)/$(LIB_DIR) -lGLESv1_CM $(LIBDRM_LIB) -lX11 + +EGLUT_DIR = $(TOP)/progs/egl/eglut + +EGLUT_DEMOS = \ + drawtex \ + gears \ + torus \ + tri + +EGLUT_X11_DEMOS := $(addsuffix _x11,$(EGLUT_DEMOS)) +EGLUT_SCREEN_DEMOS := $(addsuffix _screen,$(EGLUT_DEMOS)) + +PROGRAMS = \ + bindtex \ + es1_info \ + msaa \ + pbuffer \ + render_tex \ + texture_from_pixmap \ + two_win + + +.c.o: + $(CC) -c $(INCLUDE_DIRS) -I$(EGLUT_DIR) $(CFLAGS) $< -o $@ + + + +default: $(PROGRAMS) $(EGLUT_X11_DEMOS) $(EGLUT_SCREEN_DEMOS) + + + +bindtex: bindtex.o $(ES1_LIB_DEPS) + $(CC) $(CFLAGS) bindtex.o $(ES1_LIBS) -o $@ + + +es1_info: es1_info.o $(ES1_LIB_DEPS) + $(CC) $(CFLAGS) es1_info.o $(ES1_LIBS) -o $@ + + +msaa: msaa.o $(ES1_LIB_DEPS) + $(CC) $(CFLAGS) msaa.o $(ES1_LIBS) -o $@ + + +pbuffer: pbuffer.o $(ES1_LIB_DEPS) + $(CC) $(CFLAGS) pbuffer.o $(ES1_LIBS) -o $@ + + +render_tex: render_tex.o $(ES1_LIB_DEPS) + $(CC) $(CFLAGS) render_tex.o $(ES1_LIBS) -o $@ + + +texture_from_pixmap: texture_from_pixmap.o $(ES1_LIB_DEPS) + $(CC) $(CFLAGS) texture_from_pixmap.o $(ES1_LIBS) -o $@ + +torus: torus.o $(ES1_LIB_DEPS) + $(CC) $(CFLAGS) torus.o $(ES1_LIBS) -o $@ + + +two_win: two_win.o $(ES1_LIB_DEPS) + $(CC) $(CFLAGS) two_win.o $(ES1_LIBS) -o $@ + + +$(EGLUT_DIR)/libeglut-x11.a $(EGLUT_DIR)/libeglut-screen.a: + @$(MAKE) -C $(EGLUT_DIR) + +# define the rules for EGLUT demos +define eglut-demo-rule +$(1)_x11 $(1)_screen: $(1)_%: $(1).o $(EGLUT_DIR)/libeglut-%.a $(ES1_LIB_DEPS) +endef +$(foreach demo, $(EGLUT_DEMOS), $(eval $(call eglut-demo-rule,$(demo)))) + +# build EGLUT demos +$(EGLUT_X11_DEMOS): + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -L$(EGLUT_DIR) -leglut-$* $(ES1_LIBS) -lX11 +$(EGLUT_SCREEN_DEMOS): + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -L$(EGLUT_DIR) -leglut-$* $(ES1_LIBS) + + +clean: + -rm -f *.o *~ + -rm -f $(PROGRAMS) $(EGLUT_X11_DEMOS) $(EGLUT_SCREEN_DEMOS) + @$(MAKE) -C $(EGLUT_DIR) clean diff --git a/progs/es1/xegl/bindtex.c b/progs/egl/opengles1/bindtex.c index c243b5941b..c243b5941b 100644 --- a/progs/es1/xegl/bindtex.c +++ b/progs/egl/opengles1/bindtex.c diff --git a/progs/egl/opengles1/drawtex.c b/progs/egl/opengles1/drawtex.c new file mode 100644 index 0000000000..e9ac015340 --- /dev/null +++ b/progs/egl/opengles1/drawtex.c @@ -0,0 +1,217 @@ +/* + * Copyright (C) 2008 Tunsgten Graphics,Inc. All Rights Reserved. + */ + +/* + * Test GL_OES_draw_texture + * Brian Paul + * August 2008 + */ + +#define GL_GLEXT_PROTOTYPES + +#include <math.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <GLES/gl.h> +#include <GLES/glext.h> + +#include "eglut.h" + + +static GLfloat view_posx = 10.0, view_posy = 20.0; +static GLfloat width = 200, height = 200; +static GLboolean animate = GL_FALSE; +static int win; + + +static void +draw(void) +{ + glClear(GL_COLOR_BUFFER_BIT); + + glDrawTexfOES(view_posx, view_posy, 0.0, width, height); +} + + +/* new window size or exposure */ +static void +reshape(int width, int height) +{ + GLfloat ar = (GLfloat) width / (GLfloat) height; + + glViewport(0, 0, (GLint) width, (GLint) height); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + +#ifdef GL_VERSION_ES_CM_1_0 + glFrustumf(-ar, ar, -1, 1, 5.0, 60.0); +#else + glFrustum(-ar, ar, -1, 1, 5.0, 60.0); +#endif + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0.0, 0.0, -15.0); +} + + +static float +dist(GLuint i, GLuint j, float x, float y) +{ + return sqrt((i-x) * (i-x) + (j-y) * (j-y)); +} + +static void +make_smile_texture(void) +{ +#define SZ 128 + GLenum Filter = GL_LINEAR; + GLubyte image[SZ][SZ][4]; + GLuint i, j; + GLint cropRect[4]; + + for (i = 0; i < SZ; i++) { + for (j = 0; j < SZ; j++) { + GLfloat d_mouth = dist(i, j, SZ/2, SZ/2); + GLfloat d_rt_eye = dist(i, j, SZ*3/4, SZ*3/4); + GLfloat d_lt_eye = dist(i, j, SZ*3/4, SZ*1/4); + if (d_rt_eye < SZ / 8 || d_lt_eye < SZ / 8) { + image[i][j][0] = 20; + image[i][j][1] = 50; + image[i][j][2] = 255; + image[i][j][3] = 255; + } + else if (i < SZ/2 && d_mouth < SZ/3) { + image[i][j][0] = 255; + image[i][j][1] = 20; + image[i][j][2] = 20; + image[i][j][3] = 255; + } + else { + image[i][j][0] = 200; + image[i][j][1] = 200; + image[i][j][2] = 200; + image[i][j][3] = 255; + } + } + } + + glActiveTexture(GL_TEXTURE0); /* unit 0 */ + glBindTexture(GL_TEXTURE_2D, 42); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, SZ, SZ, 0, + GL_RGBA, GL_UNSIGNED_BYTE, image); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, Filter); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, Filter); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + + cropRect[0] = 0; + cropRect[1] = 0; + cropRect[2] = SZ; + cropRect[3] = SZ; + glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, cropRect); +#undef SZ +} + + + +static void +init(void) +{ + const char *ext = (char *) glGetString(GL_EXTENSIONS); + + if (!strstr(ext, "GL_OES_draw_texture")) { + fprintf(stderr, "Sorry, this program requires GL_OES_draw_texture"); + exit(1); + } + + glClearColor(0.4, 0.4, 0.4, 0.0); + + make_smile_texture(); + glEnable(GL_TEXTURE_2D); +} + + +static void +idle(void) +{ + if (animate) { + view_posx += 1.0; + view_posy += 2.0; + eglutPostRedisplay(); + } +} + +static void +key(unsigned char key) +{ + switch (key) { + case ' ': + animate = !animate; + break; + case 'w': + width -= 1.0f; + break; + case 'W': + width += 1.0f; + break; + case 'h': + height -= 1.0f; + break; + case 'H': + height += 1.0f; + break; + case 27: + eglutDestroyWindow(win); + exit(0); + break; + default: + break; + } +} + +static void +special_key(int key) +{ + switch (key) { + case EGLUT_KEY_LEFT: + view_posx -= 1.0; + break; + case EGLUT_KEY_RIGHT: + view_posx += 1.0; + break; + case EGLUT_KEY_UP: + view_posy += 1.0; + break; + case EGLUT_KEY_DOWN: + view_posy -= 1.0; + break; + default: + break; + } +} + +int +main(int argc, char *argv[]) +{ + eglutInitWindowSize(400, 300); + eglutInitAPIMask(EGLUT_OPENGL_ES1_BIT); + eglutInit(argc, argv); + + win = eglutCreateWindow("drawtex"); + + eglutIdleFunc(idle); + eglutReshapeFunc(reshape); + eglutDisplayFunc(draw); + eglutKeyboardFunc(key); + eglutSpecialFunc(special_key); + + init(); + + eglutMainLoop(); + + return 0; +} diff --git a/progs/es1/xegl/es1_info.c b/progs/egl/opengles1/es1_info.c index 93816b5215..93816b5215 100644 --- a/progs/es1/xegl/es1_info.c +++ b/progs/egl/opengles1/es1_info.c diff --git a/progs/es1/screen/gears.c b/progs/egl/opengles1/gears.c index c7625826b9..8462a4871a 100644 --- a/progs/es1/screen/gears.c +++ b/progs/egl/opengles1/gears.c @@ -28,7 +28,7 @@ #include <assert.h> #include <GLES/gl.h> -#include "winsys.h" +#include "eglut.h" #ifndef M_PI #define M_PI 3.14159265 @@ -247,7 +247,7 @@ draw_gear(const struct gear *gear) static void -gears_draw(void *data) +gears_draw(void) { static const GLfloat red[4] = { 0.8, 0.1, 0.0, 1.0 }; static const GLfloat green[4] = { 0.0, 0.8, 0.2, 1.0 }; @@ -288,11 +288,6 @@ gears_draw(void *data) glPopMatrix(); glPopMatrix(); - - /* advance rotation for next frame */ - angle += 0.5; /* 0.5 degree per frame */ - if (angle > 3600.0) - angle -= 3600.0; } @@ -348,27 +343,41 @@ gears_reshape(int width, int height) } -static void gears_run(void) +static void +gears_idle(void) { - winsysRun(5.0, gears_draw, NULL); + static double t0 = -1.; + double dt, t = eglutGet(EGLUT_ELAPSED_TIME) / 1000.0; + if (t0 < 0.0) + t0 = t; + dt = t - t0; + t0 = t; + + angle += 70.0 * dt; /* 70 degrees per second */ + angle = fmod(angle, 360.0); /* prevents eventual overflow */ + + eglutPostRedisplay(); } int main(int argc, char *argv[]) { - EGLint width, height; + eglutInitWindowSize(300, 300); + eglutInitAPIMask(EGLUT_OPENGL_ES1_BIT); + eglutInit(argc, argv); - if (!winsysInitScreen()) - exit(1); - winsysQueryScreenSize(&width, &height); + eglutCreateWindow("gears"); + + eglutIdleFunc(gears_idle); + eglutReshapeFunc(gears_reshape); + eglutDisplayFunc(gears_draw); gears_init(); - gears_reshape(width, height); - gears_run(); - gears_fini(); - winsysFiniScreen(); + eglutMainLoop(); + + gears_fini(); return 0; } diff --git a/progs/es1/xegl/msaa.c b/progs/egl/opengles1/msaa.c index b4c6c63217..b4c6c63217 100644 --- a/progs/es1/xegl/msaa.c +++ b/progs/egl/opengles1/msaa.c diff --git a/progs/es1/xegl/pbuffer.c b/progs/egl/opengles1/pbuffer.c index 011c2af58f..60f864445a 100644 --- a/progs/es1/xegl/pbuffer.c +++ b/progs/egl/opengles1/pbuffer.c @@ -168,6 +168,8 @@ draw_both(EGLDisplay egl_dpy, EGLSurface egl_surf, EGLSurface egl_pbuf, glReadPixels(0, 0, WinWidth, WinHeight, GL_RGBA, GL_UNSIGNED_BYTE, wbuf); printf("Window[%d,%d] = 0x%08x\n", x, y, wbuf[y*WinWidth+x]); + eglSwapBuffers(egl_dpy, egl_surf); + /* then draw to pbuffer */ if (!eglMakeCurrent(egl_dpy, egl_pbuf, egl_pbuf, egl_ctx)) { printf("Error: eglMakeCurrent(pbuffer) failed\n"); @@ -177,7 +179,6 @@ draw_both(EGLDisplay egl_dpy, EGLSurface egl_surf, EGLSurface egl_pbuf, glReadPixels(0, 0, WinWidth, WinHeight, GL_RGBA, GL_UNSIGNED_BYTE, pbuf); printf("Pbuffer[%d,%d] = 0x%08x\n", x, y, pbuf[y*WinWidth+x]); - eglSwapBuffers(egl_dpy, egl_surf); /* compare renderings */ for (dif = i = 0; i < WinWidth * WinHeight; i++) { diff --git a/progs/es1/xegl/render_tex.c b/progs/egl/opengles1/render_tex.c index 0200fa4cb0..0200fa4cb0 100644 --- a/progs/es1/xegl/render_tex.c +++ b/progs/egl/opengles1/render_tex.c diff --git a/progs/egl/opengles1/texture_from_pixmap.c b/progs/egl/opengles1/texture_from_pixmap.c new file mode 100644 index 0000000000..8e7e803d78 --- /dev/null +++ b/progs/egl/opengles1/texture_from_pixmap.c @@ -0,0 +1,579 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu <olv@lunarg.com> + */ + +/* + * This demo uses EGL_KHR_image_pixmap and GL_OES_EGL_image to demonstrate + * texture-from-pixmap. + */ + +#include <assert.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <unistd.h> /* for usleep */ +#include <sys/time.h> /* for gettimeofday */ +#include <X11/Xlib.h> +#include <X11/Xutil.h> +#include <X11/keysym.h> +#include <GLES/gl.h> +#include <GLES/glext.h> +#include <EGL/egl.h> +#include <EGL/eglext.h> + +struct app_data { + /* native */ + Display *xdpy; + Window canvas, cube; + Pixmap pix; + unsigned int width, height, depth; + GC fg, bg; + + /* EGL */ + EGLDisplay dpy; + EGLContext ctx; + EGLSurface surf; + EGLImageKHR img; + + /* OpenGL ES */ + GLuint texture; + + PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR; + PFNEGLDESTROYIMAGEKHRPROC eglDestroyImageKHR; + PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES; + + /* app state */ + Bool loop; + Bool redraw, reshape; + + struct { + Bool active; + unsigned long next_frame; /* in ms */ + float view_rotx; + float view_roty; + float view_rotz; + + } animate; + + struct { + Bool active; + int x1, y1; + int x2, y2; + } paint; +}; + +static void +gl_redraw(void) +{ + const GLfloat verts[4][2] = { + { -1, -1 }, + { 1, -1 }, + { 1, 1 }, + { -1, 1 } + }; + const GLfloat texcoords[4][2] = { + { 0, 1 }, + { 1, 1 }, + { 1, 0 }, + { 0, 0 } + }; + const GLfloat faces[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); + + glVertexPointer(2, GL_FLOAT, 0, verts); + glTexCoordPointer(2, GL_FLOAT, 0, texcoords); + + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + + for (i = 0; i < 6; i++) { + glPushMatrix(); + glRotatef(faces[i][0], faces[i][1], faces[i][2], faces[i][3]); + glTranslatef(0, 0, 1.0); + glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + glPopMatrix(); + } + + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); +} + +static void +gl_reshape(int width, int height) +{ + GLfloat ar = (GLfloat) width / (GLfloat) height; + + glViewport(0, 0, width, height); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustumf(-ar, ar, -1, 1, 5.0, 60.0); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0.0, 0.0, -10.0); +} + +static void +app_redraw(struct app_data *data) +{ + /* pixmap has changed */ + if (data->reshape || data->paint.active) { + eglWaitNative(EGL_CORE_NATIVE_ENGINE); + + if (data->reshape) { + data->glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, + (GLeglImageOES) data->img); + } + } + + XCopyArea(data->xdpy, data->pix, data->canvas, data->fg, + 0, 0, data->width, data->height, 0, 0); + + glPushMatrix(); + glRotatef(data->animate.view_rotx, 1, 0, 0); + glRotatef(data->animate.view_roty, 0, 1, 0); + glRotatef(data->animate.view_rotz, 0, 0, 1); + gl_redraw(); + glPopMatrix(); + + eglSwapBuffers(data->dpy, data->surf); +} + +static void +app_reshape(struct app_data *data) +{ + const EGLint img_attribs[] = { + EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, + EGL_NONE + }; + + XResizeWindow(data->xdpy, data->cube, data->width, data->height); + XMoveWindow(data->xdpy, data->cube, data->width, 0); + + if (data->img) + data->eglDestroyImageKHR(data->dpy, data->img); + if (data->pix) + XFreePixmap(data->xdpy, data->pix); + + data->pix = XCreatePixmap(data->xdpy, data->canvas, data->width, data->height, data->depth); + XFillRectangle(data->xdpy, data->pix, data->bg, 0, 0, data->width, data->height); + + data->img = data->eglCreateImageKHR(data->dpy, EGL_NO_CONTEXT, + EGL_NATIVE_PIXMAP_KHR, (EGLClientBuffer) data->pix, img_attribs); + + gl_reshape(data->width, data->height); +} + +static void +app_toggle_animate(struct app_data *data) +{ + data->animate.active = !data->animate.active; + + if (data->animate.active) { + struct timeval tv; + + gettimeofday(&tv, NULL); + data->animate.next_frame = tv.tv_sec * 1000 + tv.tv_usec / 1000; + } +} + +static void +app_next_event(struct app_data *data) +{ + XEvent event; + + data->reshape = False; + data->redraw = False; + data->paint.active = False; + + if (data->animate.active) { + struct timeval tv; + unsigned long now; + + gettimeofday(&tv, NULL); + now = tv.tv_sec * 1000 + tv.tv_usec / 1000; + + /* wait for next frame */ + if (!XPending(data->xdpy) && now < data->animate.next_frame) { + usleep((data->animate.next_frame - now) * 1000); + gettimeofday(&tv, NULL); + now = tv.tv_sec * 1000 + tv.tv_usec / 1000; + } + + while (now >= data->animate.next_frame) { + data->animate.view_rotx += 1.0; + data->animate.view_roty += 2.0; + data->animate.view_rotz += 1.5; + + /* 30fps */ + data->animate.next_frame += 1000 / 30; + } + + /* check again in case there were events when sleeping */ + if (!XPending(data->xdpy)) { + data->redraw = True; + return; + } + } + + XNextEvent(data->xdpy, &event); + + switch (event.type) { + case ConfigureNotify: + data->width = event.xconfigure.width / 2; + data->height = event.xconfigure.height; + data->reshape = True; + break; + case Expose: + data->redraw = True; + break; + case KeyPress: + { + int code; + + code = XLookupKeysym(&event.xkey, 0); + switch (code) { + case XK_a: + app_toggle_animate(data); + break; + case XK_Escape: + data->loop = False; + break; + default: + break; + } + } + break; + case ButtonPress: + data->paint.x1 = data->paint.x2 = event.xbutton.x; + data->paint.y1 = data->paint.y2 = event.xbutton.y; + break; + case ButtonRelease: + data->paint.active = False; + break; + case MotionNotify: + data->paint.x1 = data->paint.x2; + data->paint.y1 = data->paint.y2; + data->paint.x2 = event.xmotion.x; + data->paint.y2 = event.xmotion.y; + data->paint.active = True; + break; + default: + break; + } + + if (data->paint.active || data->reshape) + data->redraw = True; +} + +static void +app_init_gl(struct app_data *data) +{ + glClearColor(0.1, 0.1, 0.3, 0.0); + glColor4f(1.0, 1.0, 1.0, 1.0); + + glGenTextures(1, &data->texture); + + glBindTexture(GL_TEXTURE_2D, data->texture); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + + glEnable(GL_TEXTURE_2D); + glEnable(GL_DEPTH_TEST); +} + +static Bool +app_init_exts(struct app_data *data) +{ + const char *exts; + + exts = eglQueryString(data->dpy, EGL_EXTENSIONS); + data->eglCreateImageKHR = + (PFNEGLCREATEIMAGEKHRPROC) eglGetProcAddress("eglCreateImageKHR"); + data->eglDestroyImageKHR = + (PFNEGLDESTROYIMAGEKHRPROC) eglGetProcAddress("eglDestroyImageKHR"); + if (!exts || !strstr(exts, "EGL_KHR_image_pixmap") || + !data->eglCreateImageKHR || !data->eglDestroyImageKHR) { + printf("EGL does not support EGL_KHR_image_pixmap\n"); + return False; + } + + exts = (const char *) glGetString(GL_EXTENSIONS); + data->glEGLImageTargetTexture2DOES = (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC) + eglGetProcAddress("glEGLImageTargetTexture2DOES"); + if (!exts || !strstr(exts, "GL_OES_EGL_image") || + !data->glEGLImageTargetTexture2DOES) { + printf("OpenGL ES does not support GL_OES_EGL_image\n"); + return False; + } + + return True; +} + +static void +app_run(struct app_data *data) +{ + Window root; + int x, y; + unsigned int border; + + if (!eglMakeCurrent(data->dpy, data->surf, data->surf, data->ctx)) + return; + + if (!app_init_exts(data)) + return; + + printf("Draw something on the left with the mouse!\n"); + + app_init_gl(data); + + if (!XGetGeometry(data->xdpy, data->canvas, &root, &x, &y, + &data->width, &data->height, &border, &data->depth)) + return; + data->width /= 2; + + app_reshape(data); + + XMapWindow(data->xdpy, data->canvas); + XMapWindow(data->xdpy, data->cube); + + app_toggle_animate(data); + data->loop = True; + + while (data->loop) { + app_next_event(data); + + if (data->reshape) + app_reshape(data); + if (data->paint.active) { + XDrawLine(data->xdpy, data->pix, data->fg, + data->paint.x1, data->paint.y1, + data->paint.x2, data->paint.y2); + } + + if (data->redraw) + app_redraw(data); + } + + eglMakeCurrent(data->dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); +} + +static Bool +make_x_window(struct app_data *data, const char *name, + int x, int y, int width, int height) +{ + static const EGLint attribs[] = { + EGL_RED_SIZE, 1, + EGL_GREEN_SIZE, 1, + EGL_BLUE_SIZE, 1, + EGL_DEPTH_SIZE, 1, + EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT, + EGL_NONE + }; + static const EGLint ctx_attribs[] = { + EGL_CONTEXT_CLIENT_VERSION, 1, + EGL_NONE + }; + int scrnum; + XSetWindowAttributes attr; + unsigned long mask; + Window root; + Window win; + XVisualInfo *visInfo, visTemplate; + int num_visuals; + EGLConfig config; + EGLint num_configs; + EGLint vid; + + scrnum = DefaultScreen( data->xdpy ); + root = RootWindow( data->xdpy, scrnum ); + + if (!eglChooseConfig( data->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(data->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(data->xdpy, 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( data->xdpy, root, visInfo->visual, AllocNone); + attr.event_mask = StructureNotifyMask | ExposureMask | + KeyPressMask | ButtonPressMask | ButtonMotionMask; + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; + + win = XCreateWindow( data->xdpy, root, 0, 0, width * 2, 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(data->xdpy, win, &sizehints); + XSetStandardProperties(data->xdpy, win, name, name, + None, (char **)NULL, 0, &sizehints); + } + + data->canvas = win; + + attr.event_mask = 0x0; + win = XCreateWindow( data->xdpy, win, width, 0, width, height, + 0, visInfo->depth, InputOutput, + visInfo->visual, mask, &attr ); + data->cube = win; + + eglBindAPI(EGL_OPENGL_ES_API); + + data->ctx = eglCreateContext(data->dpy, config, EGL_NO_CONTEXT, ctx_attribs ); + if (!data->ctx) { + printf("Error: eglCreateContext failed\n"); + exit(1); + } + + data->surf = eglCreateWindowSurface(data->dpy, config, data->cube, NULL); + if (!data->surf) { + printf("Error: eglCreateWindowSurface failed\n"); + exit(1); + } + + XFree(visInfo); + + return (data->canvas && data->cube && data->ctx && data->surf); +} + +static void +app_fini(struct app_data *data) +{ + if (data->img) + data->eglDestroyImageKHR(data->dpy, data->img); + if (data->pix) + XFreePixmap(data->xdpy, data->pix); + + if (data->fg) + XFreeGC(data->xdpy, data->fg); + if (data->bg) + XFreeGC(data->xdpy, data->bg); + + if (data->surf) + eglDestroySurface(data->dpy, data->surf); + if (data->ctx) + eglDestroyContext(data->dpy, data->ctx); + + if (data->cube) + XDestroyWindow(data->xdpy, data->cube); + if (data->canvas) + XDestroyWindow(data->xdpy, data->canvas); + + if (data->dpy) + eglTerminate(data->dpy); + if (data->xdpy) + XCloseDisplay(data->xdpy); +} + +static Bool +app_init(struct app_data *data, int argc, char **argv) +{ + XGCValues gc_vals; + + memset(data, 0, sizeof(*data)); + + data->xdpy = XOpenDisplay(NULL); + if (!data->xdpy) + goto fail; + + data->dpy = eglGetDisplay(data->xdpy); + if (!data->dpy || !eglInitialize(data->dpy, NULL, NULL)) + goto fail; + + if (!make_x_window(data, "EGLImage TFP", 0, 0, 300, 300)) + goto fail; + + gc_vals.function = GXcopy; + gc_vals.foreground = WhitePixel(data->xdpy, DefaultScreen(data->xdpy)); + gc_vals.line_width = 3; + gc_vals.line_style = LineSolid; + gc_vals.fill_style = FillSolid; + + data->fg = XCreateGC(data->xdpy, data->canvas, + GCFunction | GCForeground | GCLineWidth | GCLineStyle | GCFillStyle, + &gc_vals); + gc_vals.foreground = BlackPixel(data->xdpy, DefaultScreen(data->xdpy)); + data->bg = XCreateGC(data->xdpy, data->canvas, + GCFunction | GCForeground | GCLineWidth | GCLineStyle | GCFillStyle, + &gc_vals); + if (!data->fg || !data->bg) + goto fail; + + return True; + +fail: + app_fini(data); + return False; +} + +int +main(int argc, char **argv) +{ + struct app_data data; + + if (app_init(&data, argc, argv)) { + app_run(&data); + app_fini(&data); + } + + return 0; +} diff --git a/progs/es1/xegl/torus.c b/progs/egl/opengles1/torus.c index 9438a4fe59..8f262b53d6 100644 --- a/progs/es1/xegl/torus.c +++ b/progs/egl/opengles1/torus.c @@ -13,14 +13,9 @@ #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 <GLES/gl.h> -#include <GLES/glext.h> -#include <EGL/egl.h> +#include "eglut.h" static const struct { GLenum internalFormat; @@ -43,6 +38,8 @@ static const struct { static GLfloat view_rotx = 0.0, view_roty = 0.0, view_rotz = 0.0; static GLint tex_format = NUM_CPAL_FORMATS; +static GLboolean animate = GL_TRUE; +static int win; static void @@ -364,293 +361,88 @@ init(void) } -/* - * 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) +idle(void) { - static const EGLint attribs[] = { - EGL_RED_SIZE, 1, - EGL_GREEN_SIZE, 1, - EGL_BLUE_SIZE, 1, - EGL_DEPTH_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_OPENGL_ES_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); + if (animate) { + view_rotx += 1.0; + view_roty += 2.0; + eglutPostRedisplay(); } - - XFree(visInfo); - - *winRet = win; - *ctxRet = ctx; } - static void -event_loop(Display *dpy, Window win, - EGLDisplay egl_dpy, EGLSurface egl_surf) +key(unsigned char key) { - int anim = 1; - - while (1) { - int redraw = 0; - - if (!anim || XPending(dpy)) { - XEvent event; - XNextEvent(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_t) { - GLint size; - tex_format = (tex_format + 1) % (NUM_CPAL_FORMATS + 1); - if (tex_format < NUM_CPAL_FORMATS) { - size = make_cpal_texture(tex_format); - printf("Using %s (%d bytes)\n", - cpal_formats[tex_format].name, size); - } - else { - size = make_texture(); - printf("Using uncompressed texture (%d bytes)\n", size); - } - } - else { - r = XLookupString(&event.xkey, buffer, sizeof(buffer), - NULL, NULL); - if (buffer[0] == ' ') { - anim = !anim; - } - else if (buffer[0] == 27) { - /* escape */ - return; - } - } - } - redraw = 1; - break; - default: - ; /*no-op*/ + switch (key) { + case ' ': + animate = !animate; + break; + case 't': + { + GLint size; + tex_format = (tex_format + 1) % (NUM_CPAL_FORMATS + 1); + if (tex_format < NUM_CPAL_FORMATS) { + size = make_cpal_texture(tex_format); + printf("Using %s (%d bytes)\n", + cpal_formats[tex_format].name, size); + } + else { + size = make_texture(); + printf("Using uncompressed texture (%d bytes)\n", size); } - } - - if (anim) { - view_rotx += 1.0; - view_roty += 2.0; - redraw = 1; - } - if (redraw) { - draw(); - eglSwapBuffers(egl_dpy, egl_surf); + eglutPostRedisplay(); } + break; + case 27: + eglutDestroyWindow(win); + exit(0); + break; + default: + break; } } - static void -usage(void) +special_key(int key) { - printf("Usage:\n"); - printf(" -display <displayname> set the display to run on\n"); - printf(" -info display OpenGL renderer info\n"); + switch (key) { + case EGLUT_KEY_LEFT: + view_roty += 5.0; + break; + case EGLUT_KEY_RIGHT: + view_roty -= 5.0; + break; + case EGLUT_KEY_UP: + view_rotx += 5.0; + break; + case EGLUT_KEY_DOWN: + view_rotx -= 5.0; + break; + default: + break; + } } - int main(int argc, char *argv[]) { - const int winWidth = 300, winHeight = 300; - 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); - - s = eglQueryString(egl_dpy, EGL_VENDOR); - printf("EGL_VENDOR = %s\n", s); - - s = eglQueryString(egl_dpy, EGL_EXTENSIONS); - printf("EGL_EXTENSIONS = %s\n", s); - - s = eglQueryString(egl_dpy, EGL_CLIENT_APIS); - printf("EGL_CLIENT_APIS = %s\n", s); + eglutInitWindowSize(300, 300); + eglutInitAPIMask(EGLUT_OPENGL_ES1_BIT); + eglutInit(argc, argv); - make_x_window(x_dpy, egl_dpy, - "torus", 0, 0, winWidth, winHeight, - &win, &egl_ctx, &egl_surf); + win = eglutCreateWindow("torus"); - XMapWindow(x_dpy, win); - if (!eglMakeCurrent(egl_dpy, egl_surf, egl_surf, egl_ctx)) { - printf("Error: eglMakeCurrent() failed\n"); - return -1; - } - - 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)); - } + eglutIdleFunc(idle); + eglutReshapeFunc(reshape); + eglutDisplayFunc(draw); + eglutKeyboardFunc(key); + eglutSpecialFunc(special_key); 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); + eglutMainLoop(); return 0; } diff --git a/progs/egl/opengles1/tri.c b/progs/egl/opengles1/tri.c new file mode 100644 index 0000000000..01ad9bd37e --- /dev/null +++ b/progs/egl/opengles1/tri.c @@ -0,0 +1,211 @@ +/* + * 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. + */ + +/* + * Draw a triangle with X/EGL and OpenGL ES 1.x + * Brian Paul + * 5 June 2008 + */ + +#define USE_FIXED_POINT 0 + + +#include <assert.h> +#include <math.h> +#include <stdio.h> +#include <GLES/gl.h> /* use OpenGL ES 1.x */ +#include <GLES/glext.h> +#include <EGL/egl.h> + +#include "eglut.h" + + +#define FLOAT_TO_FIXED(X) ((X) * 65535.0) + + + +static GLfloat view_rotx = 0.0, view_roty = 0.0, view_rotz = 0.0; + + +static void +draw(void) +{ +#if USE_FIXED_POINT + static const GLfixed verts[3][2] = { + { -65536, -65536 }, + { 65536, -65536 }, + { 0, 65536 } + }; + static const GLfixed colors[3][4] = { + { 65536, 0, 0, 65536 }, + { 0, 65536, 0 , 65536}, + { 0, 0, 65536 , 65536} + }; +#else + static const GLfloat verts[3][2] = { + { -1, -1 }, + { 1, -1 }, + { 0, 1 } + }; + static const GLfloat colors[3][4] = { + { 1, 0, 0, 1 }, + { 0, 1, 0, 1 }, + { 0, 0, 1, 1 } + }; +#endif + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glPushMatrix(); + glRotatef(view_rotx, 1, 0, 0); + glRotatef(view_roty, 0, 1, 0); + glRotatef(view_rotz, 0, 0, 1); + + { +#if USE_FIXED_POINT + glVertexPointer(2, GL_FIXED, 0, verts); + glColorPointer(4, GL_FIXED, 0, colors); +#else + glVertexPointer(2, GL_FLOAT, 0, verts); + glColorPointer(4, GL_FLOAT, 0, colors); +#endif + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_COLOR_ARRAY); + + /* draw triangle */ + glDrawArrays(GL_TRIANGLES, 0, 3); + + /* draw some points */ + glPointSizex(FLOAT_TO_FIXED(15.5)); + glDrawArrays(GL_POINTS, 0, 3); + + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); + } + + if (0) { + /* test code */ + GLfixed size; + glGetFixedv(GL_POINT_SIZE, &size); + printf("GL_POINT_SIZE = 0x%x %f\n", size, size / 65536.0); + } + + glPopMatrix(); +} + + +/* new window size or exposure */ +static void +reshape(int width, int height) +{ + GLfloat ar = (GLfloat) width / (GLfloat) height; + + glViewport(0, 0, (GLint) width, (GLint) height); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); +#ifdef GL_VERSION_ES_CM_1_0 + glFrustumf(-ar, ar, -1, 1, 5.0, 60.0); +#else + glFrustum(-ar, ar, -1, 1, 5.0, 60.0); +#endif + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0.0, 0.0, -10.0); +} + + +static void +test_query_matrix(void) +{ + PFNGLQUERYMATRIXXOESPROC procQueryMatrixx; + typedef void (*voidproc)(); + GLfixed mantissa[16]; + GLint exponent[16]; + GLbitfield rv; + int i; + + procQueryMatrixx = (PFNGLQUERYMATRIXXOESPROC) eglGetProcAddress("glQueryMatrixxOES"); + assert(procQueryMatrixx); + /* Actually try out this one */ + rv = (*procQueryMatrixx)(mantissa, exponent); + for (i = 0; i < 16; i++) { + if (rv & (1<<i)) { + printf("matrix[%d] invalid\n", i); + } + else { + printf("matrix[%d] = %f * 2^(%d)\n", i, mantissa[i]/65536.0, exponent[i]); + } + } + assert(!eglGetProcAddress("glFoo")); +} + + +static void +init(void) +{ + glClearColor(0.4, 0.4, 0.4, 0.0); + + if (0) + test_query_matrix(); +} + +static void +special_key(int special) +{ + switch (special) { + case EGLUT_KEY_LEFT: + view_roty += 5.0; + break; + case EGLUT_KEY_RIGHT: + view_roty -= 5.0; + break; + case EGLUT_KEY_UP: + view_rotx += 5.0; + break; + case EGLUT_KEY_DOWN: + view_rotx -= 5.0; + break; + default: + break; + } +} + +int +main(int argc, char *argv[]) +{ + eglutInitWindowSize(300, 300); + eglutInitAPIMask(EGLUT_OPENGL_ES1_BIT); + eglutInit(argc, argv); + + eglutCreateWindow("tri"); + + eglutReshapeFunc(reshape); + eglutDisplayFunc(draw); + eglutSpecialFunc(special_key); + + init(); + + eglutMainLoop(); + + return 0; +} diff --git a/progs/es1/xegl/two_win.c b/progs/egl/opengles1/two_win.c index 4785e5304d..4785e5304d 100644 --- a/progs/es1/xegl/two_win.c +++ b/progs/egl/opengles1/two_win.c diff --git a/progs/egl/opengles2/.gitignore b/progs/egl/opengles2/.gitignore new file mode 100644 index 0000000000..6158cc6e68 --- /dev/null +++ b/progs/egl/opengles2/.gitignore @@ -0,0 +1,3 @@ +es2_info.c +es2_info +tri diff --git a/progs/es2/xegl/Makefile b/progs/egl/opengles2/Makefile index 5bb167c1c6..710c4d8c13 100644 --- a/progs/es2/xegl/Makefile +++ b/progs/egl/opengles2/Makefile @@ -1,4 +1,4 @@ -# progs/es2/xegl/Makefile +# progs/egl/opengles2/Makefile TOP = ../../.. include $(TOP)/configs/current @@ -33,7 +33,7 @@ default: $(PROGRAMS) -es2_info.c: ../../es1/xegl/es1_info.c +es2_info.c: ../opengles1/es1_info.c cp -f $^ $@ es2_info: es2_info.o $(ES2_LIB_DEPS) diff --git a/progs/es2/xegl/tri.c b/progs/egl/opengles2/tri.c index 8981d8a7e2..8981d8a7e2 100644 --- a/progs/es2/xegl/tri.c +++ b/progs/egl/opengles2/tri.c diff --git a/progs/openvg/.gitignore b/progs/egl/openvg/.gitignore index 9b05e1e81d..3e1733c8c8 100644 --- a/progs/openvg/.gitignore +++ b/progs/egl/openvg/.gitignore @@ -1,5 +1,7 @@ -demos/lion -demos/sp +lion_x11 +lion_screen +sp_x11 +sp_screen trivial/arc trivial/cap trivial/clear diff --git a/progs/egl/openvg/Makefile b/progs/egl/openvg/Makefile new file mode 100644 index 0000000000..3683cb7814 --- /dev/null +++ b/progs/egl/openvg/Makefile @@ -0,0 +1,55 @@ +# progs/egl/openvg/Makefile + +TOP = ../../.. +include $(TOP)/configs/current + +VG_LIBS=-lm -lEGL -lOpenVG -L$(TOP)/lib -L$(TOP)/lib/gallium +INCLUDE_DIRS = -I$(TOP)/include + +EGLUT_DIR = $(TOP)/progs/egl/eglut + +EGLUT_DEMOS = \ + sp + +EGLUT_X11_DEMOS := $(addsuffix _x11,$(EGLUT_DEMOS)) +EGLUT_SCREEN_DEMOS := $(addsuffix _screen,$(EGLUT_DEMOS)) + +PROGRAMS = \ + lion_x11 \ + lion_screen + +.c.o: + $(CC) -c $(INCLUDE_DIRS) -I$(EGLUT_DIR) $(CFLAGS) $< -o $@ + + + +default: $(PROGRAMS) $(EGLUT_X11_DEMOS) $(EGLUT_SCREEN_DEMOS) + +lion_x11: lion.o lion-render.o $(EGLUT_DIR)/libeglut-x11.a + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ lion.o lion-render.o \ + -L$(EGLUT_DIR) -leglut-x11 $(VG_LIBS) -lX11 + +lion_screen: lion.o lion-render.o $(EGLUT_DIR)/libeglut-screen.a + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ lion.o lion-render.o \ + -L$(EGLUT_DIR) -leglut-screen $(VG_LIBS) + + +$(EGLUT_DIR)/libeglut-x11.a $(EGLUT_DIR)/libeglut-screen.a: + @$(MAKE) -C $(EGLUT_DIR) + +# define the rules for EGLUT demos +define eglut-demo-rule +$(1)_x11 $(1)_screen: $(1)_%: $(1).o $(EGLUT_DIR)/libeglut-%.a +endef +$(foreach demo, $(EGLUT_DEMOS), $(eval $(call eglut-demo-rule,$(demo)))) + +# build EGLUT demos +$(EGLUT_X11_DEMOS): + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -L$(EGLUT_DIR) -leglut-$* $(VG_LIBS) -lX11 +$(EGLUT_SCREEN_DEMOS): + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -L$(EGLUT_DIR) -leglut-$* $(VG_LIBS) + +clean: + rm -f *.o *~ + rm -f $(EGLUT_X11_DEMOS) $(EGLUT_SCREEN_DEMOS) + @$(MAKE) -C $(EGLUT_DIR) clean diff --git a/progs/openvg/demos/lion-render.c b/progs/egl/openvg/lion-render.c index f3f151f552..f3f151f552 100644 --- a/progs/openvg/demos/lion-render.c +++ b/progs/egl/openvg/lion-render.c diff --git a/progs/openvg/demos/lion-render.h b/progs/egl/openvg/lion-render.h index c4c020b7ed..c4c020b7ed 100644 --- a/progs/openvg/demos/lion-render.h +++ b/progs/egl/openvg/lion-render.h diff --git a/progs/egl/openvg/lion.c b/progs/egl/openvg/lion.c new file mode 100644 index 0000000000..c5dba4fcea --- /dev/null +++ b/progs/egl/openvg/lion.c @@ -0,0 +1,65 @@ +#include <VG/openvg.h> +#include <EGL/egl.h> + +#include "lion-render.h" +#include "eglut.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; + eglutPostRedisplay(); +} + + +/* 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(); +} + + +int +main(int argc, char *argv[]) +{ + eglutInitWindowSize(350, 450); + eglutInitAPIMask(EGLUT_OPENVG_BIT); + eglutInit(argc, argv); + + eglutCreateWindow("Lion Example"); + + eglutReshapeFunc(reshape); + eglutDisplayFunc(draw); + + init(); + + eglutMainLoop(); + + return 0; +} diff --git a/progs/openvg/demos/sp.c b/progs/egl/openvg/sp.c index 424ec47d69..a20c0a3b4e 100644 --- a/progs/openvg/demos/sp.c +++ b/progs/egl/openvg/sp.c @@ -1,13 +1,9 @@ -#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> +#include "eglut.h" #define ELEMENTS(x) (sizeof(x)/sizeof((x)[0])) @@ -475,36 +471,13 @@ 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()); + vgClear(0, 0, eglutGetWindowWidth(), eglutGetWindowHeight()); vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); vgLoadIdentity(); @@ -532,6 +505,18 @@ draw(void) int main(int argc, char **argv) { - set_window_size(400, 400); - return run(argc, argv, init, reshape, draw, key_press); + eglutInitWindowSize(400, 400); + eglutInitAPIMask(EGLUT_OPENVG_BIT); + eglutInit(argc, argv); + + eglutCreateWindow("sp"); + + eglutReshapeFunc(reshape); + eglutDisplayFunc(draw); + + init(); + + eglutMainLoop(); + + return 0; } diff --git a/progs/openvg/trivial/Makefile b/progs/egl/openvg/trivial/Makefile index fcb3484377..8f6d7abe89 100644 --- a/progs/openvg/trivial/Makefile +++ b/progs/egl/openvg/trivial/Makefile @@ -1,7 +1,8 @@ +# progs/egl/openvg/trivial/Makefile # These programs aren't intended to be included with the normal distro. # They're not too interesting but they're good for testing. -TOP = ../../../ +TOP = ../../../.. include $(TOP)/configs/current INCLUDES = -I. -I$(TOP)/include diff --git a/progs/openvg/trivial/arc.c b/progs/egl/openvg/trivial/arc.c index db686bea6b..db686bea6b 100644 --- a/progs/openvg/trivial/arc.c +++ b/progs/egl/openvg/trivial/arc.c diff --git a/progs/openvg/trivial/cap.c b/progs/egl/openvg/trivial/cap.c index cd84fe3ac0..cd84fe3ac0 100644 --- a/progs/openvg/trivial/cap.c +++ b/progs/egl/openvg/trivial/cap.c diff --git a/progs/openvg/trivial/clear.c b/progs/egl/openvg/trivial/clear.c index efb6bf4182..efb6bf4182 100644 --- a/progs/openvg/trivial/clear.c +++ b/progs/egl/openvg/trivial/clear.c diff --git a/progs/openvg/trivial/coord.c b/progs/egl/openvg/trivial/coord.c index 81f7cb6fc9..81f7cb6fc9 100644 --- a/progs/openvg/trivial/coord.c +++ b/progs/egl/openvg/trivial/coord.c diff --git a/progs/openvg/trivial/dash.c b/progs/egl/openvg/trivial/dash.c index 2e84ddbd4e..2e84ddbd4e 100644 --- a/progs/openvg/trivial/dash.c +++ b/progs/egl/openvg/trivial/dash.c diff --git a/progs/openvg/demos/eglcommon.c b/progs/egl/openvg/trivial/eglcommon.c index 0316e596c6..0316e596c6 100644 --- a/progs/openvg/demos/eglcommon.c +++ b/progs/egl/openvg/trivial/eglcommon.c diff --git a/progs/openvg/demos/eglcommon.h b/progs/egl/openvg/trivial/eglcommon.h index 958dae9f98..958dae9f98 100644 --- a/progs/openvg/demos/eglcommon.h +++ b/progs/egl/openvg/trivial/eglcommon.h diff --git a/progs/openvg/trivial/ellipse.c b/progs/egl/openvg/trivial/ellipse.c index 4c7d4904f8..4c7d4904f8 100644 --- a/progs/openvg/trivial/ellipse.c +++ b/progs/egl/openvg/trivial/ellipse.c diff --git a/progs/openvg/trivial/filter.c b/progs/egl/openvg/trivial/filter.c index d96257a933..d96257a933 100644 --- a/progs/openvg/trivial/filter.c +++ b/progs/egl/openvg/trivial/filter.c diff --git a/progs/openvg/trivial/gradorigin.c b/progs/egl/openvg/trivial/gradorigin.c index b376263fe5..b376263fe5 100644 --- a/progs/openvg/trivial/gradorigin.c +++ b/progs/egl/openvg/trivial/gradorigin.c diff --git a/progs/openvg/trivial/lineto.c b/progs/egl/openvg/trivial/lineto.c index 94e2981811..94e2981811 100644 --- a/progs/openvg/trivial/lineto.c +++ b/progs/egl/openvg/trivial/lineto.c diff --git a/progs/openvg/trivial/lingrad.c b/progs/egl/openvg/trivial/lingrad.c index bcaad1f101..bcaad1f101 100644 --- a/progs/openvg/trivial/lingrad.c +++ b/progs/egl/openvg/trivial/lingrad.c diff --git a/progs/openvg/trivial/lookup.c b/progs/egl/openvg/trivial/lookup.c index a103ba4488..a103ba4488 100644 --- a/progs/openvg/trivial/lookup.c +++ b/progs/egl/openvg/trivial/lookup.c diff --git a/progs/openvg/trivial/mask.c b/progs/egl/openvg/trivial/mask.c index e5c00c5699..e5c00c5699 100644 --- a/progs/openvg/trivial/mask.c +++ b/progs/egl/openvg/trivial/mask.c diff --git a/progs/openvg/trivial/mask4.c b/progs/egl/openvg/trivial/mask4.c index fe6db39648..fe6db39648 100644 --- a/progs/openvg/trivial/mask4.c +++ b/progs/egl/openvg/trivial/mask4.c diff --git a/progs/openvg/trivial/path3.c b/progs/egl/openvg/trivial/path3.c index 5ce600f65a..5ce600f65a 100644 --- a/progs/openvg/trivial/path3.c +++ b/progs/egl/openvg/trivial/path3.c diff --git a/progs/openvg/trivial/radialgrad.c b/progs/egl/openvg/trivial/radialgrad.c index cf3b1d522d..cf3b1d522d 100644 --- a/progs/openvg/trivial/radialgrad.c +++ b/progs/egl/openvg/trivial/radialgrad.c diff --git a/progs/openvg/trivial/readpixels.c b/progs/egl/openvg/trivial/readpixels.c index c8e286db9a..c8e286db9a 100644 --- a/progs/openvg/trivial/readpixels.c +++ b/progs/egl/openvg/trivial/readpixels.c diff --git a/progs/openvg/trivial/roundedrect.c b/progs/egl/openvg/trivial/roundedrect.c index c80a4ed299..c80a4ed299 100644 --- a/progs/openvg/trivial/roundedrect.c +++ b/progs/egl/openvg/trivial/roundedrect.c diff --git a/progs/openvg/trivial/star-nonzero.c b/progs/egl/openvg/trivial/star-nonzero.c index 012fbd3929..012fbd3929 100644 --- a/progs/openvg/trivial/star-nonzero.c +++ b/progs/egl/openvg/trivial/star-nonzero.c diff --git a/progs/openvg/trivial/star-oddeven.c b/progs/egl/openvg/trivial/star-oddeven.c index 17311cf720..17311cf720 100644 --- a/progs/openvg/trivial/star-oddeven.c +++ b/progs/egl/openvg/trivial/star-oddeven.c diff --git a/progs/openvg/trivial/stroke.c b/progs/egl/openvg/trivial/stroke.c index 58ae5b7bc8..58ae5b7bc8 100644 --- a/progs/openvg/trivial/stroke.c +++ b/progs/egl/openvg/trivial/stroke.c diff --git a/progs/openvg/trivial/stroke2.c b/progs/egl/openvg/trivial/stroke2.c index ce950c1886..ce950c1886 100644 --- a/progs/openvg/trivial/stroke2.c +++ b/progs/egl/openvg/trivial/stroke2.c diff --git a/progs/openvg/trivial/vguarc.c b/progs/egl/openvg/trivial/vguarc.c index 8d971d5c09..8d971d5c09 100644 --- a/progs/openvg/trivial/vguarc.c +++ b/progs/egl/openvg/trivial/vguarc.c diff --git a/progs/egl/xegl_tri.c b/progs/egl/xegl_tri.c deleted file mode 100644 index 1f1a005a21..0000000000 --- a/progs/egl/xegl_tri.c +++ /dev/null @@ -1,361 +0,0 @@ -/* - * 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. - */ - -/* - * Draw a triangle with X/EGL. - * Brian Paul - * 3 June 2008 - */ - - -#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 <GL/gl.h> /* using full OpenGL for now */ -#include <GLES/egl.h> - - -static GLfloat view_rotx = 0.0, view_roty = 0.0, view_rotz = 0.0; - - -static void -draw(void) -{ - static const GLfloat verts[3][2] = { - { -1, -1 }, - { 1, -1 }, - { 0, 1 } - }; - static const GLfloat colors[3][3] = { - { 1, 0, 0 }, - { 0, 1, 0 }, - { 0, 0, 1 } - }; - - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - glPushMatrix(); - glRotatef(view_rotx, 1, 0, 0); - glRotatef(view_roty, 0, 1, 0); - glRotatef(view_rotz, 0, 0, 1); - - { - 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); - } - - glPopMatrix(); -} - - -/* new window size or exposure */ -static void -reshape(int width, int height) -{ - GLfloat ar = (GLfloat) width / (GLfloat) height; - - 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, -10.0); -} - - -static void -init(void) -{ - glClearColor(0.4, 0.4, 0.4, 0.0); -} - - -/* - * 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_DEPTH_SIZE, 1, - EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT, - 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) || - !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_OPENGL_API); - - ctx = eglCreateContext(egl_dpy, config, EGL_NO_CONTEXT, NULL ); - if (!ctx) { - printf("Error: glXCreateContext 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: - reshape(event.xconfigure.width, event.xconfigure.height); - break; - case KeyPress: - { - char buffer[10]; - int r, code; - code = XLookupKeysym(&event.xkey, 0); - if (code == XK_Left) { - view_roty += 5.0; - } - else if (code == XK_Right) { - view_roty -= 5.0; - } - else if (code == XK_Up) { - view_rotx += 5.0; - } - else if (code == XK_Down) { - view_rotx -= 5.0; - } - else { - r = XLookupString(&event.xkey, buffer, sizeof(buffer), - NULL, NULL); - if (buffer[0] == 27) { - /* escape */ - return; - } - } - } - redraw = 1; - break; - default: - ; /*no-op*/ - } - - if (redraw) { - 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 = 300, winHeight = 300; - 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, - "xegl_tri", 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("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)); - } - - 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/es1/.gitignore b/progs/es1/.gitignore deleted file mode 100644 index 5e29a6b5fa..0000000000 --- a/progs/es1/.gitignore +++ /dev/null @@ -1,11 +0,0 @@ -screen/gears -screen/tri -xegl/bindtex -xegl/drawtex -xegl/es1_info -xegl/msaa -xegl/pbuffer -xegl/render_tex -xegl/torus -xegl/tri -xegl/two_win diff --git a/progs/es1/screen/Makefile b/progs/es1/screen/Makefile deleted file mode 100644 index 4ba2f9a7dc..0000000000 --- a/progs/es1/screen/Makefile +++ /dev/null @@ -1,32 +0,0 @@ -# progs/es1/screen/Makefile - -TOP = ../../.. -include $(TOP)/configs/current - -ES1_CFLAGS = -I$(TOP)/include -ES1_LIBS = -L$(TOP)/$(LIB_DIR) -lEGL -lGLESv1_CM - -ES1_LIB_DEPS = \ - $(TOP)/$(LIB_DIR)/libEGL.so \ - $(TOP)/$(LIB_DIR)/libGLESv1_CM.so - -WINSYS_OBJS = winsys.o - -PROGRAMS = \ - gears \ - tri - -.c.o: - $(CC) -c $(ES1_CFLAGS) $(CFLAGS) $< -o $@ - -default: $(PROGRAMS) - -gears: gears.o $(WINSYS_OBJS) $(ES1_LIB_DEPS) - $(CC) $(CFLAGS) -o $@ $@.o $(WINSYS_OBJS) $(ES1_LIBS) - -tri: tri.o $(WINSYS_OBJS) $(ES1_LIB_DEPS) - $(CC) $(CFLAGS) -o $@ $@.o $(WINSYS_OBJS) $(ES1_LIBS) - -clean: - -rm -f *.o *~ - -rm -f $(PROGRAMS) diff --git a/progs/es1/screen/winsys.c b/progs/es1/screen/winsys.c deleted file mode 100644 index 84d00471eb..0000000000 --- a/progs/es1/screen/winsys.c +++ /dev/null @@ -1,272 +0,0 @@ -/* - * Copyright (C) 2009 Chia-I Wu <olv@0xlab.org> - * - * Based on eglgears by - * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <assert.h> -#include <sys/time.h> - -#define EGL_EGLEXT_PROTOTYPES - -#include <EGL/egl.h> -#include <EGL/eglext.h> - -#include "winsys.h" - -#define MAX_MODES 100 - -static struct { - EGLBoolean verbose; - - EGLDisplay dpy; - EGLConfig conf; - - EGLScreenMESA screen; - EGLModeMESA mode; - EGLint width, height; - - EGLContext ctx; - EGLSurface surf; -} screen; - - -static EGLBoolean -init_screen(void) -{ - EGLModeMESA modes[MAX_MODES]; - EGLint num_screens, num_modes; - EGLint width, height, best_mode; - EGLint i; - - if (!eglGetScreensMESA(screen.dpy, &screen.screen, 1, &num_screens) || - !num_screens) { - printf("eglGetScreensMESA failed\n"); - return EGL_FALSE; - } - - if (!eglGetModesMESA(screen.dpy, screen.screen, modes, MAX_MODES, - &num_modes) || - !num_modes) { - printf("eglGetModesMESA failed!\n"); - return EGL_FALSE; - } - - printf("Found %d modes:\n", num_modes); - - best_mode = 0; - width = 0; - height = 0; - for (i = 0; i < num_modes; i++) { - EGLint w, h; - eglGetModeAttribMESA(screen.dpy, modes[i], EGL_WIDTH, &w); - eglGetModeAttribMESA(screen.dpy, modes[i], EGL_HEIGHT, &h); - printf("%3d: %d x %d\n", i, w, h); - if (w > width && h > height) { - width = w; - height = h; - best_mode = i; - } - } - - screen.mode = modes[best_mode]; - screen.width = width; - screen.height = height; - - return EGL_TRUE; -} - - -static EGLBoolean -init_display(void) -{ - EGLint maj, min; - const char *exts; - const EGLint attribs[] = { - EGL_SURFACE_TYPE, 0x0, /* should be EGL_SCREEN_BIT_MESA */ - EGL_RENDERABLE_TYPE, 0x0, /* should be EGL_OPENGL_ES_BIT */ - EGL_NONE - }; - EGLint num_configs; - - screen.dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); - if (!screen.dpy) { - printf("eglGetDisplay failed\n"); - return EGL_FALSE; - } - - if (!eglInitialize(screen.dpy, &maj, &min)) { - printf("eglInitialize failed\n"); - return EGL_FALSE; - } - - printf("EGL_VERSION = %s\n", eglQueryString(screen.dpy, EGL_VERSION)); - printf("EGL_VENDOR = %s\n", eglQueryString(screen.dpy, EGL_VENDOR)); - - exts = eglQueryString(screen.dpy, EGL_EXTENSIONS); - assert(exts); - - if (!strstr(exts, "EGL_MESA_screen_surface")) { - printf("EGL_MESA_screen_surface is not supported\n"); - return EGL_FALSE; - } - - if (!eglChooseConfig(screen.dpy, attribs, &screen.conf, 1, - &num_configs) || - !num_configs) { - printf("eglChooseConfig failed\n"); - return EGL_FALSE; - } - - return EGL_TRUE; -} - - -EGLBoolean -winsysInitScreen(void) -{ - EGLint surf_attribs[20]; - EGLint i; - EGLBoolean ok; - - if (!init_display()) - goto fail; - if (!init_screen()) - goto fail; - - /* create context */ - screen.ctx = eglCreateContext(screen.dpy, screen.conf, - EGL_NO_CONTEXT, NULL); - if (screen.ctx == EGL_NO_CONTEXT) { - printf("eglCreateContext failed\n"); - goto fail; - } - - i = 0; - surf_attribs[i++] = EGL_WIDTH; - surf_attribs[i++] = screen.width; - surf_attribs[i++] = EGL_HEIGHT; - surf_attribs[i++] = screen.height; - surf_attribs[i++] = EGL_NONE; - - /* create surface */ - printf("Using screen size: %d x %d\n", screen.width, screen.height); - screen.surf = eglCreateScreenSurfaceMESA(screen.dpy, screen.conf, - surf_attribs); - if (screen.surf == EGL_NO_SURFACE) { - printf("eglCreateScreenSurfaceMESA failed\n"); - goto fail; - } - - ok = eglMakeCurrent(screen.dpy, screen.surf, screen.surf, screen.ctx); - if (!ok) { - printf("eglMakeCurrent failed\n"); - goto fail; - } - - ok = eglShowScreenSurfaceMESA(screen.dpy, screen.screen, - screen.surf, screen.mode); - if (!ok) { - printf("eglShowScreenSurfaceMESA failed\n"); - goto fail; - } - - return EGL_TRUE; - -fail: - winsysFiniScreen(); - return EGL_FALSE; -} - - -EGLBoolean -winsysQueryScreenSize(EGLint *width, EGLint *height) -{ - if (!screen.dpy) - return EGL_FALSE; - - if (width) - *width = screen.width; - if (height) - *height = screen.height; - - return EGL_TRUE; -} - - -void -winsysFiniScreen(void) -{ - if (screen.dpy) { - eglMakeCurrent(screen.dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, - EGL_NO_CONTEXT); - if (screen.surf != EGL_NO_SURFACE) - eglDestroySurface(screen.dpy, screen.surf); - if (screen.ctx != EGL_NO_CONTEXT) - eglDestroyContext(screen.dpy, screen.ctx); - eglTerminate(screen.dpy); - - memset(&screen, 0, sizeof(screen)); - } -} - - -void -winsysSwapBuffers(void) -{ - eglSwapBuffers(screen.dpy, screen.surf); -} - - -/* return current time (in seconds) */ -double -winsysNow(void) -{ - struct timeval tv; - gettimeofday(&tv, NULL); - return (double) tv.tv_sec + tv.tv_usec / 1000000.0; -} - - -void -winsysRun(double seconds, void (*draw_frame)(void *data), void *data) -{ - double begin, end, last_frame, duration; - EGLint num_frames = 0; - - begin = winsysNow(); - end = begin + seconds; - - last_frame = begin; - while (last_frame < end) { - draw_frame(data); - winsysSwapBuffers(); - last_frame = winsysNow(); - num_frames++; - } - - duration = last_frame - begin; - printf("%d frames in %3.1f seconds = %6.3f FPS\n", - num_frames, duration, (double) num_frames / duration); -} diff --git a/progs/es1/screen/winsys.h b/progs/es1/screen/winsys.h deleted file mode 100644 index 679c7e0bd6..0000000000 --- a/progs/es1/screen/winsys.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2009 Chia-I Wu <olv@0xlab.org> - * - * 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. - */ - -#ifndef _WINSYS_H_ -#define _WINSYS_H_ - -#include <EGL/egl.h> - -EGLBoolean winsysInitScreen(void); -EGLBoolean winsysQueryScreenSize(EGLint *width, EGLint *height); -void winsysFiniScreen(void); - -void winsysSwapBuffers(void); -double winsysNow(void); - -void winsysRun(double seconds, void (*draw_frame)(void *data), void *data); - -#endif /* _WINSYS_H_ */ diff --git a/progs/es1/xegl/Makefile b/progs/es1/xegl/Makefile deleted file mode 100644 index 6869c44306..0000000000 --- a/progs/es1/xegl/Makefile +++ /dev/null @@ -1,82 +0,0 @@ -# progs/es1/xegl/Makefile - -TOP = ../../.. -include $(TOP)/configs/current - - -INCLUDE_DIRS = \ - -I$(TOP)/include \ - -HEADERS = $(TOP)/include/GLES/egl.h - - -ES1_LIB_DEPS = \ - $(TOP)/$(LIB_DIR)/libEGL.so \ - $(TOP)/$(LIB_DIR)/libGLESv1_CM.so - - -ES1_LIBS = \ - -L$(TOP)/$(LIB_DIR) -lEGL \ - -L$(TOP)/$(LIB_DIR) -lGLESv1_CM $(LIBDRM_LIB) -lX11 - -PROGRAMS = \ - bindtex \ - drawtex \ - es1_info \ - msaa \ - pbuffer \ - render_tex \ - torus \ - tri \ - two_win - - -.c.o: - $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $< -o $@ - - - -default: $(PROGRAMS) - - - -bindtex: bindtex.o $(ES1_LIB_DEPS) - $(CC) $(CFLAGS) bindtex.o $(ES1_LIBS) -o $@ - - -drawtex: drawtex.o $(ES1_LIB_DEPS) - $(CC) $(CFLAGS) drawtex.o $(ES1_LIBS) -o $@ - - -es1_info: es1_info.o $(ES1_LIB_DEPS) - $(CC) $(CFLAGS) es1_info.o $(ES1_LIBS) -o $@ - - -msaa: msaa.o $(ES1_LIB_DEPS) - $(CC) $(CFLAGS) msaa.o $(ES1_LIBS) -o $@ - - -pbuffer: pbuffer.o $(ES1_LIB_DEPS) - $(CC) $(CFLAGS) pbuffer.o $(ES1_LIBS) -o $@ - - -render_tex: render_tex.o $(ES1_LIB_DEPS) - $(CC) $(CFLAGS) render_tex.o $(ES1_LIBS) -o $@ - - -torus: torus.o $(ES1_LIB_DEPS) - $(CC) $(CFLAGS) torus.o $(ES1_LIBS) -o $@ - - -two_win: two_win.o $(ES1_LIB_DEPS) - $(CC) $(CFLAGS) two_win.o $(ES1_LIBS) -o $@ - - -tri: tri.o $(ES1_LIB_DEPS) - $(CC) $(CFLAGS) tri.o $(ES1_LIBS) -o $@ - - -clean: - rm -f *.o *~ - rm -f $(PROGRAMS) - diff --git a/progs/es1/xegl/drawtex.c b/progs/es1/xegl/drawtex.c deleted file mode 100644 index ca0615e267..0000000000 --- a/progs/es1/xegl/drawtex.c +++ /dev/null @@ -1,427 +0,0 @@ -/* - * Copyright (C) 2008 Tunsgten Graphics,Inc. All Rights Reserved. - */ - -/* - * Test GL_OES_draw_texture - * Brian Paul - * August 2008 - */ - -#define GL_GLEXT_PROTOTYPES - -#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 <GLES/gl.h> -#include <GLES/glext.h> -#include <EGL/egl.h> - - - -static GLfloat view_posx = 10.0, view_posy = 20.0; -static GLfloat width = 200, height = 200; - - -static void -draw(void) -{ - glClear(GL_COLOR_BUFFER_BIT); - - glDrawTexfOES(view_posx, view_posy, 0.0, width, height); -} - - -/* new window size or exposure */ -static void -reshape(int width, int height) -{ - GLfloat ar = (GLfloat) width / (GLfloat) height; - - glViewport(0, 0, (GLint) width, (GLint) height); - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - -#ifdef GL_VERSION_ES_CM_1_0 - glFrustumf(-ar, ar, -1, 1, 5.0, 60.0); -#else - glFrustum(-ar, ar, -1, 1, 5.0, 60.0); -#endif - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glTranslatef(0.0, 0.0, -15.0); -} - - -static float -dist(GLuint i, GLuint j, float x, float y) -{ - return sqrt((i-x) * (i-x) + (j-y) * (j-y)); -} - -static void -make_smile_texture(void) -{ -#define SZ 128 - GLenum Filter = GL_LINEAR; - GLubyte image[SZ][SZ][4]; - GLuint i, j; - GLint cropRect[4]; - - for (i = 0; i < SZ; i++) { - for (j = 0; j < SZ; j++) { - GLfloat d_mouth = dist(i, j, SZ/2, SZ/2); - GLfloat d_rt_eye = dist(i, j, SZ*3/4, SZ*3/4); - GLfloat d_lt_eye = dist(i, j, SZ*3/4, SZ*1/4); - if (d_rt_eye < SZ / 8 || d_lt_eye < SZ / 8) { - image[i][j][0] = 20; - image[i][j][1] = 50; - image[i][j][2] = 255; - image[i][j][3] = 255; - } - else if (i < SZ/2 && d_mouth < SZ/3) { - image[i][j][0] = 255; - image[i][j][1] = 20; - image[i][j][2] = 20; - image[i][j][3] = 255; - } - else { - image[i][j][0] = 200; - image[i][j][1] = 200; - image[i][j][2] = 200; - image[i][j][3] = 255; - } - } - } - - glActiveTexture(GL_TEXTURE0); /* unit 0 */ - glBindTexture(GL_TEXTURE_2D, 42); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, SZ, SZ, 0, - GL_RGBA, GL_UNSIGNED_BYTE, image); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, Filter); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, Filter); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); - - cropRect[0] = 0; - cropRect[1] = 0; - cropRect[2] = SZ; - cropRect[3] = SZ; - glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, cropRect); -#undef SZ -} - - - -static void -init(void) -{ - const char *ext = (char *) glGetString(GL_EXTENSIONS); - - if (!strstr(ext, "GL_OES_draw_texture")) { - fprintf(stderr, "Sorry, this program requires GL_OES_draw_texture"); - exit(1); - } - - glClearColor(0.4, 0.4, 0.4, 0.0); - - make_smile_texture(); - glEnable(GL_TEXTURE_2D); -} - - -/* - * 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_OPENGL_ES_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) -{ - int anim = 0; - - while (1) { - int redraw = 0; - - if (!anim || XPending(dpy)) { - XEvent event; - XNextEvent(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_posx -= 1.0; - } - else if (code == XK_Right) { - view_posx += 1.0; - } - else if (code == XK_Up) { - view_posy += 1.0; - } - else if (code == XK_Down) { - view_posy -= 1.0; - } - else { - r = XLookupString(&event.xkey, buffer, sizeof(buffer), - NULL, NULL); - if (buffer[0] == ' ') { - anim = !anim; - } - else if (buffer[0] == 'w') { - width -= 1.0f; - } - else if (buffer[0] == 'W') { - width += 1.0f; - } - else if (buffer[0] == 'h') { - height -= 1.0f; - } - else if (buffer[0] == 'H') { - height += 1.0f; - } - else if (buffer[0] == 27) { - /* escape */ - return; - } - } - } - redraw = 1; - break; - default: - ; /*no-op*/ - } - } - - if (anim) { - view_posx += 1.0; - view_posy += 2.0; - redraw = 1; - } - - if (redraw) { - 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 = 400, winHeight = 300; - 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); - - s = eglQueryString(egl_dpy, EGL_VENDOR); - printf("EGL_VENDOR = %s\n", s); - - s = eglQueryString(egl_dpy, EGL_EXTENSIONS); - printf("EGL_EXTENSIONS = %s\n", s); - - s = eglQueryString(egl_dpy, EGL_CLIENT_APIS); - printf("EGL_CLIENT_APIS = %s\n", s); - - make_x_window(x_dpy, egl_dpy, - "drawtex", 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("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(); - - /* 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/es1/xegl/tri.c b/progs/es1/xegl/tri.c deleted file mode 100644 index 42a978207c..0000000000 --- a/progs/es1/xegl/tri.c +++ /dev/null @@ -1,470 +0,0 @@ -/* - * 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. - */ - -/* - * Draw a triangle with X/EGL and OpenGL ES 1.x - * Brian Paul - * 5 June 2008 - */ - -#define USE_FULL_GL 0 - -#define USE_FIXED_POINT 0 - - -#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> -#if USE_FULL_GL -#include <GL/gl.h> /* use full OpenGL */ -#else -#include <GLES/gl.h> /* use OpenGL ES 1.x */ -#include <GLES/glext.h> -#endif -#include <EGL/egl.h> - - -#define FLOAT_TO_FIXED(X) ((X) * 65535.0) - - - -static GLfloat view_rotx = 0.0, view_roty = 0.0, view_rotz = 0.0; - - -static void -draw(void) -{ -#if USE_FIXED_POINT - static const GLfixed verts[3][2] = { - { -65536, -65536 }, - { 65536, -65536 }, - { 0, 65536 } - }; - static const GLfixed colors[3][4] = { - { 65536, 0, 0, 65536 }, - { 0, 65536, 0 , 65536}, - { 0, 0, 65536 , 65536} - }; -#else - static const GLfloat verts[3][2] = { - { -1, -1 }, - { 1, -1 }, - { 0, 1 } - }; - static const GLfloat colors[3][4] = { - { 1, 0, 0, 1 }, - { 0, 1, 0, 1 }, - { 0, 0, 1, 1 } - }; -#endif - - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - glPushMatrix(); - glRotatef(view_rotx, 1, 0, 0); - glRotatef(view_roty, 0, 1, 0); - glRotatef(view_rotz, 0, 0, 1); - - { -#if USE_FIXED_POINT - glVertexPointer(2, GL_FIXED, 0, verts); - glColorPointer(4, GL_FIXED, 0, colors); -#else - glVertexPointer(2, GL_FLOAT, 0, verts); - glColorPointer(4, GL_FLOAT, 0, colors); -#endif - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_COLOR_ARRAY); - - /* draw triangle */ - glDrawArrays(GL_TRIANGLES, 0, 3); - - /* draw some points */ - glPointSizex(FLOAT_TO_FIXED(15.5)); - glDrawArrays(GL_POINTS, 0, 3); - - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - } - - if (0) { - /* test code */ - GLfixed size; - glGetFixedv(GL_POINT_SIZE, &size); - printf("GL_POINT_SIZE = 0x%x %f\n", size, size / 65536.0); - } - - glPopMatrix(); -} - - -/* new window size or exposure */ -static void -reshape(int width, int height) -{ - GLfloat ar = (GLfloat) width / (GLfloat) height; - - glViewport(0, 0, (GLint) width, (GLint) height); - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); -#ifdef GL_VERSION_ES_CM_1_0 - glFrustumf(-ar, ar, -1, 1, 5.0, 60.0); -#else - glFrustum(-ar, ar, -1, 1, 5.0, 60.0); -#endif - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glTranslatef(0.0, 0.0, -10.0); -} - - -static void -test_query_matrix(void) -{ - PFNGLQUERYMATRIXXOESPROC procQueryMatrixx; - typedef void (*voidproc)(); - GLfixed mantissa[16]; - GLint exponent[16]; - GLbitfield rv; - int i; - - procQueryMatrixx = (PFNGLQUERYMATRIXXOESPROC) eglGetProcAddress("glQueryMatrixxOES"); - assert(procQueryMatrixx); - /* Actually try out this one */ - rv = (*procQueryMatrixx)(mantissa, exponent); - for (i = 0; i < 16; i++) { - if (rv & (1<<i)) { - printf("matrix[%d] invalid\n", i); - } - else { - printf("matrix[%d] = %f * 2^(%d)\n", i, mantissa[i]/65536.0, exponent[i]); - } - } - assert(!eglGetProcAddress("glFoo")); -} - - -static void -init(void) -{ - glClearColor(0.4, 0.4, 0.4, 0.0); - - if (0) - test_query_matrix(); -} - - -/* - * 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_DEPTH_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); - } - -#if USE_FULL_GL - eglBindAPI(EGL_OPENGL_API); -#else - eglBindAPI(EGL_OPENGL_ES_API); -#endif - - 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: - reshape(event.xconfigure.width, event.xconfigure.height); - break; - case KeyPress: - { - char buffer[10]; - int r, code; - code = XLookupKeysym(&event.xkey, 0); - if (code == XK_Left) { - view_roty += 5.0; - } - else if (code == XK_Right) { - view_roty -= 5.0; - } - else if (code == XK_Up) { - view_rotx += 5.0; - } - else if (code == XK_Down) { - view_rotx -= 5.0; - } - else { - r = XLookupString(&event.xkey, buffer, sizeof(buffer), - NULL, NULL); - if (buffer[0] == 27) { - /* escape */ - return; - } - } - } - redraw = 1; - break; - default: - ; /*no-op*/ - } - - if (redraw) { - 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 = 300, winHeight = 300; - 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; - - static struct { - char *name; - GLenum value; - enum {GetString, GetInteger} type; - } info_items[] = { - {"GL_RENDERER", GL_RENDERER, GetString}, - {"GL_VERSION", GL_VERSION, GetString}, - {"GL_VENDOR", GL_VENDOR, GetString}, - {"GL_EXTENSIONS", GL_EXTENSIONS, GetString}, - {"GL_MAX_PALETTE_MATRICES_OES", GL_MAX_PALETTE_MATRICES_OES, GetInteger}, - {"GL_MAX_VERTEX_UNITS_OES", GL_MAX_VERTEX_UNITS_OES, GetInteger}, - }; - - 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); - - s = eglQueryString(egl_dpy, EGL_VENDOR); - printf("EGL_VENDOR = %s\n", s); - - s = eglQueryString(egl_dpy, EGL_EXTENSIONS); - printf("EGL_EXTENSIONS = %s\n", s); - - s = eglQueryString(egl_dpy, EGL_CLIENT_APIS); - printf("EGL_CLIENT_APIS = %s\n", s); - - make_x_window(x_dpy, egl_dpy, - "OpenGL ES 1.x tri", 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) { - for (i = 0; i < sizeof(info_items)/sizeof(info_items[0]); i++) { - switch (info_items[i].type) { - case GetString: - printf("%s = %s\n", info_items[i].name, (char *)glGetString(info_items[i].value)); - break; - case GetInteger: { - GLint rv = -1; - glGetIntegerv(info_items[i].value, &rv); - printf("%s = %d\n", info_items[i].name, rv); - break; - } - } - } - }; - 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/es2/.gitignore b/progs/es2/.gitignore deleted file mode 100644 index 7d5c16936c..0000000000 --- a/progs/es2/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -xegl/es2_info.c -xegl/es2_info -xegl/tri diff --git a/progs/fpglsl/dowhile.glsl b/progs/fpglsl/dowhile.glsl new file mode 100644 index 0000000000..ed9d729675 --- /dev/null +++ b/progs/fpglsl/dowhile.glsl @@ -0,0 +1,8 @@ +void main() { + float sum = 0.0; + do { + sum += 0.1; + break; + } while (true); + gl_FragColor = vec4(sum); +} diff --git a/progs/fpglsl/dowhile2.glsl b/progs/fpglsl/dowhile2.glsl new file mode 100644 index 0000000000..f3e00b8e86 --- /dev/null +++ b/progs/fpglsl/dowhile2.glsl @@ -0,0 +1,10 @@ +void main() { + float sum = 0.0; + do { + sum += 0.1; + if (sum < 0.499999) + continue; + break; + } while (true); + gl_FragColor = vec4(sum); +} diff --git a/progs/fpglsl/for.glsl b/progs/fpglsl/for.glsl new file mode 100644 index 0000000000..862ca8bd6c --- /dev/null +++ b/progs/fpglsl/for.glsl @@ -0,0 +1,11 @@ +uniform int KernelSizeInt; + +void main() { + int i; + vec4 sum = vec4(0.0); + for (i = 0; i < KernelSizeInt; ++i) { + sum.g += 0.25; + } + sum.a = 1.0; + gl_FragColor = sum; +} diff --git a/progs/fpglsl/forbreak.glsl b/progs/fpglsl/forbreak.glsl new file mode 100644 index 0000000000..0b8d957cb0 --- /dev/null +++ b/progs/fpglsl/forbreak.glsl @@ -0,0 +1,13 @@ +uniform int KernelSizeInt; + +void main() { + int i; + vec4 sum = vec4(0.0); + for (i = 0; i < KernelSizeInt; ++i) { + sum.g += 0.25; + if (i > 0) + break; + } + sum.a = 1.0; + gl_FragColor = sum; +} diff --git a/progs/fpglsl/fp-tri.c b/progs/fpglsl/fp-tri.c index c9b08fbbad..8af09845dd 100644 --- a/progs/fpglsl/fp-tri.c +++ b/progs/fpglsl/fp-tri.c @@ -129,6 +129,11 @@ static void setup_uniforms() } { + GLint loci = glGetUniformLocationARB(program, "KernelSizeInt"); + if (loci >= 0) + glUniform1i(loci, 4); + } + { GLint loc1f = glGetUniformLocationARB(program, "KernelValue1f"); GLint loc2f = glGetUniformLocationARB(program, "KernelValue2f"); GLint loc4f = glGetUniformLocationARB(program, "KernelValue4f"); diff --git a/progs/fpglsl/simpleif.glsl b/progs/fpglsl/simpleif.glsl new file mode 100644 index 0000000000..922421b410 --- /dev/null +++ b/progs/fpglsl/simpleif.glsl @@ -0,0 +1,6 @@ +void main() { + // this should always be true + if (gl_FragCoord.x >= 0.0) { + gl_FragColor = vec4(0.5, 0.0, 0.5, 1.0); + } +} diff --git a/progs/fpglsl/while.glsl b/progs/fpglsl/while.glsl new file mode 100644 index 0000000000..05fb860ddc --- /dev/null +++ b/progs/fpglsl/while.glsl @@ -0,0 +1,7 @@ +void main() { + float sum = 0.0; + while (sum < 0.499999) { + sum += 0.1; + } + gl_FragColor = vec4(sum); +} diff --git a/progs/fpglsl/while2.glsl b/progs/fpglsl/while2.glsl new file mode 100644 index 0000000000..19c8904e28 --- /dev/null +++ b/progs/fpglsl/while2.glsl @@ -0,0 +1,9 @@ +void main() { + float sum = 0.0; + while (true) { + sum += 0.1; + if (sum > 0.8) + break; + } + gl_FragColor = vec4(sum); +} diff --git a/progs/gallium/python/retrace/README b/progs/gallium/python/retrace/README deleted file mode 100644 index 822cd11404..0000000000 --- a/progs/gallium/python/retrace/README +++ /dev/null @@ -1,17 +0,0 @@ -This is an application written in python to replay the traces captured by the - trace pipe driver. - - -To use it follow the instructions in src/gallium/drivers/trace/README and -src/gallium/state_trackers/python/README, and then do - - python src/gallium/state_trackers/python/samples/retrace/interpreter.py filename.trace - - -This is still work in progress: -- not everything is captured/replayed - - surface/textures contents -- any tiny error will result in a crash - --- -Jose Fonseca <jrfonseca@tungstengraphics.com> diff --git a/progs/gallium/python/retrace/format.py b/progs/gallium/python/retrace/format.py deleted file mode 100755 index a4285bfe07..0000000000 --- a/progs/gallium/python/retrace/format.py +++ /dev/null @@ -1,173 +0,0 @@ -#!/usr/bin/env python -########################################################################## -# -# Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. -# 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, 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 TUNGSTEN GRAPHICS AND/OR ITS 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. -# -########################################################################## - - -import sys - - -class Formatter: - '''Plain formatter''' - - def __init__(self, stream): - self.stream = stream - - def text(self, text): - self.stream.write(text) - - def newline(self): - self.text('\n') - - def function(self, name): - self.text(name) - - def variable(self, name): - self.text(name) - - def literal(self, value): - self.text(str(value)) - - def address(self, addr): - self.text(str(addr)) - - -class AnsiFormatter(Formatter): - '''Formatter for plain-text files which outputs ANSI escape codes. See - http://en.wikipedia.org/wiki/ANSI_escape_code for more information - concerning ANSI escape codes. - ''' - - _csi = '\33[' - - _normal = '0m' - _bold = '1m' - _italic = '3m' - _red = '31m' - _green = '32m' - _blue = '34m' - - def _escape(self, code): - self.text(self._csi + code) - - def function(self, name): - self._escape(self._bold) - Formatter.function(self, name) - self._escape(self._normal) - - def variable(self, name): - self._escape(self._italic) - Formatter.variable(self, name) - self._escape(self._normal) - - def literal(self, value): - self._escape(self._blue) - Formatter.literal(self, value) - self._escape(self._normal) - - def address(self, value): - self._escape(self._green) - Formatter.address(self, value) - self._escape(self._normal) - - -class WindowsConsoleFormatter(Formatter): - '''Formatter for the Windows Console. See - http://code.activestate.com/recipes/496901/ for more information. - ''' - - STD_INPUT_HANDLE = -10 - STD_OUTPUT_HANDLE = -11 - STD_ERROR_HANDLE = -12 - - FOREGROUND_BLUE = 0x01 - FOREGROUND_GREEN = 0x02 - FOREGROUND_RED = 0x04 - FOREGROUND_INTENSITY = 0x08 - BACKGROUND_BLUE = 0x10 - BACKGROUND_GREEN = 0x20 - BACKGROUND_RED = 0x40 - BACKGROUND_INTENSITY = 0x80 - - _normal = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED - _bold = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY - _italic = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED - _red = FOREGROUND_RED | FOREGROUND_INTENSITY - _green = FOREGROUND_GREEN | FOREGROUND_INTENSITY - _blue = FOREGROUND_BLUE | FOREGROUND_INTENSITY - - def __init__(self, stream): - Formatter.__init__(self, stream) - - if stream is sys.stdin: - nStdHandle = self.STD_INPUT_HANDLE - elif stream is sys.stdout: - nStdHandle = self.STD_OUTPUT_HANDLE - elif stream is sys.stderr: - nStdHandle = self.STD_ERROR_HANDLE - else: - nStdHandle = None - - if nStdHandle: - import ctypes - self.handle = ctypes.windll.kernel32.GetStdHandle(nStdHandle) - else: - self.handle = None - - def _attribute(self, attr): - if self.handle: - import ctypes - ctypes.windll.kernel32.SetConsoleTextAttribute(self.handle, attr) - - def function(self, name): - self._attribute(self._bold) - Formatter.function(self, name) - self._attribute(self._normal) - - def variable(self, name): - self._attribute(self._italic) - Formatter.variable(self, name) - self._attribute(self._normal) - - def literal(self, value): - self._attribute(self._blue) - Formatter.literal(self, value) - self._attribute(self._normal) - - def address(self, value): - self._attribute(self._green) - Formatter.address(self, value) - self._attribute(self._normal) - - -def DefaultFormatter(stream): - if sys.platform in ('linux2', 'cygwin'): - return AnsiFormatter(stream) - elif sys.platform in ('win32',): - return WindowsConsoleFormatter(stream) - else: - return Formatter(stream) - diff --git a/progs/gallium/python/retrace/interpreter.py b/progs/gallium/python/retrace/interpreter.py deleted file mode 100755 index b30469dfae..0000000000 --- a/progs/gallium/python/retrace/interpreter.py +++ /dev/null @@ -1,763 +0,0 @@ -#!/usr/bin/env python -########################################################################## -# -# Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. -# 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, 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 TUNGSTEN GRAPHICS AND/OR ITS 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. -# -########################################################################## - - -import sys -import struct - -import gallium -import model -import parse as parser - - -try: - from struct import unpack_from -except ImportError: - def unpack_from(fmt, buf, offset=0): - size = struct.calcsize(fmt) - return struct.unpack(fmt, buf[offset:offset + size]) - - -def make_image(surface, x=None, y=None, w=None, h=None): - if x is None: - x = 0 - if y is None: - y = 0 - if w is None: - w = surface.width - x - if h is None: - h = surface.height - y - data = surface.get_tile_rgba8(x, y, surface.width, surface.height) - - import Image - outimage = Image.fromstring('RGBA', (w, h), data, "raw", 'RGBA', 0, 1) - return outimage - -def save_image(filename, surface, x=None, y=None, w=None, h=None): - outimage = make_image(surface, x, y, w, h) - outimage.save(filename, "PNG") - -def show_image(surface, title, x=None, y=None, w=None, h=None): - outimage = make_image(surface, x, y, w, h) - - import Tkinter as tk - from PIL import Image, ImageTk - root = tk.Tk() - - root.title(title) - - image1 = ImageTk.PhotoImage(outimage) - w = image1.width() - h = image1.height() - x = 100 - y = 100 - root.geometry("%dx%d+%d+%d" % (w, h, x, y)) - panel1 = tk.Label(root, image=image1) - panel1.pack(side='top', fill='both', expand='yes') - panel1.image = image1 - root.mainloop() - - -class Struct: - """C-like struct""" - - # A basic Python class can pass as a C-like structure - pass - - -struct_factories = { - "pipe_blend_color": gallium.BlendColor, - "pipe_blend_state": gallium.Blend, - #"pipe_clip_state": gallium.Clip, - #"pipe_buffer": gallium.Buffer, - "pipe_depth_state": gallium.Depth, - "pipe_stencil_state": gallium.Stencil, - "pipe_alpha_state": gallium.Alpha, - "pipe_depth_stencil_alpha_state": gallium.DepthStencilAlpha, - #"pipe_framebuffer_state": gallium.Framebuffer, - "pipe_poly_stipple": gallium.PolyStipple, - "pipe_rasterizer_state": gallium.Rasterizer, - "pipe_sampler_state": gallium.Sampler, - "pipe_scissor_state": gallium.Scissor, - #"pipe_shader_state": gallium.Shader, - #"pipe_vertex_buffer": gallium.VertexBuffer, - "pipe_vertex_element": gallium.VertexElement, - "pipe_viewport_state": gallium.Viewport, - #"pipe_texture": gallium.Texture, -} - - -member_array_factories = { - #"pipe_rasterizer_state": {"sprite_coord_mode": gallium.ByteArray}, - "pipe_poly_stipple": {"stipple": gallium.UnsignedArray}, - "pipe_viewport_state": {"scale": gallium.FloatArray, "translate": gallium.FloatArray}, - #"pipe_clip_state": {"ucp": gallium.FloatArray}, - "pipe_depth_stencil_alpha_state": {"stencil": gallium.StencilArray}, - "pipe_blend_color": {"color": gallium.FloatArray}, - "pipe_sampler_state": {"border_color": gallium.FloatArray}, -} - - -class Translator(model.Visitor): - """Translate model arguments into regular Python objects""" - - def __init__(self, interpreter): - self.interpreter = interpreter - self.result = None - - def visit(self, node): - self.result = None - node.visit(self) - return self.result - - def visit_literal(self, node): - self.result = node.value - - def visit_named_constant(self, node): - # lookup the named constant in the gallium module - self.result = getattr(gallium, node.name) - - def visit_array(self, node): - array = [] - for element in node.elements: - array.append(self.visit(element)) - self.result = array - - def visit_struct(self, node): - struct_factory = struct_factories.get(node.name, Struct) - struct = struct_factory() - for member_name, member_node in node.members: - member_value = self.visit(member_node) - try: - array_factory = member_array_factories[node.name][member_name] - except KeyError: - pass - else: - assert isinstance(member_value, list) - array = array_factory(len(member_value)) - for i in range(len(member_value)): - array[i] = member_value[i] - member_value = array - #print node.name, member_name, member_value - assert isinstance(struct, Struct) or hasattr(struct, member_name) - setattr(struct, member_name, member_value) - self.result = struct - - def visit_pointer(self, node): - self.result = self.interpreter.lookup_object(node.address) - - -class Object: - - def __init__(self, interpreter, real): - self.interpreter = interpreter - self.real = real - - -class Global(Object): - - def __init__(self, interpreter, real): - self.interpreter = interpreter - self.real = real - - def pipe_winsys_create(self): - return Winsys(self.interpreter, gallium.Device()) - - def pipe_screen_create(self, winsys=None): - if winsys is None: - real = gallium.Device() - else: - real = winsys.real - return Screen(self.interpreter, real) - - def pipe_context_create(self, screen): - context = screen.real.context_create() - return Context(self.interpreter, context) - - -class Winsys(Object): - - def __init__(self, interpreter, real): - self.interpreter = interpreter - self.real = real - - def get_name(self): - pass - - def user_buffer_create(self, data, size): - # We don't really care to distinguish between user and regular buffers - buffer = self.real.buffer_create(size, - 4, - gallium.PIPE_BUFFER_USAGE_CPU_READ | - gallium.PIPE_BUFFER_USAGE_CPU_WRITE ) - assert size == len(data) - buffer.write(data) - return buffer - - def buffer_create(self, alignment, usage, size): - return self.real.buffer_create(size, alignment, usage) - - def buffer_destroy(self, buffer): - pass - - def buffer_write(self, buffer, data, size): - assert size == len(data) - buffer.write(data) - - def fence_finish(self, fence, flags): - pass - - def fence_reference(self, dst, src): - pass - - def flush_frontbuffer(self, surface): - pass - - def surface_alloc(self): - return None - - def surface_release(self, surface): - pass - - -class Transfer: - - def __init__(self, surface, x, y, w, h): - self.surface = surface - self.x = x - self.y = y - self.w = w - self.h = h - - -class Screen(Object): - - def destroy(self): - pass - - def get_name(self): - pass - - def get_vendor(self): - pass - - def get_param(self, param): - pass - - def get_paramf(self, param): - pass - - def context_create(self): - context = self.real.context_create() - return Context(self.interpreter, context) - - def is_format_supported(self, format, target, tex_usage, geom_flags): - return self.real.is_format_supported(format, target, tex_usage, geom_flags) - - def texture_create(self, templat): - return self.real.texture_create( - format = templat.format, - width = templat.width, - height = templat.height, - depth = templat.depth, - last_level = templat.last_level, - target = templat.target, - tex_usage = templat.tex_usage, - ) - - def texture_destroy(self, texture): - self.interpreter.unregister_object(texture) - - def texture_release(self, surface): - pass - - def get_tex_surface(self, texture, face, level, zslice, usage): - if texture is None: - return None - return texture.get_surface(face, level, zslice) - - def tex_surface_destroy(self, surface): - self.interpreter.unregister_object(surface) - - def tex_surface_release(self, surface): - pass - - def surface_write(self, surface, data, stride, size): - if surface is None: - return -# assert surface.nblocksy * stride == size - surface.put_tile_raw(0, 0, surface.width, surface.height, data, stride) - - def get_tex_transfer(self, texture, face, level, zslice, usage, x, y, w, h): - if texture is None: - return None - transfer = Transfer(texture.get_surface(face, level, zslice), x, y, w, h) - if transfer and usage & gallium.PIPE_TRANSFER_READ: - if self.interpreter.options.all: - self.interpreter.present(transfer.surface, 'transf_read', x, y, w, h) - return transfer - - def tex_transfer_destroy(self, transfer): - self.interpreter.unregister_object(transfer) - - def transfer_write(self, transfer, stride, data, size): - if transfer is None: - return - transfer.surface.put_tile_raw(transfer.x, transfer.y, transfer.w, transfer.h, data, stride) - if self.interpreter.options.all: - self.interpreter.present(transfer.surface, 'transf_write', transfer.x, transfer.y, transfer.w, transfer.h) - - def user_buffer_create(self, data, size): - # We don't really care to distinguish between user and regular buffers - buffer = self.real.buffer_create(size, - 4, - gallium.PIPE_BUFFER_USAGE_CPU_READ | - gallium.PIPE_BUFFER_USAGE_CPU_WRITE ) - assert size == len(data) - buffer.write(data) - return buffer - - def buffer_create(self, alignment, usage, size): - return self.real.buffer_create(size, alignment, usage) - - def buffer_destroy(self, buffer): - pass - - def buffer_write(self, buffer, data, size, offset=0): - assert size == len(data) - buffer.write(data) - - def fence_finish(self, fence, flags): - pass - - def fence_reference(self, dst, src): - pass - - def flush_frontbuffer(self, surface): - pass - - -class Context(Object): - - def __init__(self, interpreter, real): - Object.__init__(self, interpreter, real) - self.cbufs = [] - self.zsbuf = None - self.vbufs = [] - self.velems = [] - self.dirty = False - - def destroy(self): - pass - - def create_blend_state(self, state): - if isinstance(state, str): - state = gallium.Blend(state) - sys.stdout.write('\t%s\n' % state) - return state - - def bind_blend_state(self, state): - if state is not None: - self.real.set_blend(state) - - def delete_blend_state(self, state): - pass - - def create_sampler_state(self, state): - return state - - def delete_sampler_state(self, state): - pass - - def bind_vertex_sampler_states(self, num_states, states): - for i in range(num_states): - self.real.set_vertex_sampler(i, states[i]) - - def bind_fragment_sampler_states(self, num_states, states): - for i in range(num_states): - self.real.set_fragment_sampler(i, states[i]) - - def create_rasterizer_state(self, state): - return state - - def bind_rasterizer_state(self, state): - if state is not None: - self.real.set_rasterizer(state) - - def delete_rasterizer_state(self, state): - pass - - def create_depth_stencil_alpha_state(self, state): - return state - - def bind_depth_stencil_alpha_state(self, state): - if state is not None: - self.real.set_depth_stencil_alpha(state) - - def delete_depth_stencil_alpha_state(self, state): - pass - - def create_fs_state(self, state): - tokens = str(state.tokens) - shader = gallium.Shader(tokens) - return shader - - create_vs_state = create_fs_state - - def bind_fs_state(self, state): - self.real.set_fragment_shader(state) - - def bind_vs_state(self, state): - self.real.set_vertex_shader(state) - - def delete_fs_state(self, state): - pass - - delete_vs_state = delete_fs_state - - def set_blend_color(self, state): - self.real.set_blend_color(state) - - def set_stencil_ref(self, state): - self.real.set_stencil_ref(state) - - def set_clip_state(self, state): - _state = gallium.Clip() - _state.nr = state.nr - if state.nr: - # FIXME - ucp = gallium.FloatArray(gallium.PIPE_MAX_CLIP_PLANES*4) - for i in range(len(state.ucp)): - for j in range(len(state.ucp[i])): - ucp[i*4 + j] = state.ucp[i][j] - _state.ucp = ucp - self.real.set_clip(_state) - - def dump_constant_buffer(self, buffer): - if not self.interpreter.verbosity(2): - return - - data = buffer.read() - format = '4f' - index = 0 - for offset in range(0, len(data), struct.calcsize(format)): - x, y, z, w = unpack_from(format, data, offset) - sys.stdout.write('\tCONST[%2u] = {%10.4f, %10.4f, %10.4f, %10.4f}\n' % (index, x, y, z, w)) - index += 1 - sys.stdout.flush() - - def set_constant_buffer(self, shader, index, buffer): - if buffer is not None: - self.real.set_constant_buffer(shader, index, buffer) - - self.dump_constant_buffer(buffer) - - def set_framebuffer_state(self, state): - _state = gallium.Framebuffer() - _state.width = state.width - _state.height = state.height - _state.nr_cbufs = state.nr_cbufs - for i in range(len(state.cbufs)): - _state.set_cbuf(i, state.cbufs[i]) - _state.set_zsbuf(state.zsbuf) - self.real.set_framebuffer(_state) - - self.cbufs = state.cbufs - self.zsbuf = state.zsbuf - - def set_polygon_stipple(self, state): - self.real.set_polygon_stipple(state) - - def set_scissor_state(self, state): - self.real.set_scissor(state) - - def set_viewport_state(self, state): - self.real.set_viewport(state) - - def set_fragment_sampler_textures(self, num_textures, textures): - for i in range(num_textures): - self.real.set_fragment_sampler_texture(i, textures[i]) - - def set_vertex_sampler_textures(self, num_textures, textures): - for i in range(num_textures): - self.real.set_vertex_sampler_texture(i, textures[i]) - - def set_vertex_buffers(self, num_buffers, buffers): - self.vbufs = buffers[0:num_buffers] - for i in range(num_buffers): - vbuf = buffers[i] - self.real.set_vertex_buffer( - i, - stride = vbuf.stride, - max_index = vbuf.max_index, - buffer_offset = vbuf.buffer_offset, - buffer = vbuf.buffer, - ) - - def set_vertex_elements(self, num_elements, elements): - self.velems = elements[0:num_elements] - for i in range(num_elements): - self.real.set_vertex_element(i, elements[i]) - self.real.set_vertex_elements(num_elements) - - def dump_vertices(self, start, count): - if not self.interpreter.verbosity(2): - return - - for index in range(start, start + count): - if index >= start + 16: - sys.stdout.write('\t...\n') - break - sys.stdout.write('\t{\n') - for velem in self.velems: - vbuf = self.vbufs[velem.vertex_buffer_index] - - offset = vbuf.buffer_offset + velem.src_offset + vbuf.stride*index - format = { - gallium.PIPE_FORMAT_R32_FLOAT: 'f', - gallium.PIPE_FORMAT_R32G32_FLOAT: '2f', - gallium.PIPE_FORMAT_R32G32B32_FLOAT: '3f', - gallium.PIPE_FORMAT_R32G32B32A32_FLOAT: '4f', - gallium.PIPE_FORMAT_A8R8G8B8_UNORM: '4B', - gallium.PIPE_FORMAT_R8G8B8A8_UNORM: '4B', - gallium.PIPE_FORMAT_R16G16B16_SNORM: '3h', - }[velem.src_format] - - data = vbuf.buffer.read() - values = unpack_from(format, data, offset) - sys.stdout.write('\t\t{' + ', '.join(map(str, values)) + '},\n') - assert len(values) == velem.nr_components - sys.stdout.write('\t},\n') - sys.stdout.flush() - - def dump_indices(self, ibuf, isize, start, count): - if not self.interpreter.verbosity(2): - return - - format = { - 1: 'B', - 2: 'H', - 4: 'I', - }[isize] - - assert struct.calcsize(format) == isize - - data = ibuf.read() - maxindex, minindex = 0, 0xffffffff - - sys.stdout.write('\t{\n') - for i in range(start, start + count): - if i >= start + 16 and not self.interpreter.verbosity(3): - sys.stdout.write('\t...\n') - break - offset = i*isize - index, = unpack_from(format, data, offset) - sys.stdout.write('\t\t%u,\n' % index) - minindex = min(minindex, index) - maxindex = max(maxindex, index) - sys.stdout.write('\t},\n') - sys.stdout.flush() - - return minindex, maxindex - - def draw_arrays(self, mode, start, count): - self.dump_vertices(start, count) - - self.real.draw_arrays(mode, start, count) - self._set_dirty() - - def draw_elements(self, indexBuffer, indexSize, mode, start, count): - if self.interpreter.verbosity(2): - minindex, maxindex = self.dump_indices(indexBuffer, indexSize, start, count) - self.dump_vertices(minindex, maxindex - minindex) - - self.real.draw_elements(indexBuffer, indexSize, mode, start, count) - self._set_dirty() - - def draw_range_elements(self, indexBuffer, indexSize, minIndex, maxIndex, mode, start, count): - if self.interpreter.verbosity(2): - minindex, maxindex = self.dump_indices(indexBuffer, indexSize, start, count) - minindex = min(minindex, minIndex) - maxindex = min(maxindex, maxIndex) - self.dump_vertices(minindex, maxindex - minindex) - - self.real.draw_range_elements(indexBuffer, indexSize, minIndex, maxIndex, mode, start, count) - self._set_dirty() - - def surface_copy(self, dest, destx, desty, src, srcx, srcy, width, height): - if dest is not None and src is not None: - if self.interpreter.options.all: - self.interpreter.present(src, 'surface_copy_src', srcx, srcy, width, height) - self.real.surface_copy(dest, destx, desty, src, srcx, srcy, width, height) - if dest in self.cbufs: - self._set_dirty() - flags = gallium.PIPE_FLUSH_FRAME - else: - flags = 0 - self.flush(flags) - if self.interpreter.options.all: - self.interpreter.present(dest, 'surface_copy_dest', destx, desty, width, height) - - def is_texture_referenced(self, texture, face, level): - #return self.real.is_texture_referenced(format, texture, face, level) - pass - - def is_buffer_referenced(self, buf): - #return self.real.is_buffer_referenced(format, buf) - pass - - def _set_dirty(self): - if self.interpreter.options.step: - self._present() - else: - self.dirty = True - - def flush(self, flags): - self.real.flush(flags) - if self.dirty: - if flags & gallium.PIPE_FLUSH_FRAME: - self._present() - self.dirty = False - return None - - def clear(self, buffers, rgba, depth, stencil): - _rgba = gallium.FloatArray(4) - for i in range(4): - _rgba[i] = rgba[i] - self.real.clear(buffers, _rgba, depth, stencil) - - def _present(self): - self.real.flush() - - if self.cbufs and self.cbufs[0]: - self.interpreter.present(self.cbufs[0], "cbuf") - if self.zsbuf: - if self.interpreter.options.all: - self.interpreter.present(self.zsbuf, "zsbuf") - - -class Interpreter(parser.TraceDumper): - - ignore_calls = set(( - ('pipe_screen', 'is_format_supported'), - ('pipe_screen', 'get_param'), - ('pipe_screen', 'get_paramf'), - )) - - def __init__(self, stream, options): - parser.TraceDumper.__init__(self, stream) - self.options = options - self.objects = {} - self.result = None - self.globl = Global(self, None) - self.call_no = None - - def register_object(self, address, object): - self.objects[address] = object - - def unregister_object(self, object): - # FIXME: - pass - - def lookup_object(self, address): - return self.objects[address] - - def interpret(self, trace): - for call in trace.calls: - self.interpret_call(call) - - def handle_call(self, call): - if self.options.stop and call.no > self.options.stop: - sys.exit(0) - - if (call.klass, call.method) in self.ignore_calls: - return - - self.call_no = call.no - - if self.verbosity(1): - parser.TraceDumper.handle_call(self, call) - sys.stdout.flush() - - args = [(str(name), self.interpret_arg(arg)) for name, arg in call.args] - - if call.klass: - name, obj = args[0] - args = args[1:] - else: - obj = self.globl - - method = getattr(obj, call.method) - ret = method(**dict(args)) - - if call.ret and isinstance(call.ret, model.Pointer): - if ret is None: - sys.stderr.write('warning: NULL returned\n') - self.register_object(call.ret.address, ret) - - self.call_no = None - - def interpret_arg(self, node): - translator = Translator(self) - return translator.visit(node) - - def verbosity(self, level): - return self.options.verbosity >= level - - def present(self, surface, description, x=None, y=None, w=None, h=None): - if self.call_no < self.options.start: - return - - if self.options.images: - filename = '%04u_%s.png' % (self.call_no, description) - save_image(filename, surface, x, y, w, h) - else: - title = '%u. %s' % (self.call_no, description) - show_image(surface, title, x, y, w, h) - - -class Main(parser.Main): - - def get_optparser(self): - optparser = parser.Main.get_optparser(self) - optparser.add_option("-q", "--quiet", action="store_const", const=0, dest="verbosity", help="no messages") - optparser.add_option("-v", "--verbose", action="count", dest="verbosity", default=1, help="increase verbosity level") - optparser.add_option("-i", "--images", action="store_true", dest="images", default=False, help="save images instead of showing them") - optparser.add_option("-a", "--all", action="store_true", dest="all", default=False, help="show depth, stencil, and transfers") - optparser.add_option("-s", "--step", action="store_true", dest="step", default=False, help="step trhough every draw") - optparser.add_option("-f", "--from", action="store", type="int", dest="start", default=0, help="from call no") - optparser.add_option("-t", "--to", action="store", type="int", dest="stop", default=0, help="until call no") - return optparser - - def process_arg(self, stream, options): - parser = Interpreter(stream, options) - parser.parse() - - -if __name__ == '__main__': - Main().main() diff --git a/progs/gallium/python/retrace/model.py b/progs/gallium/python/retrace/model.py deleted file mode 100755 index d4a079fb1e..0000000000 --- a/progs/gallium/python/retrace/model.py +++ /dev/null @@ -1,213 +0,0 @@ -#!/usr/bin/env python -########################################################################## -# -# Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. -# 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, 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 TUNGSTEN GRAPHICS AND/OR ITS 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. -# -########################################################################## - - -'''Trace data model.''' - - -import sys -import string -import format - -try: - from cStringIO import StringIO -except ImportError: - from StringIO import StringIO - - -class Node: - - def visit(self, visitor): - raise NotImplementedError - - def __str__(self): - stream = StringIO() - formatter = format.DefaultFormatter(stream) - pretty_printer = PrettyPrinter(formatter) - self.visit(pretty_printer) - return stream.getvalue() - - -class Literal(Node): - - def __init__(self, value): - self.value = value - - def visit(self, visitor): - visitor.visit_literal(self) - - -class NamedConstant(Node): - - def __init__(self, name): - self.name = name - - def visit(self, visitor): - visitor.visit_named_constant(self) - - -class Array(Node): - - def __init__(self, elements): - self.elements = elements - - def visit(self, visitor): - visitor.visit_array(self) - - -class Struct(Node): - - def __init__(self, name, members): - self.name = name - self.members = members - - def visit(self, visitor): - visitor.visit_struct(self) - - -class Pointer(Node): - - def __init__(self, address): - self.address = address - - def visit(self, visitor): - visitor.visit_pointer(self) - - -class Call: - - def __init__(self, no, klass, method, args, ret): - self.no = no - self.klass = klass - self.method = method - self.args = args - self.ret = ret - - def visit(self, visitor): - visitor.visit_call(self) - - -class Trace: - - def __init__(self, calls): - self.calls = calls - - def visit(self, visitor): - visitor.visit_trace(self) - - -class Visitor: - - def visit_literal(self, node): - raise NotImplementedError - - def visit_named_constant(self, node): - raise NotImplementedError - - def visit_array(self, node): - raise NotImplementedError - - def visit_struct(self, node): - raise NotImplementedError - - def visit_pointer(self, node): - raise NotImplementedError - - def visit_call(self, node): - raise NotImplementedError - - def visit_trace(self, node): - raise NotImplementedError - - -class PrettyPrinter: - - def __init__(self, formatter): - self.formatter = formatter - - def visit_literal(self, node): - if isinstance(node.value, basestring): - if len(node.value) >= 4096 or node.value.strip(string.printable): - self.formatter.text('...') - return - - self.formatter.literal('"' + node.value + '"') - return - - self.formatter.literal(repr(node.value)) - - def visit_named_constant(self, node): - self.formatter.literal(node.name) - - def visit_array(self, node): - self.formatter.text('{') - sep = '' - for value in node.elements: - self.formatter.text(sep) - value.visit(self) - sep = ', ' - self.formatter.text('}') - - def visit_struct(self, node): - self.formatter.text('{') - sep = '' - for name, value in node.members: - self.formatter.text(sep) - self.formatter.variable(name) - self.formatter.text(' = ') - value.visit(self) - sep = ', ' - self.formatter.text('}') - - def visit_pointer(self, node): - self.formatter.address(node.address) - - def visit_call(self, node): - self.formatter.text('%s ' % node.no) - if node.klass is not None: - self.formatter.function(node.klass + '::' + node.method) - else: - self.formatter.function(node.method) - self.formatter.text('(') - sep = '' - for name, value in node.args: - self.formatter.text(sep) - self.formatter.variable(name) - self.formatter.text(' = ') - value.visit(self) - sep = ', ' - self.formatter.text(')') - if node.ret is not None: - self.formatter.text(' = ') - node.ret.visit(self) - - def visit_trace(self, node): - for call in node.calls: - call.visit(self) - self.formatter.newline() - diff --git a/progs/gallium/python/retrace/parse.py b/progs/gallium/python/retrace/parse.py deleted file mode 100755 index b08d368671..0000000000 --- a/progs/gallium/python/retrace/parse.py +++ /dev/null @@ -1,392 +0,0 @@ -#!/usr/bin/env python -########################################################################## -# -# Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. -# 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, 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 TUNGSTEN GRAPHICS AND/OR ITS 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. -# -########################################################################## - - -import sys -import xml.parsers.expat -import binascii -import optparse - -from model import * - - -ELEMENT_START, ELEMENT_END, CHARACTER_DATA, EOF = range(4) - - -class XmlToken: - - def __init__(self, type, name_or_data, attrs = None, line = None, column = None): - assert type in (ELEMENT_START, ELEMENT_END, CHARACTER_DATA, EOF) - self.type = type - self.name_or_data = name_or_data - self.attrs = attrs - self.line = line - self.column = column - - def __str__(self): - if self.type == ELEMENT_START: - return '<' + self.name_or_data + ' ...>' - if self.type == ELEMENT_END: - return '</' + self.name_or_data + '>' - if self.type == CHARACTER_DATA: - return self.name_or_data - if self.type == EOF: - return 'end of file' - assert 0 - - -class XmlTokenizer: - """Expat based XML tokenizer.""" - - def __init__(self, fp, skip_ws = True): - self.fp = fp - self.tokens = [] - self.index = 0 - self.final = False - self.skip_ws = skip_ws - - self.character_pos = 0, 0 - self.character_data = '' - - self.parser = xml.parsers.expat.ParserCreate() - self.parser.StartElementHandler = self.handle_element_start - self.parser.EndElementHandler = self.handle_element_end - self.parser.CharacterDataHandler = self.handle_character_data - - def handle_element_start(self, name, attributes): - self.finish_character_data() - line, column = self.pos() - token = XmlToken(ELEMENT_START, name, attributes, line, column) - self.tokens.append(token) - - def handle_element_end(self, name): - self.finish_character_data() - line, column = self.pos() - token = XmlToken(ELEMENT_END, name, None, line, column) - self.tokens.append(token) - - def handle_character_data(self, data): - if not self.character_data: - self.character_pos = self.pos() - self.character_data += data - - def finish_character_data(self): - if self.character_data: - if not self.skip_ws or not self.character_data.isspace(): - line, column = self.character_pos - token = XmlToken(CHARACTER_DATA, self.character_data, None, line, column) - self.tokens.append(token) - self.character_data = '' - - def next(self): - size = 16*1024 - while self.index >= len(self.tokens) and not self.final: - self.tokens = [] - self.index = 0 - data = self.fp.read(size) - self.final = len(data) < size - data = data.rstrip('\0') - try: - self.parser.Parse(data, self.final) - except xml.parsers.expat.ExpatError, e: - #if e.code == xml.parsers.expat.errors.XML_ERROR_NO_ELEMENTS: - if e.code == 3: - pass - else: - raise e - if self.index >= len(self.tokens): - line, column = self.pos() - token = XmlToken(EOF, None, None, line, column) - else: - token = self.tokens[self.index] - self.index += 1 - return token - - def pos(self): - return self.parser.CurrentLineNumber, self.parser.CurrentColumnNumber - - -class TokenMismatch(Exception): - - def __init__(self, expected, found): - self.expected = expected - self.found = found - - def __str__(self): - return '%u:%u: %s expected, %s found' % (self.found.line, self.found.column, str(self.expected), str(self.found)) - - - -class XmlParser: - """Base XML document parser.""" - - def __init__(self, fp): - self.tokenizer = XmlTokenizer(fp) - self.consume() - - def consume(self): - self.token = self.tokenizer.next() - - def match_element_start(self, name): - return self.token.type == ELEMENT_START and self.token.name_or_data == name - - def match_element_end(self, name): - return self.token.type == ELEMENT_END and self.token.name_or_data == name - - def element_start(self, name): - while self.token.type == CHARACTER_DATA: - self.consume() - if self.token.type != ELEMENT_START: - raise TokenMismatch(XmlToken(ELEMENT_START, name), self.token) - if self.token.name_or_data != name: - raise TokenMismatch(XmlToken(ELEMENT_START, name), self.token) - attrs = self.token.attrs - self.consume() - return attrs - - def element_end(self, name): - while self.token.type == CHARACTER_DATA: - self.consume() - if self.token.type != ELEMENT_END: - raise TokenMismatch(XmlToken(ELEMENT_END, name), self.token) - if self.token.name_or_data != name: - raise TokenMismatch(XmlToken(ELEMENT_END, name), self.token) - self.consume() - - def character_data(self, strip = True): - data = '' - while self.token.type == CHARACTER_DATA: - data += self.token.name_or_data - self.consume() - if strip: - data = data.strip() - return data - - -class TraceParser(XmlParser): - - def __init__(self, fp): - XmlParser.__init__(self, fp) - self.last_call_no = 0 - - def parse(self): - self.element_start('trace') - while self.token.type not in (ELEMENT_END, EOF): - call = self.parse_call() - self.handle_call(call) - if self.token.type != EOF: - self.element_end('trace') - - def parse_call(self): - attrs = self.element_start('call') - try: - no = int(attrs['no']) - except KeyError: - self.last_call_no += 1 - no = self.last_call_no - else: - self.last_call_no = no - klass = attrs['class'] - method = attrs['method'] - args = [] - ret = None - while self.token.type == ELEMENT_START: - if self.token.name_or_data == 'arg': - arg = self.parse_arg() - args.append(arg) - elif self.token.name_or_data == 'ret': - ret = self.parse_ret() - elif self.token.name_or_data == 'call': - # ignore nested function calls - self.parse_call() - else: - raise TokenMismatch("<arg ...> or <ret ...>", self.token) - self.element_end('call') - - return Call(no, klass, method, args, ret) - - def parse_arg(self): - attrs = self.element_start('arg') - name = attrs['name'] - value = self.parse_value() - self.element_end('arg') - - return name, value - - def parse_ret(self): - attrs = self.element_start('ret') - value = self.parse_value() - self.element_end('ret') - - return value - - def parse_value(self): - expected_tokens = ('null', 'bool', 'int', 'uint', 'float', 'string', 'enum', 'array', 'struct', 'ptr', 'bytes') - if self.token.type == ELEMENT_START: - if self.token.name_or_data in expected_tokens: - method = getattr(self, 'parse_' + self.token.name_or_data) - return method() - raise TokenMismatch(" or " .join(expected_tokens), self.token) - - def parse_null(self): - self.element_start('null') - self.element_end('null') - return Literal(None) - - def parse_bool(self): - self.element_start('bool') - value = int(self.character_data()) - self.element_end('bool') - return Literal(value) - - def parse_int(self): - self.element_start('int') - value = int(self.character_data()) - self.element_end('int') - return Literal(value) - - def parse_uint(self): - self.element_start('uint') - value = int(self.character_data()) - self.element_end('uint') - return Literal(value) - - def parse_float(self): - self.element_start('float') - value = float(self.character_data()) - self.element_end('float') - return Literal(value) - - def parse_enum(self): - self.element_start('enum') - name = self.character_data() - self.element_end('enum') - return NamedConstant(name) - - def parse_string(self): - self.element_start('string') - value = self.character_data() - self.element_end('string') - return Literal(value) - - def parse_bytes(self): - self.element_start('bytes') - value = binascii.a2b_hex(self.character_data()) - self.element_end('bytes') - return Literal(value) - - def parse_array(self): - self.element_start('array') - elems = [] - while self.token.type != ELEMENT_END: - elems.append(self.parse_elem()) - self.element_end('array') - return Array(elems) - - def parse_elem(self): - self.element_start('elem') - value = self.parse_value() - self.element_end('elem') - return value - - def parse_struct(self): - attrs = self.element_start('struct') - name = attrs['name'] - members = [] - while self.token.type != ELEMENT_END: - members.append(self.parse_member()) - self.element_end('struct') - return Struct(name, members) - - def parse_member(self): - attrs = self.element_start('member') - name = attrs['name'] - value = self.parse_value() - self.element_end('member') - - return name, value - - def parse_ptr(self): - self.element_start('ptr') - address = self.character_data() - self.element_end('ptr') - - return Pointer(address) - - def handle_call(self, call): - pass - - -class TraceDumper(TraceParser): - - def __init__(self, fp): - TraceParser.__init__(self, fp) - self.formatter = format.DefaultFormatter(sys.stdout) - self.pretty_printer = PrettyPrinter(self.formatter) - - def handle_call(self, call): - call.visit(self.pretty_printer) - self.formatter.newline() - - -class Main: - '''Common main class for all retrace command line utilities.''' - - def __init__(self): - pass - - def main(self): - optparser = self.get_optparser() - (options, args) = optparser.parse_args(sys.argv[1:]) - - if args: - for arg in args: - if arg.endswith('.gz'): - from gzip import GzipFile - stream = GzipFile(arg, 'rt') - elif arg.endswith('.bz2'): - from bz2 import BZ2File - stream = BZ2File(arg, 'rU') - else: - stream = open(arg, 'rt') - self.process_arg(stream, options) - else: - self.process_arg(stream, options) - - def get_optparser(self): - optparser = optparse.OptionParser( - usage="\n\t%prog [options] [traces] ...") - return optparser - - def process_arg(self, stream, options): - parser = TraceDumper(stream) - parser.parse() - - -if __name__ == '__main__': - Main().main() diff --git a/progs/gallium/python/retrace/parser.py b/progs/gallium/python/retrace/parser.py deleted file mode 100755 index bd47c9a6b0..0000000000 --- a/progs/gallium/python/retrace/parser.py +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env python -########################################################################## -# -# Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. -# 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, 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 TUNGSTEN GRAPHICS AND/OR ITS 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. -# -########################################################################## - - -from parse import * - - -if __name__ == '__main__': - Main().main() diff --git a/progs/gallium/python/samples/gs.py b/progs/gallium/python/samples/gs.py deleted file mode 100644 index 5c22269b18..0000000000 --- a/progs/gallium/python/samples/gs.py +++ /dev/null @@ -1,254 +0,0 @@ -#!/usr/bin/env python -########################################################################## -# -# Copyright 2009 VMware -# 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, 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 TUNGSTEN GRAPHICS AND/OR ITS 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. -# -########################################################################## - - -from gallium import * - - -def make_image(surface): - data = surface.get_tile_rgba8(0, 0, surface.width, surface.height) - - import Image - outimage = Image.fromstring('RGBA', (surface.width, surface.height), data, "raw", 'RGBA', 0, 1) - return outimage - -def save_image(filename, surface): - outimage = make_image(surface) - outimage.save(filename, "PNG") - -def show_image(surface): - outimage = make_image(surface) - - import Tkinter as tk - from PIL import Image, ImageTk - root = tk.Tk() - - root.title('background image') - - image1 = ImageTk.PhotoImage(outimage) - w = image1.width() - h = image1.height() - x = 100 - y = 100 - root.geometry("%dx%d+%d+%d" % (w, h, x, y)) - panel1 = tk.Label(root, image=image1) - panel1.pack(side='top', fill='both', expand='yes') - panel1.image = image1 - root.mainloop() - - -def test(dev): - ctx = dev.context_create() - - width = 255 - height = 255 - minz = 0.0 - maxz = 1.0 - - # disabled blending/masking - blend = Blend() - blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE - blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_ONE - blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_ZERO - blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_ZERO - blend.rt[0].colormask = PIPE_MASK_RGBA - ctx.set_blend(blend) - - # depth/stencil/alpha - depth_stencil_alpha = DepthStencilAlpha() - depth_stencil_alpha.depth.enabled = 1 - depth_stencil_alpha.depth.writemask = 1 - depth_stencil_alpha.depth.func = PIPE_FUNC_LESS - ctx.set_depth_stencil_alpha(depth_stencil_alpha) - - # rasterizer - rasterizer = Rasterizer() - rasterizer.front_winding = PIPE_WINDING_CW - rasterizer.cull_mode = PIPE_WINDING_NONE - rasterizer.scissor = 1 - ctx.set_rasterizer(rasterizer) - - # viewport - viewport = Viewport() - scale = FloatArray(4) - scale[0] = width / 2.0 - scale[1] = -height / 2.0 - scale[2] = (maxz - minz) / 2.0 - scale[3] = 1.0 - viewport.scale = scale - translate = FloatArray(4) - translate[0] = width / 2.0 - translate[1] = height / 2.0 - translate[2] = (maxz - minz) / 2.0 - translate[3] = 0.0 - viewport.translate = translate - ctx.set_viewport(viewport) - - # samplers - sampler = Sampler() - sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE - sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE - sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE - sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE - sampler.min_img_filter = PIPE_TEX_MIPFILTER_NEAREST - sampler.mag_img_filter = PIPE_TEX_MIPFILTER_NEAREST - sampler.normalized_coords = 1 - ctx.set_sampler(0, sampler) - - # scissor - scissor = Scissor() - scissor.minx = 0 - scissor.miny = 0 - scissor.maxx = width - scissor.maxy = height - ctx.set_scissor(scissor) - - clip = Clip() - clip.nr = 0 - ctx.set_clip(clip) - - # framebuffer - cbuf = dev.texture_create( - PIPE_FORMAT_B8G8R8X8_UNORM, - width, height, - tex_usage=PIPE_TEXTURE_USAGE_RENDER_TARGET, - ).get_surface() - zbuf = dev.texture_create( - PIPE_FORMAT_Z32_UNORM, - width, height, - tex_usage=PIPE_TEXTURE_USAGE_DEPTH_STENCIL, - ).get_surface() - fb = Framebuffer() - fb.width = width - fb.height = height - fb.nr_cbufs = 1 - fb.set_cbuf(0, cbuf) - fb.set_zsbuf(zbuf) - ctx.set_framebuffer(fb) - rgba = FloatArray(4); - rgba[0] = 0.0 - rgba[1] = 0.0 - rgba[2] = 0.0 - rgba[3] = 0.0 - ctx.clear(PIPE_CLEAR_COLOR | PIPE_CLEAR_DEPTHSTENCIL, rgba, 1.0, 0xff) - - # vertex shader - vs = Shader(''' - VERT - DCL IN[0], POSITION, CONSTANT - DCL IN[1], COLOR, CONSTANT - DCL OUT[0], POSITION, CONSTANT - DCL OUT[1], COLOR, CONSTANT - 0:MOV OUT[0], IN[0] - 1:MOV OUT[1], IN[1] - 2:END - ''') - ctx.set_vertex_shader(vs) - - gs = Shader(''' - GEOM - PROPERTY GS_INPUT_PRIMITIVE TRIANGLES - PROPERTY GS_OUTPUT_PRIMITIVE TRIANGLE_STRIP - DCL IN[][0], POSITION, CONSTANT - DCL IN[][1], COLOR, CONSTANT - DCL OUT[0], POSITION, CONSTANT - DCL OUT[1], COLOR, CONSTANT - 0:MOV OUT[0], IN[0][0] - 1:MOV OUT[1], IN[0][1] - 2:EMIT - 3:MOV OUT[0], IN[1][0] - 4:MOV OUT[1], IN[1][1] - 5:EMIT - 6:MOV OUT[0], IN[2][0] - 7:MOV OUT[1], IN[2][1] - 8:EMIT - 9:ENDPRIM - 10:END - ''') - ctx.set_geometry_shader(gs) - - # fragment shader - fs = Shader(''' - FRAG - DCL IN[0], COLOR, LINEAR - DCL OUT[0], COLOR, CONSTANT - 0:MOV OUT[0], IN[0] - 1:END - ''') - ctx.set_fragment_shader(fs) - - nverts = 3 - nattrs = 2 - verts = FloatArray(nverts * nattrs * 4) - - verts[ 0] = 0.0 # x1 - verts[ 1] = 0.8 # y1 - verts[ 2] = 0.2 # z1 - verts[ 3] = 1.0 # w1 - verts[ 4] = 1.0 # r1 - verts[ 5] = 0.0 # g1 - verts[ 6] = 0.0 # b1 - verts[ 7] = 1.0 # a1 - verts[ 8] = -0.8 # x2 - verts[ 9] = -0.8 # y2 - verts[10] = 0.5 # z2 - verts[11] = 1.0 # w2 - verts[12] = 0.0 # r2 - verts[13] = 1.0 # g2 - verts[14] = 0.0 # b2 - verts[15] = 1.0 # a2 - verts[16] = 0.8 # x3 - verts[17] = -0.8 # y3 - verts[18] = 0.8 # z3 - verts[19] = 1.0 # w3 - verts[20] = 0.0 # r3 - verts[21] = 0.0 # g3 - verts[22] = 1.0 # b3 - verts[23] = 1.0 # a3 - - ctx.draw_vertices(PIPE_PRIM_TRIANGLES, - nverts, - nattrs, - verts) - - ctx.flush() - - show_image(cbuf) - #show_image(zbuf) - #save_image('cbuf.png', cbuf) - #save_image('zbuf.png', zbuf) - - - -def main(): - dev = Device() - test(dev) - - -if __name__ == '__main__': - main() diff --git a/progs/gallium/python/samples/tri.py b/progs/gallium/python/samples/tri.py deleted file mode 100644 index d7fbdb10ac..0000000000 --- a/progs/gallium/python/samples/tri.py +++ /dev/null @@ -1,232 +0,0 @@ -#!/usr/bin/env python -########################################################################## -# -# Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. -# 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, 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 TUNGSTEN GRAPHICS AND/OR ITS 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. -# -########################################################################## - - -from gallium import * - - -def make_image(surface): - data = surface.get_tile_rgba8(0, 0, surface.width, surface.height) - - import Image - outimage = Image.fromstring('RGBA', (surface.width, surface.height), data, "raw", 'RGBA', 0, 1) - return outimage - -def save_image(filename, surface): - outimage = make_image(surface) - outimage.save(filename, "PNG") - -def show_image(surface): - outimage = make_image(surface) - - import Tkinter as tk - from PIL import Image, ImageTk - root = tk.Tk() - - root.title('background image') - - image1 = ImageTk.PhotoImage(outimage) - w = image1.width() - h = image1.height() - x = 100 - y = 100 - root.geometry("%dx%d+%d+%d" % (w, h, x, y)) - panel1 = tk.Label(root, image=image1) - panel1.pack(side='top', fill='both', expand='yes') - panel1.image = image1 - root.mainloop() - - -def test(dev): - ctx = dev.context_create() - - width = 255 - height = 255 - minz = 0.0 - maxz = 1.0 - - # disabled blending/masking - blend = Blend() - blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE - blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_ONE - blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_ZERO - blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_ZERO - blend.rt[0].colormask = PIPE_MASK_RGBA - ctx.set_blend(blend) - - # depth/stencil/alpha - depth_stencil_alpha = DepthStencilAlpha() - depth_stencil_alpha.depth.enabled = 1 - depth_stencil_alpha.depth.writemask = 1 - depth_stencil_alpha.depth.func = PIPE_FUNC_LESS - ctx.set_depth_stencil_alpha(depth_stencil_alpha) - - # rasterizer - rasterizer = Rasterizer() - rasterizer.front_winding = PIPE_WINDING_CW - rasterizer.cull_mode = PIPE_WINDING_NONE - rasterizer.scissor = 1 - ctx.set_rasterizer(rasterizer) - - # viewport - viewport = Viewport() - scale = FloatArray(4) - scale[0] = width / 2.0 - scale[1] = -height / 2.0 - scale[2] = (maxz - minz) / 2.0 - scale[3] = 1.0 - viewport.scale = scale - translate = FloatArray(4) - translate[0] = width / 2.0 - translate[1] = height / 2.0 - translate[2] = (maxz - minz) / 2.0 - translate[3] = 0.0 - viewport.translate = translate - ctx.set_viewport(viewport) - - # samplers - sampler = Sampler() - sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE - sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE - sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE - sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE - sampler.min_img_filter = PIPE_TEX_MIPFILTER_NEAREST - sampler.mag_img_filter = PIPE_TEX_MIPFILTER_NEAREST - sampler.normalized_coords = 1 - ctx.set_fragment_sampler(0, sampler) - - # scissor - scissor = Scissor() - scissor.minx = 0 - scissor.miny = 0 - scissor.maxx = width - scissor.maxy = height - ctx.set_scissor(scissor) - - clip = Clip() - clip.nr = 0 - ctx.set_clip(clip) - - # framebuffer - cbuf = dev.texture_create( - PIPE_FORMAT_B8G8R8X8_UNORM, - width, height, - tex_usage=PIPE_TEXTURE_USAGE_RENDER_TARGET, - ).get_surface() - zbuf = dev.texture_create( - PIPE_FORMAT_Z32_UNORM, - width, height, - tex_usage=PIPE_TEXTURE_USAGE_DEPTH_STENCIL, - ).get_surface() - fb = Framebuffer() - fb.width = width - fb.height = height - fb.nr_cbufs = 1 - fb.set_cbuf(0, cbuf) - fb.set_zsbuf(zbuf) - ctx.set_framebuffer(fb) - rgba = FloatArray(4); - rgba[0] = 0.0 - rgba[1] = 0.0 - rgba[2] = 0.0 - rgba[3] = 0.0 - ctx.clear(PIPE_CLEAR_COLOR | PIPE_CLEAR_DEPTHSTENCIL, rgba, 1.0, 0xff) - - # vertex shader - vs = Shader(''' - VERT - DCL IN[0], POSITION, CONSTANT - DCL IN[1], COLOR, CONSTANT - DCL OUT[0], POSITION, CONSTANT - DCL OUT[1], COLOR, CONSTANT - 0:MOV OUT[0], IN[0] - 1:MOV OUT[1], IN[1] - 2:END - ''') - ctx.set_vertex_shader(vs) - - # fragment shader - fs = Shader(''' - FRAG - DCL IN[0], COLOR, LINEAR - DCL OUT[0], COLOR, CONSTANT - 0:MOV OUT[0], IN[0] - 1:END - ''') - ctx.set_fragment_shader(fs) - - nverts = 3 - nattrs = 2 - verts = FloatArray(nverts * nattrs * 4) - - verts[ 0] = 0.0 # x1 - verts[ 1] = 0.8 # y1 - verts[ 2] = 0.2 # z1 - verts[ 3] = 1.0 # w1 - verts[ 4] = 1.0 # r1 - verts[ 5] = 0.0 # g1 - verts[ 6] = 0.0 # b1 - verts[ 7] = 1.0 # a1 - verts[ 8] = -0.8 # x2 - verts[ 9] = -0.8 # y2 - verts[10] = 0.5 # z2 - verts[11] = 1.0 # w2 - verts[12] = 0.0 # r2 - verts[13] = 1.0 # g2 - verts[14] = 0.0 # b2 - verts[15] = 1.0 # a2 - verts[16] = 0.8 # x3 - verts[17] = -0.8 # y3 - verts[18] = 0.8 # z3 - verts[19] = 1.0 # w3 - verts[20] = 0.0 # r3 - verts[21] = 0.0 # g3 - verts[22] = 1.0 # b3 - verts[23] = 1.0 # a3 - - ctx.draw_vertices(PIPE_PRIM_TRIANGLES, - nverts, - nattrs, - verts) - - ctx.flush() - - show_image(cbuf) - #show_image(zbuf) - #save_image('cbuf.png', cbuf) - #save_image('zbuf.png', zbuf) - - - -def main(): - dev = Device() - test(dev) - - -if __name__ == '__main__': - main() diff --git a/progs/gallium/python/tests/.gitignore b/progs/gallium/python/tests/.gitignore deleted file mode 100644 index 0dbbaeea16..0000000000 --- a/progs/gallium/python/tests/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -*.txt -*.tsv -*.dot diff --git a/progs/gallium/python/tests/base.py b/progs/gallium/python/tests/base.py deleted file mode 100755 index bd82f50811..0000000000 --- a/progs/gallium/python/tests/base.py +++ /dev/null @@ -1,344 +0,0 @@ -#!/usr/bin/env python -########################################################################## -# -# Copyright 2009 VMware, Inc. -# Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. -# 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, 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 ITS 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. -# -########################################################################## - - -"""Base classes for tests. - -Loosely inspired on Python's unittest module. -""" - - -import os.path -import sys - -from gallium import * - - -# Enumerate all pixel formats -formats = {} -for name, value in globals().items(): - if name.startswith("PIPE_FORMAT_") and isinstance(value, int): - formats[value] = name - -def is_depth_stencil_format(format): - # FIXME: make and use binding to util_format_is_depth_or_stencil - return format in ( - PIPE_FORMAT_Z32_UNORM, - PIPE_FORMAT_S8Z24_UNORM, - PIPE_FORMAT_X8Z24_UNORM, - PIPE_FORMAT_Z16_UNORM, - ) - -def make_image(width, height, rgba): - import Image - outimage = Image.new( - mode='RGB', - size=(width, height), - color=(0,0,0)) - outpixels = outimage.load() - for y in range(0, height): - for x in range(0, width): - offset = (y*width + x)*4 - r, g, b, a = [int(min(max(rgba[offset + ch], 0.0), 1.0)*255) for ch in range(4)] - outpixels[x, y] = r, g, b - return outimage - -def save_image(width, height, rgba, filename): - outimage = make_image(width, height, rgba) - outimage.save(filename, "PNG") - -def show_image(width, height, **rgbas): - import Tkinter as tk - from PIL import Image, ImageTk - - root = tk.Tk() - - x = 64 - y = 64 - - labels = rgbas.keys() - labels.sort() - for i in range(len(labels)): - label = labels[i] - outimage = make_image(width, height, rgbas[label]) - - if i: - window = tk.Toplevel(root) - else: - window = root - window.title(label) - image1 = ImageTk.PhotoImage(outimage) - w = image1.width() - h = image1.height() - window.geometry("%dx%d+%d+%d" % (w, h, x, y)) - panel1 = tk.Label(window, image=image1) - panel1.pack(side='top', fill='both', expand='yes') - panel1.image = image1 - x += w + 2 - - root.mainloop() - - -class TestFailure(Exception): - - pass - -class TestSkip(Exception): - - pass - - -class Test: - - def __init__(self): - pass - - def _run(self, result): - raise NotImplementedError - - def run(self): - result = TestResult() - self._run(result) - result.summary() - - def assert_rgba(self, surface, x, y, w, h, expected_rgba, pixel_tol=4.0/256, surface_tol=0.85): - total = h*w - different = surface.compare_tile_rgba(x, y, w, h, expected_rgba, tol=pixel_tol) - if different: - sys.stderr.write("%u out of %u pixels differ\n" % (different, total)) - - if float(total - different)/float(total) < surface_tol: - if 0: - rgba = FloatArray(h*w*4) - surface.get_tile_rgba(x, y, w, h, rgba) - show_image(w, h, Result=rgba, Expected=expected_rgba) - save_image(w, h, rgba, "result.png") - save_image(w, h, expected_rgba, "expected.png") - #sys.exit(0) - - raise TestFailure - - -class TestCase(Test): - - tags = () - - def __init__(self, dev, **kargs): - Test.__init__(self) - self.dev = dev - self.__dict__.update(kargs) - - def description(self): - descriptions = [] - for tag in self.tags: - value = self.get(tag) - if value is not None and value != '': - descriptions.append(tag + '=' + str(value)) - return ' '.join(descriptions) - - def get(self, tag): - try: - method = getattr(self, '_get_' + tag) - except AttributeError: - return getattr(self, tag, None) - else: - return method() - - def _get_target(self): - return { - PIPE_TEXTURE_1D: "1d", - PIPE_TEXTURE_2D: "2d", - PIPE_TEXTURE_3D: "3d", - PIPE_TEXTURE_CUBE: "cube", - }[self.target] - - def _get_format(self): - name = formats[self.format] - if name.startswith('PIPE_FORMAT_'): - name = name[12:] - name = name.lower() - return name - - def _get_face(self): - if self.target == PIPE_TEXTURE_CUBE: - return { - PIPE_TEX_FACE_POS_X: "+x", - PIPE_TEX_FACE_NEG_X: "-x", - PIPE_TEX_FACE_POS_Y: "+y", - PIPE_TEX_FACE_NEG_Y: "-y", - PIPE_TEX_FACE_POS_Z: "+z", - PIPE_TEX_FACE_NEG_Z: "-z", - }[self.face] - else: - return '' - - def test(self): - raise NotImplementedError - - def _run(self, result): - result.test_start(self) - try: - self.test() - except KeyboardInterrupt: - raise - except TestSkip: - result.test_skipped(self) - except TestFailure: - result.test_failed(self) - else: - result.test_passed(self) - - -class TestSuite(Test): - - def __init__(self, tests = None): - Test.__init__(self) - if tests is None: - self.tests = [] - else: - self.tests = tests - - def add_test(self, test): - self.tests.append(test) - - def _run(self, result): - for test in self.tests: - test._run(result) - - -class TestResult: - - def __init__(self): - self.tests = 0 - self.passed = 0 - self.skipped = 0 - self.failed = 0 - - self.names = ['result'] - self.types = ['pass skip fail'] - self.rows = [] - - def test_start(self, test): - sys.stdout.write("Running %s...\n" % test.description()) - sys.stdout.flush() - self.tests += 1 - - def test_passed(self, test): - sys.stdout.write("PASS\n") - sys.stdout.flush() - self.passed += 1 - self.log_result(test, 'pass') - - def test_skipped(self, test): - sys.stdout.write("SKIP\n") - sys.stdout.flush() - self.skipped += 1 - #self.log_result(test, 'skip') - - def test_failed(self, test): - sys.stdout.write("FAIL\n") - sys.stdout.flush() - self.failed += 1 - self.log_result(test, 'fail') - - def log_result(self, test, result): - row = ['']*len(self.names) - - # add result - assert self.names[0] == 'result' - assert result in ('pass', 'skip', 'fail') - row[0] = result - - # add tags - for tag in test.tags: - value = test.get(tag) - - # infer type - if value is None: - continue - elif isinstance(value, (int, float)): - value = str(value) - type = 'c' # continous - elif isinstance(value, basestring): - type = 'd' # discrete - else: - assert False - value = str(value) - type = 'd' # discrete - - # insert value - try: - col = self.names.index(tag, 1) - except ValueError: - self.names.append(tag) - self.types.append(type) - row.append(value) - else: - row[col] = value - assert self.types[col] == type - - self.rows.append(row) - - def summary(self): - sys.stdout.write("%u tests, %u passed, %u skipped, %u failed\n\n" % (self.tests, self.passed, self.skipped, self.failed)) - sys.stdout.flush() - - name, ext = os.path.splitext(os.path.basename(sys.argv[0])) - filename = name + '.tsv' - stream = file(filename, 'wt') - - # header - stream.write('\t'.join(self.names) + '\n') - stream.write('\t'.join(self.types) + '\n') - stream.write('class\n') - - # rows - for row in self.rows: - row += ['']*(len(self.names) - len(row)) - stream.write('\t'.join(row) + '\n') - - stream.close() - - # See http://www.ailab.si/orange/doc/ofb/c_otherclass.htm - try: - import orange - import orngTree - except ImportError: - sys.stderr.write('Install Orange from http://www.ailab.si/orange/ for a classification tree.\n') - return - - data = orange.ExampleTable(filename) - - tree = orngTree.TreeLearner(data, sameMajorityPruning=1, mForPruning=2) - - orngTree.printTxt(tree, maxDepth=4) - - file(name+'.txt', 'wt').write(orngTree.dumpTree(tree)) - - orngTree.printDot(tree, fileName=name+'.dot', nodeShape='ellipse', leafShape='box') diff --git a/progs/gallium/python/tests/regress/fragment-shader/.gitignore b/progs/gallium/python/tests/regress/fragment-shader/.gitignore deleted file mode 100644 index e33609d251..0000000000 --- a/progs/gallium/python/tests/regress/fragment-shader/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*.png diff --git a/progs/gallium/python/tests/regress/fragment-shader/frag-abs.sh b/progs/gallium/python/tests/regress/fragment-shader/frag-abs.sh deleted file mode 100644 index 103d7497f4..0000000000 --- a/progs/gallium/python/tests/regress/fragment-shader/frag-abs.sh +++ /dev/null @@ -1,13 +0,0 @@ -FRAG - -DCL IN[0], COLOR, LINEAR -DCL OUT[0], COLOR - -DCL TEMP[0] - -IMM FLT32 { -0.5, -0.4, -0.6, 0.0 } - -ADD TEMP[0], IN[0], IMM[0] -ABS OUT[0], TEMP[0] - -END diff --git a/progs/gallium/python/tests/regress/fragment-shader/frag-add.sh b/progs/gallium/python/tests/regress/fragment-shader/frag-add.sh deleted file mode 100644 index bcb9420596..0000000000 --- a/progs/gallium/python/tests/regress/fragment-shader/frag-add.sh +++ /dev/null @@ -1,8 +0,0 @@ -FRAG - -DCL IN[0], COLOR, LINEAR -DCL OUT[0], COLOR - -ADD OUT[0], IN[0], IN[0] - -END diff --git a/progs/gallium/python/tests/regress/fragment-shader/frag-cb-1d.sh b/progs/gallium/python/tests/regress/fragment-shader/frag-cb-1d.sh deleted file mode 100644 index 85fb9ea4e7..0000000000 --- a/progs/gallium/python/tests/regress/fragment-shader/frag-cb-1d.sh +++ /dev/null @@ -1,13 +0,0 @@ -FRAG - -DCL IN[0], COLOR, LINEAR -DCL OUT[0], COLOR -DCL CONST[1] -DCL CONST[3] -DCL TEMP[0..1] - -ADD TEMP[0], IN[0], CONST[1] -RCP TEMP[1], CONST[3].xxxx -MUL OUT[0], TEMP[0], TEMP[1] - -END diff --git a/progs/gallium/python/tests/regress/fragment-shader/frag-cb-2d.sh b/progs/gallium/python/tests/regress/fragment-shader/frag-cb-2d.sh deleted file mode 100644 index f70a5146f4..0000000000 --- a/progs/gallium/python/tests/regress/fragment-shader/frag-cb-2d.sh +++ /dev/null @@ -1,9 +0,0 @@ -FRAG - -DCL IN[0], COLOR, LINEAR -DCL OUT[0], COLOR -DCL CONST[1][1..2] - -MAD OUT[0], IN[0], CONST[1][2], CONST[1][1] - -END diff --git a/progs/gallium/python/tests/regress/fragment-shader/frag-dp3.sh b/progs/gallium/python/tests/regress/fragment-shader/frag-dp3.sh deleted file mode 100644 index b5281975d4..0000000000 --- a/progs/gallium/python/tests/regress/fragment-shader/frag-dp3.sh +++ /dev/null @@ -1,8 +0,0 @@ -FRAG - -DCL IN[0], COLOR, LINEAR -DCL OUT[0], COLOR - -DP3 OUT[0], IN[0], IN[0] - -END diff --git a/progs/gallium/python/tests/regress/fragment-shader/frag-dp4.sh b/progs/gallium/python/tests/regress/fragment-shader/frag-dp4.sh deleted file mode 100644 index d59df76e70..0000000000 --- a/progs/gallium/python/tests/regress/fragment-shader/frag-dp4.sh +++ /dev/null @@ -1,8 +0,0 @@ -FRAG - -DCL IN[0], COLOR, LINEAR -DCL OUT[0], COLOR - -DP4 OUT[0], IN[0].xyzx, IN[0].xyzx - -END diff --git a/progs/gallium/python/tests/regress/fragment-shader/frag-dst.sh b/progs/gallium/python/tests/regress/fragment-shader/frag-dst.sh deleted file mode 100644 index fbb20fa9f6..0000000000 --- a/progs/gallium/python/tests/regress/fragment-shader/frag-dst.sh +++ /dev/null @@ -1,8 +0,0 @@ -FRAG - -DCL IN[0], COLOR, LINEAR -DCL OUT[0], COLOR - -DST OUT[0], IN[0], IN[0] - -END diff --git a/progs/gallium/python/tests/regress/fragment-shader/frag-ex2.sh b/progs/gallium/python/tests/regress/fragment-shader/frag-ex2.sh deleted file mode 100644 index b511288f4b..0000000000 --- a/progs/gallium/python/tests/regress/fragment-shader/frag-ex2.sh +++ /dev/null @@ -1,11 +0,0 @@ -FRAG - -DCL IN[0], COLOR, LINEAR -DCL OUT[0], COLOR - -DCL TEMP[0] - -EX2 TEMP[0], IN[0].xxxx -MUL OUT[0], TEMP[0], IN[0] - -END diff --git a/progs/gallium/python/tests/regress/fragment-shader/frag-flr.sh b/progs/gallium/python/tests/regress/fragment-shader/frag-flr.sh deleted file mode 100644 index 99a2f96103..0000000000 --- a/progs/gallium/python/tests/regress/fragment-shader/frag-flr.sh +++ /dev/null @@ -1,15 +0,0 @@ -FRAG - -DCL IN[0], COLOR, LINEAR -DCL OUT[0], COLOR - -DCL TEMP[0] - -IMM FLT32 { 2.5, 4.0, 2.0, 1.0 } -IMM FLT32 { 0.4, 0.25, 0.5, 1.0 } - -MUL TEMP[0], IN[0], IMM[0] -FLR TEMP[0], TEMP[0] -MUL OUT[0], TEMP[0], IMM[1] - -END diff --git a/progs/gallium/python/tests/regress/fragment-shader/frag-frc.sh b/progs/gallium/python/tests/regress/fragment-shader/frag-frc.sh deleted file mode 100644 index a54c2623b0..0000000000 --- a/progs/gallium/python/tests/regress/fragment-shader/frag-frc.sh +++ /dev/null @@ -1,13 +0,0 @@ -FRAG - -DCL IN[0], COLOR, LINEAR -DCL OUT[0], COLOR - -DCL TEMP[0] - -IMM FLT32 { 2.7, 3.1, 4.5, 1.0 } - -MUL TEMP[0], IN[0], IMM[0] -FRC OUT[0], TEMP[0] - -END diff --git a/progs/gallium/python/tests/regress/fragment-shader/frag-lg2.sh b/progs/gallium/python/tests/regress/fragment-shader/frag-lg2.sh deleted file mode 100644 index 5f5b4be109..0000000000 --- a/progs/gallium/python/tests/regress/fragment-shader/frag-lg2.sh +++ /dev/null @@ -1,15 +0,0 @@ -FRAG - -DCL IN[0], COLOR, LINEAR -DCL OUT[0], COLOR - -DCL TEMP[0] - -IMM FLT32 { 1.0, 0.0, 0.0, 0.0 } -IMM FLT32 { 0.5, 0.0, 0.0, 0.0 } - -ADD TEMP[0], IN[0], IMM[0] -LG2 TEMP[0].x, TEMP[0].xxxx -ADD OUT[0], TEMP[0], IMM[1] - -END diff --git a/progs/gallium/python/tests/regress/fragment-shader/frag-lit.sh b/progs/gallium/python/tests/regress/fragment-shader/frag-lit.sh deleted file mode 100644 index 6323c4712d..0000000000 --- a/progs/gallium/python/tests/regress/fragment-shader/frag-lit.sh +++ /dev/null @@ -1,8 +0,0 @@ -FRAG - -DCL IN[0], COLOR, LINEAR -DCL OUT[0], COLOR - -LIT OUT[0], IN[0] - -END diff --git a/progs/gallium/python/tests/regress/fragment-shader/frag-lrp.sh b/progs/gallium/python/tests/regress/fragment-shader/frag-lrp.sh deleted file mode 100644 index 740809d22e..0000000000 --- a/progs/gallium/python/tests/regress/fragment-shader/frag-lrp.sh +++ /dev/null @@ -1,11 +0,0 @@ -FRAG - -DCL IN[0], COLOR, LINEAR -DCL OUT[0], COLOR - -DCL TEMP[0] - -ABS TEMP[0], IN[0] -LRP OUT[0], TEMP[0], IN[0].xxxx, IN[0].yyyy - -END diff --git a/progs/gallium/python/tests/regress/fragment-shader/frag-mad.sh b/progs/gallium/python/tests/regress/fragment-shader/frag-mad.sh deleted file mode 100644 index 413b9dc391..0000000000 --- a/progs/gallium/python/tests/regress/fragment-shader/frag-mad.sh +++ /dev/null @@ -1,11 +0,0 @@ -FRAG - -DCL IN[0], COLOR, LINEAR -DCL OUT[0], COLOR - -IMM FLT32 { 0.5, 0.4, 0.6, 1.0 } -IMM FLT32 { 0.5, 0.4, 0.6, 0.0 } - -MAD OUT[0], IN[0], IMM[0], IMM[1] - -END diff --git a/progs/gallium/python/tests/regress/fragment-shader/frag-max.sh b/progs/gallium/python/tests/regress/fragment-shader/frag-max.sh deleted file mode 100644 index b69f213261..0000000000 --- a/progs/gallium/python/tests/regress/fragment-shader/frag-max.sh +++ /dev/null @@ -1,10 +0,0 @@ -FRAG - -DCL IN[0], COLOR, LINEAR -DCL OUT[0], COLOR - -IMM FLT32 { 0.4, 0.4, 0.4, 0.0 } - -MAX OUT[0], IN[0], IMM[0] - -END diff --git a/progs/gallium/python/tests/regress/fragment-shader/frag-min.sh b/progs/gallium/python/tests/regress/fragment-shader/frag-min.sh deleted file mode 100644 index df284f49e7..0000000000 --- a/progs/gallium/python/tests/regress/fragment-shader/frag-min.sh +++ /dev/null @@ -1,10 +0,0 @@ -FRAG - -DCL IN[0], COLOR, LINEAR -DCL OUT[0], COLOR - -IMM FLT32 { 0.6, 0.6, 0.6, 1.0 } - -MIN OUT[0], IN[0], IMM[0] - -END diff --git a/progs/gallium/python/tests/regress/fragment-shader/frag-mov.sh b/progs/gallium/python/tests/regress/fragment-shader/frag-mov.sh deleted file mode 100644 index 64af72f381..0000000000 --- a/progs/gallium/python/tests/regress/fragment-shader/frag-mov.sh +++ /dev/null @@ -1,8 +0,0 @@ -FRAG - -DCL IN[0], COLOR, LINEAR -DCL OUT[0], COLOR - -MOV OUT[0], IN[0] - -END diff --git a/progs/gallium/python/tests/regress/fragment-shader/frag-mul.sh b/progs/gallium/python/tests/regress/fragment-shader/frag-mul.sh deleted file mode 100644 index bdd0b0026b..0000000000 --- a/progs/gallium/python/tests/regress/fragment-shader/frag-mul.sh +++ /dev/null @@ -1,10 +0,0 @@ -FRAG - -DCL IN[0], COLOR, LINEAR -DCL OUT[0], COLOR - -IMM FLT32 { 0.5, 0.6, 0.7, 1.0 } - -MUL OUT[0], IN[0], IMM[0] - -END diff --git a/progs/gallium/python/tests/regress/fragment-shader/frag-rcp.sh b/progs/gallium/python/tests/regress/fragment-shader/frag-rcp.sh deleted file mode 100644 index f4b611b26a..0000000000 --- a/progs/gallium/python/tests/regress/fragment-shader/frag-rcp.sh +++ /dev/null @@ -1,15 +0,0 @@ -FRAG - -DCL IN[0], COLOR, LINEAR -DCL OUT[0], COLOR - -DCL TEMP[0] - -IMM FLT32 { 1.0, 0.0, 0.0, 0.0 } -IMM FLT32 { 1.5, 0.0, 0.0, 0.0 } - -ADD TEMP[0], IN[0], IMM[0] -RCP TEMP[0].x, TEMP[0].xxxx -SUB OUT[0], TEMP[0], IMM[1] - -END diff --git a/progs/gallium/python/tests/regress/fragment-shader/frag-rsq.sh b/progs/gallium/python/tests/regress/fragment-shader/frag-rsq.sh deleted file mode 100644 index d1e9b0b53b..0000000000 --- a/progs/gallium/python/tests/regress/fragment-shader/frag-rsq.sh +++ /dev/null @@ -1,15 +0,0 @@ -FRAG - -DCL IN[0], COLOR, LINEAR -DCL OUT[0], COLOR - -DCL TEMP[0] - -IMM FLT32 { 1.0, 0.0, 0.0, 0.0 } -IMM FLT32 { 1.5, 0.0, 0.0, 0.0 } - -ADD TEMP[0], IN[0], IMM[0] -RSQ TEMP[0].x, TEMP[0].xxxx -SUB OUT[0], TEMP[0], IMM[1] - -END diff --git a/progs/gallium/python/tests/regress/fragment-shader/frag-sge.sh b/progs/gallium/python/tests/regress/fragment-shader/frag-sge.sh deleted file mode 100644 index 1f33fac472..0000000000 --- a/progs/gallium/python/tests/regress/fragment-shader/frag-sge.sh +++ /dev/null @@ -1,13 +0,0 @@ -FRAG - -DCL IN[0], COLOR, LINEAR -DCL OUT[0], COLOR - -DCL TEMP[0] - -IMM FLT32 { 0.6, 0.6, 0.6, 0.0 } - -SGE TEMP[0], IN[0], IMM[0] -MUL OUT[0], IN[0], TEMP[0] - -END diff --git a/progs/gallium/python/tests/regress/fragment-shader/frag-slt.sh b/progs/gallium/python/tests/regress/fragment-shader/frag-slt.sh deleted file mode 100644 index d58b7886a1..0000000000 --- a/progs/gallium/python/tests/regress/fragment-shader/frag-slt.sh +++ /dev/null @@ -1,13 +0,0 @@ -FRAG - -DCL IN[0], COLOR, LINEAR -DCL OUT[0], COLOR - -DCL TEMP[0] - -IMM FLT32 { 0.6, 0.6, 0.6, 0.0 } - -SLT TEMP[0], IN[0], IMM[0] -MUL OUT[0], IN[0], TEMP[0] - -END diff --git a/progs/gallium/python/tests/regress/fragment-shader/frag-srcmod-abs.sh b/progs/gallium/python/tests/regress/fragment-shader/frag-srcmod-abs.sh deleted file mode 100644 index ecd19248c6..0000000000 --- a/progs/gallium/python/tests/regress/fragment-shader/frag-srcmod-abs.sh +++ /dev/null @@ -1,13 +0,0 @@ -FRAG - -DCL IN[0], COLOR, LINEAR -DCL OUT[0], COLOR - -DCL TEMP[0] - -IMM FLT32 { -0.3, -0.5, -0.4, 0.0 } - -ADD TEMP[0], IN[0], IMM[0] -MOV OUT[0], |TEMP[0]| - -END diff --git a/progs/gallium/python/tests/regress/fragment-shader/frag-srcmod-absneg.sh b/progs/gallium/python/tests/regress/fragment-shader/frag-srcmod-absneg.sh deleted file mode 100644 index c2d99ddd15..0000000000 --- a/progs/gallium/python/tests/regress/fragment-shader/frag-srcmod-absneg.sh +++ /dev/null @@ -1,15 +0,0 @@ -FRAG - -DCL IN[0], COLOR, LINEAR -DCL OUT[0], COLOR - -DCL TEMP[0] - -IMM FLT32 { -0.2, -0.3, -0.4, 0.0 } -IMM FLT32 { -1.0, -1.0, -1.0, -1.0 } - -ADD TEMP[0], IN[0], IMM[0] -MOV TEMP[0], -|TEMP[0]| -MUL OUT[0], TEMP[0], IMM[1] - -END diff --git a/progs/gallium/python/tests/regress/fragment-shader/frag-srcmod-neg.sh b/progs/gallium/python/tests/regress/fragment-shader/frag-srcmod-neg.sh deleted file mode 100644 index a08ab6d2dc..0000000000 --- a/progs/gallium/python/tests/regress/fragment-shader/frag-srcmod-neg.sh +++ /dev/null @@ -1,11 +0,0 @@ -FRAG - -DCL IN[0], COLOR, LINEAR -DCL OUT[0], COLOR - -DCL TEMP[0] - -SUB TEMP[0], IN[0], IN[0].yzxw -MOV OUT[0], -TEMP[0] - -END diff --git a/progs/gallium/python/tests/regress/fragment-shader/frag-srcmod-swz.sh b/progs/gallium/python/tests/regress/fragment-shader/frag-srcmod-swz.sh deleted file mode 100644 index 6110647d97..0000000000 --- a/progs/gallium/python/tests/regress/fragment-shader/frag-srcmod-swz.sh +++ /dev/null @@ -1,8 +0,0 @@ -FRAG - -DCL IN[0], COLOR, LINEAR -DCL OUT[0], COLOR - -MOV OUT[0], IN[0].yxzw - -END diff --git a/progs/gallium/python/tests/regress/fragment-shader/frag-sub.sh b/progs/gallium/python/tests/regress/fragment-shader/frag-sub.sh deleted file mode 100644 index 673fca139a..0000000000 --- a/progs/gallium/python/tests/regress/fragment-shader/frag-sub.sh +++ /dev/null @@ -1,8 +0,0 @@ -FRAG - -DCL IN[0], COLOR, LINEAR -DCL OUT[0], COLOR - -SUB OUT[0], IN[0], IN[0].yzxw - -END diff --git a/progs/gallium/python/tests/regress/fragment-shader/frag-xpd.sh b/progs/gallium/python/tests/regress/fragment-shader/frag-xpd.sh deleted file mode 100644 index 6ec8b1184c..0000000000 --- a/progs/gallium/python/tests/regress/fragment-shader/frag-xpd.sh +++ /dev/null @@ -1,8 +0,0 @@ -FRAG - -DCL IN[0], COLOR, LINEAR -DCL OUT[0], COLOR - -XPD OUT[0], IN[0], IN[0].yzxw - -END diff --git a/progs/gallium/python/tests/regress/fragment-shader/fragment-shader.py b/progs/gallium/python/tests/regress/fragment-shader/fragment-shader.py deleted file mode 100644 index b758b4c622..0000000000 --- a/progs/gallium/python/tests/regress/fragment-shader/fragment-shader.py +++ /dev/null @@ -1,257 +0,0 @@ -#!/usr/bin/env python -########################################################################## -# -# 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 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 ITS 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. -# -########################################################################## - -import struct - -from gallium import * - -def make_image(surface): - data = surface.get_tile_rgba8(0, 0, surface.width, surface.height) - - import Image - outimage = Image.fromstring('RGBA', (surface.width, surface.height), data, "raw", 'RGBA', 0, 1) - return outimage - -def save_image(filename, surface): - outimage = make_image(surface) - outimage.save(filename, "PNG") - -def test(dev, name): - ctx = dev.context_create() - - width = 320 - height = 320 - minz = 0.0 - maxz = 1.0 - - # disabled blending/masking - blend = Blend() - blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE - blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_ONE - blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_ZERO - blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_ZERO - blend.rt[0].colormask = PIPE_MASK_RGBA - ctx.set_blend(blend) - - # depth/stencil/alpha - depth_stencil_alpha = DepthStencilAlpha() - depth_stencil_alpha.depth.enabled = 0 - depth_stencil_alpha.depth.writemask = 1 - depth_stencil_alpha.depth.func = PIPE_FUNC_LESS - ctx.set_depth_stencil_alpha(depth_stencil_alpha) - - # rasterizer - rasterizer = Rasterizer() - rasterizer.front_winding = PIPE_WINDING_CW - rasterizer.cull_mode = PIPE_WINDING_NONE - rasterizer.scissor = 1 - ctx.set_rasterizer(rasterizer) - - # viewport - viewport = Viewport() - scale = FloatArray(4) - scale[0] = width / 2.0 - scale[1] = -height / 2.0 - scale[2] = (maxz - minz) / 2.0 - scale[3] = 1.0 - viewport.scale = scale - translate = FloatArray(4) - translate[0] = width / 2.0 - translate[1] = height / 2.0 - translate[2] = (maxz - minz) / 2.0 - translate[3] = 0.0 - viewport.translate = translate - ctx.set_viewport(viewport) - - # samplers - sampler = Sampler() - sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE - sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE - sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE - sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE - sampler.min_img_filter = PIPE_TEX_MIPFILTER_NEAREST - sampler.mag_img_filter = PIPE_TEX_MIPFILTER_NEAREST - sampler.normalized_coords = 1 - ctx.set_fragment_sampler(0, sampler) - - # scissor - scissor = Scissor() - scissor.minx = 0 - scissor.miny = 0 - scissor.maxx = width - scissor.maxy = height - ctx.set_scissor(scissor) - - clip = Clip() - clip.nr = 0 - ctx.set_clip(clip) - - # framebuffer - cbuf = dev.texture_create( - PIPE_FORMAT_B8G8R8X8_UNORM, - width, height, - tex_usage=PIPE_TEXTURE_USAGE_RENDER_TARGET, - ).get_surface() - fb = Framebuffer() - fb.width = width - fb.height = height - fb.nr_cbufs = 1 - fb.set_cbuf(0, cbuf) - ctx.set_framebuffer(fb) - rgba = FloatArray(4); - rgba[0] = 0.5 - rgba[1] = 0.5 - rgba[2] = 0.5 - rgba[3] = 0.5 - ctx.clear(PIPE_CLEAR_COLOR, rgba, 0.0, 0) - - # vertex shader - vs = Shader(''' - VERT - DCL IN[0], POSITION - DCL IN[1], COLOR - DCL OUT[0], POSITION - DCL OUT[1], COLOR - MOV OUT[0], IN[0] - MOV OUT[1], IN[1] - END - ''') - ctx.set_vertex_shader(vs) - - # fragment shader - fs = Shader(file('frag-' + name + '.sh', 'rt').read()) - ctx.set_fragment_shader(fs) - - constbuf0 = dev.buffer_create(64, - (PIPE_BUFFER_USAGE_CONSTANT | - PIPE_BUFFER_USAGE_GPU_READ | - PIPE_BUFFER_USAGE_CPU_WRITE), - 4 * 4 * 4) - - cbdata = '' - cbdata += struct.pack('4f', 0.4, 0.0, 0.0, 1.0) - cbdata += struct.pack('4f', 1.0, 1.0, 1.0, 1.0) - cbdata += struct.pack('4f', 2.0, 2.0, 2.0, 2.0) - cbdata += struct.pack('4f', 4.0, 8.0, 16.0, 32.0) - - constbuf0.write(cbdata, 0) - - ctx.set_constant_buffer(PIPE_SHADER_FRAGMENT, - 0, - constbuf0) - - constbuf1 = dev.buffer_create(64, - (PIPE_BUFFER_USAGE_CONSTANT | - PIPE_BUFFER_USAGE_GPU_READ | - PIPE_BUFFER_USAGE_CPU_WRITE), - 4 * 4 * 4) - - cbdata = '' - cbdata += struct.pack('4f', 0.1, 0.1, 0.1, 0.1) - cbdata += struct.pack('4f', 0.25, 0.25, 0.25, 0.25) - cbdata += struct.pack('4f', 0.5, 0.5, 0.5, 0.5) - cbdata += struct.pack('4f', 0.75, 0.75, 0.75, 0.75) - - constbuf1.write(cbdata, 0) - - ctx.set_constant_buffer(PIPE_SHADER_FRAGMENT, - 1, - constbuf1) - - xy = [ - -0.8, -0.8, - 0.8, -0.8, - 0.0, 0.8, - ] - color = [ - 1.0, 0.0, 0.0, - 0.0, 1.0, 0.0, - 0.0, 0.0, 1.0, - ] - - nverts = 3 - nattrs = 2 - verts = FloatArray(nverts * nattrs * 4) - - for i in range(0, nverts): - verts[i * nattrs * 4 + 0] = xy[i * 2 + 0] # x - verts[i * nattrs * 4 + 1] = xy[i * 2 + 1] # y - verts[i * nattrs * 4 + 2] = 0.5 # z - verts[i * nattrs * 4 + 3] = 1.0 # w - verts[i * nattrs * 4 + 4] = color[i * 3 + 0] # r - verts[i * nattrs * 4 + 5] = color[i * 3 + 1] # g - verts[i * nattrs * 4 + 6] = color[i * 3 + 2] # b - verts[i * nattrs * 4 + 7] = 1.0 # a - - ctx.draw_vertices(PIPE_PRIM_TRIANGLES, - nverts, - nattrs, - verts) - - ctx.flush() - - save_image('frag-' + name + '.png', cbuf) - -def main(): - tests = [ - 'abs', - 'add', - 'cb-1d', - 'cb-2d', - 'dp3', - 'dp4', - 'dst', - 'ex2', - 'flr', - 'frc', - 'lg2', - 'lit', - 'lrp', - 'mad', - 'max', - 'min', - 'mov', - 'mul', - 'rcp', - 'rsq', - 'sge', - 'slt', - 'srcmod-abs', - 'srcmod-absneg', - 'srcmod-neg', - 'srcmod-swz', - 'sub', - 'xpd', - ] - - dev = Device() - for t in tests: - test(dev, t) - -if __name__ == '__main__': - main() diff --git a/progs/gallium/python/tests/regress/vertex-shader/.gitignore b/progs/gallium/python/tests/regress/vertex-shader/.gitignore deleted file mode 100644 index e33609d251..0000000000 --- a/progs/gallium/python/tests/regress/vertex-shader/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*.png diff --git a/progs/gallium/python/tests/regress/vertex-shader/vert-abs.sh b/progs/gallium/python/tests/regress/vertex-shader/vert-abs.sh deleted file mode 100644 index 79c9ca69fb..0000000000 --- a/progs/gallium/python/tests/regress/vertex-shader/vert-abs.sh +++ /dev/null @@ -1,15 +0,0 @@ -VERT - -DCL IN[0], POSITION -DCL IN[1], COLOR -DCL OUT[0], POSITION -DCL OUT[1], COLOR -DCL TEMP[0] - -IMM FLT32 { 0.2, 0.2, 0.0, 0.0 } - -ADD TEMP[0], IN[0], IMM[0] -ABS OUT[0], TEMP[0] -MOV OUT[1], IN[1] - -END diff --git a/progs/gallium/python/tests/regress/vertex-shader/vert-add.sh b/progs/gallium/python/tests/regress/vertex-shader/vert-add.sh deleted file mode 100644 index ca97ad05df..0000000000 --- a/progs/gallium/python/tests/regress/vertex-shader/vert-add.sh +++ /dev/null @@ -1,13 +0,0 @@ -VERT - -DCL IN[0], POSITION -DCL IN[1], COLOR -DCL OUT[0], POSITION -DCL OUT[1], COLOR - -IMM FLT32 { 0.2, -0.1, 0.0, 0.0 } - -ADD OUT[0], IN[0], IMM[0] -MOV OUT[1], IN[1] - -END diff --git a/progs/gallium/python/tests/regress/vertex-shader/vert-arl.sh b/progs/gallium/python/tests/regress/vertex-shader/vert-arl.sh deleted file mode 100644 index 321140e89e..0000000000 --- a/progs/gallium/python/tests/regress/vertex-shader/vert-arl.sh +++ /dev/null @@ -1,23 +0,0 @@ -VERT - -DCL IN[0], POSITION -DCL OUT[0], POSITION -DCL OUT[1], COLOR - -DCL TEMP[0] - -DCL ADDR[0] - -IMM FLT32 { 3.0, 1.0, 1.0, 1.0 } -IMM FLT32 { 1.0, 0.0, 0.0, 1.0 } -IMM FLT32 { 0.0, 1.0, 0.0, 1.0 } -IMM FLT32 { 0.0, 0.0, 1.0, 1.0 } -IMM FLT32 { 1.0, 1.0, 0.0, 1.0 } -IMM FLT32 { 0.0, 1.0, 1.0, 1.0 } - -MOV OUT[0], IN[0] -MUL TEMP[0], IN[0], IMM[0] -ARL ADDR[0].x, TEMP[0] -MOV OUT[1], IMM[ADDR[0].x + 3] - -END diff --git a/progs/gallium/python/tests/regress/vertex-shader/vert-arr.sh b/progs/gallium/python/tests/regress/vertex-shader/vert-arr.sh deleted file mode 100644 index d60ea46b36..0000000000 --- a/progs/gallium/python/tests/regress/vertex-shader/vert-arr.sh +++ /dev/null @@ -1,23 +0,0 @@ -VERT - -DCL IN[0], POSITION -DCL OUT[0], POSITION -DCL OUT[1], COLOR - -DCL TEMP[0] - -DCL ADDR[0] - -IMM FLT32 { 3.0, 1.0, 1.0, 1.0 } -IMM FLT32 { 1.0, 0.0, 0.0, 1.0 } -IMM FLT32 { 0.0, 1.0, 0.0, 1.0 } -IMM FLT32 { 0.0, 0.0, 1.0, 1.0 } -IMM FLT32 { 1.0, 1.0, 0.0, 1.0 } -IMM FLT32 { 0.0, 1.0, 1.0, 1.0 } - -MOV OUT[0], IN[0] -MUL TEMP[0], IN[0], IMM[0] -ARR ADDR[0].x, TEMP[0] -MOV OUT[1], IMM[ADDR[0].x + 3] - -END diff --git a/progs/gallium/python/tests/regress/vertex-shader/vert-cb-1d.sh b/progs/gallium/python/tests/regress/vertex-shader/vert-cb-1d.sh deleted file mode 100644 index b41fe5dd38..0000000000 --- a/progs/gallium/python/tests/regress/vertex-shader/vert-cb-1d.sh +++ /dev/null @@ -1,16 +0,0 @@ -VERT - -DCL IN[0], POSITION -DCL IN[1], COLOR -DCL OUT[0], POSITION -DCL OUT[1], COLOR -DCL CONST[1] -DCL CONST[3] -DCL TEMP[0..1] - -MOV OUT[0], IN[0] -ADD TEMP[0], IN[1], CONST[1] -RCP TEMP[1], CONST[3].xxxx -MUL OUT[1], TEMP[0], TEMP[1] - -END diff --git a/progs/gallium/python/tests/regress/vertex-shader/vert-cb-2d.sh b/progs/gallium/python/tests/regress/vertex-shader/vert-cb-2d.sh deleted file mode 100644 index 45f5e6b729..0000000000 --- a/progs/gallium/python/tests/regress/vertex-shader/vert-cb-2d.sh +++ /dev/null @@ -1,12 +0,0 @@ -VERT - -DCL IN[0], POSITION -DCL IN[1], COLOR -DCL OUT[0], POSITION -DCL OUT[1], COLOR -DCL CONST[1][1..2] - -MOV OUT[0], IN[0] -MAD OUT[1], IN[1], CONST[1][2], CONST[1][1] - -END diff --git a/progs/gallium/python/tests/regress/vertex-shader/vert-dp3.sh b/progs/gallium/python/tests/regress/vertex-shader/vert-dp3.sh deleted file mode 100644 index caff622fe6..0000000000 --- a/progs/gallium/python/tests/regress/vertex-shader/vert-dp3.sh +++ /dev/null @@ -1,16 +0,0 @@ -VERT - -DCL IN[0], POSITION -DCL IN[1], COLOR -DCL OUT[0], POSITION -DCL OUT[1], COLOR -DCL TEMP[0] - -IMM FLT32 { 0.0, 0.0, 1.0, 1.0 } - -DP3 TEMP[0].xy, IN[0], IN[0] -MOV TEMP[0].zw, IMM[0] -MUL OUT[0], IN[0], TEMP[0] -MOV OUT[1], IN[1] - -END diff --git a/progs/gallium/python/tests/regress/vertex-shader/vert-dp4.sh b/progs/gallium/python/tests/regress/vertex-shader/vert-dp4.sh deleted file mode 100644 index 3dd2fd1c2f..0000000000 --- a/progs/gallium/python/tests/regress/vertex-shader/vert-dp4.sh +++ /dev/null @@ -1,16 +0,0 @@ -VERT - -DCL IN[0], POSITION -DCL IN[1], COLOR -DCL OUT[0], POSITION -DCL OUT[1], COLOR -DCL TEMP[0] - -IMM FLT32 { 0.0, 0.0, 1.0, 1.0 } - -DP4 TEMP[0].xy, IN[0], IN[0] -MOV TEMP[0].zw, IMM[0] -MUL OUT[0], IN[0], TEMP[0] -MOV OUT[1], IN[1] - -END diff --git a/progs/gallium/python/tests/regress/vertex-shader/vert-dst.sh b/progs/gallium/python/tests/regress/vertex-shader/vert-dst.sh deleted file mode 100644 index da9cc18dfc..0000000000 --- a/progs/gallium/python/tests/regress/vertex-shader/vert-dst.sh +++ /dev/null @@ -1,11 +0,0 @@ -VERT - -DCL IN[0], POSITION -DCL IN[1], COLOR -DCL OUT[0], POSITION -DCL OUT[1], COLOR - -MOV OUT[0], IN[0] -DST OUT[1], IN[1], IN[0] - -END diff --git a/progs/gallium/python/tests/regress/vertex-shader/vert-ex2.sh b/progs/gallium/python/tests/regress/vertex-shader/vert-ex2.sh deleted file mode 100644 index 4637227e5c..0000000000 --- a/progs/gallium/python/tests/regress/vertex-shader/vert-ex2.sh +++ /dev/null @@ -1,18 +0,0 @@ -VERT - -DCL IN[0], POSITION -DCL IN[1], COLOR -DCL OUT[0], POSITION -DCL OUT[1], COLOR - -DCL TEMP[0..1] - -IMM FLT32 { 0.3, 0.3, 0.3, 1.0 } - -EX2 TEMP[0], IN[0] -EX2 TEMP[1], IN[1].yyyy -MUL TEMP[0], TEMP[0], IMM[0] -MOV OUT[0], IN[0] -MUL OUT[1], TEMP[0], TEMP[1] - -END diff --git a/progs/gallium/python/tests/regress/vertex-shader/vert-flr.sh b/progs/gallium/python/tests/regress/vertex-shader/vert-flr.sh deleted file mode 100644 index aa80d6e394..0000000000 --- a/progs/gallium/python/tests/regress/vertex-shader/vert-flr.sh +++ /dev/null @@ -1,23 +0,0 @@ -VERT - -DCL IN[0], POSITION -DCL OUT[0], POSITION -DCL OUT[1], COLOR - -DCL TEMP[0] - -DCL ADDR[0] - -IMM FLT32 { 3.0, 1.0, 1.0, 1.0 } -IMM FLT32 { 1.0, 0.0, 0.0, 1.0 } -IMM FLT32 { 0.0, 1.0, 0.0, 1.0 } -IMM FLT32 { 0.0, 0.0, 1.0, 1.0 } -IMM FLT32 { 1.0, 1.0, 0.0, 1.0 } -IMM FLT32 { 0.0, 1.0, 1.0, 1.0 } - -MOV OUT[0], IN[0] -MUL TEMP[0], IN[0], IMM[0] -FLR ADDR[0].x, TEMP[0] -MOV OUT[1], IMM[ADDR[0].x + 3] - -END diff --git a/progs/gallium/python/tests/regress/vertex-shader/vert-frc.sh b/progs/gallium/python/tests/regress/vertex-shader/vert-frc.sh deleted file mode 100644 index 64d1a494e1..0000000000 --- a/progs/gallium/python/tests/regress/vertex-shader/vert-frc.sh +++ /dev/null @@ -1,15 +0,0 @@ -VERT - -DCL IN[0], POSITION -DCL OUT[0], POSITION -DCL OUT[1], COLOR - -DCL TEMP[0] - -IMM FLT32 { 2.7, 3.1, 4.5, 1.0 } - -MUL TEMP[0], IN[0].xyxw, IMM[0] -MOV OUT[0], IN[0] -FRC OUT[1], TEMP[0] - -END diff --git a/progs/gallium/python/tests/regress/vertex-shader/vert-lg2.sh b/progs/gallium/python/tests/regress/vertex-shader/vert-lg2.sh deleted file mode 100644 index 5cf16fd1aa..0000000000 --- a/progs/gallium/python/tests/regress/vertex-shader/vert-lg2.sh +++ /dev/null @@ -1,18 +0,0 @@ -VERT - -DCL IN[0], POSITION -DCL IN[1], COLOR -DCL OUT[0], POSITION -DCL OUT[1], COLOR - -DCL TEMP[0] - -IMM FLT32 { 1.0, 0.0, 0.0, 0.0 } -IMM FLT32 { 0.5, 0.0, 0.0, 0.0 } - -ADD TEMP[0], IN[0], IMM[0] -LG2 TEMP[0].x, TEMP[0].xxxx -ADD OUT[0], TEMP[0], IMM[1] -MOV OUT[1], IN[1] - -END diff --git a/progs/gallium/python/tests/regress/vertex-shader/vert-lit.sh b/progs/gallium/python/tests/regress/vertex-shader/vert-lit.sh deleted file mode 100644 index a4a752d4d2..0000000000 --- a/progs/gallium/python/tests/regress/vertex-shader/vert-lit.sh +++ /dev/null @@ -1,11 +0,0 @@ -VERT - -DCL IN[0], POSITION -DCL IN[1], COLOR -DCL OUT[0], POSITION -DCL OUT[1], COLOR - -MOV OUT[0], IN[0] -LIT OUT[1], IN[1] - -END diff --git a/progs/gallium/python/tests/regress/vertex-shader/vert-lrp.sh b/progs/gallium/python/tests/regress/vertex-shader/vert-lrp.sh deleted file mode 100644 index 4bb5f3ec3f..0000000000 --- a/progs/gallium/python/tests/regress/vertex-shader/vert-lrp.sh +++ /dev/null @@ -1,14 +0,0 @@ -VERT - -DCL IN[0], POSITION -DCL IN[1], COLOR -DCL OUT[0], POSITION -DCL OUT[1], COLOR - -DCL TEMP[0] - -ABS TEMP[0], IN[0] -MOV OUT[0], IN[0] -LRP OUT[1], TEMP[0], IN[1].xxxx, IN[1].yyyy - -END diff --git a/progs/gallium/python/tests/regress/vertex-shader/vert-mad.sh b/progs/gallium/python/tests/regress/vertex-shader/vert-mad.sh deleted file mode 100644 index daaa941f15..0000000000 --- a/progs/gallium/python/tests/regress/vertex-shader/vert-mad.sh +++ /dev/null @@ -1,14 +0,0 @@ -VERT - -DCL IN[0], POSITION -DCL IN[1], COLOR -DCL OUT[0], POSITION -DCL OUT[1], COLOR - -IMM FLT32 { 0.5, 1.0, 1.0, 1.0 } -IMM FLT32 { 0.5, 0.0, 0.0, 0.0 } - -MAD OUT[0], IN[0], IMM[0], IMM[1] -MOV OUT[1], IN[1] - -END diff --git a/progs/gallium/python/tests/regress/vertex-shader/vert-max.sh b/progs/gallium/python/tests/regress/vertex-shader/vert-max.sh deleted file mode 100644 index af279ec7f4..0000000000 --- a/progs/gallium/python/tests/regress/vertex-shader/vert-max.sh +++ /dev/null @@ -1,13 +0,0 @@ -VERT - -DCL IN[0], POSITION -DCL IN[1], COLOR -DCL OUT[0], POSITION -DCL OUT[1], COLOR - -IMM FLT32 { 0.5, 0.5, 0.5, 0.0 } - -MOV OUT[0], IN[0] -MAX OUT[1], IN[1], IMM[0] - -END diff --git a/progs/gallium/python/tests/regress/vertex-shader/vert-min.sh b/progs/gallium/python/tests/regress/vertex-shader/vert-min.sh deleted file mode 100644 index 46d886c55b..0000000000 --- a/progs/gallium/python/tests/regress/vertex-shader/vert-min.sh +++ /dev/null @@ -1,13 +0,0 @@ -VERT - -DCL IN[0], POSITION -DCL IN[1], COLOR -DCL OUT[0], POSITION -DCL OUT[1], COLOR - -IMM FLT32 { 0.5, 0.5, 0.5, 0.0 } - -MOV OUT[0], IN[0] -MIN OUT[1], IN[1], IMM[0] - -END diff --git a/progs/gallium/python/tests/regress/vertex-shader/vert-mov.sh b/progs/gallium/python/tests/regress/vertex-shader/vert-mov.sh deleted file mode 100644 index 0ef91637e0..0000000000 --- a/progs/gallium/python/tests/regress/vertex-shader/vert-mov.sh +++ /dev/null @@ -1,11 +0,0 @@ -VERT - -DCL IN[0], POSITION -DCL IN[1], COLOR -DCL OUT[0], POSITION -DCL OUT[1], COLOR - -MOV OUT[0], IN[0] -MOV OUT[1], IN[1] - -END diff --git a/progs/gallium/python/tests/regress/vertex-shader/vert-mul.sh b/progs/gallium/python/tests/regress/vertex-shader/vert-mul.sh deleted file mode 100644 index d34f6cd6e3..0000000000 --- a/progs/gallium/python/tests/regress/vertex-shader/vert-mul.sh +++ /dev/null @@ -1,13 +0,0 @@ -VERT - -DCL IN[0], POSITION -DCL IN[1], COLOR -DCL OUT[0], POSITION -DCL OUT[1], COLOR - -IMM FLT32 { 0.6, 0.6, 1.0, 1.0 } - -MUL OUT[0], IN[0], IMM[0] -MOV OUT[1], IN[1] - -END diff --git a/progs/gallium/python/tests/regress/vertex-shader/vert-rcp.sh b/progs/gallium/python/tests/regress/vertex-shader/vert-rcp.sh deleted file mode 100644 index cfb3ec37dc..0000000000 --- a/progs/gallium/python/tests/regress/vertex-shader/vert-rcp.sh +++ /dev/null @@ -1,18 +0,0 @@ -VERT - -DCL IN[0], POSITION -DCL IN[1], COLOR -DCL OUT[0], POSITION -DCL OUT[1], COLOR - -DCL TEMP[0] - -IMM FLT32 { 1.0, 0.0, 0.0, 0.0 } -IMM FLT32 { 1.5, 0.0, 0.0, 0.0 } - -ADD TEMP[0], IN[0], IMM[0] -RCP TEMP[0].x, TEMP[0].xxxx -SUB OUT[0], TEMP[0], IMM[1] -MOV OUT[1], IN[1] - -END diff --git a/progs/gallium/python/tests/regress/vertex-shader/vert-rsq.sh b/progs/gallium/python/tests/regress/vertex-shader/vert-rsq.sh deleted file mode 100644 index faf1e6e7d4..0000000000 --- a/progs/gallium/python/tests/regress/vertex-shader/vert-rsq.sh +++ /dev/null @@ -1,18 +0,0 @@ -VERT - -DCL IN[0], POSITION -DCL IN[1], COLOR -DCL OUT[0], POSITION -DCL OUT[1], COLOR - -DCL TEMP[0] - -IMM FLT32 { 1.0, 0.0, 0.0, 0.0 } -IMM FLT32 { 1.5, 0.0, 0.0, 0.0 } - -ADD TEMP[0], IN[0], IMM[0] -RSQ TEMP[0].x, TEMP[0].xxxx -SUB OUT[0], TEMP[0], IMM[1] -MOV OUT[1], IN[1] - -END diff --git a/progs/gallium/python/tests/regress/vertex-shader/vert-sge.sh b/progs/gallium/python/tests/regress/vertex-shader/vert-sge.sh deleted file mode 100644 index 6de1d071ef..0000000000 --- a/progs/gallium/python/tests/regress/vertex-shader/vert-sge.sh +++ /dev/null @@ -1,16 +0,0 @@ -VERT - -DCL IN[0], POSITION -DCL IN[1], COLOR -DCL OUT[0], POSITION -DCL OUT[1], COLOR - -DCL TEMP[0] - -IMM FLT32 { -0.1, -0.1, 1.0, 0.0 } - -SGE TEMP[0], IN[0], IMM[0] -MOV OUT[0], IN[0] -MUL OUT[1], IN[1], TEMP[0] - -END diff --git a/progs/gallium/python/tests/regress/vertex-shader/vert-slt.sh b/progs/gallium/python/tests/regress/vertex-shader/vert-slt.sh deleted file mode 100644 index 9a52422984..0000000000 --- a/progs/gallium/python/tests/regress/vertex-shader/vert-slt.sh +++ /dev/null @@ -1,16 +0,0 @@ -VERT - -DCL IN[0], POSITION -DCL IN[1], COLOR -DCL OUT[0], POSITION -DCL OUT[1], COLOR - -DCL TEMP[0] - -IMM FLT32 { 0.6, 0.6, 0.0, 0.0 } - -SLT TEMP[0], IN[0], IMM[0] -MOV OUT[0], IN[0] -MUL OUT[1], IN[1], TEMP[0] - -END diff --git a/progs/gallium/python/tests/regress/vertex-shader/vert-srcmod-abs.sh b/progs/gallium/python/tests/regress/vertex-shader/vert-srcmod-abs.sh deleted file mode 100644 index dc87ce4ae7..0000000000 --- a/progs/gallium/python/tests/regress/vertex-shader/vert-srcmod-abs.sh +++ /dev/null @@ -1,15 +0,0 @@ -VERT - -DCL IN[0], POSITION -DCL IN[1], COLOR -DCL OUT[0], POSITION -DCL OUT[1], COLOR -DCL TEMP[0] - -IMM FLT32 { 0.1, 0.1, 0.0, 0.0 } - -ADD TEMP[0], IN[0], IMM[0] -MOV OUT[0], |TEMP[0]| -MOV OUT[1], IN[1] - -END diff --git a/progs/gallium/python/tests/regress/vertex-shader/vert-srcmod-absneg.sh b/progs/gallium/python/tests/regress/vertex-shader/vert-srcmod-absneg.sh deleted file mode 100644 index d82eb08fd3..0000000000 --- a/progs/gallium/python/tests/regress/vertex-shader/vert-srcmod-absneg.sh +++ /dev/null @@ -1,16 +0,0 @@ -VERT - -DCL IN[0], POSITION -DCL IN[1], COLOR -DCL OUT[0], POSITION -DCL OUT[1], COLOR -DCL TEMP[0] - -IMM FLT32 { -0.2, -0.2, 0.0, 0.0 } - -ADD TEMP[0], IN[0], IMM[0] -MOV OUT[0].xy, -|TEMP[0]| -MOV OUT[0].zw, IN[0] -MOV OUT[1], IN[1] - -END diff --git a/progs/gallium/python/tests/regress/vertex-shader/vert-srcmod-neg.sh b/progs/gallium/python/tests/regress/vertex-shader/vert-srcmod-neg.sh deleted file mode 100644 index e39bebcd9f..0000000000 --- a/progs/gallium/python/tests/regress/vertex-shader/vert-srcmod-neg.sh +++ /dev/null @@ -1,12 +0,0 @@ -VERT - -DCL IN[0], POSITION -DCL IN[1], COLOR -DCL OUT[0], POSITION -DCL OUT[1], COLOR - -MOV OUT[0].xy, -IN[0] -MOV OUT[0].zw, IN[0] -MOV OUT[1], IN[1] - -END diff --git a/progs/gallium/python/tests/regress/vertex-shader/vert-srcmod-swz.sh b/progs/gallium/python/tests/regress/vertex-shader/vert-srcmod-swz.sh deleted file mode 100644 index 6f20552f21..0000000000 --- a/progs/gallium/python/tests/regress/vertex-shader/vert-srcmod-swz.sh +++ /dev/null @@ -1,11 +0,0 @@ -VERT - -DCL IN[0], POSITION -DCL IN[1], COLOR -DCL OUT[0], POSITION -DCL OUT[1], COLOR - -MOV OUT[0], IN[0].yxzw -MOV OUT[1], IN[1] - -END diff --git a/progs/gallium/python/tests/regress/vertex-shader/vert-sub.sh b/progs/gallium/python/tests/regress/vertex-shader/vert-sub.sh deleted file mode 100644 index 0f9678b8a3..0000000000 --- a/progs/gallium/python/tests/regress/vertex-shader/vert-sub.sh +++ /dev/null @@ -1,13 +0,0 @@ -VERT - -DCL IN[0], POSITION -DCL IN[1], COLOR -DCL OUT[0], POSITION -DCL OUT[1], COLOR - -IMM FLT32 { 0.1, 0.1, 0.0, 0.0 } - -SUB OUT[0], IN[0], IMM[0] -MOV OUT[1], IN[1] - -END diff --git a/progs/gallium/python/tests/regress/vertex-shader/vert-xpd.sh b/progs/gallium/python/tests/regress/vertex-shader/vert-xpd.sh deleted file mode 100644 index 39d42ae2a0..0000000000 --- a/progs/gallium/python/tests/regress/vertex-shader/vert-xpd.sh +++ /dev/null @@ -1,11 +0,0 @@ -VERT - -DCL IN[0], POSITION -DCL IN[1], COLOR -DCL OUT[0], POSITION -DCL OUT[1], COLOR - -MOV OUT[0], IN[0] -XPD OUT[1], IN[0], IN[1] - -END diff --git a/progs/gallium/python/tests/regress/vertex-shader/vertex-shader.py b/progs/gallium/python/tests/regress/vertex-shader/vertex-shader.py deleted file mode 100644 index bd838cc282..0000000000 --- a/progs/gallium/python/tests/regress/vertex-shader/vertex-shader.py +++ /dev/null @@ -1,287 +0,0 @@ -#!/usr/bin/env python -########################################################################## -# -# 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 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 ITS 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. -# -########################################################################## - - -import struct - -from gallium import * - -def make_image(surface): - data = surface.get_tile_rgba8(0, 0, surface.width, surface.height) - - import Image - outimage = Image.fromstring('RGBA', (surface.width, surface.height), data, "raw", 'RGBA', 0, 1) - return outimage - -def save_image(filename, surface): - outimage = make_image(surface) - outimage.save(filename, "PNG") - -def test(dev, name): - ctx = dev.context_create() - - width = 320 - height = 320 - minz = 0.0 - maxz = 1.0 - - # disabled blending/masking - blend = Blend() - blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE - blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_ONE - blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_ZERO - blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_ZERO - blend.rt[0].colormask = PIPE_MASK_RGBA - ctx.set_blend(blend) - - # depth/stencil/alpha - depth_stencil_alpha = DepthStencilAlpha() - depth_stencil_alpha.depth.enabled = 0 - depth_stencil_alpha.depth.writemask = 1 - depth_stencil_alpha.depth.func = PIPE_FUNC_LESS - ctx.set_depth_stencil_alpha(depth_stencil_alpha) - - # rasterizer - rasterizer = Rasterizer() - rasterizer.front_winding = PIPE_WINDING_CW - rasterizer.cull_mode = PIPE_WINDING_NONE - rasterizer.scissor = 1 - ctx.set_rasterizer(rasterizer) - - # viewport - viewport = Viewport() - scale = FloatArray(4) - scale[0] = width / 2.0 - scale[1] = -height / 2.0 - scale[2] = (maxz - minz) / 2.0 - scale[3] = 1.0 - viewport.scale = scale - translate = FloatArray(4) - translate[0] = width / 2.0 - translate[1] = height / 2.0 - translate[2] = (maxz - minz) / 2.0 - translate[3] = 0.0 - viewport.translate = translate - ctx.set_viewport(viewport) - - # samplers - sampler = Sampler() - sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE - sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE - sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE - sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE - sampler.min_img_filter = PIPE_TEX_MIPFILTER_NEAREST - sampler.mag_img_filter = PIPE_TEX_MIPFILTER_NEAREST - sampler.normalized_coords = 1 - ctx.set_fragment_sampler(0, sampler) - - # scissor - scissor = Scissor() - scissor.minx = 0 - scissor.miny = 0 - scissor.maxx = width - scissor.maxy = height - ctx.set_scissor(scissor) - - clip = Clip() - clip.nr = 0 - ctx.set_clip(clip) - - # framebuffer - cbuf = dev.texture_create( - PIPE_FORMAT_B8G8R8X8_UNORM, - width, height, - tex_usage=PIPE_TEXTURE_USAGE_RENDER_TARGET, - ).get_surface() - fb = Framebuffer() - fb.width = width - fb.height = height - fb.nr_cbufs = 1 - fb.set_cbuf(0, cbuf) - ctx.set_framebuffer(fb) - rgba = FloatArray(4); - rgba[0] = 0.5 - rgba[1] = 0.5 - rgba[2] = 0.5 - rgba[3] = 0.5 - ctx.clear(PIPE_CLEAR_COLOR, rgba, 0.0, 0) - - # vertex shader - vs = Shader(file('vert-' + name + '.sh', 'rt').read()) - ctx.set_vertex_shader(vs) - - # fragment shader - fs = Shader(''' - FRAG - DCL IN[0], COLOR, LINEAR - DCL OUT[0], COLOR, CONSTANT - 0:MOV OUT[0], IN[0] - 1:END - ''') - ctx.set_fragment_shader(fs) - - constbuf0 = dev.buffer_create(64, - (PIPE_BUFFER_USAGE_CONSTANT | - PIPE_BUFFER_USAGE_GPU_READ | - PIPE_BUFFER_USAGE_CPU_WRITE), - 4 * 4 * 4) - - cbdata = '' - cbdata += struct.pack('4f', 0.4, 0.0, 0.0, 1.0) - cbdata += struct.pack('4f', 1.0, 1.0, 1.0, 1.0) - cbdata += struct.pack('4f', 2.0, 2.0, 2.0, 2.0) - cbdata += struct.pack('4f', 4.0, 8.0, 16.0, 32.0) - - constbuf0.write(cbdata, 0) - - ctx.set_constant_buffer(PIPE_SHADER_VERTEX, - 0, - constbuf0) - - constbuf1 = dev.buffer_create(64, - (PIPE_BUFFER_USAGE_CONSTANT | - PIPE_BUFFER_USAGE_GPU_READ | - PIPE_BUFFER_USAGE_CPU_WRITE), - 4 * 4 * 4) - - cbdata = '' - cbdata += struct.pack('4f', 0.1, 0.1, 0.1, 0.1) - cbdata += struct.pack('4f', 0.25, 0.25, 0.25, 0.25) - cbdata += struct.pack('4f', 0.5, 0.5, 0.5, 0.5) - cbdata += struct.pack('4f', 0.75, 0.75, 0.75, 0.75) - - constbuf1.write(cbdata, 0) - - ctx.set_constant_buffer(PIPE_SHADER_VERTEX, - 1, - constbuf1) - - xy = [ - 0.0, 0.8, - -0.2, 0.4, - 0.2, 0.4, - -0.4, 0.0, - 0.0, 0.0, - 0.4, 0.0, - -0.6, -0.4, - -0.2, -0.4, - 0.2, -0.4, - 0.6, -0.4, - -0.8, -0.8, - -0.4, -0.8, - 0.0, -0.8, - 0.4, -0.8, - 0.8, -0.8, - ] - color = [ - 1.0, 0.0, 0.0, - 0.0, 1.0, 0.0, - 0.0, 0.0, 1.0, - ] - tri = [ - 1, 2, 0, - 3, 4, 1, - 4, 2, 1, - 4, 5, 2, - 6, 7, 3, - 7, 4, 3, - 7, 8, 4, - 8, 5, 4, - 8, 9, 5, - 10, 11, 6, - 11, 7, 6, - 11, 12, 7, - 12, 8, 7, - 12, 13, 8, - 13, 9, 8, - 13, 14, 9, - ] - - nverts = 16 * 3 - nattrs = 2 - verts = FloatArray(nverts * nattrs * 4) - - for i in range(0, nverts): - verts[i * nattrs * 4 + 0] = xy[tri[i] * 2 + 0] # x - verts[i * nattrs * 4 + 1] = xy[tri[i] * 2 + 1] # y - verts[i * nattrs * 4 + 2] = 0.5 # z - verts[i * nattrs * 4 + 3] = 1.0 # w - verts[i * nattrs * 4 + 4] = color[(i % 3) * 3 + 0] # r - verts[i * nattrs * 4 + 5] = color[(i % 3) * 3 + 1] # g - verts[i * nattrs * 4 + 6] = color[(i % 3) * 3 + 2] # b - verts[i * nattrs * 4 + 7] = 1.0 # a - - ctx.draw_vertices(PIPE_PRIM_TRIANGLES, - nverts, - nattrs, - verts) - - ctx.flush() - - save_image('vert-' + name + '.png', cbuf) - -def main(): - tests = [ - 'abs', - 'add', - 'arl', - 'arr', - 'cb-1d', - 'cb-2d', - 'dp3', - 'dp4', - 'dst', - 'ex2', - 'flr', - 'frc', - 'lg2', - 'lit', - 'lrp', - 'mad', - 'max', - 'min', - 'mov', - 'mul', - 'rcp', - 'rsq', - 'sge', - 'slt', - 'srcmod-abs', - 'srcmod-absneg', - 'srcmod-neg', - 'srcmod-swz', - 'sub', - 'xpd', - ] - - dev = Device() - for t in tests: - test(dev, t) - -if __name__ == '__main__': - main() diff --git a/progs/gallium/python/tests/surface_copy.py b/progs/gallium/python/tests/surface_copy.py deleted file mode 100755 index a3f1b3e130..0000000000 --- a/progs/gallium/python/tests/surface_copy.py +++ /dev/null @@ -1,200 +0,0 @@ -#!/usr/bin/env python -########################################################################## -# -# 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 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 ITS 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. -# -########################################################################## - - -from gallium import * -from base import * - - -def lods(*dims): - size = max(dims) - lods = 0 - while size: - lods += 1 - size >>= 1 - return lods - - -class TextureTest(TestCase): - - tags = ( - 'target', - 'format', - 'width', - 'height', - 'depth', - 'last_level', - 'face', - 'level', - 'zslice', - ) - - def test(self): - dev = self.dev - - target = self.target - format = self.format - width = self.width - height = self.height - depth = self.depth - last_level = self.last_level - face = self.face - level = self.level - zslice = self.zslice - - # textures - dst_texture = dev.texture_create( - target = target, - format = format, - width = width, - height = height, - depth = depth, - last_level = last_level, - tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET, - ) - if dst_texture is None: - raise TestSkip - - dst_surface = dst_texture.get_surface(face = face, level = level, zslice = zslice) - - src_texture = dev.texture_create( - target = target, - format = format, - width = dst_surface.width, - height = dst_surface.height, - depth = 1, - last_level = 0, - tex_usage = PIPE_TEXTURE_USAGE_SAMPLER, - ) - - src_surface = src_texture.get_surface() - - x = 0 - y = 0 - w = dst_surface.width - h = dst_surface.height - - # ??? - stride = pf_get_stride(texture->format, w) - size = pf_get_nblocksy(texture->format) * stride - src_raw = os.urandom(size) - - src_surface.put_tile_raw(0, 0, w, h, src_raw, stride) - - ctx = self.dev.context_create() - - ctx.surface_copy(dst_surface, 0, 0, - src_surface, 0, 0, w, h) - - ctx.flush() - - dst_raw = dst_surface.get_tile_raw(0, 0, w, h) - - if dst_raw != src_raw: - raise TestFailure - - - -def main(): - dev = Device() - suite = TestSuite() - - targets = [ - PIPE_TEXTURE_2D, - PIPE_TEXTURE_CUBE, - #PIPE_TEXTURE_3D, - ] - - formats = [ - PIPE_FORMAT_B8G8R8A8_UNORM, - PIPE_FORMAT_B8G8R8X8_UNORM, - PIPE_FORMAT_B8G8R8A8_SRGB, - PIPE_FORMAT_B5G6R5_UNORM, - PIPE_FORMAT_B5G5R5A1_UNORM, - PIPE_FORMAT_B4G4R4A4_UNORM, - PIPE_FORMAT_Z32_UNORM, - PIPE_FORMAT_S8Z24_UNORM, - PIPE_FORMAT_X8Z24_UNORM, - PIPE_FORMAT_Z16_UNORM, - PIPE_FORMAT_S8_UNORM, - PIPE_FORMAT_A8_UNORM, - PIPE_FORMAT_L8_UNORM, - PIPE_FORMAT_DXT1_RGB, - PIPE_FORMAT_DXT1_RGBA, - PIPE_FORMAT_DXT3_RGBA, - PIPE_FORMAT_DXT5_RGBA, - ] - - sizes = [64, 32, 16, 8, 4, 2, 1] - #sizes = [1020, 508, 252, 62, 30, 14, 6, 3] - #sizes = [64] - #sizes = [63] - - faces = [ - PIPE_TEX_FACE_POS_X, - PIPE_TEX_FACE_NEG_X, - PIPE_TEX_FACE_POS_Y, - PIPE_TEX_FACE_NEG_Y, - PIPE_TEX_FACE_POS_Z, - PIPE_TEX_FACE_NEG_Z, - ] - - for target in targets: - for format in formats: - for size in sizes: - if target == PIPE_TEXTURE_3D: - depth = size - else: - depth = 1 - for face in faces: - if target != PIPE_TEXTURE_CUBE and face: - continue - levels = lods(size) - for last_level in range(levels): - for level in range(0, last_level + 1): - zslice = 0 - while zslice < depth >> level: - test = TextureTest( - dev = dev, - target = target, - format = format, - width = size, - height = size, - depth = depth, - last_level = last_level, - face = face, - level = level, - zslice = zslice, - ) - suite.add_test(test) - zslice = (zslice + 1)*2 - 1 - suite.run() - - -if __name__ == '__main__': - main() diff --git a/progs/gallium/python/tests/texture_render.py b/progs/gallium/python/tests/texture_render.py deleted file mode 100755 index 1e26639db6..0000000000 --- a/progs/gallium/python/tests/texture_render.py +++ /dev/null @@ -1,320 +0,0 @@ -#!/usr/bin/env python -########################################################################## -# -# 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 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 ITS 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. -# -########################################################################## - - -from gallium import * -from base import * - - -def lods(*dims): - size = max(dims) - lods = 0 - while size: - lods += 1 - size >>= 1 - return lods - - -class TextureTest(TestCase): - - tags = ( - 'target', - 'format', - 'width', - 'height', - 'depth', - 'last_level', - 'face', - 'level', - 'zslice', - ) - - def test(self): - dev = self.dev - - target = self.target - format = self.format - width = self.width - height = self.height - depth = self.depth - last_level = self.last_level - face = self.face - level = self.level - zslice = self.zslice - - # textures - dst_texture = dev.texture_create( - target = target, - format = format, - width = width, - height = height, - depth = depth, - last_level = last_level, - tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET, - ) - if dst_texture is None: - raise TestSkip - - dst_surface = dst_texture.get_surface(face = face, level = level, zslice = zslice) - - ref_texture = dev.texture_create( - target = target, - format = format, - width = dst_surface.width, - height = dst_surface.height, - depth = 1, - last_level = 0, - tex_usage = PIPE_TEXTURE_USAGE_SAMPLER, - ) - - ref_surface = ref_texture.get_surface() - - src_texture = dev.texture_create( - target = target, - format = PIPE_FORMAT_B8G8R8A8_UNORM, - width = dst_surface.width, - height = dst_surface.height, - depth = 1, - last_level = 0, - tex_usage = PIPE_TEXTURE_USAGE_SAMPLER, - ) - - src_surface = src_texture.get_surface() - - expected_rgba = FloatArray(height*width*4) - ref_surface.sample_rgba(expected_rgba) - - src_surface.put_tile_rgba(0, 0, src_surface.width, src_surface.height, expected_rgba) - - ctx = self.dev.context_create() - - # disabled blending/masking - blend = Blend() - blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE - blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_ONE - blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_ZERO - blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_ZERO - blend.rt[0].colormask = PIPE_MASK_RGBA - ctx.set_blend(blend) - - # no-op depth/stencil/alpha - depth_stencil_alpha = DepthStencilAlpha() - ctx.set_depth_stencil_alpha(depth_stencil_alpha) - - # rasterizer - rasterizer = Rasterizer() - rasterizer.front_winding = PIPE_WINDING_CW - rasterizer.cull_mode = PIPE_WINDING_NONE - rasterizer.bypass_vs_clip_and_viewport = 1 - ctx.set_rasterizer(rasterizer) - - # samplers - sampler = Sampler() - sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE - sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE - sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE - sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NEAREST - sampler.min_img_filter = PIPE_TEX_MIPFILTER_NEAREST - sampler.mag_img_filter = PIPE_TEX_MIPFILTER_NEAREST - sampler.normalized_coords = 1 - sampler.min_lod = 0 - sampler.max_lod = PIPE_MAX_TEXTURE_LEVELS - 1 - ctx.set_fragment_sampler(0, sampler) - ctx.set_fragment_sampler_texture(0, src_texture) - - # framebuffer - cbuf_tex = dev.texture_create( - PIPE_FORMAT_B8G8R8A8_UNORM, - width, - height, - tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET, - ) - - fb = Framebuffer() - fb.width = dst_surface.width - fb.height = dst_surface.height - fb.nr_cbufs = 1 - fb.set_cbuf(0, dst_surface) - ctx.set_framebuffer(fb) - rgba = FloatArray(4); - rgba[0] = 0.0 - rgba[1] = 0.0 - rgba[2] = 0.0 - rgba[3] = 0.0 - ctx.clear(PIPE_CLEAR_COLOR, rgba, 0.0, 0) - del fb - - # vertex shader - vs = Shader(''' - VERT - DCL IN[0], POSITION, CONSTANT - DCL IN[1], GENERIC, CONSTANT - DCL OUT[0], POSITION, CONSTANT - DCL OUT[1], GENERIC, CONSTANT - 0:MOV OUT[0], IN[0] - 1:MOV OUT[1], IN[1] - 2:END - ''') - #vs.dump() - ctx.set_vertex_shader(vs) - - # fragment shader - fs = Shader(''' - FRAG - DCL IN[0], GENERIC[0], LINEAR - DCL OUT[0], COLOR, CONSTANT - DCL SAMP[0], CONSTANT - 0:TEX OUT[0], IN[0], SAMP[0], 2D - 1:END - ''') - #fs.dump() - ctx.set_fragment_shader(fs) - - nverts = 4 - nattrs = 2 - verts = FloatArray(nverts * nattrs * 4) - - x = 0 - y = 0 - w = dst_surface.width - h = dst_surface.height - - pos = [ - [x, y], - [x+w, y], - [x+w, y+h], - [x, y+h], - ] - - tex = [ - [0.0, 0.0], - [1.0, 0.0], - [1.0, 1.0], - [0.0, 1.0], - ] - - for i in range(0, 4): - j = 8*i - verts[j + 0] = pos[i][0] # x - verts[j + 1] = pos[i][1] # y - verts[j + 2] = 0.0 # z - verts[j + 3] = 1.0 # w - verts[j + 4] = tex[i][0] # s - verts[j + 5] = tex[i][1] # r - verts[j + 6] = 0.0 - verts[j + 7] = 1.0 - - ctx.draw_vertices(PIPE_PRIM_TRIANGLE_FAN, - nverts, - nattrs, - verts) - - ctx.flush() - - self.assert_rgba(dst_surface, x, y, w, h, expected_rgba, 4.0/256, 0.85) - - - -def main(): - dev = Device() - suite = TestSuite() - - targets = [ - PIPE_TEXTURE_2D, - PIPE_TEXTURE_CUBE, - #PIPE_TEXTURE_3D, - ] - - formats = [ - PIPE_FORMAT_B8G8R8A8_UNORM, - PIPE_FORMAT_B8G8R8X8_UNORM, - #PIPE_FORMAT_B8G8R8A8_SRGB, - PIPE_FORMAT_B5G6R5_UNORM, - PIPE_FORMAT_B5G5R5A1_UNORM, - PIPE_FORMAT_B4G4R4A4_UNORM, - #PIPE_FORMAT_Z32_UNORM, - #PIPE_FORMAT_S8Z24_UNORM, - #PIPE_FORMAT_X8Z24_UNORM, - #PIPE_FORMAT_Z16_UNORM, - #PIPE_FORMAT_S8_UNORM, - PIPE_FORMAT_A8_UNORM, - PIPE_FORMAT_L8_UNORM, - #PIPE_FORMAT_DXT1_RGB, - #PIPE_FORMAT_DXT1_RGBA, - #PIPE_FORMAT_DXT3_RGBA, - #PIPE_FORMAT_DXT5_RGBA, - ] - - sizes = [64, 32, 16, 8, 4, 2, 1] - #sizes = [1020, 508, 252, 62, 30, 14, 6, 3] - #sizes = [64] - #sizes = [63] - - faces = [ - PIPE_TEX_FACE_POS_X, - PIPE_TEX_FACE_NEG_X, - PIPE_TEX_FACE_POS_Y, - PIPE_TEX_FACE_NEG_Y, - PIPE_TEX_FACE_POS_Z, - PIPE_TEX_FACE_NEG_Z, - ] - - for target in targets: - for format in formats: - for size in sizes: - if target == PIPE_TEXTURE_3D: - depth = size - else: - depth = 1 - for face in faces: - if target != PIPE_TEXTURE_CUBE and face: - continue - levels = lods(size) - for last_level in range(levels): - for level in range(0, last_level + 1): - zslice = 0 - while zslice < depth >> level: - test = TextureTest( - dev = dev, - target = target, - format = format, - width = size, - height = size, - depth = depth, - last_level = last_level, - face = face, - level = level, - zslice = zslice, - ) - suite.add_test(test) - zslice = (zslice + 1)*2 - 1 - suite.run() - - -if __name__ == '__main__': - main() diff --git a/progs/gallium/python/tests/texture_sample.py b/progs/gallium/python/tests/texture_sample.py deleted file mode 100755 index 49545c2e07..0000000000 --- a/progs/gallium/python/tests/texture_sample.py +++ /dev/null @@ -1,591 +0,0 @@ -#!/usr/bin/env python -########################################################################## -# -# Copyright 2009 VMware, Inc. -# Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. -# 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, 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 ITS 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. -# -########################################################################## - - -from gallium import * -from base import * - - -def lods(*dims): - size = max(dims) - lods = 0 - while size: - lods += 1 - size >>= 1 - return lods - - -def minify(dims, level = 1): - return [max(dim>>level, 1) for dim in dims] - - -def tex_coords(texture, face, level, zslice): - st = [ - [0.0, 0.0], - [1.0, 0.0], - [1.0, 1.0], - [0.0, 1.0], - ] - - if texture.target == PIPE_TEXTURE_2D: - return [[s, t, 0.0] for s, t in st] - elif texture.target == PIPE_TEXTURE_3D: - depth = texture.get_depth(level) - if depth > 1: - r = float(zslice)/float(depth - 1) - else: - r = 0.0 - return [[s, t, r] for s, t in st] - elif texture.target == PIPE_TEXTURE_CUBE: - result = [] - for s, t in st: - # See http://developer.nvidia.com/object/cube_map_ogl_tutorial.html - sc = 2.0*s - 1.0 - tc = 2.0*t - 1.0 - if face == PIPE_TEX_FACE_POS_X: - rx = 1.0 - ry = -tc - rz = -sc - if face == PIPE_TEX_FACE_NEG_X: - rx = -1.0 - ry = -tc - rz = sc - if face == PIPE_TEX_FACE_POS_Y: - rx = sc - ry = 1.0 - rz = tc - if face == PIPE_TEX_FACE_NEG_Y: - rx = sc - ry = -1.0 - rz = -tc - if face == PIPE_TEX_FACE_POS_Z: - rx = sc - ry = -tc - rz = 1.0 - if face == PIPE_TEX_FACE_NEG_Z: - rx = -sc - ry = -tc - rz = -1.0 - result.append([rx, ry, rz]) - return result - -def is_pot(n): - return n & (n - 1) == 0 - - -class TextureColorSampleTest(TestCase): - - tags = ( - 'target', - 'format', - 'width', - 'height', - 'depth', - 'last_level', - 'face', - 'level', - 'zslice', - ) - - def test(self): - dev = self.dev - - target = self.target - format = self.format - width = self.width - height = self.height - depth = self.depth - last_level = self.last_level - face = self.face - level = self.level - zslice = self.zslice - - tex_usage = PIPE_TEXTURE_USAGE_SAMPLER - geom_flags = 0 - if width != height: - geom_flags |= PIPE_TEXTURE_GEOM_NON_SQUARE - if not is_pot(width) or not is_pot(height) or not is_pot(depth): - geom_flags |= PIPE_TEXTURE_GEOM_NON_POWER_OF_TWO - - if not dev.is_format_supported(format, target, tex_usage, geom_flags): - raise TestSkip - - ctx = self.dev.context_create() - - # disabled blending/masking - blend = Blend() - blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE - blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_ONE - blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_ZERO - blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_ZERO - blend.rt[0].colormask = PIPE_MASK_RGBA - ctx.set_blend(blend) - - # no-op depth/stencil/alpha - depth_stencil_alpha = DepthStencilAlpha() - ctx.set_depth_stencil_alpha(depth_stencil_alpha) - - # rasterizer - rasterizer = Rasterizer() - rasterizer.front_winding = PIPE_WINDING_CW - rasterizer.cull_mode = PIPE_WINDING_NONE - rasterizer.bypass_vs_clip_and_viewport = 1 - ctx.set_rasterizer(rasterizer) - - # samplers - sampler = Sampler() - sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE - sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE - sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE - sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NEAREST - sampler.min_img_filter = PIPE_TEX_MIPFILTER_NEAREST - sampler.mag_img_filter = PIPE_TEX_MIPFILTER_NEAREST - sampler.normalized_coords = 1 - sampler.min_lod = 0 - sampler.max_lod = PIPE_MAX_TEXTURE_LEVELS - 1 - ctx.set_fragment_sampler(0, sampler) - - # texture - texture = dev.texture_create( - target = target, - format = format, - width = width, - height = height, - depth = depth, - last_level = last_level, - tex_usage = tex_usage, - ) - - expected_rgba = FloatArray(height*width*4) - texture.get_surface( - face = face, - level = level, - zslice = zslice, - ).sample_rgba(expected_rgba) - - ctx.set_fragment_sampler_texture(0, texture) - - # framebuffer - cbuf_tex = dev.texture_create( - PIPE_FORMAT_B8G8R8A8_UNORM, - width, - height, - tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET, - ) - - cbuf = cbuf_tex.get_surface() - fb = Framebuffer() - fb.width = width - fb.height = height - fb.nr_cbufs = 1 - fb.set_cbuf(0, cbuf) - ctx.set_framebuffer(fb) - rgba = FloatArray(4); - rgba[0] = 0.5 - rgba[1] = 0.5 - rgba[2] = 0.5 - rgba[3] = 0.5 - ctx.clear(PIPE_CLEAR_COLOR, rgba, 0.0, 0) - del fb - - # vertex shader - vs = Shader(''' - VERT - DCL IN[0], POSITION, CONSTANT - DCL IN[1], GENERIC, CONSTANT - DCL OUT[0], POSITION, CONSTANT - DCL OUT[1], GENERIC, CONSTANT - 0:MOV OUT[0], IN[0] - 1:MOV OUT[1], IN[1] - 2:END - ''') - #vs.dump() - ctx.set_vertex_shader(vs) - - # fragment shader - op = { - PIPE_TEXTURE_1D: "1D", - PIPE_TEXTURE_2D: "2D", - PIPE_TEXTURE_3D: "3D", - PIPE_TEXTURE_CUBE: "CUBE", - }[target] - fs = Shader(''' - FRAG - DCL IN[0], GENERIC[0], LINEAR - DCL OUT[0], COLOR, CONSTANT - DCL SAMP[0], CONSTANT - 0:TEX OUT[0], IN[0], SAMP[0], %s - 1:END - ''' % op) - #fs.dump() - ctx.set_fragment_shader(fs) - - nverts = 4 - nattrs = 2 - verts = FloatArray(nverts * nattrs * 4) - - x = 0 - y = 0 - w, h = minify((width, height), level) - - pos = [ - [x, y], - [x+w, y], - [x+w, y+h], - [x, y+h], - ] - - tex = tex_coords(texture, face, level, zslice) - - for i in range(0, 4): - j = 8*i - verts[j + 0] = pos[i][0] # x - verts[j + 1] = pos[i][1] # y - verts[j + 2] = 0.0 # z - verts[j + 3] = 1.0 # w - verts[j + 4] = tex[i][0] # s - verts[j + 5] = tex[i][1] # r - verts[j + 6] = tex[i][2] # q - verts[j + 7] = 1.0 - - ctx.draw_vertices(PIPE_PRIM_TRIANGLE_FAN, - nverts, - nattrs, - verts) - - ctx.flush() - - cbuf = cbuf_tex.get_surface() - - self.assert_rgba(cbuf, x, y, w, h, expected_rgba, 4.0/256, 0.85) - - -class TextureDepthSampleTest(TestCase): - - tags = ( - 'target', - 'format', - 'width', - 'height', - 'depth', - 'last_level', - 'face', - 'level', - 'zslice', - ) - - def test(self): - dev = self.dev - - target = self.target - format = self.format - width = self.width - height = self.height - depth = self.depth - last_level = self.last_level - face = self.face - level = self.level - zslice = self.zslice - - tex_usage = PIPE_TEXTURE_USAGE_SAMPLER - geom_flags = 0 - if width != height: - geom_flags |= PIPE_TEXTURE_GEOM_NON_SQUARE - if not is_pot(width) or not is_pot(height) or not is_pot(depth): - geom_flags |= PIPE_TEXTURE_GEOM_NON_POWER_OF_TWO - - if not dev.is_format_supported(format, target, tex_usage, geom_flags): - raise TestSkip - - ctx = self.dev.context_create() - - # disabled blending/masking - blend = Blend() - blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE - blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_ONE - blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_ZERO - blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_ZERO - blend.rt[0].colormask = PIPE_MASK_RGBA - ctx.set_blend(blend) - - # depth/stencil/alpha - depth_stencil_alpha = DepthStencilAlpha() - depth_stencil_alpha.depth.enabled = 1 - depth_stencil_alpha.depth.writemask = 1 - depth_stencil_alpha.depth.func = PIPE_FUNC_LESS - ctx.set_depth_stencil_alpha(depth_stencil_alpha) - - # rasterizer - rasterizer = Rasterizer() - rasterizer.front_winding = PIPE_WINDING_CW - rasterizer.cull_mode = PIPE_WINDING_NONE - rasterizer.bypass_vs_clip_and_viewport = 1 - ctx.set_rasterizer(rasterizer) - - # samplers - sampler = Sampler() - sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE - sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE - sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE - sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NEAREST - sampler.min_img_filter = PIPE_TEX_MIPFILTER_NEAREST - sampler.mag_img_filter = PIPE_TEX_MIPFILTER_NEAREST - sampler.normalized_coords = 1 - sampler.min_lod = 0 - sampler.max_lod = PIPE_MAX_TEXTURE_LEVELS - 1 - ctx.set_fragment_sampler(0, sampler) - - # texture - texture = dev.texture_create( - target = target, - format = format, - width = width, - height = height, - depth = depth, - last_level = last_level, - tex_usage = tex_usage, - ) - - expected_rgba = FloatArray(height*width*4) - texture.get_surface( - face = face, - level = level, - zslice = zslice, - ).sample_rgba(expected_rgba) - - ctx.set_fragment_sampler_texture(0, texture) - - # framebuffer - cbuf_tex = dev.texture_create( - PIPE_FORMAT_B8G8R8A8_UNORM, - width, - height, - tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET, - ) - - zsbuf_tex = dev.texture_create( - PIPE_FORMAT_X8Z24_UNORM, - width, - height, - tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET, - ) - - cbuf = cbuf_tex.get_surface() - zsbuf = zsbuf_tex.get_surface() - fb = Framebuffer() - fb.width = width - fb.height = height - fb.nr_cbufs = 1 - fb.set_cbuf(0, cbuf) - fb.set_zsbuf(zsbuf) - ctx.set_framebuffer(fb) - rgba = FloatArray(4); - rgba[0] = 0.5 - rgba[1] = 0.5 - rgba[2] = 0.5 - rgba[3] = 0.5 - ctx.clear(PIPE_CLEAR_DEPTHSTENCIL, rgba, 1.0, 0) - del fb - - # vertex shader - vs = Shader(''' - VERT - DCL IN[0], POSITION, CONSTANT - DCL IN[1], GENERIC, CONSTANT - DCL OUT[0], POSITION, CONSTANT - DCL OUT[1], GENERIC, CONSTANT - 0:MOV OUT[0], IN[0] - 1:MOV OUT[1], IN[1] - 2:END - ''') - #vs.dump() - ctx.set_vertex_shader(vs) - - # fragment shader - op = { - PIPE_TEXTURE_1D: "1D", - PIPE_TEXTURE_2D: "2D", - PIPE_TEXTURE_3D: "3D", - PIPE_TEXTURE_CUBE: "CUBE", - }[target] - fs = Shader(''' - FRAG - DCL IN[0], GENERIC[0], LINEAR - DCL SAMP[0], CONSTANT - DCL OUT[0].z, POSITION - 0:TEX OUT[0].z, IN[0], SAMP[0], %s - 1:END - ''' % op) - #fs.dump() - ctx.set_fragment_shader(fs) - - nverts = 4 - nattrs = 2 - verts = FloatArray(nverts * nattrs * 4) - - x = 0 - y = 0 - w, h = minify((width, height), level) - - pos = [ - [x, y], - [x+w, y], - [x+w, y+h], - [x, y+h], - ] - - tex = tex_coords(texture, face, level, zslice) - - for i in range(0, 4): - j = 8*i - verts[j + 0] = pos[i][0] # x - verts[j + 1] = pos[i][1] # y - verts[j + 2] = 0.0 # z - verts[j + 3] = 1.0 # w - verts[j + 4] = tex[i][0] # s - verts[j + 5] = tex[i][1] # r - verts[j + 6] = tex[i][2] # q - verts[j + 7] = 1.0 - - ctx.draw_vertices(PIPE_PRIM_TRIANGLE_FAN, - nverts, - nattrs, - verts) - - ctx.flush() - - zsbuf = zsbuf_tex.get_surface() - - self.assert_rgba(zsbuf, x, y, w, h, expected_rgba, 4.0/256, 0.85) - - - - -def main(): - dev = Device() - suite = TestSuite() - - targets = [ - PIPE_TEXTURE_2D, - PIPE_TEXTURE_CUBE, - PIPE_TEXTURE_3D, - ] - - color_formats = [ - PIPE_FORMAT_B8G8R8A8_UNORM, - PIPE_FORMAT_B8G8R8X8_UNORM, - #PIPE_FORMAT_B8G8R8A8_SRGB, - PIPE_FORMAT_B5G6R5_UNORM, - PIPE_FORMAT_B5G5R5A1_UNORM, - PIPE_FORMAT_B4G4R4A4_UNORM, - PIPE_FORMAT_A8_UNORM, - PIPE_FORMAT_L8_UNORM, - PIPE_FORMAT_UYVY, - PIPE_FORMAT_DXT1_RGB, - #PIPE_FORMAT_DXT1_RGBA, - #PIPE_FORMAT_DXT3_RGBA, - #PIPE_FORMAT_DXT5_RGBA, - ] - - depth_formats = [ - PIPE_FORMAT_Z32_UNORM, - PIPE_FORMAT_S8Z24_UNORM, - PIPE_FORMAT_X8Z24_UNORM, - PIPE_FORMAT_Z16_UNORM, - ] - - sizes = [64, 32, 16, 8, 4, 2, 1] - #sizes = [1020, 508, 252, 62, 30, 14, 6, 3] - #sizes = [64] - #sizes = [63] - - faces = [ - PIPE_TEX_FACE_POS_X, - PIPE_TEX_FACE_NEG_X, - PIPE_TEX_FACE_POS_Y, - PIPE_TEX_FACE_NEG_Y, - PIPE_TEX_FACE_POS_Z, - PIPE_TEX_FACE_NEG_Z, - ] - - for format in color_formats: - for target in targets: - for size in sizes: - if target == PIPE_TEXTURE_3D: - depth = size - else: - depth = 1 - for face in faces: - if target != PIPE_TEXTURE_CUBE and face: - continue - levels = lods(size) - for last_level in range(levels): - for level in range(0, last_level + 1): - zslice = 0 - while zslice < depth >> level: - test = TextureColorSampleTest( - dev = dev, - target = target, - format = format, - width = size, - height = size, - depth = depth, - last_level = last_level, - face = face, - level = level, - zslice = zslice, - ) - suite.add_test(test) - zslice = (zslice + 1)*2 - 1 - for format in depth_formats: - target = PIPE_TEXTURE_2D - depth = 1 - face = 0 - last_level = 0 - level = 0 - zslice = 0 - for size in sizes: - test = TextureDepthSampleTest( - dev = dev, - target = target, - format = format, - width = size, - height = size, - depth = depth, - last_level = last_level, - face = face, - level = level, - zslice = zslice, - ) - suite.add_test(test) - suite.run() - - -if __name__ == '__main__': - main() diff --git a/progs/gallium/python/tests/texture_transfer.py b/progs/gallium/python/tests/texture_transfer.py deleted file mode 100755 index 7da00e4255..0000000000 --- a/progs/gallium/python/tests/texture_transfer.py +++ /dev/null @@ -1,180 +0,0 @@ -#!/usr/bin/env python -########################################################################## -# -# Copyright 2009 VMware, Inc. -# Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. -# 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, 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 ITS 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. -# -########################################################################## - - -import os - -from gallium import * -from base import * - - -def lods(*dims): - size = max(dims) - lods = 0 - while size: - lods += 1 - size >>= 1 - return lods - - -class TextureTest(TestCase): - - tags = ( - 'target', - 'format', - 'width', - 'height', - 'depth', - 'last_level', - 'face', - 'level', - 'zslice', - ) - - def test(self): - dev = self.dev - - target = self.target - format = self.format - width = self.width - height = self.height - depth = self.depth - last_level = self.last_level - face = self.face - level = self.level - zslice = self.zslice - - tex_usage = 0 - - texture = dev.texture_create( - target = target, - format = format, - width = width, - height = height, - depth = depth, - last_level = last_level, - tex_usage = tex_usage, - ) - if texture is None: - raise TestSkip - - surface = texture.get_surface(face, level, zslice) - - # ??? - stride = pf_get_stride(texture->format, w) - size = pf_get_nblocksy(texture->format) * stride - - in_raw = os.urandom(size) - - surface.put_tile_raw(0, 0, surface.width, surface.height, in_raw, stride) - - out_raw = surface.get_tile_raw(0, 0, surface.width, surface.height) - - if in_raw != out_raw: - raise TestFailure - - -def main(): - dev = Device() - suite = TestSuite() - - targets = [ - PIPE_TEXTURE_2D, - PIPE_TEXTURE_CUBE, - PIPE_TEXTURE_3D, - ] - - formats = [ - PIPE_FORMAT_B8G8R8A8_UNORM, - PIPE_FORMAT_B8G8R8X8_UNORM, - PIPE_FORMAT_B8G8R8A8_SRGB, - PIPE_FORMAT_B5G6R5_UNORM, - PIPE_FORMAT_B5G5R5A1_UNORM, - PIPE_FORMAT_B4G4R4A4_UNORM, - PIPE_FORMAT_Z32_UNORM, - PIPE_FORMAT_S8Z24_UNORM, - PIPE_FORMAT_X8Z24_UNORM, - PIPE_FORMAT_Z16_UNORM, - PIPE_FORMAT_S8_UNORM, - PIPE_FORMAT_A8_UNORM, - PIPE_FORMAT_L8_UNORM, - PIPE_FORMAT_DXT1_RGB, - PIPE_FORMAT_DXT1_RGBA, - PIPE_FORMAT_DXT3_RGBA, - PIPE_FORMAT_DXT5_RGBA, - ] - - sizes = [64, 32, 16, 8, 4, 2, 1] - #sizes = [1020, 508, 252, 62, 30, 14, 6, 3] - #sizes = [64] - #sizes = [63] - - faces = [ - PIPE_TEX_FACE_POS_X, - PIPE_TEX_FACE_NEG_X, - PIPE_TEX_FACE_POS_Y, - PIPE_TEX_FACE_NEG_Y, - PIPE_TEX_FACE_POS_Z, - PIPE_TEX_FACE_NEG_Z, - ] - - for target in targets: - for format in formats: - for size in sizes: - if target == PIPE_TEXTURE_3D: - depth = size - else: - depth = 1 - for face in faces: - if target != PIPE_TEXTURE_CUBE and face: - continue - levels = lods(size) - for last_level in range(levels): - for level in range(0, last_level + 1): - zslice = 0 - while zslice < depth >> level: - test = TextureTest( - dev = dev, - target = target, - format = format, - width = size, - height = size, - depth = depth, - last_level = last_level, - face = face, - level = level, - zslice = zslice, - ) - suite.add_test(test) - zslice = (zslice + 1)*2 - 1 - suite.run() - - -if __name__ == '__main__': - main() diff --git a/progs/gallium/python/tests/tree.py b/progs/gallium/python/tests/tree.py deleted file mode 100755 index 0c1bcda4cf..0000000000 --- a/progs/gallium/python/tests/tree.py +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env python -# -# See also: -# http://www.ailab.si/orange/doc/ofb/c_otherclass.htm - -import os.path -import sys - -import orange -import orngTree - -for arg in sys.argv[1:]: - name, ext = os.path.splitext(arg) - - data = orange.ExampleTable(arg) - - tree = orngTree.TreeLearner(data, sameMajorityPruning=1, mForPruning=2) - - orngTree.printTxt(tree) - - file(name+'.txt', 'wt').write(orngTree.dumpTree(tree) + '\n') - - orngTree.printDot(tree, fileName=name+'.dot', nodeShape='ellipse', leafShape='box') diff --git a/progs/gallium/unit/SConscript b/progs/gallium/unit/SConscript deleted file mode 100644 index 9891440df6..0000000000 --- a/progs/gallium/unit/SConscript +++ /dev/null @@ -1,20 +0,0 @@ -Import('*') - -env = env.Clone() - -env.Prepend(LIBS = [gallium]) - -progs = [ - 'u_format_test' -] - -for prog in progs: - prog = env.Program( - target = prog, - source = prog + '.c', - ) - - # http://www.scons.org/wiki/UnitTests - test_alias = env.Alias('unit', [prog], prog[0].abspath) - AlwaysBuild(test_alias) - diff --git a/progs/gallium/unit/u_format_test.c b/progs/gallium/unit/u_format_test.c deleted file mode 100644 index 2dfba5538b..0000000000 --- a/progs/gallium/unit/u_format_test.c +++ /dev/null @@ -1,758 +0,0 @@ -/************************************************************************** - * - * Copyright 2009-2010 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, 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 ITS 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 <stdlib.h> -#include <stdio.h> - -#include "util/u_format.h" -#include "util/u_format_pack.h" - - -#define MAX_PACKED_BYTES 16 - - -/** - * A (packed, unpacked) color pair. - */ -struct util_format_test_case -{ - enum pipe_format format; - - /** - * Mask of the bits that actually meaningful data. Used to mask out the - * "X" channels. - */ - uint8_t mask[MAX_PACKED_BYTES]; - - uint8_t packed[MAX_PACKED_BYTES]; - - /** - * RGBA. - */ - double unpacked[4]; -}; - - -/* - * Helper macros to create the packed bytes for longer words. - */ - -#define PACKED_1x8(x) {x, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} -#define PACKED_2x8(x, y) {x, y, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} -#define PACKED_3x8(x, y, z) {x, y, z, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} -#define PACKED_4x8(x, y, z, w) {x, y, z, w, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} - -#define PACKED_1x16(x) {(x) & 0xff, (x) >> 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} -#define PACKED_2x16(x, y) {(x) & 0xff, (x) >> 8, (y) & 0xff, (y) >> 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} -#define PACKED_3x16(x, y, z) {(x) & 0xff, (x) >> 8, (y) & 0xff, (y) >> 8, (z) & 0xff, (z) >> 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} -#define PACKED_4x16(x, y, z, w) {(x) & 0xff, (x) >> 8, (y) & 0xff, (y) >> 8, (z) & 0xff, (z) >> 8, (w) & 0xff, (w) >> 8, 0, 0, 0, 0, 0, 0, 0, 0} - -#define PACKED_1x32(x) {(x) & 0xff, ((x) >> 8) & 0xff, ((x) >> 16) & 0xff, (x) >> 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} -#define PACKED_2x32(x, y) {(x) & 0xff, ((x) >> 8) & 0xff, ((x) >> 16) & 0xff, (x) >> 24, (y) & 0xff, ((y) >> 8) & 0xff, ((y) >> 16) & 0xff, (y) >> 24, 0, 0, 0, 0, 0, 0, 0, 0} -#define PACKED_3x32(x, y, z) {(x) & 0xff, ((x) >> 8) & 0xff, ((x) >> 16) & 0xff, (x) >> 24, (y) & 0xff, ((y) >> 8) & 0xff, ((y) >> 16) & 0xff, (y) >> 24, (z) & 0xff, ((z) >> 8) & 0xff, ((z) >> 16) & 0xff, (z) >> 24, 0, 0, 0, 0} -#define PACKED_4x32(x, y, z, w) {(x) & 0xff, ((x) >> 8) & 0xff, ((x) >> 16) & 0xff, (x) >> 24, (y) & 0xff, ((y) >> 8) & 0xff, ((y) >> 16) & 0xff, (y) >> 24, (z) & 0xff, ((z) >> 8) & 0xff, ((z) >> 16) & 0xff, (z) >> 24, (w) & 0xff, ((w) >> 8) & 0xff, ((w) >> 16) & 0xff, (w) >> 24} - - -/** - * Test cases. - * - * These were manually entered. We could generate these - * - * To keep this to a we cover only the corner cases, which should produce - * good enough coverage since that pixel format transformations are afine for - * non SRGB formats. - */ -static const struct util_format_test_case -test_cases[] = -{ - - /* - * 32-bit rendertarget formats - */ - - {PIPE_FORMAT_B8G8R8A8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), {0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_B8G8R8A8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x000000ff), {0.0, 0.0, 1.0, 0.0}}, - {PIPE_FORMAT_B8G8R8A8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x0000ff00), {0.0, 1.0, 0.0, 0.0}}, - {PIPE_FORMAT_B8G8R8A8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00ff0000), {1.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_B8G8R8A8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xff000000), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_B8G8R8A8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xffffffff), {1.0, 1.0, 1.0, 1.0}}, - - {PIPE_FORMAT_B8G8R8X8_UNORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0x00000000), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_B8G8R8X8_UNORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0x000000ff), {0.0, 0.0, 1.0, 1.0}}, - {PIPE_FORMAT_B8G8R8X8_UNORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0x0000ff00), {0.0, 1.0, 0.0, 1.0}}, - {PIPE_FORMAT_B8G8R8X8_UNORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0x00ff0000), {1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_B8G8R8X8_UNORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0xff000000), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_B8G8R8X8_UNORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0xffffffff), {1.0, 1.0, 1.0, 1.0}}, - - {PIPE_FORMAT_A8R8G8B8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), {0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_A8R8G8B8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x000000ff), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_A8R8G8B8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x0000ff00), {1.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_A8R8G8B8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00ff0000), {0.0, 1.0, 0.0, 0.0}}, - {PIPE_FORMAT_A8R8G8B8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xff000000), {0.0, 0.0, 1.0, 0.0}}, - {PIPE_FORMAT_A8R8G8B8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xffffffff), {1.0, 1.0, 1.0, 1.0}}, - - {PIPE_FORMAT_X8R8G8B8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0x00000000), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_X8R8G8B8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0x000000ff), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_X8R8G8B8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0x0000ff00), {1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_X8R8G8B8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0x00ff0000), {0.0, 1.0, 0.0, 1.0}}, - {PIPE_FORMAT_X8R8G8B8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0xff000000), {0.0, 0.0, 1.0, 1.0}}, - {PIPE_FORMAT_X8R8G8B8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0xffffffff), {1.0, 1.0, 1.0, 1.0}}, - - {PIPE_FORMAT_A8B8G8R8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), {0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_A8B8G8R8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x000000ff), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_A8B8G8R8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x0000ff00), {0.0, 0.0, 1.0, 0.0}}, - {PIPE_FORMAT_A8B8G8R8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00ff0000), {0.0, 1.0, 0.0, 0.0}}, - {PIPE_FORMAT_A8B8G8R8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xff000000), {1.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_A8B8G8R8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xffffffff), {1.0, 1.0, 1.0, 1.0}}, - - {PIPE_FORMAT_X8B8G8R8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0x00000000), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_X8B8G8R8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0x000000ff), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_X8B8G8R8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0x0000ff00), {0.0, 0.0, 1.0, 1.0}}, - {PIPE_FORMAT_X8B8G8R8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0x00ff0000), {0.0, 1.0, 0.0, 1.0}}, - {PIPE_FORMAT_X8B8G8R8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0xff000000), {1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_X8B8G8R8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0xffffffff), {1.0, 1.0, 1.0, 1.0}}, - - {PIPE_FORMAT_R10G10B10A2_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), {0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R10G10B10A2_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x000003ff), {1.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R10G10B10A2_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x000ffc00), {0.0, 1.0, 0.0, 0.0}}, - {PIPE_FORMAT_R10G10B10A2_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x3ff00000), {0.0, 0.0, 1.0, 0.0}}, - {PIPE_FORMAT_R10G10B10A2_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xc0000000), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R10G10B10A2_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xffffffff), {1.0, 1.0, 1.0, 1.0}}, - - /* - * 16-bit rendertarget formats - */ - - {PIPE_FORMAT_B5G5R5A1_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x0000), {0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_B5G5R5A1_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x001f), {0.0, 0.0, 1.0, 0.0}}, - {PIPE_FORMAT_B5G5R5A1_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x03e0), {0.0, 1.0, 0.0, 0.0}}, - {PIPE_FORMAT_B5G5R5A1_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x7c00), {1.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_B5G5R5A1_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x8000), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_B5G5R5A1_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xffff), {1.0, 1.0, 1.0, 1.0}}, - - {PIPE_FORMAT_B4G4R4A4_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x0000), {0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_B4G4R4A4_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x000f), {0.0, 0.0, 1.0, 0.0}}, - {PIPE_FORMAT_B4G4R4A4_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x00f0), {0.0, 1.0, 0.0, 0.0}}, - {PIPE_FORMAT_B4G4R4A4_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x0f00), {1.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_B4G4R4A4_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xf000), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_B4G4R4A4_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xffff), {1.0, 1.0, 1.0, 1.0}}, - - {PIPE_FORMAT_B5G6R5_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x0000), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_B5G6R5_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x001f), {0.0, 0.0, 1.0, 1.0}}, - {PIPE_FORMAT_B5G6R5_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x07e0), {0.0, 1.0, 0.0, 1.0}}, - {PIPE_FORMAT_B5G6R5_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xf800), {1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_B5G6R5_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xffff), {1.0, 1.0, 1.0, 1.0}}, - - /* - * Luminance/intensity/alpha formats - */ - - {PIPE_FORMAT_L8_UNORM, PACKED_1x8(0xff), PACKED_1x8(0x00), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_L8_UNORM, PACKED_1x8(0xff), PACKED_1x8(0xff), {1.0, 1.0, 1.0, 1.0}}, - - {PIPE_FORMAT_A8_UNORM, PACKED_1x8(0xff), PACKED_1x8(0x00), {0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_A8_UNORM, PACKED_1x8(0xff), PACKED_1x8(0xff), {0.0, 0.0, 0.0, 1.0}}, - - {PIPE_FORMAT_I8_UNORM, PACKED_1x8(0xff), PACKED_1x8(0x00), {0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_I8_UNORM, PACKED_1x8(0xff), PACKED_1x8(0xff), {1.0, 1.0, 1.0, 1.0}}, - - {PIPE_FORMAT_L8A8_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x0000), {0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_L8A8_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x00ff), {1.0, 1.0, 1.0, 0.0}}, - {PIPE_FORMAT_L8A8_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xff00), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_L8A8_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xffff), {1.0, 1.0, 1.0, 1.0}}, - - {PIPE_FORMAT_L16_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x0000), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_L16_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xffff), {1.0, 1.0, 1.0, 1.0}}, - - /* - * TODO: SRGB formats - */ - - /* - * Mixed-signed formats - */ - - {PIPE_FORMAT_R8SG8SB8UX8U_NORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0x00000000), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8SG8SB8UX8U_NORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0x0000007f), { 1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8SG8SB8UX8U_NORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0x00000081), {-1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8SG8SB8UX8U_NORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0x00007f00), { 0.0, 1.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8SG8SB8UX8U_NORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0x00008100), { 0.0, -1.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8SG8SB8UX8U_NORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0x00ff0000), { 0.0, 0.0, 1.0, 1.0}}, - {PIPE_FORMAT_R8SG8SB8UX8U_NORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0xff000000), { 0.0, 0.0, 0.0, 1.0}}, - - {PIPE_FORMAT_R5SG5SB6U_NORM, PACKED_1x16(0xffff), PACKED_1x16(0x0000), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R5SG5SB6U_NORM, PACKED_1x16(0xffff), PACKED_1x16(0x000f), { 1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R5SG5SB6U_NORM, PACKED_1x16(0xffff), PACKED_1x16(0x0011), {-1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R5SG5SB6U_NORM, PACKED_1x16(0xffff), PACKED_1x16(0x01e0), { 0.0, 1.0, 0.0, 1.0}}, - {PIPE_FORMAT_R5SG5SB6U_NORM, PACKED_1x16(0xffff), PACKED_1x16(0x0220), { 0.0, -1.0, 0.0, 1.0}}, - {PIPE_FORMAT_R5SG5SB6U_NORM, PACKED_1x16(0xffff), PACKED_1x16(0xfc00), { 0.0, 0.0, 1.0, 1.0}}, - - /* - * TODO: Depth-stencil formats - */ - - /* - * TODO: YUV formats - */ - - /* - * TODO: Compressed formats - */ - - /* - * Standard 8-bit integer formats - */ - - {PIPE_FORMAT_R8_UNORM, PACKED_1x8(0xff), PACKED_1x8(0x00), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8_UNORM, PACKED_1x8(0xff), PACKED_1x8(0xff), {1.0, 0.0, 0.0, 1.0}}, - - {PIPE_FORMAT_R8G8_UNORM, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x00, 0x00), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8_UNORM, PACKED_2x8(0xff, 0xff), PACKED_2x8(0xff, 0x00), {1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8_UNORM, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x00, 0xff), {0.0, 1.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8_UNORM, PACKED_2x8(0xff, 0xff), PACKED_2x8(0xff, 0xff), {1.0, 1.0, 0.0, 1.0}}, - - {PIPE_FORMAT_R8G8B8_UNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x00, 0x00), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8B8_UNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0xff, 0x00, 0x00), {1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8B8_UNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0xff, 0x00), {0.0, 1.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8B8_UNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x00, 0xff), {0.0, 0.0, 1.0, 1.0}}, - {PIPE_FORMAT_R8G8B8_UNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0xff, 0xff, 0xff), {1.0, 1.0, 1.0, 1.0}}, - - {PIPE_FORMAT_R8G8B8A8_UNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0x00), {0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R8G8B8A8_UNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0xff, 0x00, 0x00, 0x00), {1.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R8G8B8A8_UNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0xff, 0x00, 0x00), {0.0, 1.0, 0.0, 0.0}}, - {PIPE_FORMAT_R8G8B8A8_UNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0xff, 0x00), {0.0, 0.0, 1.0, 0.0}}, - {PIPE_FORMAT_R8G8B8A8_UNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0xff), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8B8A8_UNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0xff, 0xff, 0xff, 0xff), {1.0, 1.0, 1.0, 1.0}}, - - {PIPE_FORMAT_R8_USCALED, PACKED_1x8(0xff), PACKED_1x8(0x00), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8_USCALED, PACKED_1x8(0xff), PACKED_1x8(0xff), {255.0, 0.0, 0.0, 1.0}}, - - {PIPE_FORMAT_R8G8_USCALED, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x00, 0x00), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8_USCALED, PACKED_2x8(0xff, 0xff), PACKED_2x8(0xff, 0x00), {255.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8_USCALED, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x00, 0xff), { 0.0, 255.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8_USCALED, PACKED_2x8(0xff, 0xff), PACKED_2x8(0xff, 0xff), {255.0, 255.0, 0.0, 1.0}}, - - {PIPE_FORMAT_R8G8B8_USCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x00, 0x00), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8B8_USCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0xff, 0x00, 0x00), {255.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8B8_USCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0xff, 0x00), { 0.0, 255.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8B8_USCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x00, 0xff), { 0.0, 0.0, 255.0, 1.0}}, - {PIPE_FORMAT_R8G8B8_USCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0xff, 0xff, 0xff), {255.0, 255.0, 255.0, 1.0}}, - - {PIPE_FORMAT_R8G8B8A8_USCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0x00), { 0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R8G8B8A8_USCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0xff, 0x00, 0x00, 0x00), {255.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R8G8B8A8_USCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0xff, 0x00, 0x00), { 0.0, 255.0, 0.0, 0.0}}, - {PIPE_FORMAT_R8G8B8A8_USCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0xff, 0x00), { 0.0, 0.0, 255.0, 0.0}}, - {PIPE_FORMAT_R8G8B8A8_USCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0xff), { 0.0, 0.0, 0.0, 255.0}}, - {PIPE_FORMAT_R8G8B8A8_USCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0xff, 0xff, 0xff, 0xff), {255.0, 255.0, 255.0, 255.0}}, - - {PIPE_FORMAT_R8_SNORM, PACKED_1x8(0xff), PACKED_1x8(0x00), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8_SNORM, PACKED_1x8(0xff), PACKED_1x8(0x7f), { 1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8_SNORM, PACKED_1x8(0xff), PACKED_1x8(0x81), {-1.0, 0.0, 0.0, 1.0}}, - - {PIPE_FORMAT_R8G8_SNORM, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x00, 0x00), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8_SNORM, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x7f, 0x00), { 1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8_SNORM, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x81, 0x00), {-1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8_SNORM, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x00, 0x7f), { 0.0, 1.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8_SNORM, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x00, 0x81), { 0.0, -1.0, 0.0, 1.0}}, - - {PIPE_FORMAT_R8G8B8_SNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x00, 0x00), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8B8_SNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x7f, 0x00, 0x00), { 1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8B8_SNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x81, 0x00, 0x00), {-1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8B8_SNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x7f, 0x00), { 0.0, 1.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8B8_SNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x81, 0x00), { 0.0, -1.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8B8_SNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x00, 0x7f), { 0.0, 0.0, 1.0, 1.0}}, - {PIPE_FORMAT_R8G8B8_SNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x00, 0x81), { 0.0, 0.0, -1.0, 1.0}}, - - {PIPE_FORMAT_R8G8B8A8_SNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0x00), { 0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R8G8B8A8_SNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x7f, 0x00, 0x00, 0x00), { 1.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R8G8B8A8_SNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x81, 0x00, 0x00, 0x00), {-1.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R8G8B8A8_SNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x7f, 0x00, 0x00), { 0.0, 1.0, 0.0, 0.0}}, - {PIPE_FORMAT_R8G8B8A8_SNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x81, 0x00, 0x00), { 0.0, -1.0, 0.0, 0.0}}, - {PIPE_FORMAT_R8G8B8A8_SNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x7f, 0x00), { 0.0, 0.0, 1.0, 0.0}}, - {PIPE_FORMAT_R8G8B8A8_SNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x81, 0x00), { 0.0, 0.0, -1.0, 0.0}}, - {PIPE_FORMAT_R8G8B8A8_SNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0x7f), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8B8A8_SNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0x81), { 0.0, 0.0, 0.0, -1.0}}, - - {PIPE_FORMAT_R8_SSCALED, PACKED_1x8(0xff), PACKED_1x8(0x00), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8_SSCALED, PACKED_1x8(0xff), PACKED_1x8(0x7f), { 127.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8_SSCALED, PACKED_1x8(0xff), PACKED_1x8(0x80), {-128.0, 0.0, 0.0, 1.0}}, - - {PIPE_FORMAT_R8G8_SSCALED, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x00, 0x00), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8_SSCALED, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x7f, 0x00), { 127.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8_SSCALED, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x80, 0x00), {-128.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8_SSCALED, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x00, 0x7f), { 0.0, 127.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8_SSCALED, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x00, 0x80), { 0.0, -128.0, 0.0, 1.0}}, - - {PIPE_FORMAT_R8G8B8_SSCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x00, 0x00), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8B8_SSCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x7f, 0x00, 0x00), { 127.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8B8_SSCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x80, 0x00, 0x00), {-128.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8B8_SSCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x7f, 0x00), { 0.0, 127.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8B8_SSCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x80, 0x00), { 0.0, -128.0, 0.0, 1.0}}, - {PIPE_FORMAT_R8G8B8_SSCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x00, 0x7f), { 0.0, 0.0, 127.0, 1.0}}, - {PIPE_FORMAT_R8G8B8_SSCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x00, 0x80), { 0.0, 0.0, -128.0, 1.0}}, - - {PIPE_FORMAT_R8G8B8A8_SSCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0x00), { 0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R8G8B8A8_SSCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x7f, 0x00, 0x00, 0x00), { 127.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R8G8B8A8_SSCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x80, 0x00, 0x00, 0x00), {-128.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R8G8B8A8_SSCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x7f, 0x00, 0x00), { 0.0, 127.0, 0.0, 0.0}}, - {PIPE_FORMAT_R8G8B8A8_SSCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x80, 0x00, 0x00), { 0.0, -128.0, 0.0, 0.0}}, - {PIPE_FORMAT_R8G8B8A8_SSCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x7f, 0x00), { 0.0, 0.0, 127.0, 0.0}}, - {PIPE_FORMAT_R8G8B8A8_SSCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x80, 0x00), { 0.0, 0.0, -128.0, 0.0}}, - {PIPE_FORMAT_R8G8B8A8_SSCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0x7f), { 0.0, 0.0, 0.0, 127.0}}, - {PIPE_FORMAT_R8G8B8A8_SSCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0x80), { 0.0, 0.0, 0.0, -128.0}}, - - /* - * Standard 16-bit integer formats - */ - - {PIPE_FORMAT_R16_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x0000), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xffff), {1.0, 0.0, 0.0, 1.0}}, - - {PIPE_FORMAT_R16G16_UNORM, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x0000, 0x0000), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16_UNORM, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0xffff, 0x0000), {1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16_UNORM, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x0000, 0xffff), {0.0, 1.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16_UNORM, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0xffff, 0xffff), {1.0, 1.0, 0.0, 1.0}}, - - {PIPE_FORMAT_R16G16B16_UNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x0000, 0x0000), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16B16_UNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0xffff, 0x0000, 0x0000), {1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16B16_UNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0xffff, 0x0000), {0.0, 1.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16B16_UNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x0000, 0xffff), {0.0, 0.0, 1.0, 1.0}}, - {PIPE_FORMAT_R16G16B16_UNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0xffff, 0xffff, 0xffff), {1.0, 1.0, 1.0, 1.0}}, - - {PIPE_FORMAT_R16G16B16A16_UNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x0000, 0x0000), {0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R16G16B16A16_UNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0xffff, 0x0000, 0x0000, 0x0000), {1.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R16G16B16A16_UNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0xffff, 0x0000, 0x0000), {0.0, 1.0, 0.0, 0.0}}, - {PIPE_FORMAT_R16G16B16A16_UNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0xffff, 0x0000), {0.0, 0.0, 1.0, 0.0}}, - {PIPE_FORMAT_R16G16B16A16_UNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x0000, 0xffff), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16B16A16_UNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), {1.0, 1.0, 1.0, 1.0}}, - - {PIPE_FORMAT_R16_USCALED, PACKED_1x16(0xffff), PACKED_1x16(0x0000), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16_USCALED, PACKED_1x16(0xffff), PACKED_1x16(0xffff), {65535.0, 0.0, 0.0, 1.0}}, - - {PIPE_FORMAT_R16G16_USCALED, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x0000, 0x0000), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16_USCALED, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0xffff, 0x0000), {65535.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16_USCALED, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x0000, 0xffff), { 0.0, 65535.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16_USCALED, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0xffff, 0xffff), {65535.0, 65535.0, 0.0, 1.0}}, - - {PIPE_FORMAT_R16G16B16_USCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x0000, 0x0000), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16B16_USCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0xffff, 0x0000, 0x0000), {65535.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16B16_USCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0xffff, 0x0000), { 0.0, 65535.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16B16_USCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x0000, 0xffff), { 0.0, 0.0, 65535.0, 1.0}}, - {PIPE_FORMAT_R16G16B16_USCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0xffff, 0xffff, 0xffff), {65535.0, 65535.0, 65535.0, 1.0}}, - - {PIPE_FORMAT_R16G16B16A16_USCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x0000, 0x0000), { 0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R16G16B16A16_USCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0xffff, 0x0000, 0x0000, 0x0000), {65535.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R16G16B16A16_USCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0xffff, 0x0000, 0x0000), { 0.0, 65535.0, 0.0, 0.0}}, - {PIPE_FORMAT_R16G16B16A16_USCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0xffff, 0x0000), { 0.0, 0.0, 65535.0, 0.0}}, - {PIPE_FORMAT_R16G16B16A16_USCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x0000, 0xffff), { 0.0, 0.0, 0.0, 65535.0}}, - {PIPE_FORMAT_R16G16B16A16_USCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), {65535.0, 65535.0, 65535.0, 65535.0}}, - - {PIPE_FORMAT_R16_SNORM, PACKED_1x16(0xffff), PACKED_1x16(0x0000), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16_SNORM, PACKED_1x16(0xffff), PACKED_1x16(0x7fff), { 1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16_SNORM, PACKED_1x16(0xffff), PACKED_1x16(0x8001), { -1.0, 0.0, 0.0, 1.0}}, - - {PIPE_FORMAT_R16G16_SNORM, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x0000, 0x0000), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16_SNORM, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x7fff, 0x0000), { 1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16_SNORM, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x8001, 0x0000), { -1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16_SNORM, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x0000, 0x7fff), { 0.0, 1.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16_SNORM, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x0000, 0x8001), { 0.0, -1.0, 0.0, 1.0}}, - - {PIPE_FORMAT_R16G16B16_SNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x0000, 0x0000), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16B16_SNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x7fff, 0x0000, 0x0000), { 1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16B16_SNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x8001, 0x0000, 0x0000), { -1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16B16_SNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x7fff, 0x0000), { 0.0, 1.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16B16_SNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x8001, 0x0000), { 0.0, -1.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16B16_SNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x0000, 0x7fff), { 0.0, 0.0, 1.0, 1.0}}, - {PIPE_FORMAT_R16G16B16_SNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x0000, 0x8001), { 0.0, 0.0, -1.0, 1.0}}, - - {PIPE_FORMAT_R16G16B16A16_SNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x0000, 0x0000), { 0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R16G16B16A16_SNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x7fff, 0x0000, 0x0000, 0x0000), { 1.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R16G16B16A16_SNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x8001, 0x0000, 0x0000, 0x0000), { -1.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R16G16B16A16_SNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x7fff, 0x0000, 0x0000), { 0.0, 1.0, 0.0, 0.0}}, - {PIPE_FORMAT_R16G16B16A16_SNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x8001, 0x0000, 0x0000), { 0.0, -1.0, 0.0, 0.0}}, - {PIPE_FORMAT_R16G16B16A16_SNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x7fff, 0x0000), { 0.0, 0.0, 1.0, 0.0}}, - {PIPE_FORMAT_R16G16B16A16_SNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x8001, 0x0000), { 0.0, 0.0, -1.0, 0.0}}, - {PIPE_FORMAT_R16G16B16A16_SNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x0000, 0x7fff), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16B16A16_SNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x0000, 0x8001), { 0.0, 0.0, 0.0, -1.0}}, - - {PIPE_FORMAT_R16_SSCALED, PACKED_1x16(0xffff), PACKED_1x16(0x0000), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16_SSCALED, PACKED_1x16(0xffff), PACKED_1x16(0x7fff), { 32767.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16_SSCALED, PACKED_1x16(0xffff), PACKED_1x16(0x8000), {-32768.0, 0.0, 0.0, 1.0}}, - - {PIPE_FORMAT_R16G16_SSCALED, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x0000, 0x0000), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16_SSCALED, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x7fff, 0x0000), { 32767.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16_SSCALED, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x8000, 0x0000), {-32768.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16_SSCALED, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x0000, 0x7fff), { 0.0, 32767.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16_SSCALED, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x0000, 0x8000), { 0.0, -32768.0, 0.0, 1.0}}, - - {PIPE_FORMAT_R16G16B16_SSCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x0000, 0x0000), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16B16_SSCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x7fff, 0x0000, 0x0000), { 32767.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16B16_SSCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x8000, 0x0000, 0x0000), {-32768.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16B16_SSCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x7fff, 0x0000), { 0.0, 32767.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16B16_SSCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x8000, 0x0000), { 0.0, -32768.0, 0.0, 1.0}}, - {PIPE_FORMAT_R16G16B16_SSCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x0000, 0x7fff), { 0.0, 0.0, 32767.0, 1.0}}, - {PIPE_FORMAT_R16G16B16_SSCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x0000, 0x8000), { 0.0, 0.0, -32768.0, 1.0}}, - - {PIPE_FORMAT_R16G16B16A16_SSCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x0000, 0x0000), { 0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R16G16B16A16_SSCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x7fff, 0x0000, 0x0000, 0x0000), { 32767.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R16G16B16A16_SSCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x8000, 0x0000, 0x0000, 0x0000), {-32768.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R16G16B16A16_SSCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x7fff, 0x0000, 0x0000), { 0.0, 32767.0, 0.0, 0.0}}, - {PIPE_FORMAT_R16G16B16A16_SSCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x8000, 0x0000, 0x0000), { 0.0, -32768.0, 0.0, 0.0}}, - {PIPE_FORMAT_R16G16B16A16_SSCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x7fff, 0x0000), { 0.0, 0.0, 32767.0, 0.0}}, - {PIPE_FORMAT_R16G16B16A16_SSCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x8000, 0x0000), { 0.0, 0.0, -32768.0, 0.0}}, - {PIPE_FORMAT_R16G16B16A16_SSCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x0000, 0x7fff), { 0.0, 0.0, 0.0, 32767.0}}, - {PIPE_FORMAT_R16G16B16A16_SSCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x0000, 0x8000), { 0.0, 0.0, 0.0, -32768.0}}, - - /* - * Standard 32-bit integer formats - * - * NOTE: We can't accurately represent integers larger than +/-0x1000000 - * with single precision floats, so that's as far as we test. - */ - - {PIPE_FORMAT_R32_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xffffffff), {1.0, 0.0, 0.0, 1.0}}, - - {PIPE_FORMAT_R32G32_UNORM, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0x00000000), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32_UNORM, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0xffffffff, 0x00000000), {1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32_UNORM, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0xffffffff), {0.0, 1.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32_UNORM, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0xffffffff, 0xffffffff), {1.0, 1.0, 0.0, 1.0}}, - - {PIPE_FORMAT_R32G32B32_UNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0x00000000), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32B32_UNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0xffffffff, 0x00000000, 0x00000000), {1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32B32_UNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0xffffffff, 0x00000000), {0.0, 1.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32B32_UNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0xffffffff), {0.0, 0.0, 1.0, 1.0}}, - {PIPE_FORMAT_R32G32B32_UNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), {1.0, 1.0, 1.0, 1.0}}, - - {PIPE_FORMAT_R32G32B32A32_UNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0x00000000), {0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_UNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0xffffffff, 0x00000000, 0x00000000, 0x00000000), {1.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_UNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0xffffffff, 0x00000000, 0x00000000), {0.0, 1.0, 0.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_UNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0xffffffff, 0x00000000), {0.0, 0.0, 1.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_UNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0xffffffff), {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32B32A32_UNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), {1.0, 1.0, 1.0, 1.0}}, - - {PIPE_FORMAT_R32_USCALED, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32_USCALED, PACKED_1x32(0xffffffff), PACKED_1x32(0x01000000), {16777216.0, 0.0, 0.0, 1.0}}, - - {PIPE_FORMAT_R32G32_USCALED, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0x00000000), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32_USCALED, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x01000000, 0x00000000), {16777216.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32_USCALED, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0x01000000), { 0.0, 16777216.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32_USCALED, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x01000000, 0x01000000), {16777216.0, 16777216.0, 0.0, 1.0}}, - - {PIPE_FORMAT_R32G32B32_USCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0x00000000), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32B32_USCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x01000000, 0x00000000, 0x00000000), {16777216.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32B32_USCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x01000000, 0x00000000), { 0.0, 16777216.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32B32_USCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0x01000000), { 0.0, 0.0, 16777216.0, 1.0}}, - {PIPE_FORMAT_R32G32B32_USCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x01000000, 0x01000000, 0x01000000), {16777216.0, 16777216.0, 16777216.0, 1.0}}, - - {PIPE_FORMAT_R32G32B32A32_USCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0x00000000), { 0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_USCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x01000000, 0x00000000, 0x00000000, 0x00000000), {16777216.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_USCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x01000000, 0x00000000, 0x00000000), { 0.0, 16777216.0, 0.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_USCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x01000000, 0x00000000), { 0.0, 0.0, 16777216.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_USCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0x01000000), { 0.0, 0.0, 0.0, 16777216.0}}, - {PIPE_FORMAT_R32G32B32A32_USCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x01000000, 0x01000000, 0x01000000, 0x01000000), {16777216.0, 16777216.0, 16777216.0, 16777216.0}}, - - {PIPE_FORMAT_R32_SNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32_SNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x7fffffff), { 1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32_SNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x80000001), { -1.0, 0.0, 0.0, 1.0}}, - - {PIPE_FORMAT_R32G32_SNORM, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0x00000000), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32_SNORM, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x7fffffff, 0x00000000), { 1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32_SNORM, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x80000001, 0x00000000), { -1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32_SNORM, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0x7fffffff), { 0.0, 1.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32_SNORM, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0x80000001), { 0.0, -1.0, 0.0, 1.0}}, - - {PIPE_FORMAT_R32G32B32_SNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0x00000000), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32B32_SNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x7fffffff, 0x00000000, 0x00000000), { 1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32B32_SNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x80000001, 0x00000000, 0x00000000), { -1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32B32_SNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x7fffffff, 0x00000000), { 0.0, 1.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32B32_SNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x80000001, 0x00000000), { 0.0, -1.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32B32_SNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0x7fffffff), { 0.0, 0.0, 1.0, 1.0}}, - {PIPE_FORMAT_R32G32B32_SNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0x80000001), { 0.0, 0.0, -1.0, 1.0}}, - - {PIPE_FORMAT_R32G32B32A32_SNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0x00000000), { 0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_SNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x7fffffff, 0x00000000, 0x00000000, 0x00000000), { 1.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_SNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x80000001, 0x00000000, 0x00000000, 0x00000000), { -1.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_SNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x7fffffff, 0x00000000, 0x00000000), { 0.0, 1.0, 0.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_SNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x80000001, 0x00000000, 0x00000000), { 0.0, -1.0, 0.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_SNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x7fffffff, 0x00000000), { 0.0, 0.0, 1.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_SNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x80000001, 0x00000000), { 0.0, 0.0, -1.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_SNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0x7fffffff), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32B32A32_SNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0x80000001), { 0.0, 0.0, 0.0, -1.0}}, - - {PIPE_FORMAT_R32_SSCALED, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32_SSCALED, PACKED_1x32(0xffffffff), PACKED_1x32(0x01000000), { 16777216.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32_SSCALED, PACKED_1x32(0xffffffff), PACKED_1x32(0xff000000), {-16777216.0, 0.0, 0.0, 1.0}}, - - {PIPE_FORMAT_R32G32_SSCALED, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0x00000000), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32_SSCALED, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x01000000, 0x00000000), { 16777216.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32_SSCALED, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0xff000000, 0x00000000), {-16777216.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32_SSCALED, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0x01000000), { 0.0, 16777216.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32_SSCALED, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0xff000000), { 0.0, -16777216.0, 0.0, 1.0}}, - - {PIPE_FORMAT_R32G32B32_SSCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0x00000000), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32B32_SSCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x01000000, 0x00000000, 0x00000000), { 16777216.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32B32_SSCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0xff000000, 0x00000000, 0x00000000), {-16777216.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32B32_SSCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x01000000, 0x00000000), { 0.0, 16777216.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32B32_SSCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0xff000000, 0x00000000), { 0.0, -16777216.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32B32_SSCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0x01000000), { 0.0, 0.0, 16777216.0, 1.0}}, - {PIPE_FORMAT_R32G32B32_SSCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0xff000000), { 0.0, 0.0, -16777216.0, 1.0}}, - - {PIPE_FORMAT_R32G32B32A32_SSCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0x00000000), { 0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_SSCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x01000000, 0x00000000, 0x00000000, 0x00000000), { 16777216.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_SSCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0xff000000, 0x00000000, 0x00000000, 0x00000000), {-16777216.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_SSCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x01000000, 0x00000000, 0x00000000), { 0.0, 16777216.0, 0.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_SSCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0xff000000, 0x00000000, 0x00000000), { 0.0, -16777216.0, 0.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_SSCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x01000000, 0x00000000), { 0.0, 0.0, 16777216.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_SSCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0xff000000, 0x00000000), { 0.0, 0.0, -16777216.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_SSCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0x01000000), { 0.0, 0.0, 0.0, 16777216.0}}, - {PIPE_FORMAT_R32G32B32A32_SSCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0xff000000), { 0.0, 0.0, 0.0, -16777216.0}}, - - /* - * Standard 32-bit float formats - */ - - {PIPE_FORMAT_R32_FLOAT, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32_FLOAT, PACKED_1x32(0xffffffff), PACKED_1x32(0x3f800000), { 1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32_FLOAT, PACKED_1x32(0xffffffff), PACKED_1x32(0xbf800000), { -1.0, 0.0, 0.0, 1.0}}, - - {PIPE_FORMAT_R32G32_FLOAT, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0x00000000), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32_FLOAT, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x3f800000, 0x00000000), { 1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32_FLOAT, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0xbf800000, 0x00000000), {-1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32_FLOAT, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0x3f800000), { 0.0, 1.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32_FLOAT, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0xbf800000), { 0.0, -1.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32_FLOAT, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x3f800000, 0x3f800000), { 1.0, 1.0, 0.0, 1.0}}, - - {PIPE_FORMAT_R32G32B32_FLOAT, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0x00000000), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32B32_FLOAT, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x3f800000, 0x00000000, 0x00000000), { 1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32B32_FLOAT, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0xbf800000, 0x00000000, 0x00000000), {-1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32B32_FLOAT, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x3f800000, 0x00000000), { 0.0, 1.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32B32_FLOAT, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0xbf800000, 0x00000000), { 0.0, -1.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32B32_FLOAT, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0x3f800000), { 0.0, 0.0, 1.0, 1.0}}, - {PIPE_FORMAT_R32G32B32_FLOAT, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0xbf800000), { 0.0, 0.0, -1.0, 1.0}}, - {PIPE_FORMAT_R32G32B32_FLOAT, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x3f800000, 0x3f800000, 0x3f800000), { 1.0, 1.0, 1.0, 1.0}}, - - {PIPE_FORMAT_R32G32B32A32_FLOAT, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0x00000000), { 0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_FLOAT, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x3f800000, 0x00000000, 0x00000000, 0x00000000), { 1.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_FLOAT, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0xbf800000, 0x00000000, 0x00000000, 0x00000000), {-1.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_FLOAT, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x3f800000, 0x00000000, 0x00000000), { 0.0, 1.0, 0.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_FLOAT, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0xbf800000, 0x00000000, 0x00000000), { 0.0, -1.0, 0.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_FLOAT, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x3f800000, 0x00000000), { 0.0, 0.0, 1.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_FLOAT, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0xbf800000, 0x00000000), { 0.0, 0.0, -1.0, 0.0}}, - {PIPE_FORMAT_R32G32B32A32_FLOAT, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0x3f800000), { 0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R32G32B32A32_FLOAT, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0xbf800000), { 0.0, 0.0, 0.0, -1.0}}, - {PIPE_FORMAT_R32G32B32A32_FLOAT, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000), { 1.0, 1.0, 1.0, 1.0}}, -}; - - -static boolean -test_format_unpack_4f(const struct util_format_test_case *test) -{ - float unpacked[4]; - unsigned i; - boolean success; - - util_format_unpack_4f(test->format, unpacked, test->packed); - - success = TRUE; - for (i = 0; i < 4; ++i) - if (test->unpacked[i] != unpacked[i]) - success = FALSE; - - if (!success) { - printf("FAILED: (%f %f %f %f) obtained\n", unpacked[0], unpacked[1], unpacked[2], unpacked[3]); - printf(" (%f %f %f %f) expected\n", test->unpacked[0], test->unpacked[1], test->unpacked[2], test->unpacked[3]); - } - - return success; -} - - -static boolean -test_format_pack_4f(const struct util_format_test_case *test) -{ - uint8_t packed[MAX_PACKED_BYTES]; - unsigned i; - boolean success; - - memset(packed, 0, sizeof packed); - - util_format_pack_4f(test->format, packed, test->unpacked[0], test->unpacked[1], test->unpacked[2], test->unpacked[3]); - - success = TRUE; - for (i = 0; i < MAX_PACKED_BYTES; ++i) - if ((test->packed[i] & test->mask[i]) != (packed[i] & test->mask[i])) - success = FALSE; - - if (!success) { - /* TODO: print more than 4 bytes */ - printf("FAILED: (%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x) obtained\n", - packed[0], packed[1], packed[2], packed[3], - packed[4], packed[5], packed[6], packed[7], - packed[8], packed[9], packed[10], packed[11], - packed[12], packed[13], packed[14], packed[15]); - printf(" (%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x) expected\n", - test->packed[0], test->packed[1], test->packed[2], test->packed[3], - test->packed[4], test->packed[5], test->packed[6], test->packed[7], - test->packed[8], test->packed[9], test->packed[10], test->packed[11], - test->packed[12], test->packed[13], test->packed[14], test->packed[15]); - } - - return success; -} - - -static void -convert_4f_to_4ub(uint8_t *dst, const double *src) -{ - unsigned i; - - for (i = 0; i < 4; ++i) - dst[i] = CLAMP(src[i], 0.0, 1.0) * 255.0; -} - - -static boolean -test_format_unpack_4ub(const struct util_format_test_case *test) -{ - uint8_t unpacked[4]; - uint8_t expected[4]; - unsigned i; - boolean success; - - util_format_unpack_4ub(test->format, unpacked, test->packed); - - convert_4f_to_4ub(expected, test->unpacked); - - success = TRUE; - for (i = 0; i < 4; ++i) - if (expected[i] != unpacked[i]) - success = FALSE; - - if (!success) { - printf("FAILED: (0x%02x 0x%02x 0x%02x 0x%02x) obtained\n", unpacked[0], unpacked[1], unpacked[2], unpacked[3]); - printf(" (0x%02x 0x%02x 0x%02x 0x%02x) expected\n", expected[0], expected[1], expected[2], expected[3]); - } - - return success; -} - - -static boolean -test_format_pack_4ub(const struct util_format_test_case *test) -{ - uint8_t unpacked[4]; - uint8_t packed[MAX_PACKED_BYTES]; - unsigned i; - boolean success; - - convert_4f_to_4ub(unpacked, test->unpacked); - - memset(packed, 0, sizeof packed); - - util_format_pack_4ub(test->format, packed, unpacked[0], unpacked[1], unpacked[2], unpacked[3]); - - success = TRUE; - for (i = 0; i < MAX_PACKED_BYTES; ++i) - if ((test->packed[i] & test->mask[i]) != (packed[i] & test->mask[i])) - success = FALSE; - - if (!success) { - /* TODO: print more than 4 bytes */ - printf("FAILED: (%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x) obtained\n", - packed[0], packed[1], packed[2], packed[3], - packed[4], packed[5], packed[6], packed[7], - packed[8], packed[9], packed[10], packed[11], - packed[12], packed[13], packed[14], packed[15]); - printf(" (%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x) expected\n", - test->packed[0], test->packed[1], test->packed[2], test->packed[3], - test->packed[4], test->packed[5], test->packed[6], test->packed[7], - test->packed[8], test->packed[9], test->packed[10], test->packed[11], - test->packed[12], test->packed[13], test->packed[14], test->packed[15]); - } - - return success; -} - - -typedef boolean -(*test_func_t)(const struct util_format_test_case *test); - - -static boolean -test_one(test_func_t func, const char *suffix) -{ - enum pipe_format last_format = PIPE_FORMAT_NONE; - unsigned i; - bool success = TRUE; - - for (i = 0; i < sizeof(test_cases)/sizeof(test_cases[0]); ++i) { - if (test_cases[i].format != last_format) { - const struct util_format_description *format_desc; - format_desc = util_format_description(test_cases[i].format); - printf("Testing %s.%s ...\n", format_desc->name, suffix); - last_format = test_cases[i].format; - } - - if (!func(&test_cases[i])) - success = FALSE; - } - - return success; -} - - -static boolean -test_all(void) -{ - bool success = TRUE; - - if (!test_one(&test_format_pack_4f, "pack_4f")) - success = FALSE; - - if (!test_one(&test_format_unpack_4f, "unpack_4f")) - success = FALSE; - - if (!test_one(&test_format_pack_4ub, "pack_4ub")) - success = FALSE; - - if (!test_one(&test_format_unpack_4ub, "unpack_4ub")) - success = FALSE; - - return success; -} - - -int main(int argc, char **argv) -{ - boolean success; - - success = test_all(); - - return success ? 0 : 1; -} diff --git a/progs/glsl/.gitignore b/progs/glsl/.gitignore index 986775bac2..9d403ec6d6 100644 --- a/progs/glsl/.gitignore +++ b/progs/glsl/.gitignore @@ -6,6 +6,7 @@ convolutions deriv extfuncs.h fragcoord +fsraytrace identity linktest mandelbrot @@ -31,3 +32,4 @@ trirast twoside vert-or-frag-only vert-tex +vsraytrace diff --git a/progs/glsl/Makefile b/progs/glsl/Makefile index 3b5a5959ae..6030c8002f 100644 --- a/progs/glsl/Makefile +++ b/progs/glsl/Makefile @@ -26,6 +26,7 @@ PROG_SOURCES = \ convolutions.c \ deriv.c \ fragcoord.c \ + fsraytrace.c \ identity.c \ linktest.c \ mandelbrot.c \ @@ -46,7 +47,8 @@ PROG_SOURCES = \ trirast.c \ twoside.c \ vert-or-frag-only.c \ - vert-tex.c + vert-tex.c \ + vsraytrace.c UTIL_HEADERS = \ extfuncs.h \ diff --git a/progs/glsl/SConscript b/progs/glsl/SConscript index 8f2ebcf69c..02884e5a71 100644 --- a/progs/glsl/SConscript +++ b/progs/glsl/SConscript @@ -8,6 +8,7 @@ progs = [ 'convolutions', 'deriv', 'fragcoord', + 'fsraytrace', 'identity', 'linktest', 'mandelbrot', @@ -27,6 +28,7 @@ progs = [ 'twoside', 'vert-or-frag-only', 'vert-tex', + 'vsraytrace', ] for prog in progs: diff --git a/progs/glsl/fsraytrace.c b/progs/glsl/fsraytrace.c new file mode 100644 index 0000000000..af72a99099 --- /dev/null +++ b/progs/glsl/fsraytrace.c @@ -0,0 +1,412 @@ +/* -*- mode: c; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; coding: utf-8-unix -*- */ +/* + Copyright (c) 2010 Kristóf Ralovich + + 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 THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + + +#include <stdio.h> +#include <stdlib.h> +#include <GL/glew.h> +#include <GL/glut.h> +#include "shaderutil.h" +#include <math.h> + +static int Win; +static int WinWidth = 512, WinHeight = 512; +static int mouseGrabbed = 0; +static GLuint vertShader; +static GLuint fragShader; +static GLuint program; +static float rot[9] = {1,0,0, 0,1,0, 0,0,1}; + +static const char* vsSource = + "varying vec2 rayDir; \n" + " \n" + "void main() \n" + "{ \n" + " rayDir = gl_MultiTexCoord0.xy - vec2(0.5,0.5); \n" + " gl_Position = gl_ProjectionMatrix * gl_Vertex; \n" + "}\n"; + +static const char* fsSource = + "const float INF = 9999.9; \n" + "const float EPSILON = 0.00001; \n" + "const vec3 lightPos = vec3(0.0, 8.0, 1.0); \n" + "const vec4 backgroundColor = vec4(0.2,0.3,0.4,1); \n" + " \n" + "varying vec2 rayDir; \n" + " \n" + "uniform mat3 rot; \n" + " \n" + "struct Ray \n" + "{ \n" + "vec3 orig; \n" + "vec3 dir; \n" + "}; \n" + " \n" + "struct Sphere \n" + "{ \n" + " vec3 c; \n" + " float r; \n" + "}; \n" + " \n" + "struct Isec \n" + "{ \n" + " float t; \n" + " int idx; \n" + " vec3 hit; \n" + " vec3 n; \n" + "}; \n" + " \n" +#ifdef __APPLE__ + "Sphere spheres0 = Sphere( vec3(0.0,0.0,-1.0), 0.5 ); \n" + "Sphere spheres1 = Sphere( vec3(-3.0,0.0,-1.0), 1.5 ); \n" + "Sphere spheres2 = Sphere( vec3(0.0,3.0,-1.0), 0.5 ); \n" + "Sphere spheres3 = Sphere( vec3(2.0,0.0,-1.0), 1.0 ); \n" +#else + "const Sphere spheres0 = Sphere( vec3(0.0,0.0,-1.0), 0.5 ); \n" + "const Sphere spheres1 = Sphere( vec3(-3.0,0.0,-1.0), 1.5 ); \n" + "const Sphere spheres2 = Sphere( vec3(0.0,3.0,-1.0), 0.5 ); \n" + "const Sphere spheres3 = Sphere( vec3(2.0,0.0,-1.0), 1.0 ); \n" +#endif + " \n" + "// Mesa intel gen4 generates \"unsupported IR in fragment shader 13\" for\n" + "// sqrt, let's work around. \n" + "float \n" + "sqrt_hack(float f2) \n" + "{ \n" + " vec3 v = vec3(f2,0.0,0.0); \n" + " return length(v); \n" + "} \n" + " \n" + "void \n" + "intersect(const in Ray ray, \n" + " const in Sphere sph, \n" + " const in int idx, \n" + " inout Isec isec) \n" + "{ \n" + " // Project both o and the sphere to the plane perpendicular to d \n" + " // and containing c. Let x be the point where the ray intersects \n" + " // the plane. If |x-c| < r, the ray intersects the sphere. \n" + " vec3 o = ray.orig; \n" + " vec3 d = ray.dir; \n" + " vec3 n = -d; \n" + " vec3 c = sph.c; \n" + " float r = sph.r; \n" + " float t = dot(c-o,n)/dot(n,d); \n" + " vec3 x = o+d*t; \n" + " float e = length(x-c); \n" + " if(e > r) \n" + " { \n" + " // no intersection \n" + " return; \n" + " } \n" + " \n" + " // Apply Pythagorean theorem on the (intersection,x,c) triangle \n" + " // to get the distance between c and the intersection. \n" + "#ifndef BUGGY_INTEL_GEN4_GLSL \n" + " float f = sqrt(r*r - e*e); \n" + "#else \n" + " float f = sqrt_hack(r*r - e*e); \n" + "#endif \n" + " float dist = t - f; \n" + " if(dist < 0.0) \n" + " { \n" + " // inside the sphere \n" + " return; \n" + " } \n" + " \n" + " if(dist < EPSILON) \n" + " return; \n" + " \n" + " if(dist > isec.t) \n" + " return; \n" + " \n" + " isec.t = dist; \n" + " isec.idx = idx; \n" + " \n" + " isec.hit = ray.orig + ray.dir * isec.t; \n" + " isec.n = (isec.hit - c) / r; \n" + "} \n" + " \n" + "Isec \n" + "intersect(const in Ray ray, \n" + " const in float max_t /*= INF*/) \n" + "{ \n" + " Isec nearest; \n" + " nearest.t = max_t; \n" + " nearest.idx = -1; \n" + " \n" + " intersect(ray, spheres0, 0, nearest); \n" + " intersect(ray, spheres1, 1, nearest); \n" + " intersect(ray, spheres2, 2, nearest); \n" + " intersect(ray, spheres3, 3, nearest); \n" + " \n" + " return nearest; \n" + "} \n" + " \n" + "vec4 \n" + "idx2color(const in int idx) \n" + "{ \n" + " vec4 diff; \n" + " if(idx == 0) \n" + " diff = vec4(1.0, 0.0, 0.0, 0.0); \n" + " else if(idx == 1) \n" + " diff = vec4(0.0, 1.0, 0.0, 0.0); \n" + " else if(idx == 2) \n" + " diff = vec4(0.0, 0.0, 1.0, 0.0); \n" + " else if(idx == 3) \n" + " diff = vec4(1.0, 1.0, 0.0, 0.0); \n" + " return diff; \n" + "} \n" + " \n" + "vec4 \n" + "trace0(const in Ray ray) \n" + "{ \n" + " Isec isec = intersect(ray, INF); \n" + " \n" + " if(isec.idx == -1) \n" + " { \n" + " return backgroundColor; \n" + " } \n" + " \n" + " vec4 diff = idx2color(isec.idx); \n" + " \n" + " vec3 N = isec.n; \n" + " vec3 L = normalize(lightPos-isec.hit); \n" + " vec3 camera_dir = normalize(ray.orig - isec.hit); \n" + " return dot(N,L)*diff + pow( \n" + " clamp(dot(reflect(-L,N),camera_dir),0.0,1.0),16.0); \n" + "} \n" + " \n" + "vec4 \n" + "trace1(const in Ray ray) \n" + "{ \n" + " Isec isec = intersect(ray, INF); \n" + " \n" + " if(isec.idx == -1) \n" + " { \n" + " return backgroundColor; \n" + " } \n" + " \n" + " Ray reflRay = Ray(isec.hit, reflect(ray.dir, isec.n)); \n" + " \n" + " vec4 reflCol = trace0(reflRay); \n" + " \n" + " vec4 diff = idx2color(isec.idx) + reflCol; \n" + " \n" + " vec3 N = isec.n; \n" + " vec3 L = normalize(lightPos-isec.hit); \n" + " vec3 camera_dir = normalize(ray.orig - isec.hit); \n" + " return dot(N,L)*diff + pow( \n" + " clamp(dot(reflect(-L,N),camera_dir),0.0,1.0),16.0); \n" + "} \n" + " \n" + "void main() \n" + "{ \n" + " const float z = -0.5; \n" + " const vec3 cameraPos = vec3(0,0,3); \n" + " Ray r = Ray(cameraPos, normalize(vec3(rayDir, z) * rot)); \n" + " gl_FragColor = trace1(r); \n" + "}\n"; + +static +float +deg2rad(const float degree) +{ + return( degree * 0.017453292519943295769236907684886F); +} + +static void +rotate_xy(float* mat3, const float degreesAroundX, const float degreesAroundY) +{ + const float rad1 = deg2rad(degreesAroundX); + const float c1 = cosf(rad1); + const float s1 = sinf(rad1); + const float rad2 = deg2rad(degreesAroundY); + const float c2 = cosf(rad2); + const float s2 = sinf(rad2); + mat3[0] = c2; mat3[3] = 0.0F; mat3[6] = s2; + mat3[1] = s1*s2; mat3[4] = c1; mat3[7] = -s1*c2; + mat3[2] = -c1*s2;mat3[5] = s1; mat3[8] = c1*c2; +} + +static void +identity(float* mat3) +{ + mat3[0] = 1.0F; mat3[3] = 0.0F; mat3[6] = 0.0F; + mat3[1] = 0.0F; mat3[4] = 1.0F; mat3[7] = 0.0F; + mat3[2] = 0.0F; mat3[5] = 0.0F; mat3[8] = 1.0F; +} + +static void +Draw(void) +{ + GLint location = glGetUniformLocation(program, "rot"); + static const float m = -10.F; + static const float p = 10.F; + static const float d = -0.5F; + + glUseProgram(program); + glUniformMatrix3fv(location, 1, 0, rot); + + glBegin(GL_QUADS); + { + glTexCoord2f(0.0F, 0.0F); glVertex3f(m, m, d); + glTexCoord2f(1.0F, 0.0F); glVertex3f(p, m, d); + glTexCoord2f(1.0F, 1.0F); glVertex3f(p, p, d); + glTexCoord2f(0.0F, 1.0F); glVertex3f(m, p, d); + } + glEnd(); + glUseProgram(0); + + glutSwapBuffers(); + + { + static int frames = 0; + static int t0 = 0; + static int t1 = 0; + float dt; + frames++; + t1 = glutGet(GLUT_ELAPSED_TIME); + dt = (float)(t1-t0)/1000.0F; + if(dt >= 5.0F) + { + float fps = (float)frames / dt; + printf("%f FPS (%d frames in %f seconds)\n", fps, frames, dt); + frames = 0; + t0 = t1; + } + } +} + + +static void +Reshape(int width, int height) +{ + WinWidth = width; + WinHeight = height; + glViewport(0, 0, width, height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-10, 10, -10, 10, -1, 1); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + + +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 +drag(int x, int y) +{ + float scale = 1.5F; + if(mouseGrabbed) + { + static GLfloat xRot = 0, yRot = 0; + xRot = (float)(x - WinWidth/2) / scale; + yRot = (float)(y - WinHeight/2) / scale; + identity(rot); + rotate_xy(rot, yRot, xRot); + glutPostRedisplay(); + } +} + + +static +void +mouse(int button, int state, int x, int y) +{ + mouseGrabbed = (state == GLUT_DOWN); +} + + +static void +Init(void) +{ + glDisable(GL_DEPTH_TEST); + + if(!ShadersSupported()) + { + fprintf(stderr, "Shaders are not supported!\n"); + exit(-1); + } + + vertShader = CompileShaderText(GL_VERTEX_SHADER, vsSource); + fragShader = CompileShaderText(GL_FRAGMENT_SHADER, fsSource); + program = LinkShaders(vertShader, fragShader); + glUseProgram(0); + + if(glGetError() != 0) + { + fprintf(stderr, "Shaders were not loaded!\n"); + exit(-1); + } + + if(!glIsShader(vertShader)) + { + fprintf(stderr, "Vertex shader failed!\n"); + exit(-1); + } + + if(!glIsProgram(program)) + { + fprintf(stderr, "Shader program failed!\n"); + exit(-1); + } + + printf("GL_RENDERER = %s\n",(const char *) glGetString(GL_RENDERER)); +} + + +int +main(int argc, char *argv[]) +{ + glutInitWindowSize(WinWidth, WinHeight); + glutInit(&argc, argv); + glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); + Win = glutCreateWindow(argv[0]); + glewInit(); + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutDisplayFunc(Draw); + glutMouseFunc(mouse); + glutMotionFunc(drag); + glutIdleFunc(Draw); + Init(); + glutMainLoop(); + return 0; +} + diff --git a/progs/glsl/vsraytrace.c b/progs/glsl/vsraytrace.c new file mode 100644 index 0000000000..64d928883e --- /dev/null +++ b/progs/glsl/vsraytrace.c @@ -0,0 +1,401 @@ +/* -*- mode: c; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; coding: utf-8-unix -*- */ +/* + Copyright (c) 2010 Kristóf Ralovich + + 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 THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + + +#include <stdio.h> +#include <stdlib.h> +#include <GL/glew.h> +#include <GL/glut.h> +#include "shaderutil.h" +#include <math.h> + +static int Win; +static int WinWidth = 256, WinHeight = 256; +static GLboolean mouseGrabbed = GL_FALSE; +static GLuint vertShader; +static GLuint program; +float rot[9] = {1,0,0, 0,1,0, 0,0,1}; + +static const char* vsSource = + "const float INF = 9999.9; \n" + "const float EPSILON = 0.00001; \n" + "const vec3 lightPos = vec3(0.0, 8.0, 1.0); \n" + "const vec4 backgroundColor = vec4(0.2,0.3,0.4,1); \n" + " \n" + "uniform mat3 rot; \n" + " \n" + "struct Ray \n" + "{ \n" + "vec3 orig; \n" + "vec3 dir; \n" + "}; \n" + " \n" + "struct Sphere \n" + "{ \n" + " vec3 c; \n" + " float r; \n" + "}; \n" + " \n" + "struct Isec \n" + "{ \n" + " float t; \n" + " int idx; \n" + " vec3 hit; \n" + " vec3 n; \n" + "}; \n" + " \n" +#ifdef __APPLE__ + "Sphere spheres0 = Sphere( vec3(0.0,0.0,-1.0), 0.5 ); \n" + "Sphere spheres1 = Sphere( vec3(-3.0,0.0,-1.0), 1.5 ); \n" + "Sphere spheres2 = Sphere( vec3(0.0,3.0,-1.0), 0.5 ); \n" + "Sphere spheres3 = Sphere( vec3(2.0,0.0,-1.0), 1.0 ); \n" +#else + "const Sphere spheres0 = Sphere( vec3(0.0,0.0,-1.0), 0.5 ); \n" + "const Sphere spheres1 = Sphere( vec3(-3.0,0.0,-1.0), 1.5 ); \n" + "const Sphere spheres2 = Sphere( vec3(0.0,3.0,-1.0), 0.5 ); \n" + "const Sphere spheres3 = Sphere( vec3(2.0,0.0,-1.0), 1.0 ); \n" +#endif + " \n" + "// Mesa intel gen4 generates \"unsupported IR in fragment shader 13\" for\n" + "// sqrt, let's work around. \n" + "float \n" + "sqrt_hack(float f2) \n" + "{ \n" + " vec3 v = vec3(f2,0.0,0.0); \n" + " return length(v); \n" + "} \n" + " \n" + "void \n" + "intersect(const in Ray ray, \n" + " const in Sphere sph, \n" + " const in int idx, \n" + " inout Isec isec) \n" + "{ \n" + " // Project both o and the sphere to the plane perpendicular to d \n" + " // and containing c. Let x be the point where the ray intersects \n" + " // the plane. If |x-c| < r, the ray intersects the sphere. \n" + " vec3 o = ray.orig; \n" + " vec3 d = ray.dir; \n" + " vec3 n = -d; \n" + " vec3 c = sph.c; \n" + " float r = sph.r; \n" + " float t = dot(c-o,n)/dot(n,d); \n" + " vec3 x = o+d*t; \n" + " float e = length(x-c); \n" + " if(e > r) \n" + " { \n" + " // no intersection \n" + " return; \n" + " } \n" + " \n" + " // Apply Pythagorean theorem on the (intersection,x,c) triangle \n" + " // to get the distance between c and the intersection. \n" + "#define BUGGY_INTEL_GEN4_GLSL 1 \n" + "#ifndef BUGGY_INTEL_GEN4_GLSL \n" + " float f = sqrt(r*r - e*e); \n" + "#else \n" + " float f = sqrt_hack(r*r - e*e); \n" + "#endif \n" + " float dist = t - f; \n" + " if(dist < 0.0) \n" + " { \n" + " // inside the sphere \n" + " return; \n" + " } \n" + " \n" + " if(dist < EPSILON) \n" + " return; \n" + " \n" + " if(dist > isec.t) \n" + " return; \n" + " \n" + " isec.t = dist; \n" + " isec.idx = idx; \n" + " \n" + " isec.hit = ray.orig + ray.dir * isec.t; \n" + " isec.n = (isec.hit - c) / r; \n" + "} \n" + " \n" + "Isec \n" + "intersect(const in Ray ray, \n" + " const in float max_t /*= INF*/) \n" + "{ \n" + " Isec nearest; \n" + " nearest.t = max_t; \n" + " nearest.idx = -1; \n" + " \n" + " intersect(ray, spheres0, 0, nearest); \n" + " intersect(ray, spheres1, 1, nearest); \n" + " intersect(ray, spheres2, 2, nearest); \n" + " intersect(ray, spheres3, 3, nearest); \n" + " \n" + " return nearest; \n" + "} \n" + " \n" + "vec4 \n" + "idx2color(const in int idx) \n" + "{ \n" + " vec4 diff; \n" + " if(idx == 0) \n" + " diff = vec4(1.0, 0.0, 0.0, 0.0); \n" + " else if(idx == 1) \n" + " diff = vec4(0.0, 1.0, 0.0, 0.0); \n" + " else if(idx == 2) \n" + " diff = vec4(0.0, 0.0, 1.0, 0.0); \n" + " else if(idx == 3) \n" + " diff = vec4(1.0, 1.0, 0.0, 0.0); \n" + " return diff; \n" + "} \n" + " \n" + "vec4 \n" + "trace0(const in Ray ray) \n" + "{ \n" + " Isec isec = intersect(ray, INF); \n" + " \n" + " if(isec.idx == -1) \n" + " { \n" + " return backgroundColor; \n" + " } \n" + " \n" + " vec4 diff = idx2color(isec.idx); \n" + " \n" + " vec3 N = isec.n; \n" + " vec3 L = normalize(lightPos-isec.hit); \n" + " vec3 camera_dir = normalize(ray.orig - isec.hit); \n" + " return dot(N,L)*diff + pow( \n" + " clamp(dot(reflect(-L,N),camera_dir),0.0,1.0),16.0); \n" + "} \n" + " \n" + "vec4 \n" + "trace1(const in Ray ray) \n" + "{ \n" + " Isec isec = intersect(ray, INF); \n" + " \n" + " if(isec.idx == -1) \n" + " { \n" + " return backgroundColor; \n" + " } \n" + " \n" + " Ray reflRay = Ray(isec.hit, reflect(ray.dir, isec.n)); \n" + " \n" + " vec4 reflCol = trace0(reflRay); \n" + " \n" + " vec4 diff = idx2color(isec.idx) + reflCol; \n" + " \n" + " vec3 N = isec.n; \n" + " vec3 L = normalize(lightPos-isec.hit); \n" + " vec3 camera_dir = normalize(ray.orig - isec.hit); \n" + " return dot(N,L)*diff + pow( \n" + " clamp(dot(reflect(-L,N),camera_dir),0.0,1.0),16.0); \n" + "} \n" + " \n" + "void main() \n" + "{ \n" + " const vec3 cameraPos = vec3(0,0,3); \n" + " vec3 rayDir = normalize(vec3(gl_Vertex.x, gl_Vertex.y, -1.0) * rot);\n" + " Ray ray = Ray(cameraPos, rayDir); \n" + " gl_Position = gl_Vertex; \n" + " gl_FrontColor = trace1(ray); \n" + "}\n"; + + +static +float +deg2rad(const float degree) +{ + return( degree * 0.017453292519943295769236907684886F); +} + +static void +rotate_xy(float* mat3, const float degreesAroundX, const float degreesAroundY) +{ + const float rad1 = deg2rad(degreesAroundX); + const float c1 = cosf(rad1); + const float s1 = sinf(rad1); + const float rad2 = deg2rad(degreesAroundY); + const float c2 = cosf(rad2); + const float s2 = sinf(rad2); + mat3[0] = c2; mat3[3] = 0.0F; mat3[6] = s2; + mat3[1] = s1*s2; mat3[4] = c1; mat3[7] = -s1*c2; + mat3[2] = -c1*s2;mat3[5] = s1; mat3[8] = c1*c2; +} + +static void +identity(float* mat3) +{ + mat3[0] = 1.0F; mat3[3] = 0.0F; mat3[6] = 0.0F; + mat3[1] = 0.0F; mat3[4] = 1.0F; mat3[7] = 0.0F; + mat3[2] = 0.0F; mat3[5] = 0.0F; mat3[8] = 1.0F; +} + +static void +Draw(void) +{ + const float w = 0.5F * WinWidth; + const float h = 0.5F * WinHeight; + int x,y; + + GLint location = glGetUniformLocation(program, "rot"); + + glUseProgram(program); + glUniformMatrix3fv(location, 1, 0, rot); + glBegin(GL_POINTS); + for(y = 0; y < WinHeight; y++) + { + for(x = 0; x < WinWidth; x++) + { + const float posx = x / w - 1.0F; + const float posy = y / h - 1.0F; + glVertex2f(posx, posy); + } + } + glEnd(); + glUseProgram(0); + + glutSwapBuffers(); + + { + static int frames = 0; + static int t0 = 0; + static int t1 = 0; + float dt; + frames++; + t1 = glutGet(GLUT_ELAPSED_TIME); + dt = (float)(t1-t0)/1000.0F; + if (dt >= 5.0F) + { + float fps = (float)frames / dt; + printf("%f FPS (%d frames in %f seconds)\n", fps, frames, dt); + frames = 0; + t0 = t1; + } + } +} + + +static void +Reshape(int width, int height) +{ + WinWidth = width; + WinHeight = height; + glViewport(0, 0, width, height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + + +static void +Key(unsigned char key, int x, int y) +{ + if(key == 27) + { + glutDestroyWindow(Win); + exit(0); + } + glutPostRedisplay(); +} + + +static +void +drag(int x, int y) +{ + float scale = 1.5F; + if(mouseGrabbed) + { + static GLfloat xRot = 0, yRot = 0; + xRot = (float)(x - WinWidth/2) / scale; + yRot = (float)(y - WinHeight/2) / scale; + identity(rot); + rotate_xy(rot, yRot, xRot); + glutPostRedisplay(); + } +} + + +static +void +mouse(int button, int state, int x, int y) +{ + mouseGrabbed = (state == GLUT_DOWN); +} + + +static void +Init(void) +{ + glDisable(GL_DEPTH_TEST); + + if(!ShadersSupported()) + { + fprintf(stderr, "Shaders are not supported!\n"); + exit(-1); + } + + vertShader = CompileShaderText(GL_VERTEX_SHADER, vsSource); + program = LinkShaders(vertShader, 0); + glUseProgram(0); + + if(glGetError() != 0) + { + fprintf(stderr, "Shaders were not loaded!\n"); + exit(-1); + } + + if(!glIsShader(vertShader)) + { + fprintf(stderr, "Vertex shader failed!\n"); + exit(-1); + } + + if(!glIsProgram(program)) + { + fprintf(stderr, "Shader program failed!\n"); + exit(-1); + } + + printf("GL_RENDERER = %s\n",(const char *) glGetString(GL_RENDERER)); +} + + +int +main(int argc, char *argv[]) +{ + glutInitWindowSize(WinWidth, WinHeight); + glutInit(&argc, argv); + glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); + Win = glutCreateWindow(argv[0]); + glewInit(); + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutDisplayFunc(Draw); + glutIdleFunc(Draw); + glutMouseFunc(mouse); + glutMotionFunc(drag); + Init(); + glutMainLoop(); + return 0; +} + diff --git a/progs/objviewer/skybox.c b/progs/objviewer/skybox.c index 4e30742e20..93331b9c16 100644 --- a/progs/objviewer/skybox.c +++ b/progs/objviewer/skybox.c @@ -88,9 +88,9 @@ LoadSkyBoxCubeTexture(const char *filePosX, return 0; if (!load(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, fileNegX, GL_TRUE, GL_TRUE)) return 0; - if (!load(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, filePosY, 1+GL_FALSE, GL_TRUE)) + if (!load(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, filePosY, GL_TRUE, GL_TRUE)) return 0; - if (!load(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, fileNegY, 1+GL_FALSE, GL_TRUE)) + if (!load(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, fileNegY, GL_TRUE, GL_TRUE)) return 0; if (!load(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, filePosZ, GL_TRUE, GL_TRUE)) return 0; diff --git a/progs/openvg/demos/Makefile b/progs/openvg/demos/Makefile deleted file mode 100644 index 89b0ce441b..0000000000 --- a/progs/openvg/demos/Makefile +++ /dev/null @@ -1,39 +0,0 @@ -# progs/vg/Makefile - -TOP = ../../.. -include $(TOP)/configs/current - -VG_LIBS=-lm -pthread -lX11 -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/lion.c b/progs/openvg/demos/lion.c deleted file mode 100644 index adb269bfd8..0000000000 --- a/progs/openvg/demos/lion.c +++ /dev/null @@ -1,289 +0,0 @@ -#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_RENDERABLE_TYPE, EGL_OPENVG_BIT, - 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) || - !num_configs) { - printf("Error: couldn't get an EGL visual config\n"); - exit(1); - } - - assert(config); - - 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/trivial/eglcommon.c b/progs/openvg/trivial/eglcommon.c deleted file mode 100644 index 0316e596c6..0000000000 --- a/progs/openvg/trivial/eglcommon.c +++ /dev/null @@ -1,289 +0,0 @@ -#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_RENDERABLE_TYPE, EGL_OPENVG_BIT, - 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) || - !num_configs) { - printf("Error: couldn't get an EGL visual config\n"); - exit(1); - } - - assert(config); - - 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 deleted file mode 100644 index 958dae9f98..0000000000 --- a/progs/openvg/trivial/eglcommon.h +++ /dev/null @@ -1,20 +0,0 @@ -#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/samples/copy.c b/progs/samples/copy.c index 391c637d6f..353a3a2e1a 100644 --- a/progs/samples/copy.c +++ b/progs/samples/copy.c @@ -25,6 +25,7 @@ #include <stdio.h> #include <string.h> #include <stdlib.h> +#include <GL/glew.h> #include <GL/glut.h> @@ -35,7 +36,6 @@ GLint windW, windH; char *fileName = 0; PPMImage *image; -float point[3]; float zoom; GLint x, y; @@ -97,27 +97,27 @@ static void Mouse(int button, int state, int mouseX, int mouseY) static void Draw(void) { + GLint src[3], dst[3]; glClear(GL_COLOR_BUFFER_BIT); - point[0] = (windW / 2) - (image->sizeX / 2); - point[1] = (windH / 2) - (image->sizeY / 2); - point[2] = 0; - glRasterPos3fv(point); + src[0] = (int) ((windW / 2.0) - (image->sizeX / 2.0)); + src[1] = (int) ((windH / 2.0) - (image->sizeY / 2.0)); + src[2] = 0; + glWindowPos3ivARB(src); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glPixelZoom(1.0, 1.0); glDrawPixels(image->sizeX, image->sizeY, GL_RGB, GL_UNSIGNED_BYTE, image->data); - point[0] = (float)x; - point[1] = windH - (float)y; - point[2] = 0.0; - glRasterPos3fv(point); + dst[0] = x; + dst[1] = windH - y; + dst[2] = 0; + glWindowPos3ivARB(dst); glPixelZoom(zoom, zoom); - glCopyPixels((windW/2)-(image->sizeX/2), - (windH/2)-(image->sizeY/2), + glCopyPixels(src[0], src[1], image->sizeX, image->sizeY, GL_COLOR); glFlush(); @@ -170,8 +170,8 @@ int main(int argc, char **argv) image = LoadPPM(fileName); - windW = 300; - windH = 300; + windW = 2*300; + windH = 2*300; glutInitWindowPosition(0, 0); glutInitWindowSize( windW, windH); type = GLUT_RGB; @@ -182,6 +182,7 @@ int main(int argc, char **argv) exit(1); } + glewInit(); Init(); glutReshapeFunc(Reshape); diff --git a/progs/samples/loadppm.c b/progs/samples/loadppm.c index be056d6294..adae9b491e 100644 --- a/progs/samples/loadppm.c +++ b/progs/samples/loadppm.c @@ -9,7 +9,7 @@ static PPMImage *LoadPPM(const char *filename) char buff[16]; PPMImage *result; FILE *fp; - int maxval; + int maxval, w, h; fp = fopen(filename, "rb"); if (!fp) @@ -37,11 +37,13 @@ static PPMImage *LoadPPM(const char *filename) exit(1); } - if (fscanf(fp, "%lu %lu", &result->sizeX, &result->sizeY) != 2) + if (fscanf(fp, "%d %d", &w, &h) != 2) { fprintf(stderr, "Error loading image `%s'\n", filename); exit(1); } + result->sizeX = w; + result->sizeY = h; if (fscanf(fp, "%d", &maxval) != 1) { diff --git a/progs/tests/fbotest1.c b/progs/tests/fbotest1.c index 0cd7f95c35..a95fdff74c 100644 --- a/progs/tests/fbotest1.c +++ b/progs/tests/fbotest1.c @@ -36,8 +36,8 @@ Display( void ) /* draw to user framebuffer */ glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, MyFB); - glDrawBuffer(GL_COLOR_ATTACHMENT1_EXT); - glReadBuffer(GL_COLOR_ATTACHMENT1_EXT); + glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT); + glReadBuffer(GL_COLOR_ATTACHMENT0_EXT); status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { @@ -161,7 +161,7 @@ Init( void ) assert(i == MyFB); CheckError(__LINE__); - glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, + glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, MyRB); glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGB, Width, Height); diff --git a/progs/tests/fbotest2.c b/progs/tests/fbotest2.c index f9c506193f..faf0dd8748 100644 --- a/progs/tests/fbotest2.c +++ b/progs/tests/fbotest2.c @@ -33,15 +33,16 @@ CheckError(int line) static void Display( void ) { - GLubyte *buffer = malloc(Width * Height * 4); + GLboolean copyPix = GL_FALSE; + GLboolean blitPix = GL_FALSE; GLenum status; CheckError(__LINE__); /* draw to user framebuffer */ glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, MyFB); - glDrawBuffer(GL_COLOR_ATTACHMENT1_EXT); - glReadBuffer(GL_COLOR_ATTACHMENT1_EXT); + glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT); + glReadBuffer(GL_COLOR_ATTACHMENT0_EXT); status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { @@ -63,16 +64,43 @@ Display( void ) glutSolidTeapot(2.0); glPopMatrix(); - /* read from user framebuffer */ - glReadPixels(0, 0, Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, buffer); + if (copyPix) { + glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, MyFB); + glReadBuffer(GL_COLOR_ATTACHMENT0_EXT); + glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0); + glDrawBuffer(GL_BACK); - /* draw to window */ - glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); - glDisable(GL_DEPTH_TEST); /* in case window has depth buffer */ - glWindowPos2iARB(0, 0); - glDrawPixels(Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, buffer); + glDisable(GL_DEPTH_TEST); /* in case window has depth buffer */ + + glWindowPos2iARB(0, 0); + glCopyPixels(0, 0, Width, Height, GL_COLOR); + } + else if (blitPix) { + glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, MyFB); + glReadBuffer(GL_COLOR_ATTACHMENT0_EXT); + glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0); + glDrawBuffer(GL_BACK); + + glDisable(GL_DEPTH_TEST); /* in case window has depth buffer */ + + glBlitFramebufferEXT(0, 0, Width, Height, + 0, 0, Width, Height, + GL_COLOR_BUFFER_BIT, GL_NEAREST); + } + else { + GLubyte *buffer = malloc(Width * Height * 4); + /* read from user framebuffer */ + glReadPixels(0, 0, Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, buffer); + + /* draw to window */ + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); + glDisable(GL_DEPTH_TEST); /* in case window has depth buffer */ + glWindowPos2iARB(0, 0); + glDrawPixels(Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, buffer); + + free(buffer); + } - free(buffer); glutSwapBuffers(); CheckError(__LINE__); } @@ -163,7 +191,7 @@ Init( void ) glGenRenderbuffersEXT(1, &ColorRb); glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, ColorRb); assert(glIsRenderbufferEXT(ColorRb)); - glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, + glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, ColorRb); glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGB, Width, Height); diff --git a/progs/tests/fbotest3.c b/progs/tests/fbotest3.c index 8e288b38b8..c176f82d2b 100644 --- a/progs/tests/fbotest3.c +++ b/progs/tests/fbotest3.c @@ -50,8 +50,8 @@ Display( void ) /* draw to user framebuffer */ glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, MyFB); - glDrawBuffer(GL_COLOR_ATTACHMENT1_EXT); - glReadBuffer(GL_COLOR_ATTACHMENT1_EXT); + glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT); + glReadBuffer(GL_COLOR_ATTACHMENT0_EXT); status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { @@ -189,7 +189,7 @@ Init( void ) glGenRenderbuffersEXT(1, &ColorRb); glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, ColorRb); assert(glIsRenderbufferEXT(ColorRb)); - glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, + glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, ColorRb); glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGB, Width, Height); diff --git a/progs/tests/stencil_twoside.c b/progs/tests/stencil_twoside.c index 7d871e5877..1010139a20 100644 --- a/progs/tests/stencil_twoside.c +++ b/progs/tests/stencil_twoside.c @@ -26,7 +26,7 @@ * \file stencil_twoside.c * * Simple test of GL_ATI_separate_stencil (or the OGL 2.0 equivalent) functionality. - * Four squares are drawn + * Five squares (or six if stencil wrap is available) are drawn * with different stencil modes, but all should be rendered with the same * final color. */ @@ -37,7 +37,7 @@ #include <GL/glut.h> static int use20syntax = 1; -static int Width = 550; +static int Width = 650; static int Height = 200; static const GLfloat Near = 5.0, Far = 25.0; @@ -70,7 +70,7 @@ static void Display( void ) */ glDisable(GL_STENCIL_TEST); - glTranslatef(-6.0, 0, 0); + glTranslatef(-7.0, 0, 0); glBegin(GL_QUADS); glColor3f( 0.5, 0.5, 0.5 ); glVertex2f(-1, -1); @@ -85,6 +85,9 @@ static void Display( void ) /* Draw the first two squares using incr for the affected face */ + /************************************************************************* + * 2nd square + */ if (use20syntax) { stencil_func_separate(GL_FRONT, GL_ALWAYS, 0, ~0); stencil_func_separate(GL_BACK, GL_ALWAYS, 0, ~0); @@ -98,8 +101,8 @@ static void Display( void ) glTranslatef(3.0, 0, 0); glBegin(GL_QUADS); glColor3f( 0.9, 0.9, 0.9 ); - /* this should be front facing */ for ( i = 0 ; i < (max_stencil + 5) ; i++ ) { + /* this should be front facing */ glVertex2f(-1, -1); glVertex2f( 1, -1); glVertex2f( 1, 1); @@ -107,6 +110,7 @@ static void Display( void ) } glEnd(); + /* stencil vals should be equal to max_stencil */ glStencilFunc(GL_EQUAL, max_stencil, ~0); glBegin(GL_QUADS); glColor3f( 0.5, 0.5, 0.5 ); @@ -116,6 +120,9 @@ static void Display( void ) glVertex2f(-1, 1); glEnd(); + /************************************************************************* + * 3rd square + */ if (use20syntax) { stencil_func_separate(GL_FRONT, GL_ALWAYS, 0, ~0); stencil_func_separate(GL_BACK, GL_ALWAYS, 0, ~0); @@ -129,9 +136,8 @@ static void Display( void ) glTranslatef(3.0, 0, 0); glBegin(GL_QUADS); glColor3f( 0.9, 0.9, 0.9 ); - - /* this should be back facing */ for ( i = 0 ; i < (max_stencil + 5) ; i++ ) { + /* this should be back facing */ glVertex2f(-1, -1); glVertex2f(-1, 1); glVertex2f( 1, 1); @@ -139,6 +145,7 @@ static void Display( void ) } glEnd(); + /* stencil vals should be equal to max_stencil */ glStencilFunc(GL_EQUAL, max_stencil, ~0); glBegin(GL_QUADS); glColor3f( 0.5, 0.5, 0.5 ); @@ -148,6 +155,9 @@ static void Display( void ) glVertex2f(-1, 1); glEnd(); + /************************************************************************* + * 4th square + */ if (use20syntax) { stencil_func_separate(GL_FRONT, GL_NEVER, 0, ~0); stencil_func_separate(GL_BACK, GL_ALWAYS, 0, ~0); @@ -161,15 +171,13 @@ static void Display( void ) glTranslatef(3.0, 0, 0); glBegin(GL_QUADS); glColor3f( 0.9, 0.9, 0.9 ); - - /* this should be back facing */ for ( i = 0 ; i < (max_stencil + 5) ; i++ ) { - /* this should be back facing */ + /* this should be back facing */ glVertex2f(-1, -1); glVertex2f(-1, 1); glVertex2f( 1, 1); glVertex2f( 1, -1); - /* this should be front facing */ + /* this should be front facing */ glVertex2f(-1, -1); glVertex2f( 1, -1); glVertex2f( 1, 1); @@ -177,6 +185,7 @@ static void Display( void ) } glEnd(); + /* stencil vals should be equal to max_stencil */ glStencilFunc(GL_EQUAL, max_stencil, ~0); glBegin(GL_QUADS); glColor3f( 0.5, 0.5, 0.5 ); @@ -186,6 +195,9 @@ static void Display( void ) glVertex2f(-1, 1); glEnd(); + /************************************************************************* + * 5th square + */ if (use20syntax) { stencil_func_separate(GL_FRONT, GL_ALWAYS, 0, ~0); stencil_func_separate(GL_BACK, GL_ALWAYS, 0, ~0); @@ -193,21 +205,19 @@ static void Display( void ) else { stencil_func_separate_ati(GL_ALWAYS, GL_ALWAYS, 0, ~0); } - stencil_op_separate(GL_FRONT, GL_KEEP, GL_KEEP, GL_DECR); - stencil_op_separate(GL_BACK, GL_KEEP, GL_KEEP, GL_INCR); + stencil_op_separate(GL_FRONT, GL_KEEP, GL_KEEP, GL_INCR); + stencil_op_separate(GL_BACK, GL_KEEP, GL_KEEP, GL_DECR); glTranslatef(3.0, 0, 0); glBegin(GL_QUADS); glColor3f( 0.9, 0.9, 0.9 ); - - /* this should be back facing */ for ( i = 0 ; i < (max_stencil + 5) ; i++ ) { - /* this should be back facing */ + /* this should be back facing */ glVertex2f(-1, -1); glVertex2f(-1, 1); glVertex2f( 1, 1); glVertex2f( 1, -1); - /* this should be front facing */ + /* this should be front facing */ glVertex2f(-1, -1); glVertex2f( 1, -1); glVertex2f( 1, 1); @@ -224,6 +234,47 @@ static void Display( void ) glVertex2f(-1, 1); glEnd(); + /************************************************************************* + * 6th square + */ + if (glutExtensionSupported("GL_EXT_stencil_wrap")) { + if (use20syntax) { + stencil_func_separate(GL_FRONT, GL_ALWAYS, 0, ~0); + stencil_func_separate(GL_BACK, GL_ALWAYS, 0, ~0); + } + else { + stencil_func_separate_ati(GL_ALWAYS, GL_ALWAYS, 0, ~0); + } + stencil_op_separate(GL_FRONT, GL_KEEP, GL_KEEP, GL_KEEP); + stencil_op_separate(GL_BACK, GL_KEEP, GL_KEEP, GL_INCR_WRAP); + + glTranslatef(3.0, 0, 0); + glBegin(GL_QUADS); + glColor3f( 0.9, 0.9, 0.9 ); + for ( i = 0 ; i < (max_stencil + 5) ; i++ ) { + /* this should be back facing */ + glVertex2f(-1, -1); + glVertex2f(-1, 1); + glVertex2f( 1, 1); + glVertex2f( 1, -1); + /* this should be front facing */ + glVertex2f(-1, -1); + glVertex2f( 1, -1); + glVertex2f( 1, 1); + glVertex2f(-1, 1); + } + glEnd(); + + glStencilFunc(GL_EQUAL, 260 - 255, ~0); + glBegin(GL_QUADS); + glColor3f( 0.5, 0.5, 0.5 ); + glVertex2f(-1, -1); + glVertex2f( 1, -1); + glVertex2f( 1, 1); + glVertex2f(-1, 1); + glEnd(); + } + glPopMatrix(); glutSwapBuffers(); @@ -278,7 +329,7 @@ static void Init( void ) stencil_func_separate_ati = (PFNGLSTENCILFUNCSEPARATEATIPROC) glutGetProcAddress( "glStencilFuncSeparateATI" ); stencil_op_separate = (PFNGLSTENCILOPSEPARATEPROC) glutGetProcAddress( "glStencilOpSeparate" ); - printf("\nAll 5 squares should be the same color.\n"); + printf("\nAll 5 (or 6) squares should be the same color.\n"); } diff --git a/progs/trivial/.gitignore b/progs/trivial/.gitignore index caf930d921..2b42f04289 100644 --- a/progs/trivial/.gitignore +++ b/progs/trivial/.gitignore @@ -1,5 +1,6 @@ clear clear-fbo +clear-fbo-scissor clear-fbo-tex clear-random clear-repeat diff --git a/progs/trivial/Makefile b/progs/trivial/Makefile index b4a903cb68..a10748f948 100644 --- a/progs/trivial/Makefile +++ b/progs/trivial/Makefile @@ -11,6 +11,7 @@ include $(TOP)/configs/current LIBS = -L$(TOP)/$(LIB_DIR) -l $(GLEW_LIB) -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) $(APP_LIB_DEPS) SOURCES = \ + clear-fbo-scissor.c \ clear-fbo-tex.c \ clear-fbo.c \ clear-scissor.c \ diff --git a/progs/trivial/SConscript b/progs/trivial/SConscript index f480da047e..24b4f91fb0 100644 --- a/progs/trivial/SConscript +++ b/progs/trivial/SConscript @@ -1,7 +1,8 @@ Import('*') progs = [ - 'clear-fbo-tex', + 'clear-fbo-scissor', + 'clear-fbo-tex', 'clear-fbo', 'clear-scissor', 'clear-undefined', diff --git a/progs/trivial/clear-fbo-scissor.c b/progs/trivial/clear-fbo-scissor.c new file mode 100644 index 0000000000..6a605e16a8 --- /dev/null +++ b/progs/trivial/clear-fbo-scissor.c @@ -0,0 +1,234 @@ +/* + * Use scissor to clear the four quadrants of the FBO to different + * colors. Then draw a grey triangle in the middle. + */ + + +#include <assert.h> +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <string.h> +#include <GL/glew.h> +#include <GL/glut.h> +#include <GL/glu.h> + + +static int Width = 512, Height = 512; +static GLuint MyFB, MyRB; +static GLboolean UseTex = GL_FALSE; +static GLboolean UseCopyPix = GL_FALSE; + + +#define CheckError() \ + do { \ + GLenum err = glGetError(); \ + if (err != GL_NO_ERROR) \ + printf("Error: %s\n", gluErrorString(err)); \ + assert(err == GL_NO_ERROR); \ + } while (0) + + +static void +Init(void) +{ + GLenum status; + + fprintf(stderr, "GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + fprintf(stderr, "GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); + fprintf(stderr, "GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); + fflush(stderr); + + if (!glutExtensionSupported("GL_EXT_framebuffer_object")) { + printf("GL_EXT_framebuffer_object not found!\n"); + exit(0); + } + + glGenFramebuffersEXT(1, &MyFB); + glGenRenderbuffersEXT(1, &MyRB); + + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, MyFB); + + if (UseTex) { + GLuint tex; + glGenTextures(1, &tex); + glBindTexture(GL_TEXTURE_2D, tex); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Width, Height, 0, + GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, + GL_COLOR_ATTACHMENT0_EXT, + GL_TEXTURE_2D, tex, 0); + } + else { + glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, MyRB); + + glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, + GL_COLOR_ATTACHMENT0_EXT, + GL_RENDERBUFFER_EXT, MyRB); + + glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGB, Width, Height); + } + + status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); + if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { + fprintf(stderr, "Framebuffer object is incomplete (0x%x)!\n", status); + } + + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); +} + + +static void +Reshape(int width, int height) +{ + glViewport(0, 0, width, height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); + glMatrixMode(GL_MODELVIEW); + + Width = width; + Height = height; + if (!UseTex) { + glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGB, Width, Height); + } +} + + +static void +Key(unsigned char key, int x, int y) +{ + if (key == 27) { + exit(0); + } + glutPostRedisplay(); +} + + +static void +Draw(void) +{ + GLboolean scissor = GL_TRUE; + + /* draw to user framebuffer */ + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, MyFB); + glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT); + glReadBuffer(GL_COLOR_ATTACHMENT0_EXT); + + glViewport(0, 0, Width, Height); + CheckError(); + + if (scissor) { + glEnable(GL_SCISSOR_TEST); + + /* lower-left = red */ + glClearColor(1, 0, 0, 0); + glScissor(0, 0, Width / 2, Height / 2); + glClear(GL_COLOR_BUFFER_BIT); + + /* lower-right = green */ + glClearColor(0, 1, 0, 0); + glScissor(Width / 2, 0, Width - Width / 2, Height / 2); + glClear(GL_COLOR_BUFFER_BIT); + + /* upper-left = blue */ + glClearColor(0, 0, 1, 0); + glScissor(0, Height / 2, Width / 2, Height - Height / 2); + glClear(GL_COLOR_BUFFER_BIT); + + /* upper-right = white */ + glClearColor(1, 1, 1, 0); + glScissor(Width / 2, Height / 2, Width - Width / 2, Height - Height / 2); + glClear(GL_COLOR_BUFFER_BIT); + + glDisable(GL_SCISSOR_TEST); + } + else { + glClearColor(0, 1, 0, 0); + glClear(GL_COLOR_BUFFER_BIT); + } + + CheckError(); + + /* gray triangle in middle, pointing up */ + glColor3f(0.5, 0.5, 0.5); + glBegin(GL_TRIANGLES); + glVertex2f(Width/4, Height/4); + glVertex2f(Width*3/4, Height/4); + glVertex2f(Width/2, Height*3/4); + glVertex2f(-0.5, -0.5); + glVertex2f(+0.5, -0.5); + glVertex2f( 0.0, 0.7); + glEnd(); + + CheckError(); + + /* copy fbo to window */ + glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, MyFB); + glReadBuffer(GL_COLOR_ATTACHMENT0_EXT); + glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0); + glDrawBuffer(GL_BACK); + + if (UseCopyPix) { + glWindowPos2i(0, 0); + glCopyPixels(0, 0, Width, Height, GL_COLOR); + } + else { + GLubyte *buffer = malloc(Width * Height * 4); + + /* read from user framebuffer */ + glReadPixels(0, 0, Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, buffer); + + /* draw to window */ + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); + glWindowPos2iARB(0, 0); + glDrawPixels(Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, buffer); + + free(buffer); + } + + /* Bind normal framebuffer */ + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); + + glutSwapBuffers(); + + CheckError(); +} + + +int +main(int argc, char *argv[]) +{ + int i; + + glutInit(&argc, argv); + glutInitWindowPosition(100, 0); + glutInitWindowSize(Width, Height); + glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-t") == 0) + UseTex = GL_TRUE; + else if (strcmp(argv[i], "-c") == 0) + UseCopyPix = GL_TRUE; + } + + if (UseTex) + printf("Using render to texture\n"); + else + printf("Using user-created render buffer\n"); + + if (!glutCreateWindow(argv[0])) { + exit(1); + } + + glewInit(); + Init(); + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutDisplayFunc(Draw); + glutMainLoop(); + return 0; +} diff --git a/progs/trivial/tri-stencil.c b/progs/trivial/tri-stencil.c index 9f68bca914..d66b68c415 100644 --- a/progs/trivial/tri-stencil.c +++ b/progs/trivial/tri-stencil.c @@ -77,6 +77,7 @@ static void Draw(void) glStencilFunc(GL_ALWAYS, 1, 1); glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); + /* red triangle (setting stencil to 1) */ glColor3ub(200, 0, 0); glBegin(GL_POLYGON); glVertex3i(-4, -4, 0); @@ -88,6 +89,7 @@ static void Draw(void) glStencilFunc(GL_EQUAL, 1, 1); glStencilOp(GL_INCR, GL_KEEP, GL_DECR); + /* green quad (if over red, decr stencil to 0, else incr to 1) */ glColor3ub(0, 200, 0); glBegin(GL_POLYGON); glVertex3i(3, 3, 0); @@ -101,6 +103,7 @@ static void Draw(void) glStencilFunc(GL_EQUAL, 1, 1); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); + /* blue quad (where stencil == 1) */ glColor3ub(0, 0, 200); glBegin(GL_POLYGON); glVertex3f(2.5, 2.5, 0); diff --git a/progs/xdemos/Makefile b/progs/xdemos/Makefile index d81caab4dd..2663015b2c 100644 --- a/progs/xdemos/Makefile +++ b/progs/xdemos/Makefile @@ -9,9 +9,9 @@ INCDIR = $(TOP)/include LIB_DEP = $(TOP)/$(LIB_DIR)/$(GL_LIB_NAME) # Add X11 and pthread libs to satisfy GNU gold. -APP_LIB_DEPS += -lX11 -lpthread +APP_LIB_DEPS += $(X11_LIBS) -lpthread -LIBS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) -L$(libdir) $(APP_LIB_DEPS) +LIBS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) $(APP_LIB_DEPS) PROGS = \ corender \ diff --git a/progs/xdemos/omlsync.c b/progs/xdemos/omlsync.c index a2baf4ad72..061d6c6861 100644 --- a/progs/xdemos/omlsync.c +++ b/progs/xdemos/omlsync.c @@ -249,11 +249,13 @@ int main(int argc, char *argv[]) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glRectf(0, 0, width, height); - glXSwapBuffersMscOML(disp, winGL, 0, divisor, remainder); - - if (wait_interval) { + if (!wait_interval) + glXSwapBuffersMscOML(disp, winGL, 0, divisor, + remainder); + else { glXWaitForMscOML(disp, winGL, msc + wait_interval, - 0, 0, &ust, &msc, &sbc); + divisor, remainder, &ust, &msc, &sbc); + glXSwapBuffersMscOML(disp, winGL, 0, 0, 0); } } |