From 3f9de6ff7dbfc417b50ac27be8461304f0134f91 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Wed, 14 May 2008 17:20:25 +0200 Subject: egl: Updated EGL samples to use new i915 EGL winsys --- progs/egl/Makefile | 8 +++++++- progs/egl/demo1.c | 2 +- progs/egl/demo2.c | 2 +- progs/egl/demo3.c | 2 +- progs/egl/eglgears.c | 2 +- progs/egl/eglinfo.c | 2 +- 6 files changed, 12 insertions(+), 6 deletions(-) (limited to 'progs/egl') diff --git a/progs/egl/Makefile b/progs/egl/Makefile index 33447a9d57..da710cbbbf 100644 --- a/progs/egl/Makefile +++ b/progs/egl/Makefile @@ -46,7 +46,7 @@ demo3.o: demo3.c $(HEADERS) eglinfo: eglinfo.o $(TOP)/$(LIB_DIR)/libEGL.so - $(CC) $(CFLAGS) eglinfo.o -L$(TOP)/$(LIB_DIR) -lEGL $(LIBDRM_LIB) -o $@ + $(CC) $(CFLAGS) eglinfo.o -L$(TOP)/$(LIB_DIR) -lGL -lEGL $(LIBDRM_LIB) -o $@ eglinfo.o: eglinfo.c $(HEADERS) $(CC) -c $(CFLAGS) -I$(TOP)/include eglinfo.c @@ -63,3 +63,9 @@ clean: rm -f *.o *~ rm -f *.so rm -f $(PROGRAMS) + +run: + LD_LIBRARY_PATH=$(TOP)/lib ./eglgears + +debug: + LD_LIBRARY_PATH=$(TOP)/lib gdb ./eglgears diff --git a/progs/egl/demo1.c b/progs/egl/demo1.c index 9ef17e38b7..0cc6f59777 100644 --- a/progs/egl/demo1.c +++ b/progs/egl/demo1.c @@ -102,7 +102,7 @@ main(int argc, char *argv[]) /* EGLDisplay d = eglGetDisplay(EGL_DEFAULT_DISPLAY); */ - EGLDisplay d = eglGetDisplay("!fb_dri"); + EGLDisplay d = eglGetDisplay("!EGL_i915"); assert(d); if (!eglInitialize(d, &maj, &min)) { diff --git a/progs/egl/demo2.c b/progs/egl/demo2.c index 17bbca6158..3f6f53c18e 100644 --- a/progs/egl/demo2.c +++ b/progs/egl/demo2.c @@ -102,7 +102,7 @@ main(int argc, char *argv[]) /* EGLDisplay d = eglGetDisplay(EGL_DEFAULT_DISPLAY); */ - EGLDisplay d = eglGetDisplay("!fb_dri"); + EGLDisplay d = eglGetDisplay("!EGL_i915"); assert(d); if (!eglInitialize(d, &maj, &min)) { diff --git a/progs/egl/demo3.c b/progs/egl/demo3.c index 9edf7c952b..e9d2180bf0 100644 --- a/progs/egl/demo3.c +++ b/progs/egl/demo3.c @@ -576,7 +576,7 @@ main(int argc, char *argv[]) /* EGLDisplay d = eglGetDisplay(EGL_DEFAULT_DISPLAY); */ - EGLDisplay d = eglGetDisplay(":0"); + EGLDisplay d = eglGetDisplay("!EGL_i915"); assert(d); if (!eglInitialize(d, &maj, &min)) { diff --git a/progs/egl/eglgears.c b/progs/egl/eglgears.c index 9feee20d88..909f4837b2 100644 --- a/progs/egl/eglgears.c +++ b/progs/egl/eglgears.c @@ -385,7 +385,7 @@ main(int argc, char *argv[]) } /* DBR : Create EGL context/surface etc */ - d = eglGetDisplay(":0"); + d = eglGetDisplay("!EGL_i915"); assert(d); if (!eglInitialize(d, &maj, &min)) { diff --git a/progs/egl/eglinfo.c b/progs/egl/eglinfo.c index f9c2475445..85de2173fc 100644 --- a/progs/egl/eglinfo.c +++ b/progs/egl/eglinfo.c @@ -140,7 +140,7 @@ main(int argc, char *argv[]) { int maj, min; /*EGLDisplay d = eglGetDisplay(EGL_DEFAULT_DISPLAY);*/ - EGLDisplay d = eglGetDisplay(":0"); + EGLDisplay d = eglGetDisplay("!EGL_i915"); if (!eglInitialize(d, &maj, &min)) { printf("eglinfo: eglInitialize failed\n"); -- cgit v1.2.3 From 0a4867bd4c20faf96af2df6ae31b83854082a820 Mon Sep 17 00:00:00 2001 From: Dan Nicholson Date: Sat, 29 Sep 2007 11:23:22 -0700 Subject: Ignore more generated files in progs/ Many of the directories in progs/ were missing .gitignore files or were tracking generated files. This patch is basically the process of running `make' in each directory and then finding the untracked files with `git-ls-files -o --exclude-per-directory=.gitignore'. The existing files were also sorted. --- progs/beos/.gitignore | 3 +++ progs/directfb/.gitignore | 4 ++++ progs/egl/.gitignore | 5 +++++ progs/fbdev/.gitignore | 1 + progs/miniglx/.gitignore | 6 ++++++ progs/osdemos/.gitignore | 8 ++++++++ progs/samples/.gitignore | 34 +++++++++++++++++----------------- progs/slang/.gitignore | 3 +++ progs/tests/.gitignore | 10 +++++++++- progs/tools/trace/.gitignore | 1 + progs/vp/.gitignore | 1 + 11 files changed, 58 insertions(+), 18 deletions(-) create mode 100644 progs/beos/.gitignore create mode 100644 progs/directfb/.gitignore create mode 100644 progs/egl/.gitignore create mode 100644 progs/fbdev/.gitignore create mode 100644 progs/miniglx/.gitignore create mode 100644 progs/osdemos/.gitignore create mode 100644 progs/slang/.gitignore create mode 100644 progs/tools/trace/.gitignore create mode 100644 progs/vp/.gitignore (limited to 'progs/egl') diff --git a/progs/beos/.gitignore b/progs/beos/.gitignore new file mode 100644 index 0000000000..53011ca2e6 --- /dev/null +++ b/progs/beos/.gitignore @@ -0,0 +1,3 @@ +demo +GLInfo +sample diff --git a/progs/directfb/.gitignore b/progs/directfb/.gitignore new file mode 100644 index 0000000000..55d65fb5b0 --- /dev/null +++ b/progs/directfb/.gitignore @@ -0,0 +1,4 @@ +df_gears +df_morph3d +df_reflect +multi_window diff --git a/progs/egl/.gitignore b/progs/egl/.gitignore new file mode 100644 index 0000000000..1751108235 --- /dev/null +++ b/progs/egl/.gitignore @@ -0,0 +1,5 @@ +demo1 +demo2 +demo3 +eglgears +eglinfo diff --git a/progs/fbdev/.gitignore b/progs/fbdev/.gitignore new file mode 100644 index 0000000000..b9ddf559fd --- /dev/null +++ b/progs/fbdev/.gitignore @@ -0,0 +1 @@ +glfbdevtest diff --git a/progs/miniglx/.gitignore b/progs/miniglx/.gitignore new file mode 100644 index 0000000000..f630f591f6 --- /dev/null +++ b/progs/miniglx/.gitignore @@ -0,0 +1,6 @@ +manytex +miniglxsample +miniglxtest +sample_server +sample_server2 +texline diff --git a/progs/osdemos/.gitignore b/progs/osdemos/.gitignore new file mode 100644 index 0000000000..5c78f12481 --- /dev/null +++ b/progs/osdemos/.gitignore @@ -0,0 +1,8 @@ +osdemo +osdemo16 +osdemo32 +ostest1 +readtex.c +readtex.h +showbuffer.c +showbuffer.h diff --git a/progs/samples/.gitignore b/progs/samples/.gitignore index 9635c7f450..f60d6e94ea 100644 --- a/progs/samples/.gitignore +++ b/progs/samples/.gitignore @@ -1,24 +1,41 @@ .cvsignore accum +anywin +bdemo +binfo bitmap1 bitmap2 blendeq blendxor +bugger copy cursor +demo depth eval +ffset fog font +font +incopy line logo +lthreads +lxdemo +lxgears +lxheads +lxinfo +lxpixmap nurb oglinfo olympic overlay +pend point prim quad +readtex.c +readtex.h select shape sphere @@ -28,20 +45,3 @@ stretch texture tri wave -bugger -pend -lthreads -lxdemo -lxgears -lxheads -lxinfo -lxpixmap -anywin -ffset -bdemo -binfo -incopy -demo -font -readtex.c -readtex.h diff --git a/progs/slang/.gitignore b/progs/slang/.gitignore new file mode 100644 index 0000000000..8a42b018e6 --- /dev/null +++ b/progs/slang/.gitignore @@ -0,0 +1,3 @@ +cltest +sotest +vstest diff --git a/progs/tests/.gitignore b/progs/tests/.gitignore index 2c0e16c35e..2455d5e9f7 100644 --- a/progs/tests/.gitignore +++ b/progs/tests/.gitignore @@ -1,5 +1,5 @@ .cvsignore -getproclist.h +afsmultiarb antialias arbfpspec arbfptest1 @@ -25,13 +25,21 @@ fogcoord fptest1 fptexture getprocaddress +getproclist.h +interleave invert +jkrahntest manytex multipal no_s3tc packedpixels pbo +prog_parameter projtex +random +readrate +readtex.c +readtex.h seccolor sharedtex stencil_wrap diff --git a/progs/tools/trace/.gitignore b/progs/tools/trace/.gitignore new file mode 100644 index 0000000000..afe0c5829e --- /dev/null +++ b/progs/tools/trace/.gitignore @@ -0,0 +1 @@ +gltrace.cc diff --git a/progs/vp/.gitignore b/progs/vp/.gitignore new file mode 100644 index 0000000000..a5ff993525 --- /dev/null +++ b/progs/vp/.gitignore @@ -0,0 +1 @@ +vp-tris -- cgit v1.2.3 From 096b79bf17900ba3d335c6b415461f198051e75b Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Tue, 27 May 2008 13:47:07 -0600 Subject: updates for EGL 1.4 --- progs/egl/demo1.c | 5 ++++- progs/egl/demo2.c | 57 ++++++++++++++++++++++++++++++++++++------------------- 2 files changed, 42 insertions(+), 20 deletions(-) (limited to 'progs/egl') diff --git a/progs/egl/demo1.c b/progs/egl/demo1.c index 0cc6f59777..52673187c4 100644 --- a/progs/egl/demo1.c +++ b/progs/egl/demo1.c @@ -2,7 +2,10 @@ * Exercise EGL API functions */ +#define EGL_EGLEXT_PROTOTYPES + #include +#include #include #include #include @@ -102,7 +105,7 @@ main(int argc, char *argv[]) /* EGLDisplay d = eglGetDisplay(EGL_DEFAULT_DISPLAY); */ - EGLDisplay d = eglGetDisplay("!EGL_i915"); + EGLDisplay d = eglGetDisplay((EGLNativeDisplayType) "!EGL_i915"); assert(d); if (!eglInitialize(d, &maj, &min)) { diff --git a/progs/egl/demo2.c b/progs/egl/demo2.c index 3f6f53c18e..c95aaafa13 100644 --- a/progs/egl/demo2.c +++ b/progs/egl/demo2.c @@ -2,35 +2,54 @@ * Exercise EGL API functions */ +#define EGL_EGLEXT_PROTOTYPES + #include #include #include #include #include +#include +#include /*#define FRONTBUFFER*/ -static void _subset_Rectf(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2) +static void _subset_Rectf(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2, + GLfloat r, GLfloat g, GLfloat b) { - glBegin( GL_QUADS ); - glVertex2f( x1, y1 ); - glVertex2f( x2, y1 ); - glVertex2f( x2, y2 ); - glVertex2f( x1, y2 ); - glEnd(); + GLfloat v[4][2], c[4][4]; + int i; + + v[0][0] = x1; v[0][1] = y1; + v[1][0] = x2; v[1][1] = y1; + v[2][0] = x2; v[2][1] = y2; + v[3][0] = x1; v[3][1] = y2; + + for (i = 0; i < 4; i++) { + c[i][0] = r; + c[i][1] = g; + c[i][2] = b; + c[i][3] = 1.0; + } + + glVertexPointer(2, GL_FLOAT, 0, v); + glColorPointer(4, GL_FLOAT, 0, v); + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_COLOR_ARRAY); + + glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); } static void redraw(EGLDisplay dpy, EGLSurface surf, int rot) { - printf("Redraw event\n"); + GLfloat r, g, b; -#ifdef FRONTBUFFER - glDrawBuffer( GL_FRONT ); -#else - glDrawBuffer( GL_BACK ); -#endif + printf("Redraw event\n"); glClearColor( rand()/(float)RAND_MAX, rand()/(float)RAND_MAX, @@ -39,13 +58,14 @@ static void redraw(EGLDisplay dpy, EGLSurface surf, int rot) glClear( GL_COLOR_BUFFER_BIT ); - glColor3f( rand()/(float)RAND_MAX, - rand()/(float)RAND_MAX, - rand()/(float)RAND_MAX ); + r = rand()/(float)RAND_MAX; + g = rand()/(float)RAND_MAX; + b = rand()/(float)RAND_MAX; + glPushMatrix(); glRotatef(rot, 0, 0, 1); glScalef(.5, .5, .5); - _subset_Rectf( -1, -1, 1, 1 ); + _subset_Rectf( -1, -1, 1, 1, r, g, b ); glPopMatrix(); #ifdef FRONTBUFFER @@ -102,7 +122,7 @@ main(int argc, char *argv[]) /* EGLDisplay d = eglGetDisplay(EGL_DEFAULT_DISPLAY); */ - EGLDisplay d = eglGetDisplay("!EGL_i915"); + EGLDisplay d = eglGetDisplay((EGLNativeDisplayType) "!EGL_i915"); assert(d); if (!eglInitialize(d, &maj, &min)) { @@ -161,7 +181,6 @@ main(int argc, char *argv[]) } glViewport(0, 0, 1024, 768); - glDrawBuffer( GL_FRONT ); glClearColor( 0, 1.0, -- cgit v1.2.3 From a6af2e3345a23e66385433b066329f77ec69abcb Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Tue, 27 May 2008 13:47:23 -0600 Subject: include eglext.h, define EGL_EGLEXT_PROTOTYPES --- progs/egl/eglgears.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'progs/egl') diff --git a/progs/egl/eglgears.c b/progs/egl/eglgears.c index 909f4837b2..5a79c00b4c 100644 --- a/progs/egl/eglgears.c +++ b/progs/egl/eglgears.c @@ -27,13 +27,16 @@ * Program runs for 5 seconds then exits, outputing framerate to console */ +#define EGL_EGLEXT_PROTOTYPES + +#include #include #include #include #include #include #include -#include +#include #define MAX_CONFIGS 10 #define MAX_MODES 100 -- cgit v1.2.3 From d8a693ee49ab2c5699a12f8595be8b8606971dbd Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Wed, 28 May 2008 01:16:06 +0200 Subject: egl: Make demo3 compile --- progs/egl/demo3.c | 1 + 1 file changed, 1 insertion(+) (limited to 'progs/egl') diff --git a/progs/egl/demo3.c b/progs/egl/demo3.c index e9d2180bf0..6ea7578793 100644 --- a/progs/egl/demo3.c +++ b/progs/egl/demo3.c @@ -3,6 +3,7 @@ */ #include +#include #include #include #include -- cgit v1.2.3 From 3e867959e92dea55f963841b2dc03d323e2f8188 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Wed, 28 May 2008 01:17:28 +0200 Subject: egl: Fix warning in eglgears --- progs/egl/eglgears.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'progs/egl') diff --git a/progs/egl/eglgears.c b/progs/egl/eglgears.c index 5a79c00b4c..a004cb7e86 100644 --- a/progs/egl/eglgears.c +++ b/progs/egl/eglgears.c @@ -388,7 +388,7 @@ main(int argc, char *argv[]) } /* DBR : Create EGL context/surface etc */ - d = eglGetDisplay("!EGL_i915"); + d = eglGetDisplay((EGLNativeDisplayType)"!EGL_i915"); assert(d); if (!eglInitialize(d, &maj, &min)) { -- cgit v1.2.3 From 8cd33faee61626de7320efb4e20d95e4cfb7a573 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 28 May 2008 15:25:01 -0600 Subject: egl: query/print EGL_CLIENT_APIS --- progs/egl/eglinfo.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'progs/egl') diff --git a/progs/egl/eglinfo.c b/progs/egl/eglinfo.c index 85de2173fc..442de5d63f 100644 --- a/progs/egl/eglinfo.c +++ b/progs/egl/eglinfo.c @@ -150,6 +150,9 @@ main(int argc, char *argv[]) printf("EGL API version: %d.%d\n", maj, min); printf("EGL vendor string: %s\n", eglQueryString(d, EGL_VENDOR)); printf("EGL version string: %s\n", eglQueryString(d, EGL_VERSION)); +#ifdef EGL_VERSION_1_2 + printf("EGL client APIs: %s\n", eglQueryString(d, EGL_CLIENT_APIS)); +#endif printf("EGL extensions string:\n"); printf(" %s\n", eglQueryString(d, EGL_EXTENSIONS)); printf("\n"); -- cgit v1.2.3 From 80ed996803cf198cc498f1b9cc952ab2662c946f Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Fri, 30 May 2008 11:43:35 -0600 Subject: egl: new version of gears demo that uses Xlib+EGL (and full OpenGL for now) --- progs/egl/Makefile | 10 +- progs/egl/xeglgears.c | 604 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 613 insertions(+), 1 deletion(-) create mode 100644 progs/egl/xeglgears.c (limited to 'progs/egl') diff --git a/progs/egl/Makefile b/progs/egl/Makefile index da710cbbbf..ae2267f38f 100644 --- a/progs/egl/Makefile +++ b/progs/egl/Makefile @@ -13,7 +13,8 @@ PROGRAMS = \ demo2 \ demo3 \ eglinfo \ - eglgears + eglgears \ + xeglgears .c.o: @@ -59,6 +60,13 @@ eglgears.o: eglgears.c $(HEADERS) $(CC) -c $(CFLAGS) -I$(TOP)/include eglgears.c +xeglgears: xeglgears.o $(TOP)/$(LIB_DIR)/libEGL.so + $(CC) $(CFLAGS) xeglgears.o -L$(TOP)/$(LIB_DIR) -lEGL $(LIBDRM_LIB) $(APP_LIB_DEPS) -o $@ + +xeglgears.o: xeglgears.c $(HEADERS) + $(CC) -c $(CFLAGS) -I$(TOP)/include xeglgears.c + + clean: rm -f *.o *~ rm -f *.so diff --git a/progs/egl/xeglgears.c b/progs/egl/xeglgears.c new file mode 100644 index 0000000000..503958cf8c --- /dev/null +++ b/progs/egl/xeglgears.c @@ -0,0 +1,604 @@ +/* + * 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. + */ + +/* + * Ported to X/EGL/GLES. XXX Actually, uses full OpenGL ATM. + * Brian Paul + * 30 May 2008 + */ + +/* + * Command line options: + * -info print GL implementation information + * + */ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#define BENCHMARK + +#ifdef BENCHMARK + +/* XXX this probably isn't very portable */ + +#include +#include + +/* 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 + + +static GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0; +static GLint gear1, gear2, gear3; +static GLfloat angle = 0.0; + +static GLboolean fullscreen = GL_FALSE; /* Create a single fullscreen window */ + + +/* + * + * Draw a gear wheel. You'll probably want to call this function when + * building a display list since we do a lot of trig here. + * + * Input: inner_radius - radius of hole at center + * outer_radius - radius at center of teeth + * width - width of gear + * teeth - number of teeth + * tooth_depth - depth of tooth + */ +static void +gear(GLfloat inner_radius, GLfloat outer_radius, GLfloat width, + GLint teeth, GLfloat tooth_depth) +{ + GLint i; + GLfloat r0, r1, r2; + GLfloat angle, da; + GLfloat u, v, len; + + r0 = inner_radius; + r1 = outer_radius - tooth_depth / 2.0; + r2 = outer_radius + tooth_depth / 2.0; + + da = 2.0 * M_PI / teeth / 4.0; + + glShadeModel(GL_FLAT); + + glNormal3f(0.0, 0.0, 1.0); + + /* draw front face */ + glBegin(GL_QUAD_STRIP); + for (i = 0; i <= teeth; i++) { + angle = i * 2.0 * M_PI / teeth; + glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5); + glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5); + if (i < teeth) { + glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5); + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), + width * 0.5); + } + } + glEnd(); + + /* draw front sides of teeth */ + glBegin(GL_QUADS); + da = 2.0 * M_PI / teeth / 4.0; + for (i = 0; i < teeth; i++) { + angle = i * 2.0 * M_PI / teeth; + + glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5); + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5); + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), + width * 0.5); + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), + width * 0.5); + } + glEnd(); + + glNormal3f(0.0, 0.0, -1.0); + + /* draw back face */ + glBegin(GL_QUAD_STRIP); + for (i = 0; i <= teeth; i++) { + angle = i * 2.0 * M_PI / teeth; + glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5); + glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5); + if (i < teeth) { + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), + -width * 0.5); + glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5); + } + } + glEnd(); + + /* draw back sides of teeth */ + glBegin(GL_QUADS); + da = 2.0 * M_PI / teeth / 4.0; + for (i = 0; i < teeth; i++) { + angle = i * 2.0 * M_PI / teeth; + + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), + -width * 0.5); + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), + -width * 0.5); + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5); + glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5); + } + glEnd(); + + /* draw outward faces of teeth */ + glBegin(GL_QUAD_STRIP); + for (i = 0; i < teeth; i++) { + angle = i * 2.0 * M_PI / teeth; + + glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5); + glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5); + u = r2 * cos(angle + da) - r1 * cos(angle); + v = r2 * sin(angle + da) - r1 * sin(angle); + len = sqrt(u * u + v * v); + u /= len; + v /= len; + glNormal3f(v, -u, 0.0); + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5); + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5); + glNormal3f(cos(angle), sin(angle), 0.0); + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), + width * 0.5); + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), + -width * 0.5); + u = r1 * cos(angle + 3 * da) - r2 * cos(angle + 2 * da); + v = r1 * sin(angle + 3 * da) - r2 * sin(angle + 2 * da); + glNormal3f(v, -u, 0.0); + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), + width * 0.5); + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), + -width * 0.5); + glNormal3f(cos(angle), sin(angle), 0.0); + } + + glVertex3f(r1 * cos(0), r1 * sin(0), width * 0.5); + glVertex3f(r1 * cos(0), r1 * sin(0), -width * 0.5); + + glEnd(); + + glShadeModel(GL_SMOOTH); + + /* draw inside radius cylinder */ + glBegin(GL_QUAD_STRIP); + for (i = 0; i <= teeth; i++) { + angle = i * 2.0 * M_PI / teeth; + glNormal3f(-cos(angle), -sin(angle), 0.0); + glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5); + glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5); + } + glEnd(); +} + + +static void +draw(void) +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glPushMatrix(); + glRotatef(view_rotx, 1.0, 0.0, 0.0); + glRotatef(view_roty, 0.0, 1.0, 0.0); + glRotatef(view_rotz, 0.0, 0.0, 1.0); + + glPushMatrix(); + glTranslatef(-3.0, -2.0, 0.0); + glRotatef(angle, 0.0, 0.0, 1.0); + glCallList(gear1); + glPopMatrix(); + + glPushMatrix(); + glTranslatef(3.1, -2.0, 0.0); + glRotatef(-2.0 * angle - 9.0, 0.0, 0.0, 1.0); + glCallList(gear2); + glPopMatrix(); + + glPushMatrix(); + glTranslatef(-3.1, 4.2, 0.0); + glRotatef(-2.0 * angle - 25.0, 0.0, 0.0, 1.0); + glCallList(gear3); + glPopMatrix(); + + 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, -40.0); +} + + + +static void +init(void) +{ + static GLfloat pos[4] = { 5.0, 5.0, 10.0, 0.0 }; + static GLfloat red[4] = { 0.8, 0.1, 0.0, 1.0 }; + static GLfloat green[4] = { 0.0, 0.8, 0.2, 1.0 }; + static GLfloat blue[4] = { 0.2, 0.2, 1.0, 1.0 }; + + glLightfv(GL_LIGHT0, GL_POSITION, pos); + glEnable(GL_CULL_FACE); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glEnable(GL_DEPTH_TEST); + + /* make the gears */ + gear1 = glGenLists(1); + glNewList(gear1, GL_COMPILE); + glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red); + gear(1.0, 4.0, 1.0, 20, 0.7); + glEndList(); + + gear2 = glGenLists(1); + glNewList(gear2, GL_COMPILE); + glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green); + gear(0.5, 2.0, 2.0, 10, 0.7); + glEndList(); + + gear3 = glGenLists(1); + glNewList(gear3, GL_COMPILE); + glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue); + gear(1.3, 2.0, 0.5, 10, 0.7); + glEndList(); + + glEnable(GL_NORMALIZE); + + glClearColor(0.2, 0.2, 0.2, 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_DOUBLEBUFFER,*/ + 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; + + scrnum = DefaultScreen( x_dpy ); + root = RootWindow( x_dpy, scrnum ); + + if (fullscreen) { + x = 0; y = 0; + width = DisplayWidth( x_dpy, scrnum ); + height = DisplayHeight( x_dpy, scrnum ); + } + + if (!eglChooseConfig( egl_dpy, attribs, &config, 1, &num_configs)) { + printf("Error: couldn't get an EGL visual config\n"); + exit(1); + } + + /* choose X window visual similar to EGL config */ + visTemplate.screen = DefaultScreen(x_dpy); + visTemplate.depth = 32; /* 24? */ + visInfo = XGetVisualInfo(x_dpy, + (VisualDepthMask | VisualScreenMask), + &visTemplate, &num_visuals); + if (!visInfo) { + printf("Error: couldn't get X visual\n"); + exit(1); + } + + /* window attributes */ + attr.background_pixel = 0; + attr.border_pixel = 0; + attr.colormap = XCreateColormap( x_dpy, root, visInfo->visual, AllocNone); + attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask; + attr.override_redirect = fullscreen; + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect; + + win = XCreateWindow( x_dpy, root, 0, 0, width, height, + 0, visInfo->depth, InputOutput, + visInfo->visual, mask, &attr ); + + /* set hints and properties */ + { + XSizeHints sizehints; + sizehints.x = x; + sizehints.y = y; + sizehints.width = width; + sizehints.height = height; + sizehints.flags = USSize | USPosition; + XSetNormalHints(x_dpy, win, &sizehints); + XSetStandardProperties(x_dpy, win, name, name, + None, (char **)NULL, 0, &sizehints); + } + + 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); + + XFree(visInfo); + + *winRet = win; + *ctxRet = ctx; +} + + +static void +event_loop(Display *dpy, Window win, + EGLDisplay egl_dpy, EGLSurface egl_surf) +{ + while (1) { + while (XPending(dpy) > 0) { + XEvent event; + XNextEvent(dpy, &event); + switch (event.type) { + case Expose: + /* we'll redraw below */ + break; + case ConfigureNotify: + reshape(event.xconfigure.width, event.xconfigure.height); + break; + case KeyPress: + { + char buffer[10]; + int r, code; + code = XLookupKeysym(&event.xkey, 0); + if (code == XK_Left) { + view_roty += 5.0; + } + else if (code == XK_Right) { + view_roty -= 5.0; + } + else if (code == XK_Up) { + view_rotx += 5.0; + } + else if (code == XK_Down) { + view_rotx -= 5.0; + } + else { + r = XLookupString(&event.xkey, buffer, sizeof(buffer), + NULL, NULL); + if (buffer[0] == 27) { + /* escape */ + return; + } + } + } + } + } + + { + static int frames = 0; + static double tRot0 = -1.0, tRate0 = -1.0; + double dt, t = current_time(); + if (tRot0 < 0.0) + tRot0 = t; + dt = t - tRot0; + tRot0 = t; + + /* advance rotation for next frame */ + angle += 70.0 * dt; /* 70 degrees per second */ + if (angle > 3600.0) + angle -= 3600.0; + + draw(); + eglSwapBuffers(egl_dpy, egl_surf); + + frames++; + + if (tRate0 < 0.0) + tRate0 = t; + if (t - tRate0 >= 5.0) { + GLfloat seconds = t - tRate0; + GLfloat fps = frames / seconds; + printf("%d frames in %3.1f seconds = %6.3f FPS\n", frames, seconds, + fps); + tRate0 = t; + frames = 0; + } + } + } +} + + +static void +usage(void) +{ + printf("Usage:\n"); + printf(" -display set the display to run on\n"); + printf(" -fullscreen run in fullscreen mode\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 if (strcmp(argv[i], "-fullscreen") == 0) { + fullscreen = 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, + "glxgears", 0, 0, winWidth, winHeight, + &win, &egl_ctx, &egl_surf); + + XMapWindow(x_dpy, win); + eglMakeCurrent(egl_dpy, egl_surf, egl_surf, egl_ctx); + + 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); + + glDeleteLists(gear1, 1); + glDeleteLists(gear2, 1); + glDeleteLists(gear3, 1); + + eglDestroyContext(egl_dpy, egl_ctx); + eglDestroySurface(egl_dpy, egl_surf); + eglTerminate(egl_dpy); + + + XDestroyWindow(x_dpy, win); + XCloseDisplay(x_dpy); + + return 0; +} -- cgit v1.2.3 From 6b9b49127e575ecfae08a78b991e89cb484150a4 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Fri, 30 May 2008 13:46:50 -0600 Subject: egl: bind the OpenGL API --- progs/egl/xeglgears.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'progs/egl') diff --git a/progs/egl/xeglgears.c b/progs/egl/xeglgears.c index 503958cf8c..519d4bb692 100644 --- a/progs/egl/xeglgears.c +++ b/progs/egl/xeglgears.c @@ -409,6 +409,8 @@ make_x_window(Display *x_dpy, EGLDisplay egl_dpy, 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"); -- cgit v1.2.3 From af540ef3692e2dd047c6355c67b3ba5a99a75395 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 4 Jun 2008 10:11:25 -0600 Subject: egl: updated egl.h include paths --- progs/egl/demo1.c | 4 ++-- progs/egl/demo2.c | 4 ++-- progs/egl/demo3.c | 5 ++++- progs/egl/eglgears.c | 4 ++-- progs/egl/eglinfo.c | 2 +- progs/egl/xeglgears.c | 2 +- 6 files changed, 12 insertions(+), 9 deletions(-) (limited to 'progs/egl') diff --git a/progs/egl/demo1.c b/progs/egl/demo1.c index 52673187c4..49b6624538 100644 --- a/progs/egl/demo1.c +++ b/progs/egl/demo1.c @@ -4,8 +4,8 @@ #define EGL_EGLEXT_PROTOTYPES -#include -#include +#include +#include #include #include #include diff --git a/progs/egl/demo2.c b/progs/egl/demo2.c index c95aaafa13..d7283e13bd 100644 --- a/progs/egl/demo2.c +++ b/progs/egl/demo2.c @@ -9,8 +9,8 @@ #include #include -#include -#include +#include +#include #include /*#define FRONTBUFFER*/ diff --git a/progs/egl/demo3.c b/progs/egl/demo3.c index 6ea7578793..a6096a257e 100644 --- a/progs/egl/demo3.c +++ b/progs/egl/demo3.c @@ -2,7 +2,10 @@ * Exercise EGL API functions */ -#include +#define EGL_EGLEXT_PROTOTYPES + +#include +#include #include #include #include diff --git a/progs/egl/eglgears.c b/progs/egl/eglgears.c index a004cb7e86..20f6c1ff6e 100644 --- a/progs/egl/eglgears.c +++ b/progs/egl/eglgears.c @@ -35,8 +35,8 @@ #include #include #include -#include -#include +#include +#include #define MAX_CONFIGS 10 #define MAX_MODES 100 diff --git a/progs/egl/eglinfo.c b/progs/egl/eglinfo.c index 442de5d63f..f0fd442990 100644 --- a/progs/egl/eglinfo.c +++ b/progs/egl/eglinfo.c @@ -25,7 +25,7 @@ */ -#include +#include #include #include #include diff --git a/progs/egl/xeglgears.c b/progs/egl/xeglgears.c index 519d4bb692..d5fbc03410 100644 --- a/progs/egl/xeglgears.c +++ b/progs/egl/xeglgears.c @@ -40,7 +40,7 @@ #include #include #include -#include +#include #define BENCHMARK -- cgit v1.2.3 From 88f86c9d026fc71b78cc6d71c0faaed38d0d6927 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Wed, 4 Jun 2008 18:58:22 +0200 Subject: egl: Added peglgears, gears that uses pbuffers --- progs/egl/Makefile | 10 +- progs/egl/peglgears.c | 449 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 457 insertions(+), 2 deletions(-) create mode 100644 progs/egl/peglgears.c (limited to 'progs/egl') diff --git a/progs/egl/Makefile b/progs/egl/Makefile index ae2267f38f..29e0d407e3 100644 --- a/progs/egl/Makefile +++ b/progs/egl/Makefile @@ -14,6 +14,7 @@ PROGRAMS = \ demo3 \ eglinfo \ eglgears \ + peglgears \ xeglgears @@ -59,6 +60,11 @@ eglgears: eglgears.o $(TOP)/$(LIB_DIR)/libEGL.so eglgears.o: eglgears.c $(HEADERS) $(CC) -c $(CFLAGS) -I$(TOP)/include eglgears.c +peglgears: peglgears.o $(TOP)/$(LIB_DIR)/libEGL.so + $(CC) $(CFLAGS) peglgears.o -L$(TOP)/$(LIB_DIR) -lEGL $(LIBDRM_LIB) $(APP_LIB_DEPS) -o $@ + +peglgears.o: peglgears.c $(HEADERS) + $(CC) -c $(CFLAGS) -I$(TOP)/include peglgears.c xeglgears: xeglgears.o $(TOP)/$(LIB_DIR)/libEGL.so $(CC) $(CFLAGS) xeglgears.o -L$(TOP)/$(LIB_DIR) -lEGL $(LIBDRM_LIB) $(APP_LIB_DEPS) -o $@ @@ -73,7 +79,7 @@ clean: rm -f $(PROGRAMS) run: - LD_LIBRARY_PATH=$(TOP)/lib ./eglgears + LD_LIBRARY_PATH=$(TOP)/lib ./peglgears debug: - LD_LIBRARY_PATH=$(TOP)/lib gdb ./eglgears + LD_LIBRARY_PATH=$(TOP)/lib gdb ./peglgears diff --git a/progs/egl/peglgears.c b/progs/egl/peglgears.c new file mode 100644 index 0000000000..bac16453c1 --- /dev/null +++ b/progs/egl/peglgears.c @@ -0,0 +1,449 @@ +/* + * 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. + */ + +/* + * This is a port of the infamous "glxgears" demo to straight EGL + * Port by Dane Rushton 10 July 2005 + * + * No command line options. + * Program runs for 5 seconds then exits, outputing framerate to console + */ + +#define EGL_EGLEXT_PROTOTYPES + +#include +#include +#include +#include +#include +#include +#include +#include + +#define MAX_CONFIGS 10 +#define MAX_MODES 100 + +#define BENCHMARK + +#ifdef BENCHMARK + +/* XXX this probably isn't very portable */ + +#include +#include + +/* 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 + + +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 + * building a display list since we do a lot of trig here. + * + * Input: inner_radius - radius of hole at center + * outer_radius - radius at center of teeth + * width - width of gear + * teeth - number of teeth + * tooth_depth - depth of tooth + */ +static void +gear(GLfloat inner_radius, GLfloat outer_radius, GLfloat width, + GLint teeth, GLfloat tooth_depth) +{ + GLint i; + GLfloat r0, r1, r2; + GLfloat angle, da; + GLfloat u, v, len; + + r0 = inner_radius; + r1 = outer_radius - tooth_depth / 2.0; + r2 = outer_radius + tooth_depth / 2.0; + + da = 2.0 * M_PI / teeth / 4.0; + + glShadeModel(GL_FLAT); + + glNormal3f(0.0, 0.0, 1.0); + + /* draw front face */ + glBegin(GL_QUAD_STRIP); + for (i = 0; i <= teeth; i++) { + angle = i * 2.0 * M_PI / teeth; + glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5); + glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5); + if (i < teeth) { + glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5); + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), + width * 0.5); + } + } + glEnd(); + + /* draw front sides of teeth */ + glBegin(GL_QUADS); + da = 2.0 * M_PI / teeth / 4.0; + for (i = 0; i < teeth; i++) { + angle = i * 2.0 * M_PI / teeth; + + glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5); + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5); + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), + width * 0.5); + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), + width * 0.5); + } + glEnd(); + + glNormal3f(0.0, 0.0, -1.0); + + /* draw back face */ + glBegin(GL_QUAD_STRIP); + for (i = 0; i <= teeth; i++) { + angle = i * 2.0 * M_PI / teeth; + glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5); + glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5); + if (i < teeth) { + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), + -width * 0.5); + glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5); + } + } + glEnd(); + + /* draw back sides of teeth */ + glBegin(GL_QUADS); + da = 2.0 * M_PI / teeth / 4.0; + for (i = 0; i < teeth; i++) { + angle = i * 2.0 * M_PI / teeth; + + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), + -width * 0.5); + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), + -width * 0.5); + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5); + glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5); + } + glEnd(); + + /* draw outward faces of teeth */ + glBegin(GL_QUAD_STRIP); + for (i = 0; i < teeth; i++) { + angle = i * 2.0 * M_PI / teeth; + + glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5); + glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5); + u = r2 * cos(angle + da) - r1 * cos(angle); + v = r2 * sin(angle + da) - r1 * sin(angle); + len = sqrt(u * u + v * v); + u /= len; + v /= len; + glNormal3f(v, -u, 0.0); + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5); + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5); + glNormal3f(cos(angle), sin(angle), 0.0); + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), + width * 0.5); + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), + -width * 0.5); + u = r1 * cos(angle + 3 * da) - r2 * cos(angle + 2 * da); + v = r1 * sin(angle + 3 * da) - r2 * sin(angle + 2 * da); + glNormal3f(v, -u, 0.0); + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), + width * 0.5); + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), + -width * 0.5); + glNormal3f(cos(angle), sin(angle), 0.0); + } + + glVertex3f(r1 * cos(0), r1 * sin(0), width * 0.5); + glVertex3f(r1 * cos(0), r1 * sin(0), -width * 0.5); + + glEnd(); + + glShadeModel(GL_SMOOTH); + + /* draw inside radius cylinder */ + glBegin(GL_QUAD_STRIP); + for (i = 0; i <= teeth; i++) { + angle = i * 2.0 * M_PI / teeth; + glNormal3f(-cos(angle), -sin(angle), 0.0); + glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5); + glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5); + } + glEnd(); +} + + +static void +draw(void) +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glPushMatrix(); + glRotatef(view_rotx, 1.0, 0.0, 0.0); + glRotatef(view_roty, 0.0, 1.0, 0.0); + glRotatef(view_rotz, 0.0, 0.0, 1.0); + + glPushMatrix(); + glTranslatef(-3.0, -2.0, 0.0); + glRotatef(angle, 0.0, 0.0, 1.0); + glCallList(gear1); + glPopMatrix(); + + glPushMatrix(); + glTranslatef(3.1, -2.0, 0.0); + glRotatef(-2.0 * angle - 9.0, 0.0, 0.0, 1.0); + glCallList(gear2); + glPopMatrix(); + + glPushMatrix(); + glTranslatef(-3.1, 4.2, 0.0); + glRotatef(-2.0 * angle - 25.0, 0.0, 0.0, 1.0); + glCallList(gear3); + glPopMatrix(); + + glPopMatrix(); +} + + +/* new window size or exposure */ +static void +reshape(int width, int height) +{ + glViewport(0, 0, (GLint) width, (GLint) height); + + GLfloat h = (GLfloat) height / (GLfloat) width; + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-1.0, 1.0, -h, h, 5.0, 60.0); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0.0, 0.0, -40.0); +} + + + +static void +init(void) +{ + static GLfloat pos[4] = { 5.0, 5.0, 10.0, 0.0 }; + static GLfloat red[4] = { 0.8, 0.1, 0.0, 1.0 }; + static GLfloat green[4] = { 0.0, 0.8, 0.2, 1.0 }; + static GLfloat blue[4] = { 0.2, 0.2, 1.0, 1.0 }; + + glLightfv(GL_LIGHT0, GL_POSITION, pos); + glEnable(GL_CULL_FACE); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glEnable(GL_DEPTH_TEST); + + /* make the gears */ + gear1 = glGenLists(1); + glNewList(gear1, GL_COMPILE); + glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red); + gear(1.0, 4.0, 1.0, 20, 0.7); + glEndList(); + + gear2 = glGenLists(1); + glNewList(gear2, GL_COMPILE); + glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green); + gear(0.5, 2.0, 2.0, 10, 0.7); + glEndList(); + + gear3 = glGenLists(1); + glNewList(gear3, GL_COMPILE); + glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue); + gear(1.3, 2.0, 0.5, 10, 0.7); + glEndList(); + + glEnable(GL_NORMALIZE); +} + + + + +static void run_gears(EGLDisplay dpy, EGLSurface surf, int ttr) +{ + double st = current_time(); + double ct = st; + int frames = 0; + 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++; + } + + GLfloat seconds = ct - st; + GLfloat fps = frames / seconds; + printf("%d frames in %3.1f seconds = %6.3f FPS\n", frames, seconds, fps); + +} + + +int +main(int argc, char *argv[]) +{ + int major, minor; + EGLContext ctx; + EGLSurface surface; + EGLConfig configs[MAX_CONFIGS]; + EGLint numConfigs, i; + EGLBoolean b; + EGLDisplay d; + EGLint screenAttribs[10]; + GLboolean printInfo = GL_FALSE; + EGLint width = 300, height = 300; + + /* 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((EGLNativeDisplayType)"!EGL_i915"); + assert(d); + + if (!eglInitialize(d, &major, &minor)) { + printf("peglgears: eglInitialize failed\n"); + return 0; + } + + printf("peglgears: EGL version = %d.%d\n", major, minor); + printf("peglgears: EGL_VENDOR = %s\n", eglQueryString(d, EGL_VENDOR)); + + eglGetConfigs(d, configs, MAX_CONFIGS, &numConfigs); + + eglBindAPI(EGL_OPENGL_API); + + ctx = eglCreateContext(d, configs[0], EGL_NO_CONTEXT, NULL); + if (ctx == EGL_NO_CONTEXT) { + printf("peglgears: 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; + + surface = eglCreatePbufferSurface(d, configs[0], screenAttribs); + if (surface == EGL_NO_SURFACE) { + printf("peglgears: failed to create pbuffer surface\n"); + return 0; + } + + b = eglMakeCurrent(d, surface, surface, ctx); + if (!b) { + printf("peglgears: 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_gears(d, surface, 5.0); + + eglDestroySurface(d, surface); + eglDestroyContext(d, ctx); + eglTerminate(d); + + return 0; +} -- cgit v1.2.3 From b9d35c7c44ddda1cc7fdd9a34a9cf4696b6baba3 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 4 Jun 2008 11:36:01 -0600 Subject: egl: query/print EGL_NATIVE_VISUAL_ID Other whitespace/etc clean-ups. --- progs/egl/eglinfo.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'progs/egl') diff --git a/progs/egl/eglinfo.c b/progs/egl/eglinfo.c index f0fd442990..89feec9be4 100644 --- a/progs/egl/eglinfo.c +++ b/progs/egl/eglinfo.c @@ -48,8 +48,8 @@ PrintConfigs(EGLDisplay d) eglGetConfigs(d, configs, MAX_CONFIGS, &numConfigs); printf("Configurations:\n"); - printf(" bf lv d st colorbuffer dp st supported\n"); - printf(" id sz l b ro r g b a th cl surfaces \n"); + printf(" bf lv d st colorbuffer dp st vis supported\n"); + printf(" id sz l b ro r g b a th cl id surfaces \n"); printf("---------------------------------------------------\n"); for (i = 0; i < numConfigs; i++) { EGLint id, size, level; @@ -57,6 +57,7 @@ PrintConfigs(EGLDisplay d) EGLint depth, stencil; EGLint surfaces; EGLint doubleBuf = 1, stereo = 0; + EGLint vid; char surfString[100] = ""; eglGetConfigAttrib(d, configs[i], EGL_CONFIG_ID, &id); @@ -69,6 +70,7 @@ PrintConfigs(EGLDisplay d) eglGetConfigAttrib(d, configs[i], EGL_ALPHA_SIZE, &alpha); eglGetConfigAttrib(d, configs[i], EGL_DEPTH_SIZE, &depth); eglGetConfigAttrib(d, configs[i], EGL_STENCIL_SIZE, &stencil); + eglGetConfigAttrib(d, configs[i], EGL_NATIVE_VISUAL_ID, &vid); eglGetConfigAttrib(d, configs[i], EGL_SURFACE_TYPE, &surfaces); if (surfaces & EGL_WINDOW_BIT) @@ -84,12 +86,12 @@ PrintConfigs(EGLDisplay d) if (strlen(surfString) > 0) surfString[strlen(surfString) - 1] = 0; - printf("0x%02x %2d %2d %c %c %2d %2d %2d %2d %2d %2d %-12s\n", + printf("0x%02x %2d %2d %c %c %2d %2d %2d %2d %2d %2d 0x%02x %-12s\n", id, size, level, doubleBuf ? 'y' : '.', stereo ? 'y' : '.', red, green, blue, alpha, - depth, stencil, surfString); + depth, stencil, vid, surfString); } } @@ -139,8 +141,7 @@ int main(int argc, char *argv[]) { int maj, min; - /*EGLDisplay d = eglGetDisplay(EGL_DEFAULT_DISPLAY);*/ - EGLDisplay d = eglGetDisplay("!EGL_i915"); + EGLDisplay d = eglGetDisplay(EGL_DEFAULT_DISPLAY); if (!eglInitialize(d, &maj, &min)) { printf("eglinfo: eglInitialize failed\n"); @@ -155,12 +156,9 @@ main(int argc, char *argv[]) #endif printf("EGL extensions string:\n"); printf(" %s\n", eglQueryString(d, EGL_EXTENSIONS)); - printf("\n"); PrintConfigs(d); - printf("\n"); - PrintModes(d); eglTerminate(d); -- cgit v1.2.3 From bf527cc8d41c277e610d4d51d3b1394e1d417805 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 4 Jun 2008 11:40:25 -0600 Subject: egl: fix X visual selection --- progs/egl/xeglgears.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'progs/egl') diff --git a/progs/egl/xeglgears.c b/progs/egl/xeglgears.c index d5fbc03410..72ed005283 100644 --- a/progs/egl/xeglgears.c +++ b/progs/egl/xeglgears.c @@ -357,7 +357,7 @@ make_x_window(Display *x_dpy, EGLDisplay egl_dpy, int num_visuals; EGLContext ctx; EGLConfig config; - EGLint num_configs; + EGLint num_configs, vid; scrnum = DefaultScreen( x_dpy ); root = RootWindow( x_dpy, scrnum ); @@ -373,12 +373,14 @@ make_x_window(Display *x_dpy, EGLDisplay egl_dpy, exit(1); } - /* choose X window visual similar to EGL config */ - visTemplate.screen = DefaultScreen(x_dpy); - visTemplate.depth = 32; /* 24? */ - visInfo = XGetVisualInfo(x_dpy, - (VisualDepthMask | VisualScreenMask), - &visTemplate, &num_visuals); + 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); -- cgit v1.2.3 From 2154cb4994c49031b8614dfad8e97c730f4702a6 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 4 Jun 2008 11:41:37 -0600 Subject: egl: single triangle test --- progs/egl/Makefile | 10 +- progs/egl/xegl_tri.c | 359 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 368 insertions(+), 1 deletion(-) create mode 100644 progs/egl/xegl_tri.c (limited to 'progs/egl') diff --git a/progs/egl/Makefile b/progs/egl/Makefile index 29e0d407e3..3bde6029ac 100644 --- a/progs/egl/Makefile +++ b/progs/egl/Makefile @@ -15,7 +15,8 @@ PROGRAMS = \ eglinfo \ eglgears \ peglgears \ - xeglgears + xeglgears \ + xegl_tri .c.o: @@ -73,6 +74,13 @@ xeglgears.o: xeglgears.c $(HEADERS) $(CC) -c $(CFLAGS) -I$(TOP)/include xeglgears.c +xegl_tri: xegl_tri.o $(TOP)/$(LIB_DIR)/libEGL.so + $(CC) $(CFLAGS) xegl_tri.o -L$(TOP)/$(LIB_DIR) -lEGL $(LIBDRM_LIB) $(APP_LIB_DEPS) -o $@ + +xegl_tri.o: xegl_tri.c $(HEADERS) + $(CC) -c $(CFLAGS) -I$(TOP)/include xegl_tri.c + + clean: rm -f *.o *~ rm -f *.so diff --git a/progs/egl/xegl_tri.c b/progs/egl/xegl_tri.c new file mode 100644 index 0000000000..65f352ddfa --- /dev/null +++ b/progs/egl/xegl_tri.c @@ -0,0 +1,359 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include +#include +#include /* using full OpenGL for now */ +#include + + +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_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_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 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; +} -- cgit v1.2.3 From 4e52fa9b91b9480b4cfd179b888884bfb67bd5ed Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Mon, 16 Jun 2008 12:20:17 +0200 Subject: git: Updated .gitignore files --- progs/egl/.gitignore | 3 +++ progs/trivial/.gitignore | 10 ++++++++++ 2 files changed, 13 insertions(+) (limited to 'progs/egl') diff --git a/progs/egl/.gitignore b/progs/egl/.gitignore index 1751108235..336d82cd28 100644 --- a/progs/egl/.gitignore +++ b/progs/egl/.gitignore @@ -3,3 +3,6 @@ demo2 demo3 eglgears eglinfo +peglgears +xeglgears +xegl_tri diff --git a/progs/trivial/.gitignore b/progs/trivial/.gitignore index 30f03e9103..a6629446d1 100644 --- a/progs/trivial/.gitignore +++ b/progs/trivial/.gitignore @@ -2,6 +2,7 @@ clear clear-fbo clear-fbo-tex clear-scissor +clear-undefined dlist-dangling dlist-edgeflag dlist-edgeflag-dangling @@ -37,6 +38,8 @@ point-wide point-wide-smooth poly poly-flat +poly-flat-clip +poly-flat-unfilled-clip poly-unfilled quad quad-clip @@ -73,6 +76,11 @@ tri-cull tri-cull-both tri-dlist tri-edgeflag +trifan +trifan-flat +trifan-flat-clip +trifan-flat-unfilled-clip +trifan-unfilled tri-fbo tri-fbo-tex tri-flat @@ -96,10 +104,12 @@ tri-z tri-z-eq tristrip tristrip-clip +tristrip-flat vbo-drawarrays vbo-drawelements vbo-drawrange vp-array +vp-array-int vp-clip vp-line-clip vp-tri -- cgit v1.2.3 From 52912d86167e39bf3655edf773d394fda8718ca4 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Fri, 4 Jul 2008 19:33:09 +0200 Subject: egl: Add egltri First tri for EGL drivers with mesa screen ext --- progs/egl/.gitignore | 1 + progs/egl/Makefile | 14 ++- progs/egl/egltri.c | 264 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 277 insertions(+), 2 deletions(-) create mode 100644 progs/egl/egltri.c (limited to 'progs/egl') diff --git a/progs/egl/.gitignore b/progs/egl/.gitignore index 336d82cd28..497b0ebbe3 100644 --- a/progs/egl/.gitignore +++ b/progs/egl/.gitignore @@ -3,6 +3,7 @@ demo2 demo3 eglgears eglinfo +egltri peglgears xeglgears xegl_tri diff --git a/progs/egl/Makefile b/progs/egl/Makefile index 3bde6029ac..948d735609 100644 --- a/progs/egl/Makefile +++ b/progs/egl/Makefile @@ -12,6 +12,7 @@ PROGRAMS = \ demo1 \ demo2 \ demo3 \ + egltri \ eglinfo \ eglgears \ peglgears \ @@ -48,6 +49,13 @@ demo3.o: demo3.c $(HEADERS) $(CC) -c $(CFLAGS) -I$(TOP)/include demo3.c +egltri: egltri.o $(TOP)/$(LIB_DIR)/libEGL.so + $(CC) $(CFLAGS) egltri.o -L$(TOP)/$(LIB_DIR) -lGL -lEGL $(LIBDRM_LIB) -o $@ + +egltri.o: egltri.c $(HEADERS) + $(CC) -c $(CFLAGS) -I$(TOP)/include egltri.c + + eglinfo: eglinfo.o $(TOP)/$(LIB_DIR)/libEGL.so $(CC) $(CFLAGS) eglinfo.o -L$(TOP)/$(LIB_DIR) -lGL -lEGL $(LIBDRM_LIB) -o $@ @@ -61,12 +69,14 @@ eglgears: eglgears.o $(TOP)/$(LIB_DIR)/libEGL.so eglgears.o: eglgears.c $(HEADERS) $(CC) -c $(CFLAGS) -I$(TOP)/include eglgears.c + peglgears: peglgears.o $(TOP)/$(LIB_DIR)/libEGL.so $(CC) $(CFLAGS) peglgears.o -L$(TOP)/$(LIB_DIR) -lEGL $(LIBDRM_LIB) $(APP_LIB_DEPS) -o $@ peglgears.o: peglgears.c $(HEADERS) $(CC) -c $(CFLAGS) -I$(TOP)/include peglgears.c + xeglgears: xeglgears.o $(TOP)/$(LIB_DIR)/libEGL.so $(CC) $(CFLAGS) xeglgears.o -L$(TOP)/$(LIB_DIR) -lEGL $(LIBDRM_LIB) $(APP_LIB_DEPS) -o $@ @@ -87,7 +97,7 @@ clean: rm -f $(PROGRAMS) run: - LD_LIBRARY_PATH=$(TOP)/lib ./peglgears + LD_LIBRARY_PATH=$(TOP)/lib ./egltri debug: - LD_LIBRARY_PATH=$(TOP)/lib gdb ./peglgears + LD_LIBRARY_PATH=$(TOP)/lib gdb ./eglgears diff --git a/progs/egl/egltri.c b/progs/egl/egltri.c new file mode 100644 index 0000000000..78c67939b2 --- /dev/null +++ b/progs/egl/egltri.c @@ -0,0 +1,264 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include +#include + +#define MAX_CONFIGS 10 +#define MAX_MODES 100 + + +/* XXX this probably isn't very portable */ + +#include +#include + +/* 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; + + while (ct - st < ttr) + { + double tt = current_time(); + double dt = tt - ct; + ct = tt; + + draw(); + + eglSwapBuffers(dpy, surf); + + frames++; + } + + GLfloat seconds = ct - st; + GLfloat 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((EGLNativeDisplayType)"!EGL_i915"); + 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 && w <= 1280 && h <= 1024) { + width = w; + height = h; + chosenMode = i; + } + } + printf("egltri: Using screen mode/size %d: %d x %d\n", chosenMode, width, height); + + 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; +} -- cgit v1.2.3 From b6db08a91be3203222cda21012791659483b4e5e Mon Sep 17 00:00:00 2001 From: Alan Hourihane Date: Sun, 17 Aug 2008 19:13:17 +0100 Subject: choose a 1024x768 resolution --- progs/egl/egltri.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'progs/egl') diff --git a/progs/egl/egltri.c b/progs/egl/egltri.c index 78c67939b2..43190ba7e1 100644 --- a/progs/egl/egltri.c +++ b/progs/egl/egltri.c @@ -201,7 +201,7 @@ int main(int argc, char *argv[]) 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 && w <= 1280 && h <= 1024) { + if (w > width && h > height && w <= 1024 && h <= 768) { width = w; height = h; chosenMode = i; -- cgit v1.2.3 From 5c9d0c7052112a888174828024b75767222915b9 Mon Sep 17 00:00:00 2001 From: Alan Hourihane Date: Sun, 17 Aug 2008 21:59:00 +0100 Subject: pick first mode --- progs/egl/eglgears.c | 2 +- progs/egl/egltri.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'progs/egl') diff --git a/progs/egl/eglgears.c b/progs/egl/eglgears.c index 20f6c1ff6e..31346d9523 100644 --- a/progs/egl/eglgears.c +++ b/progs/egl/eglgears.c @@ -415,7 +415,7 @@ main(int argc, char *argv[]) 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 && w <= 1280 && h <= 1024) { + if (w > width && h > height) { width = w; height = h; chosenMode = i; diff --git a/progs/egl/egltri.c b/progs/egl/egltri.c index 43190ba7e1..44096d94a2 100644 --- a/progs/egl/egltri.c +++ b/progs/egl/egltri.c @@ -201,7 +201,7 @@ int main(int argc, char *argv[]) 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 && w <= 1024 && h <= 768) { + if (w > width && h > height) { width = w; height = h; chosenMode = i; -- cgit v1.2.3 From 3b3d34d637d413af48fa5bd037b579ccb4ea7bb5 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 17 Sep 2008 15:29:59 -0600 Subject: egl: print multisample info --- progs/egl/eglinfo.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'progs/egl') diff --git a/progs/egl/eglinfo.c b/progs/egl/eglinfo.c index 89feec9be4..14620a9759 100644 --- a/progs/egl/eglinfo.c +++ b/progs/egl/eglinfo.c @@ -48,9 +48,9 @@ PrintConfigs(EGLDisplay d) eglGetConfigs(d, configs, MAX_CONFIGS, &numConfigs); printf("Configurations:\n"); - printf(" bf lv d st colorbuffer dp st vis supported\n"); - printf(" id sz l b ro r g b a th cl id surfaces \n"); - printf("---------------------------------------------------\n"); + printf(" bf lv d st colorbuffer dp st ms vis supported\n"); + printf(" id sz l b ro r g b a th cl ns b id surfaces \n"); + printf("--------------------------------------------------------\n"); for (i = 0; i < numConfigs; i++) { EGLint id, size, level; EGLint red, green, blue, alpha; @@ -58,6 +58,7 @@ PrintConfigs(EGLDisplay d) EGLint surfaces; EGLint doubleBuf = 1, stereo = 0; EGLint vid; + EGLint samples, sampleBuffers; char surfString[100] = ""; eglGetConfigAttrib(d, configs[i], EGL_CONFIG_ID, &id); @@ -73,6 +74,9 @@ PrintConfigs(EGLDisplay d) eglGetConfigAttrib(d, configs[i], EGL_NATIVE_VISUAL_ID, &vid); eglGetConfigAttrib(d, configs[i], EGL_SURFACE_TYPE, &surfaces); + eglGetConfigAttrib(d, configs[i], EGL_SAMPLES, &samples); + eglGetConfigAttrib(d, configs[i], EGL_SAMPLE_BUFFERS, &sampleBuffers); + if (surfaces & EGL_WINDOW_BIT) strcat(surfString, "win,"); if (surfaces & EGL_PBUFFER_BIT) @@ -86,12 +90,13 @@ PrintConfigs(EGLDisplay d) if (strlen(surfString) > 0) surfString[strlen(surfString) - 1] = 0; - printf("0x%02x %2d %2d %c %c %2d %2d %2d %2d %2d %2d 0x%02x %-12s\n", + printf("0x%02x %2d %2d %c %c %2d %2d %2d %2d %2d %2d %2d%2d 0x%02x %-12s\n", id, size, level, doubleBuf ? 'y' : '.', stereo ? 'y' : '.', red, green, blue, alpha, - depth, stencil, vid, surfString); + depth, stencil, + samples, sampleBuffers, vid, surfString); } } -- cgit v1.2.3 From d142f216d2827218d2ad596625fb0054cb7d7fe4 Mon Sep 17 00:00:00 2001 From: Alan Hourihane Date: Fri, 26 Sep 2008 11:16:39 +0100 Subject: link EGL demos with -lGL --- progs/egl/Makefile | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'progs/egl') diff --git a/progs/egl/Makefile b/progs/egl/Makefile index 75cd411d93..f31c21e87e 100644 --- a/progs/egl/Makefile +++ b/progs/egl/Makefile @@ -36,56 +36,56 @@ demo1.o: demo1.c $(HEADERS) demo2: demo2.o $(TOP)/$(LIB_DIR)/libEGL.so - $(CC) $(CFLAGS) $(LDFLAGS) demo2.o -L$(TOP)/$(LIB_DIR) -lEGL $(LIBDRM_LIB) $(APP_LIB_DEPS) -o $@ + $(CC) $(CFLAGS) $(LDFLAGS) demo2.o -L$(TOP)/$(LIB_DIR) -lEGL -lGL $(LIBDRM_LIB) $(APP_LIB_DEPS) -o $@ demo2.o: demo2.c $(HEADERS) $(CC) -c $(CFLAGS) -I$(TOP)/include demo2.c demo3: demo3.o $(TOP)/$(LIB_DIR)/libEGL.so - $(CC) $(CFLAGS) $(LDFLAGS) demo3.o -L$(TOP)/$(LIB_DIR) -lEGL $(LIBDRM_LIB) $(APP_LIB_DEPS) -o $@ + $(CC) $(CFLAGS) $(LDFLAGS) demo3.o -L$(TOP)/$(LIB_DIR) -lEGL -lGL $(LIBDRM_LIB) $(APP_LIB_DEPS) -o $@ demo3.o: demo3.c $(HEADERS) $(CC) -c $(CFLAGS) -I$(TOP)/include demo3.c egltri: egltri.o $(TOP)/$(LIB_DIR)/libEGL.so - $(CC) $(CFLAGS) egltri.o -L$(TOP)/$(LIB_DIR) -lEGL $(LIBDRM_LIB) -o $@ + $(CC) $(CFLAGS) egltri.o -L$(TOP)/$(LIB_DIR) -lEGL -lGL $(LIBDRM_LIB) -o $@ egltri.o: egltri.c $(HEADERS) $(CC) -c $(CFLAGS) -I$(TOP)/include egltri.c eglinfo: eglinfo.o $(TOP)/$(LIB_DIR)/libEGL.so - $(CC) $(CFLAGS) $(LDFLAGS) eglinfo.o -L$(TOP)/$(LIB_DIR) -lEGL $(LIBDRM_LIB) -o $@ + $(CC) $(CFLAGS) $(LDFLAGS) eglinfo.o -L$(TOP)/$(LIB_DIR) -lEGL -lGL $(LIBDRM_LIB) -o $@ eglinfo.o: eglinfo.c $(HEADERS) $(CC) -c $(CFLAGS) -I$(TOP)/include eglinfo.c eglgears: eglgears.o $(TOP)/$(LIB_DIR)/libEGL.so - $(CC) $(CFLAGS) $(LDFLAGS) eglgears.o -L$(TOP)/$(LIB_DIR) -lEGL $(LIBDRM_LIB) $(APP_LIB_DEPS) -o $@ + $(CC) $(CFLAGS) $(LDFLAGS) eglgears.o -L$(TOP)/$(LIB_DIR) -lEGL -lGL $(LIBDRM_LIB) $(APP_LIB_DEPS) -o $@ eglgears.o: eglgears.c $(HEADERS) $(CC) -c $(CFLAGS) -I$(TOP)/include eglgears.c peglgears: peglgears.o $(TOP)/$(LIB_DIR)/libEGL.so - $(CC) $(CFLAGS) peglgears.o -L$(TOP)/$(LIB_DIR) -lEGL $(LIBDRM_LIB) $(APP_LIB_DEPS) -o $@ + $(CC) $(CFLAGS) peglgears.o -L$(TOP)/$(LIB_DIR) -lEGL -lGL $(LIBDRM_LIB) $(APP_LIB_DEPS) -o $@ peglgears.o: peglgears.c $(HEADERS) $(CC) -c $(CFLAGS) -I$(TOP)/include peglgears.c xeglgears: xeglgears.o $(TOP)/$(LIB_DIR)/libEGL.so - $(CC) $(CFLAGS) xeglgears.o -L$(TOP)/$(LIB_DIR) -lEGL $(LIBDRM_LIB) $(APP_LIB_DEPS) -o $@ + $(CC) $(CFLAGS) xeglgears.o -L$(TOP)/$(LIB_DIR) -lEGL -lGL $(LIBDRM_LIB) $(APP_LIB_DEPS) -o $@ xeglgears.o: xeglgears.c $(HEADERS) $(CC) -c $(CFLAGS) -I$(TOP)/include xeglgears.c xegl_tri: xegl_tri.o $(TOP)/$(LIB_DIR)/libEGL.so - $(CC) $(CFLAGS) xegl_tri.o -L$(TOP)/$(LIB_DIR) -lEGL $(LIBDRM_LIB) $(APP_LIB_DEPS) -o $@ + $(CC) $(CFLAGS) xegl_tri.o -L$(TOP)/$(LIB_DIR) -lEGL -lGL $(LIBDRM_LIB) $(APP_LIB_DEPS) -o $@ xegl_tri.o: xegl_tri.c $(HEADERS) $(CC) -c $(CFLAGS) -I$(TOP)/include xegl_tri.c -- cgit v1.2.3 From a5df724c52d19ccc5e9151493e889095c186135d Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Sat, 17 Jan 2009 20:50:00 +0100 Subject: egl: Make eglinfo print screen info --- progs/egl/eglinfo.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'progs/egl') diff --git a/progs/egl/eglinfo.c b/progs/egl/eglinfo.c index 14620a9759..4486916e95 100644 --- a/progs/egl/eglinfo.c +++ b/progs/egl/eglinfo.c @@ -24,8 +24,10 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#define EGL_EGLEXT_PROTOTYPES #include +#include #include #include #include @@ -35,7 +37,6 @@ #define MAX_MODES 1000 #define MAX_SCREENS 10 - /** * Print table of all available configurations. */ -- cgit v1.2.3 From b6b619c6ffadfd93281073317e19fb90fc68a1c0 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Sun, 18 Jan 2009 05:14:01 +0100 Subject: egl: Add eglscreen to help debug egl mesa screen --- progs/egl/.gitignore | 1 + progs/egl/Makefile | 6 +++ progs/egl/eglscreen.c | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 123 insertions(+) create mode 100644 progs/egl/eglscreen.c (limited to 'progs/egl') diff --git a/progs/egl/.gitignore b/progs/egl/.gitignore index 497b0ebbe3..793c6c0f61 100644 --- a/progs/egl/.gitignore +++ b/progs/egl/.gitignore @@ -3,6 +3,7 @@ demo2 demo3 eglgears eglinfo +eglscreen egltri peglgears xeglgears diff --git a/progs/egl/Makefile b/progs/egl/Makefile index f31c21e87e..e1fdb1ce63 100644 --- a/progs/egl/Makefile +++ b/progs/egl/Makefile @@ -15,6 +15,7 @@ PROGRAMS = \ egltri \ eglinfo \ eglgears \ + eglscreen \ peglgears \ xeglgears \ xegl_tri @@ -69,6 +70,11 @@ eglgears: eglgears.o $(TOP)/$(LIB_DIR)/libEGL.so eglgears.o: eglgears.c $(HEADERS) $(CC) -c $(CFLAGS) -I$(TOP)/include eglgears.c +eglscreen: eglscreen.o $(TOP)/$(LIB_DIR)/libEGL.so + $(CC) $(CFLAGS) $(LDFLAGS) eglscreen.o -L$(TOP)/$(LIB_DIR) -lEGL -lGL $(LIBDRM_LIB) $(APP_LIB_DEPS) -o $@ + +eglscreen.o: eglscreen.c $(HEADERS) + $(CC) -c $(CFLAGS) -I$(TOP)/include eglscreen.c peglgears: peglgears.o $(TOP)/$(LIB_DIR)/libEGL.so $(CC) $(CFLAGS) peglgears.o -L$(TOP)/$(LIB_DIR) -lEGL -lGL $(LIBDRM_LIB) $(APP_LIB_DEPS) -o $@ diff --git a/progs/egl/eglscreen.c b/progs/egl/eglscreen.c new file mode 100644 index 0000000000..f3b7f04f96 --- /dev/null +++ b/progs/egl/eglscreen.c @@ -0,0 +1,116 @@ +/* + * 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. + */ + +/* + * Stolen from eglgears + * + * Creates a surface and show that on the first screen + */ + +#define EGL_EGLEXT_PROTOTYPES + +#include +#include +#include +#include +#include +#include +#include +#include + +#define MAX_CONFIGS 10 +#define MAX_MODES 100 + +int +main(int argc, char *argv[]) +{ + int maj, min; + 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; + EGLint width = 0, height = 0; + + d = eglGetDisplay((EGLNativeDisplayType)"!EGL_i915"); + assert(d); + + if (!eglInitialize(d, &maj, &min)) { + printf("eglscreen: eglInitialize failed\n"); + exit(1); + } + + printf("eglscreen: EGL version = %d.%d\n", maj, min); + printf("eglscreen: 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("eglscreen: eglGetModesMESA failed!\n"); + return 0; + } + + /* Print list of modes, and find the one to use */ + printf("eglscreen: 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("eglscreen: Using screen mode/size %d: %d x %d\n", chosenMode, width, height); + + /* 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("eglscreen: Failed to create screen surface\n"); + return 0; + } + + b = eglShowScreenSurfaceMESA(d, screen, screen_surf, mode[chosenMode]); + if (!b) { + printf("eglscreen: Show surface failed\n"); + return 0; + } + + eglDestroySurface(d, screen_surf); + eglTerminate(d); + + return 0; +} -- cgit v1.2.3 From 94ddd621d13310aca229ab64a86aee3d4db680e8 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Sun, 18 Jan 2009 13:40:24 +0100 Subject: egl: Make eglscreen sleep for five seconds --- progs/egl/eglscreen.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'progs/egl') diff --git a/progs/egl/eglscreen.c b/progs/egl/eglscreen.c index f3b7f04f96..c0b5a210a4 100644 --- a/progs/egl/eglscreen.c +++ b/progs/egl/eglscreen.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -109,6 +110,8 @@ main(int argc, char *argv[]) return 0; } + usleep(5000000); + eglDestroySurface(d, screen_surf); eglTerminate(d); -- cgit v1.2.3 From 1fd411539b9b7b8ae46c1aff0a000d9b4a8f5f3b Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Mon, 19 Jan 2009 02:29:54 +0100 Subject: egl: eglinfo load i915 driver --- progs/egl/eglinfo.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'progs/egl') diff --git a/progs/egl/eglinfo.c b/progs/egl/eglinfo.c index 4486916e95..feae954b75 100644 --- a/progs/egl/eglinfo.c +++ b/progs/egl/eglinfo.c @@ -147,7 +147,8 @@ int main(int argc, char *argv[]) { int maj, min; - EGLDisplay d = eglGetDisplay(EGL_DEFAULT_DISPLAY); + //EGLDisplay d = eglGetDisplay((EGLNativeDisplayType)"!EGL_i915"); + EGLDisplay d = eglGetDisplay((EGLNativeDisplayType)"!EGL_i915"); if (!eglInitialize(d, &maj, &min)) { printf("eglinfo: eglInitialize failed\n"); -- cgit v1.2.3 From 721f80b82ac1f1535f55367d921a2a292eb4898f Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Thu, 16 Jul 2009 08:29:19 -0600 Subject: egl: Add xeglthreads Signed-off-by: Chia-I Wu --- progs/egl/.gitignore | 1 + progs/egl/Makefile | 8 + progs/egl/xeglthreads.c | 766 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 775 insertions(+) create mode 100644 progs/egl/xeglthreads.c (limited to 'progs/egl') diff --git a/progs/egl/.gitignore b/progs/egl/.gitignore index 793c6c0f61..f417aefb93 100644 --- a/progs/egl/.gitignore +++ b/progs/egl/.gitignore @@ -7,4 +7,5 @@ eglscreen egltri peglgears xeglgears +xeglthreads xegl_tri diff --git a/progs/egl/Makefile b/progs/egl/Makefile index e1fdb1ce63..d3c32d46f7 100644 --- a/progs/egl/Makefile +++ b/progs/egl/Makefile @@ -18,6 +18,7 @@ PROGRAMS = \ eglscreen \ peglgears \ xeglgears \ + xeglthreads \ xegl_tri @@ -90,6 +91,13 @@ xeglgears.o: xeglgears.c $(HEADERS) $(CC) -c $(CFLAGS) -I$(TOP)/include xeglgears.c +xeglthreads: xeglthreads.o $(TOP)/$(LIB_DIR)/libEGL.so + $(CC) $(CFLAGS) xeglthreads.o -L$(TOP)/$(LIB_DIR) -lEGL -lGL $(LIBDRM_LIB) $(APP_LIB_DEPS) -o $@ + +xeglthreads.o: xeglthreads.c $(HEADERS) + $(CC) -c $(CFLAGS) -I$(TOP)/include xeglthreads.c + + xegl_tri: xegl_tri.o $(TOP)/$(LIB_DIR)/libEGL.so $(CC) $(CFLAGS) xegl_tri.o -L$(TOP)/$(LIB_DIR) -lEGL -lGL $(LIBDRM_LIB) $(APP_LIB_DEPS) -o $@ diff --git a/progs/egl/xeglthreads.c b/progs/egl/xeglthreads.c new file mode 100644 index 0000000000..5cc856ab3f --- /dev/null +++ b/progs/egl/xeglthreads.c @@ -0,0 +1,766 @@ +/* + * Copyright (C) 2000 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * Ported to EGL by Chia-I Wu + */ + + +/* + * This program tests EGL thread safety. + * Command line options: + * -p Open a display connection for each thread + * -l Enable application-side locking + * -n Number of threads to create (default is 2) + * -display Specify X display (default is $DISPLAY) + * -t Use texture mapping + * + * Brian Paul 20 July 2000 + */ + + +/* + * Notes: + * - Each thread gets its own EGL context. + * + * - The EGL contexts share texture objects. + * + * - When 't' is pressed to update the texture image, the window/thread which + * has input focus is signalled to change the texture. The other threads + * should see the updated texture the next time they call glBindTexture. + */ + + +#if defined(PTHREADS) /* defined by Mesa on Linux and other platforms */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +/* + * Each window/thread/context: + */ +struct winthread { + Display *Dpy; + int Index; + pthread_t Thread; + Window Win; + EGLDisplay Display; + EGLContext Context; + EGLSurface Surface; + float Angle; + int WinWidth, WinHeight; + GLboolean NewSize; + GLboolean Initialized; + GLboolean MakeNewTexture; +}; + + +#define MAX_WINTHREADS 100 +static struct winthread WinThreads[MAX_WINTHREADS]; +static int NumWinThreads = 0; +static volatile GLboolean ExitFlag = GL_FALSE; + +static GLboolean MultiDisplays = 0; +static GLboolean Locking = 0; +static GLboolean Texture = GL_FALSE; +static GLuint TexObj = 12; +static GLboolean Animate = GL_TRUE; + +static pthread_mutex_t Mutex; +static pthread_cond_t CondVar; +static pthread_mutex_t CondMutex; + + +static void +Error(const char *msg) +{ + fprintf(stderr, "Error: %s\n", msg); + exit(1); +} + + +static void +signal_redraw(void) +{ + pthread_mutex_lock(&CondMutex); + pthread_cond_broadcast(&CondVar); + pthread_mutex_unlock(&CondMutex); +} + + +static void +MakeNewTexture(struct winthread *wt) +{ +#define TEX_SIZE 128 + static float step = 0.0; + GLfloat image[TEX_SIZE][TEX_SIZE][4]; + GLint width; + int i, j; + + for (j = 0; j < TEX_SIZE; j++) { + for (i = 0; i < TEX_SIZE; i++) { + float dt = 5.0 * (j - 0.5 * TEX_SIZE) / TEX_SIZE; + float ds = 5.0 * (i - 0.5 * TEX_SIZE) / TEX_SIZE; + float r = dt * dt + ds * ds + step; + image[j][i][0] = + image[j][i][1] = + image[j][i][2] = 0.75 + 0.25 * cos(r); + image[j][i][3] = 1.0; + } + } + + step += 0.5; + + glBindTexture(GL_TEXTURE_2D, TexObj); + + glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width); + if (width) { + assert(width == TEX_SIZE); + /* sub-tex replace */ + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, TEX_SIZE, TEX_SIZE, + GL_RGBA, GL_FLOAT, image); + } + else { + /* create new */ + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TEX_SIZE, TEX_SIZE, 0, + GL_RGBA, GL_FLOAT, image); + } +} + + + +/* draw a colored cube */ +static void +draw_object(void) +{ + glPushMatrix(); + glScalef(0.75, 0.75, 0.75); + + glColor3f(1, 0, 0); + + if (Texture) { + glBindTexture(GL_TEXTURE_2D, TexObj); + glEnable(GL_TEXTURE_2D); + } + else { + glDisable(GL_TEXTURE_2D); + } + + glBegin(GL_QUADS); + + /* -X */ + glColor3f(0, 1, 1); + glTexCoord2f(0, 0); glVertex3f(-1, -1, -1); + glTexCoord2f(1, 0); glVertex3f(-1, 1, -1); + glTexCoord2f(1, 1); glVertex3f(-1, 1, 1); + glTexCoord2f(0, 1); glVertex3f(-1, -1, 1); + + /* +X */ + glColor3f(1, 0, 0); + glTexCoord2f(0, 0); glVertex3f(1, -1, -1); + glTexCoord2f(1, 0); glVertex3f(1, 1, -1); + glTexCoord2f(1, 1); glVertex3f(1, 1, 1); + glTexCoord2f(0, 1); glVertex3f(1, -1, 1); + + /* -Y */ + glColor3f(1, 0, 1); + glTexCoord2f(0, 0); glVertex3f(-1, -1, -1); + glTexCoord2f(1, 0); glVertex3f( 1, -1, -1); + glTexCoord2f(1, 1); glVertex3f( 1, -1, 1); + glTexCoord2f(0, 1); glVertex3f(-1, -1, 1); + + /* +Y */ + glColor3f(0, 1, 0); + glTexCoord2f(0, 0); glVertex3f(-1, 1, -1); + glTexCoord2f(1, 0); glVertex3f( 1, 1, -1); + glTexCoord2f(1, 1); glVertex3f( 1, 1, 1); + glTexCoord2f(0, 1); glVertex3f(-1, 1, 1); + + /* -Z */ + glColor3f(1, 1, 0); + glTexCoord2f(0, 0); glVertex3f(-1, -1, -1); + glTexCoord2f(1, 0); glVertex3f( 1, -1, -1); + glTexCoord2f(1, 1); glVertex3f( 1, 1, -1); + glTexCoord2f(0, 1); glVertex3f(-1, 1, -1); + + /* +Y */ + glColor3f(0, 0, 1); + glTexCoord2f(0, 0); glVertex3f(-1, -1, 1); + glTexCoord2f(1, 0); glVertex3f( 1, -1, 1); + glTexCoord2f(1, 1); glVertex3f( 1, 1, 1); + glTexCoord2f(0, 1); glVertex3f(-1, 1, 1); + + glEnd(); + + glPopMatrix(); +} + + +/* signal resize of given window */ +static void +resize(struct winthread *wt, int w, int h) +{ + wt->NewSize = GL_TRUE; + wt->WinWidth = w; + wt->WinHeight = h; + if (!Animate) + signal_redraw(); +} + + +/* + * We have an instance of this for each thread. + */ +static void +draw_loop(struct winthread *wt) +{ + while (!ExitFlag) { + + if (Locking) + pthread_mutex_lock(&Mutex); + + if (!wt->Initialized) { + eglMakeCurrent(wt->Display, wt->Surface, wt->Surface, wt->Context); + printf("xeglthreads: %d: GL_RENDERER = %s\n", wt->Index, + (char *) glGetString(GL_RENDERER)); + if (Texture /*&& wt->Index == 0*/) { + MakeNewTexture(wt); + } + wt->Initialized = GL_TRUE; + } + + if (Locking) + pthread_mutex_unlock(&Mutex); + + glEnable(GL_DEPTH_TEST); + + if (wt->NewSize) { + GLfloat w = (float) wt->WinWidth / (float) wt->WinHeight; + glViewport(0, 0, wt->WinWidth, wt->WinHeight); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-w, w, -1.0, 1.0, 1.5, 10); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0, 0, -2.5); + wt->NewSize = GL_FALSE; + } + + if (wt->MakeNewTexture) { + MakeNewTexture(wt); + wt->MakeNewTexture = GL_FALSE; + } + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glPushMatrix(); + glRotatef(wt->Angle, 0, 1, 0); + glRotatef(wt->Angle, 1, 0, 0); + glScalef(0.7, 0.7, 0.7); + draw_object(); + glPopMatrix(); + + if (Locking) + pthread_mutex_lock(&Mutex); + + eglSwapBuffers(wt->Display, wt->Surface); + + if (Locking) + pthread_mutex_unlock(&Mutex); + + if (Animate) { + usleep(5000); + } + else { + /* wait for signal to draw */ + pthread_mutex_lock(&CondMutex); + pthread_cond_wait(&CondVar, &CondMutex); + pthread_mutex_unlock(&CondMutex); + } + wt->Angle += 1.0; + } +} + + +static void +keypress(XEvent *event, struct winthread *wt) +{ + char buf[100]; + KeySym keySym; + XComposeStatus stat; + + XLookupString(&event->xkey, buf, sizeof(buf), &keySym, &stat); + + switch (keySym) { + case XK_Escape: + /* tell all threads to exit */ + if (!Animate) { + signal_redraw(); + } + ExitFlag = GL_TRUE; + /*printf("exit draw_loop %d\n", wt->Index);*/ + return; + case XK_t: + case XK_T: + if (Texture) { + wt->MakeNewTexture = GL_TRUE; + if (!Animate) + signal_redraw(); + } + break; + case XK_a: + case XK_A: + Animate = !Animate; + if (Animate) /* yes, prev Animate state! */ + signal_redraw(); + break; + case XK_s: + case XK_S: + if (!Animate) + signal_redraw(); + break; + default: + ; /* nop */ + } +} + + +/* + * The main process thread runs this loop. + * Single display connection for all threads. + */ +static void +event_loop(Display *dpy) +{ + XEvent event; + int i; + + assert(!MultiDisplays); + + while (!ExitFlag) { + + if (Locking) { + while (1) { + int k; + pthread_mutex_lock(&Mutex); + k = XPending(dpy); + if (k) { + XNextEvent(dpy, &event); + pthread_mutex_unlock(&Mutex); + break; + } + pthread_mutex_unlock(&Mutex); + usleep(5000); + } + } + else { + XNextEvent(dpy, &event); + } + + switch (event.type) { + case ConfigureNotify: + /* Find winthread for this event's window */ + for (i = 0; i < NumWinThreads; i++) { + struct winthread *wt = &WinThreads[i]; + if (event.xconfigure.window == wt->Win) { + resize(wt, event.xconfigure.width, + event.xconfigure.height); + break; + } + } + break; + case KeyPress: + for (i = 0; i < NumWinThreads; i++) { + struct winthread *wt = &WinThreads[i]; + if (event.xkey.window == wt->Win) { + keypress(&event, wt); + break; + } + } + break; + default: + /*no-op*/ ; + } + } +} + + +/* + * Separate display connection for each thread. + */ +static void +event_loop_multi(void) +{ + XEvent event; + int w = 0; + + assert(MultiDisplays); + + while (!ExitFlag) { + struct winthread *wt = &WinThreads[w]; + if (XPending(wt->Dpy)) { + XNextEvent(wt->Dpy, &event); + switch (event.type) { + case ConfigureNotify: + resize(wt, event.xconfigure.width, event.xconfigure.height); + break; + case KeyPress: + keypress(&event, wt); + break; + default: + ; /* nop */ + } + } + w = (w + 1) % NumWinThreads; + usleep(5000); + } +} + + + +/* + * we'll call this once for each thread, before the threads are created. + */ +static void +create_window(struct winthread *wt, EGLContext shareCtx) +{ + Window win; + EGLContext ctx; + EGLSurface surf; + EGLint attribs[] = { EGL_RED_SIZE, 1, + EGL_GREEN_SIZE, 1, + EGL_BLUE_SIZE, 1, + EGL_DEPTH_SIZE, 1, + EGL_NONE }; + EGLConfig config; + EGLint num_configs; + EGLint vid; + int scrnum; + XSetWindowAttributes attr; + unsigned long mask; + Window root; + XVisualInfo *visinfo, visTemplate; + int num_visuals; + int width = 160, height = 160; + int xpos = (wt->Index % 8) * (width + 10); + int ypos = (wt->Index / 8) * (width + 20); + + scrnum = DefaultScreen(wt->Dpy); + root = RootWindow(wt->Dpy, scrnum); + + if (!eglChooseConfig(wt->Display, attribs, &config, 1, &num_configs)) { + Error("Unable to choose an EGL config"); + } + + assert(config); + assert(num_configs > 0); + + if (!eglGetConfigAttrib(wt->Display, config, EGL_NATIVE_VISUAL_ID, &vid)) { + Error("Unable to get visual id of EGL config\n"); + } + + visTemplate.visualid = vid; + visinfo = XGetVisualInfo(wt->Dpy, VisualIDMask, + &visTemplate, &num_visuals); + if (!visinfo) { + Error("Unable to find RGB, Z, double-buffered visual"); + } + + /* window attributes */ + attr.background_pixel = 0; + attr.border_pixel = 0; + attr.colormap = XCreateColormap(wt->Dpy, root, visinfo->visual, AllocNone); + attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask; + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; + + win = XCreateWindow(wt->Dpy, root, xpos, ypos, width, height, + 0, visinfo->depth, InputOutput, + visinfo->visual, mask, &attr); + if (!win) { + Error("Couldn't create window"); + } + + XFree(visinfo); + + { + XSizeHints sizehints; + sizehints.x = xpos; + sizehints.y = ypos; + sizehints.width = width; + sizehints.height = height; + sizehints.flags = USSize | USPosition; + XSetNormalHints(wt->Dpy, win, &sizehints); + XSetStandardProperties(wt->Dpy, win, "xeglthreads", "xeglthreads", + None, (char **)NULL, 0, &sizehints); + } + + eglBindAPI(EGL_OPENGL_API); + + ctx = eglCreateContext(wt->Display, config, shareCtx, NULL); + if (!ctx) { + Error("Couldn't create EGL context"); + } + surf = eglCreateWindowSurface(wt->Display, config, win, NULL); + if (!surf) { + Error("Couldn't create EGL surface"); + } + + XMapWindow(wt->Dpy, win); + XSync(wt->Dpy, 0); + + /* save the info for this window/context */ + wt->Win = win; + wt->Context = ctx; + wt->Surface = surf; + wt->Angle = 0.0; + wt->WinWidth = width; + wt->WinHeight = height; + wt->NewSize = GL_TRUE; +} + + +/* + * Called by pthread_create() + */ +static void * +thread_function(void *p) +{ + struct winthread *wt = (struct winthread *) p; + draw_loop(wt); + return NULL; +} + + +/* + * called before exit to wait for all threads to finish + */ +static void +clean_up(void) +{ + int i; + + /* wait for threads to finish */ + for (i = 0; i < NumWinThreads; i++) { + pthread_join(WinThreads[i].Thread, NULL); + } + + for (i = 0; i < NumWinThreads; i++) { + eglDestroyContext(WinThreads[i].Dpy, WinThreads[i].Context); + XDestroyWindow(WinThreads[i].Dpy, WinThreads[i].Win); + } +} + + +static void +usage(void) +{ + printf("xeglthreads: test of EGL/GL thread safety (any key = exit)\n"); + printf("Usage:\n"); + printf(" xeglthreads [options]\n"); + printf("Options:\n"); + printf(" -display DISPLAYNAME Specify display string\n"); + printf(" -n NUMTHREADS Number of threads to create\n"); + printf(" -p Use a separate display connection for each thread\n"); + printf(" -l Use application-side locking\n"); + printf(" -t Enable texturing\n"); + printf("Keyboard:\n"); + printf(" Esc Exit\n"); + printf(" t Change texture image (requires -t option)\n"); + printf(" a Toggle animation\n"); + printf(" s Step rotation (when not animating)\n"); +} + + +int +main(int argc, char *argv[]) +{ + char *displayName = NULL; + int numThreads = 2; + Display *dpy = NULL; + EGLDisplay *egl_dpy = NULL; + int i; + Status threadStat; + + if (argc == 1) { + usage(); + } + else { + int i; + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-display") == 0 && i + 1 < argc) { + displayName = argv[i + 1]; + i++; + } + else if (strcmp(argv[i], "-p") == 0) { + MultiDisplays = 1; + } + else if (strcmp(argv[i], "-l") == 0) { + Locking = 1; + } + else if (strcmp(argv[i], "-t") == 0) { + Texture = 1; + } + else if (strcmp(argv[i], "-n") == 0 && i + 1 < argc) { + numThreads = atoi(argv[i + 1]); + if (numThreads < 1) + numThreads = 1; + else if (numThreads > MAX_WINTHREADS) + numThreads = MAX_WINTHREADS; + i++; + } + else { + usage(); + exit(1); + } + } + } + + if (Locking) + printf("xeglthreads: Using explicit locks around Xlib calls.\n"); + else + printf("xeglthreads: No explict locking.\n"); + + if (MultiDisplays) + printf("xeglthreads: Per-thread display connections.\n"); + else + printf("xeglthreads: Single display connection.\n"); + + /* + * VERY IMPORTANT: call XInitThreads() before any other Xlib functions. + */ + if (!MultiDisplays) { + if (!Locking) { + threadStat = XInitThreads(); + if (threadStat) { + printf("XInitThreads() returned %d (success)\n", + (int) threadStat); + } + else { + printf("XInitThreads() returned 0 " + "(failure- this program may fail)\n"); + } + } + + dpy = XOpenDisplay(displayName); + if (!dpy) { + fprintf(stderr, "Unable to open display %s\n", + XDisplayName(displayName)); + return -1; + } + egl_dpy = eglGetDisplay(dpy); + if (!egl_dpy) { + fprintf(stderr, "Unable to get EGL display\n"); + XCloseDisplay(dpy); + return -1; + } + if (!eglInitialize(egl_dpy, NULL, NULL)) { + fprintf(stderr, "Unable to initialize EGL display\n"); + return -1; + } + } + + pthread_mutex_init(&Mutex, NULL); + pthread_mutex_init(&CondMutex, NULL); + pthread_cond_init(&CondVar, NULL); + + printf("xeglthreads: creating windows\n"); + + NumWinThreads = numThreads; + + /* Create the EGL windows and contexts */ + for (i = 0; i < numThreads; i++) { + EGLContext share; + + if (MultiDisplays) { + WinThreads[i].Dpy = XOpenDisplay(displayName); + assert(WinThreads[i].Dpy); + WinThreads[i].Display = eglGetDisplay(WinThreads[i].Dpy); + assert(eglInitialize(WinThreads[i].Display, NULL, NULL)); + } + else { + WinThreads[i].Dpy = dpy; + WinThreads[i].Display = egl_dpy; + } + WinThreads[i].Index = i; + WinThreads[i].Initialized = GL_FALSE; + + share = (Texture && i > 0) ? WinThreads[0].Context : 0; + + create_window(&WinThreads[i], share); + } + + printf("xeglthreads: creating threads\n"); + + /* Create the threads */ + for (i = 0; i < numThreads; i++) { + pthread_create(&WinThreads[i].Thread, NULL, thread_function, + (void*) &WinThreads[i]); + printf("xeglthreads: Created thread %p\n", + (void *) WinThreads[i].Thread); + } + + if (MultiDisplays) + event_loop_multi(); + else + event_loop(dpy); + + clean_up(); + + if (MultiDisplays) { + for (i = 0; i < numThreads; i++) { + eglTerminate(WinThreads[i].Display); + XCloseDisplay(WinThreads[i].Dpy); + } + } + else { + eglTerminate(dpy); + XCloseDisplay(dpy); + } + + return 0; +} + + +#else /* PTHREADS */ + + +#include + +int +main(int argc, char *argv[]) +{ + printf("Sorry, this program wasn't compiled with PTHREADS defined.\n"); + return 0; +} + + +#endif /* PTHREADS */ -- cgit v1.2.3 From 30bccf8ea9cd84d1a52a31b6f86b783dfb919374 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Thu, 16 Jul 2009 21:21:59 -0700 Subject: xeglthreads: Check current context for EGL per-thread support. Signed-off-by: Chia-I Wu --- progs/egl/xeglthreads.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'progs/egl') diff --git a/progs/egl/xeglthreads.c b/progs/egl/xeglthreads.c index 5cc856ab3f..508dbc0943 100644 --- a/progs/egl/xeglthreads.c +++ b/progs/egl/xeglthreads.c @@ -261,6 +261,12 @@ draw_loop(struct winthread *wt) if (Locking) pthread_mutex_unlock(&Mutex); + eglBindAPI(EGL_OPENGL_API); + if (eglGetCurrentContext() != wt->Context) { + printf("xeglthreads: current context %p != %p\n", + eglGetCurrentContext(), wt->Context); + } + glEnable(GL_DEPTH_TEST); if (wt->NewSize) { @@ -308,6 +314,7 @@ draw_loop(struct winthread *wt) } wt->Angle += 1.0; } + eglMakeCurrent(wt->Display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); } @@ -574,7 +581,7 @@ clean_up(void) } for (i = 0; i < NumWinThreads; i++) { - eglDestroyContext(WinThreads[i].Dpy, WinThreads[i].Context); + eglDestroyContext(WinThreads[i].Display, WinThreads[i].Context); XDestroyWindow(WinThreads[i].Dpy, WinThreads[i].Win); } } @@ -742,7 +749,7 @@ main(int argc, char *argv[]) } } else { - eglTerminate(dpy); + eglTerminate(egl_dpy); XCloseDisplay(dpy); } -- cgit v1.2.3 From 246f58d922272a778454a466abd50106317e16ac Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Wed, 5 Aug 2009 16:08:48 -0600 Subject: progs/egl: Add xeglbindtex. This is a simple demo for eglBindTexImage. It uses a OpenGL context, instead of the required OpenGL ES one. But it still suffices the demo and test purpose. Signed-off-by: Chia-I Wu --- progs/egl/Makefile | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'progs/egl') diff --git a/progs/egl/Makefile b/progs/egl/Makefile index d3c32d46f7..fd72f540ca 100644 --- a/progs/egl/Makefile +++ b/progs/egl/Makefile @@ -17,6 +17,7 @@ PROGRAMS = \ eglgears \ eglscreen \ peglgears \ + xeglbindtex \ xeglgears \ xeglthreads \ xegl_tri @@ -84,6 +85,12 @@ peglgears.o: peglgears.c $(HEADERS) $(CC) -c $(CFLAGS) -I$(TOP)/include peglgears.c +xeglbindtex: xeglbindtex.o $(TOP)/$(LIB_DIR)/libEGL.so + $(CC) $(CFLAGS) xeglbindtex.o -L$(TOP)/$(LIB_DIR) -lEGL -lGL $(LIBDRM_LIB) $(APP_LIB_DEPS) -o $@ + +xeglbindtex.o: xeglbindtex.c $(HEADERS) + $(CC) -c $(CFLAGS) -I$(TOP)/include xeglbindtex.c + xeglgears: xeglgears.o $(TOP)/$(LIB_DIR)/libEGL.so $(CC) $(CFLAGS) xeglgears.o -L$(TOP)/$(LIB_DIR) -lEGL -lGL $(LIBDRM_LIB) $(APP_LIB_DEPS) -o $@ -- cgit v1.2.3 From e179ab2815f4de7a704f057204e692b136e7a0b3 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Thu, 6 Aug 2009 08:39:25 -0600 Subject: progs/egl: Add xeglbindtex, really. Missed this file in the earlier commit. --- progs/egl/xeglbindtex.c | 474 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 474 insertions(+) create mode 100644 progs/egl/xeglbindtex.c (limited to 'progs/egl') diff --git a/progs/egl/xeglbindtex.c b/progs/egl/xeglbindtex.c new file mode 100644 index 0000000000..fdd9fe2b87 --- /dev/null +++ b/progs/egl/xeglbindtex.c @@ -0,0 +1,474 @@ +/* + * Simple demo for eglBindTexImage. Based on xegl_tri.c by + * + * Copyright (C) 2008 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* + * The spec says that eglBindTexImage supports only OpenGL ES context, but this + * demo uses OpenGL context. Keep in mind that this is non-standard. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static EGLDisplay dpy; +static EGLContext ctx_win, ctx_pbuf; +static EGLSurface surf_win, surf_pbuf; +static GLuint tex_pbuf; + +static GLfloat view_rotx = 0.0, view_roty = 0.0, view_rotz = 0.0; +static GLboolean blend = GL_TRUE; +static GLuint color_flow; + +static void +make_pbuffer(int width, int height) +{ + static const EGLint config_attribs[] = { + EGL_RED_SIZE, 8, + EGL_GREEN_SIZE, 8, + EGL_BLUE_SIZE, 8, + EGL_BIND_TO_TEXTURE_RGB, EGL_TRUE, + EGL_NONE + }; + EGLint pbuf_attribs[] = { + EGL_WIDTH, width, + EGL_HEIGHT, height, + EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGB, + EGL_TEXTURE_TARGET, EGL_TEXTURE_2D, + EGL_NONE + }; + EGLConfig config; + EGLint num_configs; + + if (!eglChooseConfig(dpy, config_attribs, &config, 1, &num_configs)) { + printf("Error: couldn't get an EGL visual config for pbuffer\n"); + exit(1); + } + + eglBindAPI(EGL_OPENGL_API); + ctx_pbuf = eglCreateContext(dpy, config, EGL_NO_CONTEXT, NULL ); + surf_pbuf = eglCreatePbufferSurface(dpy, config, pbuf_attribs); + if (surf_pbuf == EGL_NO_SURFACE) { + printf("failed to allocate pbuffer\n"); + exit(1); + } + + glGenTextures(1, &tex_pbuf); +} + +static void +use_pbuffer(void) +{ + static int initialized; + + eglMakeCurrent(dpy, surf_pbuf, surf_pbuf, ctx_pbuf); + if (!initialized) { + EGLint width, height; + GLfloat ar; + + initialized = 1; + + eglQuerySurface(dpy, surf_pbuf, EGL_WIDTH, &width); + eglQuerySurface(dpy, surf_pbuf, EGL_WIDTH, &height); + ar = (GLfloat) width / (GLfloat) height; + + glViewport(0, 0, (GLint) width, (GLint) height); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-ar, ar, -1, 1, 1.0, 10.0); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + + /* y-inverted */ + glScalef(1.0, -1.0, 1.0); + + glTranslatef(0.0, 0.0, -5.0); + + glClearColor(0.2, 0.2, 0.2, 0.0); + } +} + +static void +make_window(Display *x_dpy, const char *name, + int x, int y, int width, int height, + Window *winRet) +{ + static const EGLint attribs[] = { + EGL_RED_SIZE, 8, + EGL_GREEN_SIZE, 8, + EGL_BLUE_SIZE, 8, + EGL_ALPHA_SIZE, 8, + EGL_DEPTH_SIZE, 8, + EGL_NONE + }; + + int scrnum; + XSetWindowAttributes attr; + unsigned long mask; + Window root; + Window win; + XVisualInfo *visInfo, visTemplate; + int num_visuals; + EGLConfig config; + EGLint num_configs, vid; + + scrnum = DefaultScreen( x_dpy ); + root = RootWindow( x_dpy, scrnum ); + + if (!eglChooseConfig(dpy, attribs, &config, 1, &num_configs)) { + printf("Error: couldn't get an EGL visual config\n"); + exit(1); + } + + if (!eglGetConfigAttrib(dpy, config, EGL_NATIVE_VISUAL_ID, &vid)) { + printf("Error: eglGetConfigAttrib() failed\n"); + exit(1); + } + + /* The X window visual must match the EGL config */ + visTemplate.visualid = vid; + visInfo = XGetVisualInfo(x_dpy, VisualIDMask, &visTemplate, &num_visuals); + if (!visInfo) { + printf("Error: couldn't get X visual\n"); + exit(1); + } + + /* window attributes */ + attr.background_pixel = 0; + attr.border_pixel = 0; + attr.colormap = XCreateColormap( x_dpy, root, visInfo->visual, AllocNone); + attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask; + attr.override_redirect = 0; + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect; + + win = XCreateWindow( x_dpy, root, 0, 0, width, height, + 0, visInfo->depth, InputOutput, + visInfo->visual, mask, &attr ); + + /* set hints and properties */ + { + XSizeHints sizehints; + sizehints.x = x; + sizehints.y = y; + sizehints.width = width; + sizehints.height = height; + sizehints.flags = USSize | USPosition; + XSetNormalHints(x_dpy, win, &sizehints); + XSetStandardProperties(x_dpy, win, name, name, + None, (char **)NULL, 0, &sizehints); + } + + eglBindAPI(EGL_OPENGL_API); + ctx_win = eglCreateContext(dpy, config, EGL_NO_CONTEXT, NULL ); + if (!ctx_win) { + printf("Error: glXCreateContext failed\n"); + exit(1); + } + + surf_win = eglCreateWindowSurface(dpy, config, win, NULL); + + XFree(visInfo); + + *winRet = win; +} + +static void +use_window(void) +{ + static int initialized; + + eglMakeCurrent(dpy, surf_win, surf_win, ctx_win); + if (!initialized) { + initialized = 1; + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, tex_pbuf); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + } +} + +static void +draw_triangle(void) +{ + static const GLfloat verts[3][2] = { + { -3, -3 }, + { 3, -3 }, + { 0, 3 } + }; + GLfloat colors[3][3] = { + { 1, 0, 0 }, + { 0, 1, 0 }, + { 0, 0, 1 } + }; + GLint i; + + /* flow the color */ + for (i = 0; i < 3; i++) { + GLint first = (i + color_flow / 256) % 3; + GLint second = (first + 1) % 3; + GLint third = (second + 1) % 3; + GLfloat c = (color_flow % 256) / 256.0f; + + c = c * c * c; + colors[i][first] = 1.0f - c; + colors[i][second] = c; + colors[i][third] = 0.0f; + } + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glVertexPointer(2, GL_FLOAT, 0, verts); + glColorPointer(3, GL_FLOAT, 0, colors); + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_COLOR_ARRAY); + + glDrawArrays(GL_TRIANGLES, 0, 3); + + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); +} + +static void +draw_textured_cube(void) +{ + static const GLfloat verts[][2] = { + { -4, -4 }, + { 4, -4 }, + { 4, 4 }, + { -4, 4 } + }; + static const GLfloat colors[][4] = { + { 1, 1, 1, 0.5 }, + { 1, 1, 1, 0.5 }, + { 1, 1, 1, 0.5 }, + { 1, 1, 1, 0.5 } + }; + static const GLfloat texs[][2] = { + { 0, 0 }, + { 1, 0 }, + { 1, 1 }, + { 0, 1 } + }; + static const GLfloat xforms[6][4] = { + { 0, 0, 1, 0 }, + { 90, 0, 1, 0 }, + { 180, 0, 1, 0 }, + { 270, 0, 1, 0 }, + { 90, 1, 0, 0 }, + { -90, 1, 0, 0 } + }; + GLint i; + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + if (blend) { + glDisable(GL_DEPTH_TEST); + glEnable(GL_BLEND); + } else { + glEnable(GL_DEPTH_TEST); + glDisable(GL_BLEND); + } + + glVertexPointer(2, GL_FLOAT, 0, verts); + glColorPointer(4, GL_FLOAT, 0, colors); + glTexCoordPointer(2, GL_FLOAT, 0, texs); + + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_COLOR_ARRAY); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + + for (i = 0; i < 6; i++) { + glPushMatrix(); + glRotatef(xforms[i][0], xforms[i][1], xforms[i][2], xforms[i][3]); + glTranslatef(0, 0, 4.1); + glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + glPopMatrix(); + } + + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); +} + +static void +draw(void) +{ + use_pbuffer(); + draw_triangle(); + + use_window(); + + eglBindTexImage(dpy, surf_pbuf, EGL_BACK_BUFFER); + + glPushMatrix(); + glRotatef(view_rotx, 1, 0, 0); + glRotatef(view_roty, 0, 1, 0); + glRotatef(view_rotz, 0, 0, 1); + + draw_textured_cube(); + + glPopMatrix(); + + eglReleaseTexImage(dpy, surf_pbuf, EGL_BACK_BUFFER); +} + +/* new window size or exposure */ +static void +reshape(int width, int height) +{ + GLfloat ar = (GLfloat) width / (GLfloat) height; + + use_window(); + + glViewport(0, 0, (GLint) width, (GLint) height); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-ar, ar, -1, 1, 5.0, 60.0); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0.0, 0.0, -40.0); +} + +static void +event_loop(Display *x_dpy, Window win) +{ + while (1) { + int redraw = 1; + + if (XPending(x_dpy) > 0) { + XEvent event; + XNextEvent(x_dpy, &event); + + switch (event.type) { + case Expose: + redraw = 1; + break; + case ConfigureNotify: + reshape(event.xconfigure.width, event.xconfigure.height); + break; + case KeyPress: + { + char buffer[10]; + int r, code; + code = XLookupKeysym(&event.xkey, 0); + if (code == XK_Left) { + view_roty += 5.0; + } + else if (code == XK_Right) { + view_roty -= 5.0; + } + else if (code == XK_Up) { + view_rotx += 5.0; + } + else if (code == XK_Down) { + view_rotx -= 5.0; + } + else if (code == XK_b) { + blend = !blend; + } + else { + r = XLookupString(&event.xkey, buffer, sizeof(buffer), + NULL, NULL); + if (buffer[0] == 27) { + /* escape */ + return; + } + } + } + redraw = 1; + break; + default: + ; /*no-op*/ + } + } + + if (redraw) { + view_rotx += 1.0; + view_roty += 2.0; + view_rotz += 1.5; + color_flow += 20; + draw(); + eglSwapBuffers(dpy, surf_win); + } + } +} + +int +main(int argc, char *argv[]) +{ + const int winWidth = 300, winHeight = 300; + Display *x_dpy; + Window win; + char *dpyName = NULL; + EGLint egl_major, egl_minor; + const char *s; + + x_dpy = XOpenDisplay(dpyName); + if (!x_dpy) { + printf("Error: couldn't open display %s\n", + dpyName ? dpyName : getenv("DISPLAY")); + return -1; + } + + dpy = eglGetDisplay(x_dpy); + if (!dpy) { + printf("Error: eglGetDisplay() failed\n"); + return -1; + } + + if (!eglInitialize(dpy, &egl_major, &egl_minor)) { + printf("Error: eglInitialize() failed\n"); + return -1; + } + + s = eglQueryString(dpy, EGL_VERSION); + printf("EGL_VERSION = %s\n", s); + + make_window(x_dpy, "color flow", 0, 0, winWidth, winHeight, &win); + make_pbuffer(winWidth, winHeight); + + XMapWindow(x_dpy, win); + + reshape(winWidth, winHeight); + event_loop(x_dpy, win); + + glDeleteTextures(1, &tex_pbuf); + + eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + eglTerminate(dpy); + + XDestroyWindow(x_dpy, win); + XCloseDisplay(x_dpy); + + return 0; +} -- cgit v1.2.3 From e3734e46850c3cf9a80df32bacae92593a416c14 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Fri, 14 Aug 2009 18:05:19 +0800 Subject: egl: Make lookup functions static inline. progs/egl/demo3.c is also changed since it uses an internal function. Signed-off-by: Chia-I Wu --- progs/egl/demo3.c | 2 +- src/egl/main/egldisplay.c | 66 --------------------------- src/egl/main/egldisplay.h | 112 ++++++++++++++++++++++++++++++++-------------- 3 files changed, 79 insertions(+), 101 deletions(-) (limited to 'progs/egl') diff --git a/progs/egl/demo3.c b/progs/egl/demo3.c index a6096a257e..daab62d173 100644 --- a/progs/egl/demo3.c +++ b/progs/egl/demo3.c @@ -551,7 +551,7 @@ write_ppm(const char *filename, const GLubyte *buffer, int width, int height) } } -#include "../src/egl/main/egldisplay.h" +#include "../../src/egl/main/egldisplay.h" typedef struct fb_display { diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c index 000db6c69a..7f1c53abf8 100644 --- a/src/egl/main/egldisplay.c +++ b/src/egl/main/egldisplay.c @@ -113,28 +113,6 @@ _eglUnlinkDisplay(_EGLDisplay *dpy) } -/** - * Return the handle of a linked display, or EGL_NO_DISPLAY. - */ -EGLDisplay -_eglGetDisplayHandle(_EGLDisplay *dpy) -{ - return (EGLDisplay) ((dpy) ? dpy : EGL_NO_DISPLAY); -} - - -/** - * Lookup a handle to find the linked display. - * Return NULL if the handle has no corresponding linked display. - */ -_EGLDisplay * -_eglLookupDisplay(EGLDisplay display) -{ - _EGLDisplay *dpy = (_EGLDisplay *) display; - return dpy; -} - - /** * Find the display corresponding to the specified native display id in all * linked displays. @@ -256,28 +234,6 @@ _eglUnlinkContext(_EGLContext *ctx) } -/** - * Return the handle of a linked context, or EGL_NO_CONTEXT. - */ -EGLContext -_eglGetContextHandle(_EGLContext *ctx) -{ - return (EGLContext) ((ctx && ctx->Display) ? ctx : EGL_NO_CONTEXT); -} - - -/** - * Lookup a handle to find the linked context. - * Return NULL if the handle has no corresponding linked context. - */ -_EGLContext * -_eglLookupContext(EGLContext ctx, _EGLDisplay *dpy) -{ - _EGLContext *context = (_EGLContext *) ctx; - return (context && context->Display) ? context : NULL; -} - - /** * Link a surface to a display and return the handle of the link. * The handle can be passed to client directly. @@ -319,25 +275,3 @@ _eglUnlinkSurface(_EGLSurface *surf) surf->Next = NULL; surf->Display = NULL; } - - -/** - * Return the handle of a linked surface, or EGL_NO_SURFACE. - */ -EGLSurface -_eglGetSurfaceHandle(_EGLSurface *surf) -{ - return (EGLSurface) ((surf && surf->Display) ? surf : EGL_NO_SURFACE); -} - - -/** - * Lookup a handle to find the linked surface. - * Return NULL if the handle has no corresponding linked surface. - */ -_EGLSurface * -_eglLookupSurface(EGLSurface surface, _EGLDisplay *dpy) -{ - _EGLSurface *surf = (_EGLSurface *) surface; - return (surf && surf->Display) ? surf : NULL; -} diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h index 19a4d4e542..e8a3d49d96 100644 --- a/src/egl/main/egldisplay.h +++ b/src/egl/main/egldisplay.h @@ -6,8 +6,9 @@ #endif #include "egltypedefs.h" -#include "eglhash.h" #include "egldefines.h" +#include "eglcontext.h" +#include "eglsurface.h" /** @@ -76,24 +77,6 @@ extern void _eglUnlinkDisplay(_EGLDisplay *dpy); -extern EGLDisplay -_eglGetDisplayHandle(_EGLDisplay *display); - - -extern _EGLDisplay * -_eglLookupDisplay(EGLDisplay dpy); - - -/** - * Return true if the display is linked. - */ -static INLINE EGLBoolean -_eglIsDisplayLinked(_EGLDisplay *dpy) -{ - return (EGLBoolean) (_eglGetDisplayHandle(dpy) != EGL_NO_DISPLAY); -} - - extern _EGLDisplay * _eglFindDisplay(NativeDisplayType nativeDisplay); @@ -114,37 +97,98 @@ extern void _eglUnlinkContext(_EGLContext *ctx); -extern EGLContext -_eglGetContextHandle(_EGLContext *ctx); +extern EGLSurface +_eglLinkSurface(_EGLSurface *surf, _EGLDisplay *dpy); -extern _EGLContext * -_eglLookupContext(EGLContext ctx, _EGLDisplay *dpy); +extern void +_eglUnlinkSurface(_EGLSurface *surf); /** - * Return true if the context is linked to a display. + * Lookup a handle to find the linked display. + * Return NULL if the handle has no corresponding linked display. + */ +static INLINE _EGLDisplay * +_eglLookupDisplay(EGLDisplay display) +{ + _EGLDisplay *dpy = (_EGLDisplay *) display; + return dpy; +} + + +/** + * Return the handle of a linked display, or EGL_NO_DISPLAY. + */ +static INLINE EGLDisplay +_eglGetDisplayHandle(_EGLDisplay *dpy) +{ + return (EGLDisplay) ((dpy) ? dpy : EGL_NO_DISPLAY); +} + + +/** + * Return true if the display is linked. */ static INLINE EGLBoolean -_eglIsContextLinked(_EGLContext *ctx) +_eglIsDisplayLinked(_EGLDisplay *dpy) { - return (EGLBoolean) (_eglGetContextHandle(ctx) != EGL_NO_CONTEXT); + return (EGLBoolean) (_eglGetDisplayHandle(dpy) != EGL_NO_DISPLAY); } -extern EGLSurface -_eglLinkSurface(_EGLSurface *surf, _EGLDisplay *dpy); +/** + * Lookup a handle to find the linked context. + * Return NULL if the handle has no corresponding linked context. + */ +static INLINE _EGLContext * +_eglLookupContext(EGLContext context, _EGLDisplay *dpy) +{ + _EGLContext *ctx = (_EGLContext *) context; + return (ctx && ctx->Display) ? ctx : NULL; +} -extern void -_eglUnlinkSurface(_EGLSurface *surf); +/** + * Return the handle of a linked context, or EGL_NO_CONTEXT. + */ +static INLINE EGLContext +_eglGetContextHandle(_EGLContext *ctx) +{ + return (EGLContext) ((ctx && ctx->Display) ? ctx : EGL_NO_CONTEXT); +} -extern EGLSurface -_eglGetSurfaceHandle(_EGLSurface *); + +/** + * Return true if the context is linked to a display. + */ +static INLINE EGLBoolean +_eglIsContextLinked(_EGLContext *ctx) +{ + return (EGLBoolean) (_eglGetContextHandle(ctx) != EGL_NO_CONTEXT); +} -extern _EGLSurface * -_eglLookupSurface(EGLSurface surf, _EGLDisplay *dpy); +/** + * Lookup a handle to find the linked surface. + * Return NULL if the handle has no corresponding linked surface. + */ +static INLINE _EGLSurface * +_eglLookupSurface(EGLSurface surface, _EGLDisplay *dpy) +{ + _EGLSurface *surf = (_EGLSurface *) surface; + return (surf && surf->Display) ? surf : NULL; +} + + +/** + * Return the handle of a linked surface, or EGL_NO_SURFACE. + */ +static INLINE EGLSurface +_eglGetSurfaceHandle(_EGLSurface *surf) +{ + return (EGLSurface) ((surf && surf->Display) ? surf : EGL_NO_SURFACE); +} /** -- cgit v1.2.3 From cefe9c4f394ff7007d33d932191e2fcaf9d08e87 Mon Sep 17 00:00:00 2001 From: Younes Manton Date: Wed, 26 Aug 2009 20:13:11 -0400 Subject: mesa: gitignore --- progs/demos/.gitignore | 1 + progs/egl/.gitignore | 1 + 2 files changed, 2 insertions(+) (limited to 'progs/egl') diff --git a/progs/demos/.gitignore b/progs/demos/.gitignore index f3c7091bcc..5dd974b63d 100644 --- a/progs/demos/.gitignore +++ b/progs/demos/.gitignore @@ -63,3 +63,4 @@ tunnel2 vao_demo Windows winpos +*.rgb diff --git a/progs/egl/.gitignore b/progs/egl/.gitignore index f417aefb93..7a13d4686a 100644 --- a/progs/egl/.gitignore +++ b/progs/egl/.gitignore @@ -6,6 +6,7 @@ eglinfo eglscreen egltri peglgears +xeglbindtex xeglgears xeglthreads xegl_tri -- cgit v1.2.3 From 8d0bdfa4335ea07a747f53635a57414d15c234b7 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Wed, 26 Aug 2009 12:44:02 +0800 Subject: progs: EGL/X progs should link to libX11. Since 5a459d58fca2b71cb77c39f98df8a81ce6298421, libEGL no longer links to libX11. Add the dependency to affected progs and cleanup prog/egl/Makefile. Signed-off-by: Chia-I Wu --- progs/egl/Makefile | 99 ++++++++++++------------------------------- progs/openvg/demos/Makefile | 2 +- progs/openvg/trivial/Makefile | 2 +- 3 files changed, 29 insertions(+), 74 deletions(-) (limited to 'progs/egl') diff --git a/progs/egl/Makefile b/progs/egl/Makefile index fd72f540ca..ff9a858c56 100644 --- a/progs/egl/Makefile +++ b/progs/egl/Makefile @@ -7,6 +7,9 @@ include $(TOP)/configs/current INCLUDE_DIRS = -I$(TOP)/include HEADERS = $(TOP)/include/GLES/egl.h +LIB_DEP = $(TOP)/$(LIB_DIR)/libEGL.so + +LIBS = -L$(TOP)/$(LIB_DIR) -lEGL -lGL PROGRAMS = \ demo1 \ @@ -30,90 +33,42 @@ PROGRAMS = \ default: $(PROGRAMS) +demo1: demo1.o $(HEADERS) $(LIB_DEP) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB) -demo1: demo1.o $(TOP)/$(LIB_DIR)/libEGL.so - $(CC) $(CFLAGS) $(LDFLAGS) demo1.o -L$(TOP)/$(LIB_DIR) -lEGL $(LIBDRM_LIB) -o $@ - -demo1.o: demo1.c $(HEADERS) - $(CC) -c $(CFLAGS) -I$(TOP)/include demo1.c - - -demo2: demo2.o $(TOP)/$(LIB_DIR)/libEGL.so - $(CC) $(CFLAGS) $(LDFLAGS) demo2.o -L$(TOP)/$(LIB_DIR) -lEGL -lGL $(LIBDRM_LIB) $(APP_LIB_DEPS) -o $@ - -demo2.o: demo2.c $(HEADERS) - $(CC) -c $(CFLAGS) -I$(TOP)/include demo2.c - - -demo3: demo3.o $(TOP)/$(LIB_DIR)/libEGL.so - $(CC) $(CFLAGS) $(LDFLAGS) demo3.o -L$(TOP)/$(LIB_DIR) -lEGL -lGL $(LIBDRM_LIB) $(APP_LIB_DEPS) -o $@ - -demo3.o: demo3.c $(HEADERS) - $(CC) -c $(CFLAGS) -I$(TOP)/include demo3.c - - -egltri: egltri.o $(TOP)/$(LIB_DIR)/libEGL.so - $(CC) $(CFLAGS) egltri.o -L$(TOP)/$(LIB_DIR) -lEGL -lGL $(LIBDRM_LIB) -o $@ - -egltri.o: egltri.c $(HEADERS) - $(CC) -c $(CFLAGS) -I$(TOP)/include egltri.c - +demo2: demo2.o $(HEADERS) $(LIB_DEP) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB) -eglinfo: eglinfo.o $(TOP)/$(LIB_DIR)/libEGL.so - $(CC) $(CFLAGS) $(LDFLAGS) eglinfo.o -L$(TOP)/$(LIB_DIR) -lEGL -lGL $(LIBDRM_LIB) -o $@ +demo3: demo3.o $(HEADERS) $(LIB_DEP) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB) -eglinfo.o: eglinfo.c $(HEADERS) - $(CC) -c $(CFLAGS) -I$(TOP)/include eglinfo.c +egltri: egltri.o $(HEADERS) $(LIB_DEP) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB) +eglinfo: eglinfo.o $(HEADERS) $(LIB_DEP) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB) -eglgears: eglgears.o $(TOP)/$(LIB_DIR)/libEGL.so - $(CC) $(CFLAGS) $(LDFLAGS) eglgears.o -L$(TOP)/$(LIB_DIR) -lEGL -lGL $(LIBDRM_LIB) $(APP_LIB_DEPS) -o $@ +eglgears: eglgears.o $(HEADERS) $(LIB_DEP) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB) -eglgears.o: eglgears.c $(HEADERS) - $(CC) -c $(CFLAGS) -I$(TOP)/include eglgears.c +eglscreen: eglscreen.o $(HEADERS) $(LIB_DEP) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB) -eglscreen: eglscreen.o $(TOP)/$(LIB_DIR)/libEGL.so - $(CC) $(CFLAGS) $(LDFLAGS) eglscreen.o -L$(TOP)/$(LIB_DIR) -lEGL -lGL $(LIBDRM_LIB) $(APP_LIB_DEPS) -o $@ +peglgears: peglgears.o $(HEADERS) $(LIB_DEP) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB) -eglscreen.o: eglscreen.c $(HEADERS) - $(CC) -c $(CFLAGS) -I$(TOP)/include eglscreen.c +xeglbindtex: xeglbindtex.o $(HEADERS) $(LIB_DEP) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lX11 -peglgears: peglgears.o $(TOP)/$(LIB_DIR)/libEGL.so - $(CC) $(CFLAGS) peglgears.o -L$(TOP)/$(LIB_DIR) -lEGL -lGL $(LIBDRM_LIB) $(APP_LIB_DEPS) -o $@ +xeglgears: xeglgears.o $(HEADERS) $(LIB_DEP) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lX11 -peglgears.o: peglgears.c $(HEADERS) - $(CC) -c $(CFLAGS) -I$(TOP)/include peglgears.c - - -xeglbindtex: xeglbindtex.o $(TOP)/$(LIB_DIR)/libEGL.so - $(CC) $(CFLAGS) xeglbindtex.o -L$(TOP)/$(LIB_DIR) -lEGL -lGL $(LIBDRM_LIB) $(APP_LIB_DEPS) -o $@ - -xeglbindtex.o: xeglbindtex.c $(HEADERS) - $(CC) -c $(CFLAGS) -I$(TOP)/include xeglbindtex.c - -xeglgears: xeglgears.o $(TOP)/$(LIB_DIR)/libEGL.so - $(CC) $(CFLAGS) xeglgears.o -L$(TOP)/$(LIB_DIR) -lEGL -lGL $(LIBDRM_LIB) $(APP_LIB_DEPS) -o $@ - -xeglgears.o: xeglgears.c $(HEADERS) - $(CC) -c $(CFLAGS) -I$(TOP)/include xeglgears.c - - -xeglthreads: xeglthreads.o $(TOP)/$(LIB_DIR)/libEGL.so - $(CC) $(CFLAGS) xeglthreads.o -L$(TOP)/$(LIB_DIR) -lEGL -lGL $(LIBDRM_LIB) $(APP_LIB_DEPS) -o $@ - -xeglthreads.o: xeglthreads.c $(HEADERS) - $(CC) -c $(CFLAGS) -I$(TOP)/include xeglthreads.c - - -xegl_tri: xegl_tri.o $(TOP)/$(LIB_DIR)/libEGL.so - $(CC) $(CFLAGS) xegl_tri.o -L$(TOP)/$(LIB_DIR) -lEGL -lGL $(LIBDRM_LIB) $(APP_LIB_DEPS) -o $@ - -xegl_tri.o: xegl_tri.c $(HEADERS) - $(CC) -c $(CFLAGS) -I$(TOP)/include xegl_tri.c +xeglthreads: xeglthreads.o $(HEADERS) $(LIB_DEP) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lX11 +xegl_tri: xegl_tri.o $(HEADERS) $(LIB_DEP) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lX11 clean: -rm -f *.o *~ - -rm -f *.so -rm -f $(PROGRAMS) - diff --git a/progs/openvg/demos/Makefile b/progs/openvg/demos/Makefile index 6e15342c7f..89b0ce441b 100644 --- a/progs/openvg/demos/Makefile +++ b/progs/openvg/demos/Makefile @@ -3,7 +3,7 @@ TOP = ../../.. include $(TOP)/configs/current -VG_LIBS=-lm -pthread -lEGL -lOpenVG +VG_LIBS=-lm -pthread -lX11 -lEGL -lOpenVG INCLUDE_DIRS = -I$(TOP)/include PROGRAMS = \ diff --git a/progs/openvg/trivial/Makefile b/progs/openvg/trivial/Makefile index 362360e596..fcb3484377 100644 --- a/progs/openvg/trivial/Makefile +++ b/progs/openvg/trivial/Makefile @@ -5,7 +5,7 @@ TOP = ../../../ include $(TOP)/configs/current INCLUDES = -I. -I$(TOP)/include -LIBS=-L$(TOP)/$(LIB_DIR) -lm -lEGL -lOpenVG -lpthread +LIBS=-L$(TOP)/$(LIB_DIR) -lm -lX11 -lEGL -lOpenVG -lpthread CFLAGS += $(INCLUDES) HEADERS=eglcommon.h -- cgit v1.2.3