diff options
Diffstat (limited to 'progs')
-rw-r--r-- | progs/SConscript | 1 | ||||
-rw-r--r-- | progs/egl/egltri.c | 264 | ||||
-rw-r--r-- | progs/egl/eglut/Makefile | 35 | ||||
-rw-r--r-- | progs/egl/eglut/eglut.c | 346 | ||||
-rw-r--r-- | progs/egl/eglut/eglut.h | 68 | ||||
-rw-r--r-- | progs/egl/eglut/eglut_screen.c | 154 | ||||
-rw-r--r-- | progs/egl/eglut/eglut_x11.c | 220 | ||||
-rw-r--r-- | progs/egl/eglut/eglutint.h | 78 | ||||
-rw-r--r-- | progs/egl/opengl/.gitignore (renamed from progs/egl/.gitignore) | 7 | ||||
-rw-r--r-- | progs/egl/opengl/Makefile (renamed from progs/egl/Makefile) | 47 | ||||
-rw-r--r-- | progs/egl/opengl/demo1.c (renamed from progs/egl/demo1.c) | 0 | ||||
-rw-r--r-- | progs/egl/opengl/demo2.c (renamed from progs/egl/demo2.c) | 0 | ||||
-rw-r--r-- | progs/egl/opengl/demo3.c (renamed from progs/egl/demo3.c) | 0 | ||||
-rw-r--r-- | progs/egl/opengl/eglgears.c (renamed from progs/egl/eglgears.c) | 241 | ||||
-rw-r--r-- | progs/egl/opengl/eglinfo.c (renamed from progs/egl/eglinfo.c) | 0 | ||||
-rw-r--r-- | progs/egl/opengl/eglscreen.c (renamed from progs/egl/eglscreen.c) | 0 | ||||
-rw-r--r-- | progs/egl/opengl/egltri.c (renamed from progs/es1/screen/tri.c) | 138 | ||||
-rw-r--r-- | progs/egl/opengl/peglgears.c (renamed from progs/egl/peglgears.c) | 0 | ||||
-rw-r--r-- | progs/egl/opengl/xeglgears.c (renamed from progs/egl/xeglgears.c) | 0 | ||||
-rw-r--r-- | progs/egl/opengl/xeglthreads.c (renamed from progs/egl/xeglthreads.c) | 0 | ||||
-rw-r--r-- | progs/egl/opengles1/.gitignore | 15 | ||||
-rw-r--r-- | progs/egl/opengles1/Makefile | 102 | ||||
-rw-r--r-- | progs/egl/opengles1/bindtex.c (renamed from progs/es1/xegl/bindtex.c) | 0 | ||||
-rw-r--r-- | progs/egl/opengles1/drawtex.c | 217 | ||||
-rw-r--r-- | progs/egl/opengles1/es1_info.c (renamed from progs/es1/xegl/es1_info.c) | 0 | ||||
-rw-r--r-- | progs/egl/opengles1/gears.c (renamed from progs/es1/screen/gears.c) | 43 | ||||
-rw-r--r-- | progs/egl/opengles1/msaa.c (renamed from progs/es1/xegl/msaa.c) | 0 | ||||
-rw-r--r-- | progs/egl/opengles1/pbuffer.c (renamed from progs/es1/xegl/pbuffer.c) | 3 | ||||
-rw-r--r-- | progs/egl/opengles1/render_tex.c (renamed from progs/es1/xegl/render_tex.c) | 0 | ||||
-rw-r--r-- | progs/egl/opengles1/texture_from_pixmap.c | 578 | ||||
-rw-r--r-- | progs/egl/opengles1/torus.c (renamed from progs/es1/xegl/torus.c) | 328 | ||||
-rw-r--r-- | progs/egl/opengles1/tri.c | 211 | ||||
-rw-r--r-- | progs/egl/opengles1/two_win.c (renamed from progs/es1/xegl/two_win.c) | 0 | ||||
-rw-r--r-- | progs/egl/opengles2/.gitignore | 3 | ||||
-rw-r--r-- | progs/egl/opengles2/Makefile (renamed from progs/es2/xegl/Makefile) | 4 | ||||
-rw-r--r-- | progs/egl/opengles2/tri.c (renamed from progs/es2/xegl/tri.c) | 0 | ||||
-rw-r--r-- | progs/egl/openvg/.gitignore (renamed from progs/openvg/.gitignore) | 6 | ||||
-rw-r--r-- | progs/egl/openvg/Makefile | 55 | ||||
-rw-r--r-- | progs/egl/openvg/lion-render.c (renamed from progs/openvg/demos/lion-render.c) | 0 | ||||
-rw-r--r-- | progs/egl/openvg/lion-render.h (renamed from progs/openvg/demos/lion-render.h) | 0 | ||||
-rw-r--r-- | progs/egl/openvg/lion.c | 65 | ||||
-rw-r--r-- | progs/egl/openvg/sp.c (renamed from progs/openvg/demos/sp.c) | 47 | ||||
-rw-r--r-- | progs/egl/openvg/trivial/Makefile (renamed from progs/openvg/trivial/Makefile) | 3 | ||||
-rw-r--r-- | progs/egl/openvg/trivial/arc.c (renamed from progs/openvg/trivial/arc.c) | 0 | ||||
-rw-r--r-- | progs/egl/openvg/trivial/cap.c (renamed from progs/openvg/trivial/cap.c) | 0 | ||||
-rw-r--r-- | progs/egl/openvg/trivial/clear.c (renamed from progs/openvg/trivial/clear.c) | 0 | ||||
-rw-r--r-- | progs/egl/openvg/trivial/coord.c (renamed from progs/openvg/trivial/coord.c) | 0 | ||||
-rw-r--r-- | progs/egl/openvg/trivial/dash.c (renamed from progs/openvg/trivial/dash.c) | 0 | ||||
-rw-r--r-- | progs/egl/openvg/trivial/eglcommon.c (renamed from progs/openvg/demos/eglcommon.c) | 0 | ||||
-rw-r--r-- | progs/egl/openvg/trivial/eglcommon.h (renamed from progs/openvg/demos/eglcommon.h) | 0 | ||||
-rw-r--r-- | progs/egl/openvg/trivial/ellipse.c (renamed from progs/openvg/trivial/ellipse.c) | 0 | ||||
-rw-r--r-- | progs/egl/openvg/trivial/filter.c (renamed from progs/openvg/trivial/filter.c) | 0 | ||||
-rw-r--r-- | progs/egl/openvg/trivial/gradorigin.c (renamed from progs/openvg/trivial/gradorigin.c) | 0 | ||||
-rw-r--r-- | progs/egl/openvg/trivial/lineto.c (renamed from progs/openvg/trivial/lineto.c) | 0 | ||||
-rw-r--r-- | progs/egl/openvg/trivial/lingrad.c (renamed from progs/openvg/trivial/lingrad.c) | 0 | ||||
-rw-r--r-- | progs/egl/openvg/trivial/lookup.c (renamed from progs/openvg/trivial/lookup.c) | 0 | ||||
-rw-r--r-- | progs/egl/openvg/trivial/mask.c (renamed from progs/openvg/trivial/mask.c) | 0 | ||||
-rw-r--r-- | progs/egl/openvg/trivial/mask4.c (renamed from progs/openvg/trivial/mask4.c) | 0 | ||||
-rw-r--r-- | progs/egl/openvg/trivial/path3.c (renamed from progs/openvg/trivial/path3.c) | 0 | ||||
-rw-r--r-- | progs/egl/openvg/trivial/radialgrad.c (renamed from progs/openvg/trivial/radialgrad.c) | 0 | ||||
-rw-r--r-- | progs/egl/openvg/trivial/readpixels.c (renamed from progs/openvg/trivial/readpixels.c) | 0 | ||||
-rw-r--r-- | progs/egl/openvg/trivial/roundedrect.c (renamed from progs/openvg/trivial/roundedrect.c) | 0 | ||||
-rw-r--r-- | progs/egl/openvg/trivial/star-nonzero.c (renamed from progs/openvg/trivial/star-nonzero.c) | 0 | ||||
-rw-r--r-- | progs/egl/openvg/trivial/star-oddeven.c (renamed from progs/openvg/trivial/star-oddeven.c) | 0 | ||||
-rw-r--r-- | progs/egl/openvg/trivial/stroke.c (renamed from progs/openvg/trivial/stroke.c) | 0 | ||||
-rw-r--r-- | progs/egl/openvg/trivial/stroke2.c (renamed from progs/openvg/trivial/stroke2.c) | 0 | ||||
-rw-r--r-- | progs/egl/openvg/trivial/vguarc.c (renamed from progs/openvg/trivial/vguarc.c) | 0 | ||||
-rw-r--r-- | progs/egl/xegl_tri.c | 361 | ||||
-rw-r--r-- | progs/es1/.gitignore | 11 | ||||
-rw-r--r-- | progs/es1/screen/Makefile | 32 | ||||
-rw-r--r-- | progs/es1/screen/winsys.c | 272 | ||||
-rw-r--r-- | progs/es1/screen/winsys.h | 36 | ||||
-rw-r--r-- | progs/es1/xegl/Makefile | 82 | ||||
-rw-r--r-- | progs/es1/xegl/drawtex.c | 427 | ||||
-rw-r--r-- | progs/es1/xegl/tri.c | 470 | ||||
-rw-r--r-- | progs/es2/.gitignore | 3 | ||||
-rwxr-xr-x | progs/gallium/python/tests/base.py | 74 | ||||
-rwxr-xr-x | progs/gallium/python/tests/surface_copy.py | 116 | ||||
-rwxr-xr-x | progs/gallium/python/tests/texture_blit.py | 9 | ||||
-rwxr-xr-x | progs/gallium/python/tests/texture_render.py | 4 | ||||
-rwxr-xr-x | progs/gallium/python/tests/texture_transfer.py | 109 | ||||
-rw-r--r-- | progs/gallium/unit/Makefile | 44 | ||||
-rw-r--r-- | progs/gallium/unit/SConscript | 5 | ||||
-rw-r--r-- | progs/gallium/unit/u_format_test.c | 267 | ||||
-rw-r--r-- | progs/gallium/unit/u_half_test.c | 32 | ||||
-rw-r--r-- | progs/openvg/demos/Makefile | 39 | ||||
-rw-r--r-- | progs/openvg/demos/lion.c | 289 | ||||
-rw-r--r-- | progs/openvg/trivial/eglcommon.c | 289 | ||||
-rw-r--r-- | progs/openvg/trivial/eglcommon.h | 20 | ||||
-rw-r--r-- | progs/xdemos/Makefile | 45 |
90 files changed, 2879 insertions, 3436 deletions
diff --git a/progs/SConscript b/progs/SConscript index a90e13b4cb..4cd35fec64 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 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/Makefile b/progs/egl/opengl/Makefile index 890240f9a3..9a91df9906 100644 --- a/progs/egl/Makefile +++ b/progs/egl/opengl/Makefile @@ -1,6 +1,6 @@ # progs/egl/Makefile -TOP = ../.. +TOP = ../../.. include $(TOP)/configs/current @@ -9,28 +9,34 @@ 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 +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 \ - egltri \ eglinfo \ - eglgears \ eglscreen \ peglgears \ xeglgears \ - xeglthreads \ - xegl_tri + xeglthreads .c.o: - $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $< -o $@ + $(CC) -c $(INCLUDE_DIRS) -I$(EGLUT_DIR) $(CFLAGS) $< -o $@ -default: $(PROGRAMS) +default: $(PROGRAMS) $(EGLUT_X11_DEMOS) $(EGLUT_SCREEN_DEMOS) demo1: demo1.o $(HEADERS) $(LIB_DEP) $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB) @@ -41,15 +47,9 @@ demo2: demo2.o $(HEADERS) $(LIB_DEP) 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) @@ -62,9 +62,22 @@ xeglgears: xeglgears.o $(HEADERS) $(LIB_DEP) xeglthreads: xeglthreads.o $(HEADERS) $(LIB_DEP) $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lpthread -lm $(X11_LIBS) -xegl_tri: xegl_tri.o $(HEADERS) $(LIB_DEP) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -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) + -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..79b9474a57 --- /dev/null +++ b/progs/egl/opengles1/texture_from_pixmap.c @@ -0,0 +1,578 @@ +/* + * 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 + * 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. + * + * 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..5a10cc8055 --- /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 +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/gallium/python/tests/base.py b/progs/gallium/python/tests/base.py index 8c55e3ae5d..d8cf84db36 100755 --- a/progs/gallium/python/tests/base.py +++ b/progs/gallium/python/tests/base.py @@ -116,7 +116,7 @@ class Test: def run(self): result = TestResult() self._run(result) - result.summary() + result.report() def assert_rgba(self, ctx, surface, x, y, w, h, expected_rgba, pixel_tol=4.0/256, surface_tol=0.85): total = h*w @@ -250,7 +250,7 @@ class TestResult: sys.stdout.write("SKIP\n") sys.stdout.flush() self.skipped += 1 - #self.log_result(test, 'skip') + self.log_result(test, 'skip') def test_failed(self, test): sys.stdout.write("FAIL\n") @@ -296,11 +296,16 @@ class TestResult: self.rows.append(row) - def summary(self): + def report(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])) + + tree = self.report_tree(name) + self.report_junit(name, stdout=tree) + + def report_tree(self, name): filename = name + '.tsv' stream = file(filename, 'wt') @@ -311,6 +316,8 @@ class TestResult: # rows for row in self.rows: + if row[0] == 'skip': + continue row += ['']*(len(self.names) - len(row)) stream.write('\t'.join(row) + '\n') @@ -322,7 +329,7 @@ class TestResult: import orngTree except ImportError: sys.stderr.write('Install Orange from http://www.ailab.si/orange/ for a classification tree.\n') - return + return None data = orange.ExampleTable(filename) @@ -330,6 +337,63 @@ class TestResult: orngTree.printTxt(tree, maxDepth=4) - file(name+'.txt', 'wt').write(orngTree.dumpTree(tree)) + text_tree = orngTree.dumpTree(tree) + + file(name + '.txt', 'wt').write(text_tree) orngTree.printDot(tree, fileName=name+'.dot', nodeShape='ellipse', leafShape='box') + + return text_tree + + def report_junit(self, name, stdout=None, stderr=None): + """Write test results in ANT's junit XML format, to use with Hudson CI. + + See also: + - http://fisheye.hudson-ci.org/browse/Hudson/trunk/hudson/main/core/src/test/resources/hudson/tasks/junit + - http://www.junit.org/node/399 + - http://wiki.apache.org/ant/Proposals/EnhancedTestReports + """ + + stream = file(name + '.xml', 'wt') + + stream.write('<?xml version="1.0" encoding="UTF-8" ?>\n') + stream.write('<testsuite name="%s">\n' % self.escape_xml(name)) + stream.write(' <properties>\n') + stream.write(' </properties>\n') + + names = self.names[1:] + + for row in self.rows: + + test_name = ' '.join(['%s=%s' % pair for pair in zip(self.names[1:], row[1:])]) + + stream.write(' <testcase name="%s">\n' % (self.escape_xml(test_name))) + + result = row[0] + if result == 'pass': + pass + elif result == 'skip': + stream.write(' <skipped/>\n') + else: + stream.write(' <failure/>\n') + + stream.write(' </testcase>\n') + + if stdout: + stream.write(' <system-out>%s</system-out>\n' % self.escape_xml(stdout)) + if stderr: + stream.write(' <system-err>%s</system-err>\n' % self.escape_xml(stderr)) + + stream.write('</testsuite>\n') + + stream.close() + + def escape_xml(self, s): + '''Escape a XML string.''' + s = s.replace('&', '&') + s = s.replace('<', '<') + s = s.replace('>', '>') + s = s.replace('"', '"') + s = s.replace("'", ''') + return s + diff --git a/progs/gallium/python/tests/surface_copy.py b/progs/gallium/python/tests/surface_copy.py index 9364fd1110..3eefa690bd 100755 --- a/progs/gallium/python/tests/surface_copy.py +++ b/progs/gallium/python/tests/surface_copy.py @@ -27,6 +27,9 @@ ########################################################################## +import os +import random + from gallium import * from base import * @@ -68,6 +71,14 @@ class TextureTest(TestCase): level = self.level zslice = self.zslice + tex_usage = PIPE_TEXTURE_USAGE_SAMPLER + geom_flags = 0 + if not dev.is_format_supported(format, target, tex_usage, geom_flags): + raise TestSkip + + if not dev.is_format_supported(format, target, tex_usage, geom_flags): + raise TestSkip + # textures dst_texture = dev.texture_create( target = target, @@ -76,10 +87,8 @@ class TextureTest(TestCase): height = height, depth = depth, last_level = last_level, - tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET, + tex_usage = tex_usage, ) - if dst_texture is None: - raise TestSkip dst_surface = dst_texture.get_surface(face = face, level = level, zslice = zslice) @@ -95,8 +104,6 @@ class TextureTest(TestCase): src_surface = src_texture.get_surface() - x = 0 - y = 0 w = dst_surface.width h = dst_surface.height @@ -113,7 +120,6 @@ class TextureTest(TestCase): if dst_raw != src_raw: raise TestFailure - def main(): @@ -124,27 +130,7 @@ def main(): 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, + PIPE_TEXTURE_3D, ] sizes = [64, 32, 16, 8, 4, 2, 1] @@ -161,36 +147,52 @@ def main(): 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, - ctx = ctx, - 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 + try: + n = int(sys.argv[1]) + except: + n = 10000 + + for i in range(n): + format = random.choice(formats.keys()) + if not util_format_is_depth_or_stencil(format): + is_depth_or_stencil = util_format_is_depth_or_stencil(format) + + if is_depth_or_stencil: + target = PIPE_TEXTURE_2D + else: + target = random.choice(targets) + + size = random.choice(sizes) + + if target == PIPE_TEXTURE_3D: + depth = size + else: + depth = 1 + + if target == PIPE_TEXTURE_CUBE: + face = random.choice(faces) + else: + face = PIPE_TEX_FACE_POS_X + + levels = lods(size) + last_level = random.randint(0, levels - 1) + level = random.randint(0, last_level) + zslice = random.randint(0, max(depth >> level, 1) - 1) + + test = TextureTest( + dev = dev, + ctx = ctx, + 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() diff --git a/progs/gallium/python/tests/texture_blit.py b/progs/gallium/python/tests/texture_blit.py index 5ae0a7398d..a68c081931 100755 --- a/progs/gallium/python/tests/texture_blit.py +++ b/progs/gallium/python/tests/texture_blit.py @@ -191,7 +191,7 @@ class TextureColorSampleTest(TestCase): zslice = zslice, ) - ctx.surface_sample_rgba(surface, expected_rgba) + ctx.surface_sample_rgba(surface, expected_rgba, True) ctx.set_fragment_sampler_texture(0, texture) @@ -428,7 +428,7 @@ class TextureDepthSampleTest(TestCase): zslice = zslice, ) - ctx.surface_sample_rgba(surface, expected_rgba) + ctx.surface_sample_rgba(surface, expected_rgba, True) ctx.set_fragment_sampler_texture(0, texture) @@ -555,6 +555,7 @@ def main(): random.seed(0xdead3eef) dev = Device() + ctx = dev.context_create() suite = TestSuite() targets = [ @@ -577,8 +578,6 @@ def main(): PIPE_TEX_FACE_NEG_Z, ] - ctx = dev.context_create() - try: n = int(sys.argv[1]) except: @@ -602,7 +601,7 @@ def main(): depth = 1 if target == PIPE_TEXTURE_CUBE: - face =random.choice(faces) + face = random.choice(faces) else: face = PIPE_TEX_FACE_POS_X diff --git a/progs/gallium/python/tests/texture_render.py b/progs/gallium/python/tests/texture_render.py index 1e26639db6..12def7ec72 100755 --- a/progs/gallium/python/tests/texture_render.py +++ b/progs/gallium/python/tests/texture_render.py @@ -258,10 +258,10 @@ def main(): PIPE_FORMAT_B5G5R5A1_UNORM, PIPE_FORMAT_B4G4R4A4_UNORM, #PIPE_FORMAT_Z32_UNORM, - #PIPE_FORMAT_S8Z24_UNORM, + #PIPE_FORMAT_S8_USCALED_Z24_UNORM, #PIPE_FORMAT_X8Z24_UNORM, #PIPE_FORMAT_Z16_UNORM, - #PIPE_FORMAT_S8_UNORM, + #PIPE_FORMAT_S8_USCALED, PIPE_FORMAT_A8_UNORM, PIPE_FORMAT_L8_UNORM, #PIPE_FORMAT_DXT1_RGB, diff --git a/progs/gallium/python/tests/texture_transfer.py b/progs/gallium/python/tests/texture_transfer.py index 97a28e01a4..639d3d362c 100755 --- a/progs/gallium/python/tests/texture_transfer.py +++ b/progs/gallium/python/tests/texture_transfer.py @@ -29,6 +29,7 @@ import os +import random from gallium import * from base import * @@ -71,8 +72,12 @@ class TextureTest(TestCase): level = self.level zslice = self.zslice - tex_usage = 0 + tex_usage = PIPE_TEXTURE_USAGE_SAMPLER + geom_flags = 0 + if not dev.is_format_supported(format, target, tex_usage, geom_flags): + raise TestSkip + # textures texture = dev.texture_create( target = target, format = format, @@ -82,13 +87,11 @@ class TextureTest(TestCase): last_level = last_level, tex_usage = tex_usage, ) - if texture is None: - raise TestSkip surface = texture.get_surface(face, level, zslice) - stride = util_format_get_stride(format, width) - size = util_format_get_nblocksy(format, height) * stride + stride = util_format_get_stride(format, surface.width) + size = util_format_get_nblocksy(format, surface.height) * stride in_raw = os.urandom(size) @@ -111,26 +114,6 @@ def main(): 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] @@ -145,36 +128,52 @@ def main(): 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, - ctx = ctx, - 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 + try: + n = int(sys.argv[1]) + except: + n = 10000 + + for i in range(n): + format = random.choice(formats.keys()) + if not util_format_is_depth_or_stencil(format): + is_depth_or_stencil = util_format_is_depth_or_stencil(format) + + if is_depth_or_stencil: + target = PIPE_TEXTURE_2D + else: + target = random.choice(targets) + + size = random.choice(sizes) + + if target == PIPE_TEXTURE_3D: + depth = size + else: + depth = 1 + + if target == PIPE_TEXTURE_CUBE: + face = random.choice(faces) + else: + face = PIPE_TEX_FACE_POS_X + + levels = lods(size) + last_level = random.randint(0, levels - 1) + level = random.randint(0, last_level) + zslice = random.randint(0, max(depth >> level, 1) - 1) + + test = TextureTest( + dev = dev, + ctx = ctx, + 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() diff --git a/progs/gallium/unit/Makefile b/progs/gallium/unit/Makefile new file mode 100644 index 0000000000..f3dbd7695c --- /dev/null +++ b/progs/gallium/unit/Makefile @@ -0,0 +1,44 @@ +# progs/gallium/simple/Makefile + +TOP = ../../.. +include $(TOP)/configs/current + +INCLUDES = \ + -I. \ + -I$(TOP)/src/gallium/include \ + -I$(TOP)/src/gallium/auxiliary \ + -I$(TOP)/src/gallium/drivers \ + -I$(TOP)/src/gallium/winsys \ + $(PROG_INCLUDES) + +LINKS = \ + $(TOP)/src/gallium/drivers/trace/libtrace.a \ + $(TOP)/src/gallium/winsys/sw/null/libws_null.a \ + $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ + $(GALLIUM_AUXILIARIES) \ + $(PROG_LINKS) + +SOURCES = \ + u_format_test.c \ + u_half_test.c + +OBJECTS = $(SOURCES:.c=.o) + +PROGS = $(OBJECTS:.o=) + +##### TARGETS ##### + +default: $(PROGS) + +clean: + -rm -f $(PROGS) + -rm -f *.o + -rm -f result.bmp + +##### RULES ##### + +$(OBJECTS): %.o: %.c + $(CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) $(PROG_DEFINES) $< -o $@ + +$(PROGS): %: %.o + $(CC) $(LDFLAGS) $< $(LINKS) -lm -lpthread -ldl -o $@ diff --git a/progs/gallium/unit/SConscript b/progs/gallium/unit/SConscript index 9891440df6..0db3bb687c 100644 --- a/progs/gallium/unit/SConscript +++ b/progs/gallium/unit/SConscript @@ -5,7 +5,8 @@ env = env.Clone() env.Prepend(LIBS = [gallium]) progs = [ - 'u_format_test' + 'u_format_test', + 'u_half_test' ] for prog in progs: @@ -13,6 +14,8 @@ for prog in progs: target = prog, source = prog + '.c', ) + + env.InstallProgram(prog) # http://www.scons.org/wiki/UnitTests test_alias = env.Alias('unit', [prog], prog[0].abspath) diff --git a/progs/gallium/unit/u_format_test.c b/progs/gallium/unit/u_format_test.c index 54cb6b879e..53e028482b 100644 --- a/progs/gallium/unit/u_format_test.c +++ b/progs/gallium/unit/u_format_test.c @@ -28,36 +28,133 @@ #include <stdlib.h> #include <stdio.h> +#include <float.h> +#include "util/u_half.h" #include "util/u_format.h" #include "util/u_format_tests.h" +#include "util/u_format_s3tc.h" static boolean -test_format_fetch_float(const struct util_format_description *format_desc, - const struct util_format_test_case *test) +compare_float(float x, float y) +{ + float error = y - x; + + if (error < 0.0f) + error = -error; + + if (error > FLT_EPSILON) { + return FALSE; + } + + return TRUE; +} + + +static void +print_packed(const struct util_format_description *format_desc, + const char *prefix, + const uint8_t *packed, + const char *suffix) { - float unpacked[4]; unsigned i; - boolean success; + const char *sep = ""; + + printf("%s", prefix); + for (i = 0; i < format_desc->block.bits/8; ++i) { + printf("%s%02x", sep, packed[i]); + sep = " "; + } + printf("%s", suffix); +} + + +static void +print_unpacked_doubl(const struct util_format_description *format_desc, + const char *prefix, + const double unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4], + const char *suffix) +{ + unsigned i, j; + const char *sep = ""; + + printf("%s", prefix); + for (i = 0; i < format_desc->block.height; ++i) { + for (j = 0; j < format_desc->block.width; ++j) { + printf("%s{%f, %f, %f, %f}", sep, unpacked[i][j][0], unpacked[i][j][1], unpacked[i][j][2], unpacked[i][j][3]); + sep = ", "; + } + sep = ",\n"; + } + printf("%s", suffix); +} - /* - * TODO: test block formats too. - */ - if (format_desc->block.width != 1 && format_desc->block.height != 1) { - return TRUE; + +static void +print_unpacked_float(const struct util_format_description *format_desc, + const char *prefix, + const float unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4], + const char *suffix) +{ + unsigned i, j; + const char *sep = ""; + + printf("%s", prefix); + for (i = 0; i < format_desc->block.height; ++i) { + for (j = 0; j < format_desc->block.width; ++j) { + printf("%s{%f, %f, %f, %f}", sep, unpacked[i][j][0], unpacked[i][j][1], unpacked[i][j][2], unpacked[i][j][3]); + sep = ", "; + } + sep = ",\n"; } + printf("%s", suffix); +} - format_desc->fetch_float(unpacked, test->packed, 0, 0); + +static void +print_unpacked_8unorm(const struct util_format_description *format_desc, + const char *prefix, + const uint8_t unpacked[][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4], + const char *suffix) +{ + unsigned i, j; + const char *sep = ""; + + printf("%s", prefix); + for (i = 0; i < format_desc->block.height; ++i) { + for (j = 0; j < format_desc->block.width; ++j) { + printf("%s{0x%02x, 0x%02x, 0x%02x, 0x%02x}", sep, unpacked[i][j][0], unpacked[i][j][1], unpacked[i][j][2], unpacked[i][j][3]); + sep = ", "; + } + } + printf("%s", suffix); +} + + +static boolean +test_format_fetch_float(const struct util_format_description *format_desc, + const struct util_format_test_case *test) +{ + float unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4] = { { { 0 } } }; + unsigned i, j, k; + boolean success; success = TRUE; - for (i = 0; i < 4; ++i) - if (test->unpacked[i] != unpacked[i]) - success = FALSE; + for (i = 0; i < format_desc->block.height; ++i) { + for (j = 0; j < format_desc->block.width; ++j) { + format_desc->fetch_float(unpacked[i][j], test->packed, j, i); + for (k = 0; k < 4; ++k) { + if (!compare_float(test->unpacked[i][j][k], unpacked[i][j][k])) { + 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]); + print_unpacked_float(format_desc, "FAILED: ", unpacked, " obtained\n"); + print_unpacked_doubl(format_desc, " ", test->unpacked, " expected\n"); } return success; @@ -68,20 +165,26 @@ static boolean test_format_unpack_float(const struct util_format_description *format_desc, const struct util_format_test_case *test) { - float unpacked[4]; - unsigned i; + float unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4] = { { { 0 } } }; + unsigned i, j, k; boolean success; - format_desc->unpack_float(unpacked, 0, test->packed, 0, 1, 1); + format_desc->unpack_float(&unpacked[0][0][0], sizeof unpacked[0], test->packed, 0, format_desc->block.width, format_desc->block.height); success = TRUE; - for (i = 0; i < 4; ++i) - if (test->unpacked[i] != unpacked[i]) - success = FALSE; + for (i = 0; i < format_desc->block.height; ++i) { + for (j = 0; j < format_desc->block.width; ++j) { + for (k = 0; k < 4; ++k) { + if (!compare_float(test->unpacked[i][j][k], unpacked[i][j][k])) { + 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]); + print_unpacked_float(format_desc, "FAILED: ", unpacked, " obtained\n"); + print_unpacked_doubl(format_desc, " ", test->unpacked, " expected\n"); } return success; @@ -89,38 +192,43 @@ test_format_unpack_float(const struct util_format_description *format_desc, static boolean + test_format_pack_float(const struct util_format_description *format_desc, const struct util_format_test_case *test) { - float unpacked[4]; + float unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4]; uint8_t packed[UTIL_FORMAT_MAX_PACKED_BYTES]; - unsigned i; + unsigned i, j, k; boolean success; - memset(packed, 0, sizeof packed); + if (test->format == PIPE_FORMAT_DXT1_RGBA) { + /* + * Skip S3TC as packed representation is not canonical. + * + * TODO: Do a round trip conversion. + */ + return TRUE; + } - for (i = 0; i < 4; ++i) - unpacked[i] = (float) test->unpacked[i]; + memset(packed, 0, sizeof packed); + for (i = 0; i < format_desc->block.height; ++i) { + for (j = 0; j < format_desc->block.width; ++j) { + for (k = 0; k < 4; ++k) { + unpacked[i][j][k] = (float) test->unpacked[i][j][k]; + } + } + } - format_desc->pack_float(packed, 0, unpacked, 0, 1, 1); + format_desc->pack_float(packed, 0, &unpacked[0][0][0], sizeof unpacked[0], format_desc->block.width, format_desc->block.height); success = TRUE; - for (i = 0; i < UTIL_FORMAT_MAX_PACKED_BYTES; ++i) + for (i = 0; i < format_desc->block.bits/8; ++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]); + print_packed(format_desc, "FAILED: ", packed, " obtained\n"); + print_packed(format_desc, " ", test->packed, " expected\n"); } return success; @@ -133,7 +241,7 @@ convert_float_to_8unorm(uint8_t *dst, const double *src) unsigned i; boolean accurate = TRUE; - for (i = 0; i < 4; ++i) { + for (i = 0; i < UTIL_FORMAT_MAX_UNPACKED_HEIGHT*UTIL_FORMAT_MAX_UNPACKED_WIDTH*4; ++i) { if (src[i] < 0.0) { accurate = FALSE; dst[i] = 0; @@ -155,23 +263,29 @@ static boolean test_format_unpack_8unorm(const struct util_format_description *format_desc, const struct util_format_test_case *test) { - uint8_t unpacked[4]; - uint8_t expected[4]; - unsigned i; + uint8_t unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4] = { { { 0 } } }; + uint8_t expected[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4] = { { { 0 } } }; + unsigned i, j, k; boolean success; - format_desc->unpack_8unorm(unpacked, 0, test->packed, 0, 1, 1); + format_desc->unpack_8unorm(&unpacked[0][0][0], sizeof unpacked[0], test->packed, 0, 1, 1); - convert_float_to_8unorm(expected, test->unpacked); + convert_float_to_8unorm(&expected[0][0][0], &test->unpacked[0][0][0]); success = TRUE; - for (i = 0; i < 4; ++i) - if (expected[i] != unpacked[i]) - success = FALSE; + for (i = 0; i < format_desc->block.height; ++i) { + for (j = 0; j < format_desc->block.width; ++j) { + for (k = 0; k < 4; ++k) { + if (expected[i][j][k] != unpacked[i][j][k]) { + 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]); + print_unpacked_8unorm(format_desc, "FAILED: ", unpacked, " obtained\n"); + print_unpacked_8unorm(format_desc, " ", expected, " expected\n"); } return success; @@ -182,12 +296,21 @@ static boolean test_format_pack_8unorm(const struct util_format_description *format_desc, const struct util_format_test_case *test) { - uint8_t unpacked[4]; + uint8_t unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4]; uint8_t packed[UTIL_FORMAT_MAX_PACKED_BYTES]; unsigned i; boolean success; - if (!convert_float_to_8unorm(unpacked, test->unpacked)) { + if (test->format == PIPE_FORMAT_DXT1_RGBA) { + /* + * Skip S3TC as packed representation is not canonical. + * + * TODO: Do a round trip conversion. + */ + return TRUE; + } + + if (!convert_float_to_8unorm(&unpacked[0][0][0], &test->unpacked[0][0][0])) { /* * Skip test cases which cannot be represented by four unorm bytes. */ @@ -196,25 +319,16 @@ test_format_pack_8unorm(const struct util_format_description *format_desc, memset(packed, 0, sizeof packed); - format_desc->pack_8unorm(packed, 0, unpacked, 0, 1, 1); + format_desc->pack_8unorm(packed, 0, &unpacked[0][0][0], sizeof unpacked[0], 1, 1); success = TRUE; - for (i = 0; i < UTIL_FORMAT_MAX_PACKED_BYTES; ++i) + for (i = 0; i < format_desc->block.bits/8; ++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]); + print_packed(format_desc, "FAILED: ", packed, " obtained\n"); + print_packed(format_desc, " ", test->packed, " expected\n"); } return success; @@ -236,15 +350,26 @@ test_one(test_func_t func, const char *suffix) for (i = 0; i < util_format_nr_test_cases; ++i) { const struct util_format_test_case *test = &util_format_test_cases[i]; const struct util_format_description *format_desc; + bool skip = FALSE; + format_desc = util_format_description(test->format); + if (format_desc->layout == UTIL_FORMAT_LAYOUT_S3TC && + !util_format_s3tc_enabled) { + skip = TRUE; + } + if (test->format != last_format) { - printf("Testing util_format_%s_%s ...\n", format_desc->short_name, suffix); + printf("%s util_format_%s_%s ...\n", + skip ? "Skipping" : "Testing", format_desc->short_name, suffix); last_format = test->format; } - if (!func(format_desc, &util_format_test_cases[i])) - success = FALSE; + if (!skip) { + if (!func(format_desc, &util_format_test_cases[i])) { + success = FALSE; + } + } } return success; @@ -279,6 +404,8 @@ int main(int argc, char **argv) { boolean success; + util_format_s3tc_init(); + success = test_all(); return success ? 0 : 1; diff --git a/progs/gallium/unit/u_half_test.c b/progs/gallium/unit/u_half_test.c new file mode 100644 index 0000000000..9e3392e6d6 --- /dev/null +++ b/progs/gallium/unit/u_half_test.c @@ -0,0 +1,32 @@ +#include <stdlib.h> +#include <stdio.h> +#include <float.h> + +#include "util/u_math.h" +#include "util/u_half.h" + +int +main(int argc, char **argv) +{ + unsigned i; + unsigned roundtrip_fails = 0; + for(i = 0; i < 1 << 16; ++i) + { + half h = (half) i; + union fi f; + half rh; + f.ui = util_half_to_floatui(h); + rh = util_floatui_to_half(f.ui); + if(h != rh) + { + printf("Roundtrip failed: %x -> %x = %f -> %x\n", h, f.ui, f.f, rh); + ++roundtrip_fails; + } + } + + if(roundtrip_fails) + printf("Failure! %u/65536 half floats failed a conversion to float and back.\n", roundtrip_fails); + else + printf("Success!\n"); + 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/xdemos/Makefile b/progs/xdemos/Makefile index 660c540657..2663015b2c 100644 --- a/progs/xdemos/Makefile +++ b/progs/xdemos/Makefile @@ -53,17 +53,18 @@ EXTRA_PROGS = \ ##### RULES ##### -.SUFFIXES: -.SUFFIXES: .c +.o: $(LIB_DEP) + $(APP_CC) $(CFLAGS) $(LDFLAGS) $< $(LIBS) -o $@ -.c: $(LIB_DEP) - $(APP_CC) -I$(INCDIR) $(X11_INCLUDES) $(CFLAGS) $(LDFLAGS) $< $(LIBS) -o $@ +.c.o: + $(APP_CC) -I$(INCDIR) $(X11_INCLUDES) $(CFLAGS) $< -c -o $@ ##### TARGETS ##### default: $(PROGS) +$(PROGS): $(PROGS:%=%.o) extra: $(EXTRA_PROGS) @@ -74,45 +75,29 @@ clean: # special cases +pbutil.o: pbutil.h +pbinfo.o: pbutil.h pbinfo: pbinfo.o pbutil.o $(APP_CC) $(CFLAGS) $(LDFLAGS) pbinfo.o pbutil.o $(LIBS) -o $@ +pbdemo.o: pbutil.h pbdemo: pbdemo.o pbutil.o $(APP_CC) $(CFLAGS) $(LDFLAGS) pbdemo.o pbutil.o $(LIBS) -o $@ -pbinfo.o: pbinfo.c pbutil.h - $(APP_CC) -c -I. -I$(INCDIR) $(X11_INCLUDES) $(CFLAGS) pbinfo.c - -pbdemo.o: pbdemo.c pbutil.h - $(APP_CC) -c -I. -I$(INCDIR) $(X11_INCLUDES) $(CFLAGS) pbdemo.c - -pbutil.o: pbutil.c pbutil.h - $(APP_CC) -c -I. -I$(INCDIR) $(X11_INCLUDES) $(CFLAGS) pbutil.c - +glxgears_fbconfig.o: pbutil.h glxgears_fbconfig: glxgears_fbconfig.o pbutil.o $(APP_CC) $(CFLAGS) $(LDFLAGS) glxgears_fbconfig.o pbutil.o $(LIBS) -o $@ -glxgears_fbconfig.o: glxgears_fbconfig.c pbutil.h - $(APP_CC) -I$(INCDIR) $(X11_INCLUDES) $(CFLAGS) -c -I. $(CFLAGS) glxgears_fbconfig.c - +xuserotfont.o: xuserotfont.h +xrotfontdemo.o: xuserotfont.h xrotfontdemo: xrotfontdemo.o xuserotfont.o $(APP_CC) $(CFLAGS) $(LDFLAGS) xrotfontdemo.o xuserotfont.o $(LIBS) -o $@ -xuserotfont.o: xuserotfont.c xuserotfont.h - $(APP_CC) -c -I. -I$(INCDIR) $(X11_INCLUDES) $(CFLAGS) xuserotfont.c - -xrotfontdemo.o: xrotfontdemo.c xuserotfont.h - $(APP_CC) -c -I. -I$(INCDIR) $(X11_INCLUDES) $(CFLAGS) xrotfontdemo.c - +ipc.o: ipc.h +corender.o: ipc.h corender: corender.o ipc.o $(APP_CC) $(CFLAGS) $(LDFLAGS) corender.o ipc.o $(LIBS) -o $@ -corender.o: corender.c ipc.h - $(APP_CC) -c -I. -I$(INCDIR) $(X11_INCLUDES) $(CFLAGS) corender.c - -ipc.o: ipc.c ipc.h - $(APP_CC) -c -I. -I$(INCDIR) $(X11_INCLUDES) $(CFLAGS) ipc.c - -yuvrect_client: yuvrect_client.c - $(APP_CC) -I$(INCDIR) $(X11_INCLUDES) $(CFLAGS) $< $(LDFLAGS) $(LIBS) -l$(GLU_LIB) -o $@ +yuvrect_client: yuvrect_client.o + $(APP_CC) $(CFLAGS) $< $(LDFLAGS) $(LIBS) -l$(GLU_LIB) -o $@ |