diff options
Diffstat (limited to 'progs/egl')
29 files changed, 0 insertions, 9943 deletions
diff --git a/progs/egl/opengl/.gitignore b/progs/egl/opengl/.gitignore deleted file mode 100644 index 49c3a511f3..0000000000 --- a/progs/egl/opengl/.gitignore +++ /dev/null @@ -1,13 +0,0 @@ -demo1 -demo2 -demo3 -eglgears_x11 -eglgears_screen -eglinfo -eglscreen -egltri_x11 -egltri_screen -peglgears -xeglbindtex -xeglgears -xeglthreads diff --git a/progs/egl/opengl/Makefile b/progs/egl/opengl/Makefile deleted file mode 100644 index a49255bbb2..0000000000 --- a/progs/egl/opengl/Makefile +++ /dev/null @@ -1,79 +0,0 @@ -# progs/egl/Makefile - -TOP = ../../.. -include $(TOP)/configs/current - - -INCLUDE_DIRS = -I$(TOP)/include $(X11_CFLAGS) - -HEADERS = $(TOP)/include/GLES/egl.h -LIB_DEP = $(TOP)/$(LIB_DIR)/$(EGL_LIB_NAME) - -LIBS = -L$(TOP)/$(LIB_DIR) -l$(EGL_LIB) -l$(GL_LIB) -lm - -EGLUT_DIR = $(TOP)/progs/egl/eglut - -EGLUT_DEMOS = \ - eglgears \ - egltri - -EGLUT_X11_DEMOS := $(addsuffix _x11,$(EGLUT_DEMOS)) -EGLUT_SCREEN_DEMOS := $(addsuffix _screen,$(EGLUT_DEMOS)) - -PROGRAMS = \ - demo1 \ - demo2 \ - demo3 \ - eglinfo \ - eglscreen \ - peglgears \ - xeglgears \ - xeglthreads - - -.c.o: - $(CC) -c $(INCLUDE_DIRS) -I$(EGLUT_DIR) $(CFLAGS) $< -o $@ - - - -default: $(PROGRAMS) $(EGLUT_X11_DEMOS) $(EGLUT_SCREEN_DEMOS) - -demo1: demo1.o $(HEADERS) $(LIB_DEP) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB) - -demo2: demo2.o $(HEADERS) $(LIB_DEP) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB) - -demo3: demo3.o $(HEADERS) $(LIB_DEP) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB) - -eglinfo: eglinfo.o $(HEADERS) $(LIB_DEP) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) - -eglscreen: eglscreen.o $(HEADERS) $(LIB_DEP) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB) - -peglgears: peglgears.o $(HEADERS) $(LIB_DEP) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB) -lm - -xeglgears: xeglgears.o $(HEADERS) $(LIB_DEP) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lm $(X11_LIBS) - -xeglthreads: xeglthreads.o $(HEADERS) $(LIB_DEP) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lpthread -lm $(X11_LIBS) - -# define the rules for EGLUT demos -define eglut-demo-rule -$(1)_x11 $(1)_screen: $(1)_%: $(1).o $(EGLUT_DIR)/libeglut-%.a $(LIB_DEP) -endef -$(foreach demo, $(EGLUT_DEMOS), $(eval $(call eglut-demo-rule,$(demo)))) - -# build EGLUT demos -$(EGLUT_X11_DEMOS): - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -L$(EGLUT_DIR) -leglut-$* $(LIBS) $(X11_LIBS) -$(EGLUT_SCREEN_DEMOS): - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -L$(EGLUT_DIR) -leglut-$* $(LIBS) - -clean: - -rm -f *.o *~ - -rm -f $(PROGRAMS) $(EGLUT_X11_DEMOS) $(EGLUT_SCREEN_DEMOS) diff --git a/progs/egl/opengl/demo1.c b/progs/egl/opengl/demo1.c deleted file mode 100644 index d892734ee5..0000000000 --- a/progs/egl/opengl/demo1.c +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Exercise EGL API functions - */ - -#define EGL_EGLEXT_PROTOTYPES - -#include <EGL/egl.h> -#include <EGL/eglext.h> -#include <assert.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - - -/** - * Test EGL_MESA_screen_surface functions - */ -static void -TestScreens(EGLDisplay dpy) -{ -#define MAX 8 - EGLScreenMESA screens[MAX]; - EGLint numScreens; - EGLint i; - - eglGetScreensMESA(dpy, screens, MAX, &numScreens); - printf("Found %d screens\n", numScreens); - for (i = 0; i < numScreens; i++) { - printf(" Screen %d handle: %d\n", i, (int) screens[i]); - } -} - -/** - * Print table of all available configurations. - */ -static void -PrintConfigs(EGLDisplay d, EGLConfig *configs, EGLint numConfigs) -{ - EGLint i; - - 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("----------------------------------------------\n"); - for (i = 0; i < numConfigs; i++) { - EGLint id, size, level; - EGLint red, green, blue, alpha; - EGLint depth, stencil; - EGLint surfaces; - EGLint doubleBuf = 1, stereo = 0; - char surfString[100] = ""; - - eglGetConfigAttrib(d, configs[i], EGL_CONFIG_ID, &id); - eglGetConfigAttrib(d, configs[i], EGL_BUFFER_SIZE, &size); - eglGetConfigAttrib(d, configs[i], EGL_LEVEL, &level); - - eglGetConfigAttrib(d, configs[i], EGL_RED_SIZE, &red); - eglGetConfigAttrib(d, configs[i], EGL_GREEN_SIZE, &green); - eglGetConfigAttrib(d, configs[i], EGL_BLUE_SIZE, &blue); - 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_SURFACE_TYPE, &surfaces); - - if (surfaces & EGL_WINDOW_BIT) - strcat(surfString, "win,"); - if (surfaces & EGL_PBUFFER_BIT) - strcat(surfString, "pb,"); - if (surfaces & EGL_PIXMAP_BIT) - strcat(surfString, "pix,"); - if (strlen(surfString) > 0) - surfString[strlen(surfString) - 1] = 0; - - printf("0x%02x %2d %2d %c %c %2d %2d %2d %2d %2d %2d %-12s\n", - id, size, level, - doubleBuf ? 'y' : '.', - stereo ? 'y' : '.', - red, green, blue, alpha, - depth, stencil, surfString); - } -} - - - -int -main(int argc, char *argv[]) -{ - int maj, min; - EGLContext ctx; - EGLSurface pbuffer; - EGLConfig *configs; - EGLint numConfigs; - EGLBoolean b; - const EGLint pbufAttribs[] = { - EGL_WIDTH, 500, - EGL_HEIGHT, 500, - EGL_NONE - }; - - EGLDisplay d = eglGetDisplay(EGL_DEFAULT_DISPLAY); - assert(d); - - if (!eglInitialize(d, &maj, &min)) { - printf("demo: eglInitialize failed\n"); - exit(1); - } - - printf("EGL version = %d.%d\n", maj, min); - printf("EGL_VENDOR = %s\n", eglQueryString(d, EGL_VENDOR)); - - eglGetConfigs(d, NULL, 0, &numConfigs); - configs = malloc(sizeof(*configs) *numConfigs); - eglGetConfigs(d, configs, numConfigs, &numConfigs); - - PrintConfigs(d, configs, numConfigs); - - eglBindAPI(EGL_OPENGL_API); - ctx = eglCreateContext(d, configs[0], EGL_NO_CONTEXT, NULL); - if (ctx == EGL_NO_CONTEXT) { - printf("failed to create context\n"); - return 0; - } - - pbuffer = eglCreatePbufferSurface(d, configs[0], pbufAttribs); - if (pbuffer == EGL_NO_SURFACE) { - printf("failed to create pbuffer\n"); - return 0; - } - - free(configs); - - b = eglMakeCurrent(d, pbuffer, pbuffer, ctx); - if (!b) { - printf("make current failed\n"); - return 0; - } - - b = eglMakeCurrent(d, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); - - TestScreens(d); - - eglDestroySurface(d, pbuffer); - eglDestroyContext(d, ctx); - eglTerminate(d); - - return 0; -} diff --git a/progs/egl/opengl/demo2.c b/progs/egl/opengl/demo2.c deleted file mode 100644 index b9e92f62ac..0000000000 --- a/progs/egl/opengl/demo2.c +++ /dev/null @@ -1,216 +0,0 @@ -/* - * Exercise EGL API functions - */ - -#define EGL_EGLEXT_PROTOTYPES - -#include <assert.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> - -#include <EGL/egl.h> -#include <EGL/eglext.h> -#include <GLES/gl.h> - -/*#define FRONTBUFFER*/ - -static void _subset_Rectf(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2, - GLfloat r, GLfloat g, GLfloat b) -{ - 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) -{ - GLfloat r, g, b; - - printf("Redraw event\n"); - - glClearColor( rand()/(float)RAND_MAX, - rand()/(float)RAND_MAX, - rand()/(float)RAND_MAX, - 1); - - glClear( GL_COLOR_BUFFER_BIT ); - - 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, r, g, b ); - glPopMatrix(); - -#ifdef FRONTBUFFER - glFlush(); -#else - eglSwapBuffers( dpy, surf ); -#endif - glFinish(); -} - - -/** - * Test EGL_MESA_screen_surface functions - */ -static void -TestScreens(EGLDisplay dpy) -{ -#define MAX 8 - EGLScreenMESA screens[MAX]; - EGLint numScreens; - EGLint i; - - eglGetScreensMESA(dpy, screens, MAX, &numScreens); - printf("Found %d screens\n", numScreens); - for (i = 0; i < numScreens; i++) { - printf(" Screen %d handle: %d\n", i, (int) screens[i]); - } -} - - -int -main(int argc, char *argv[]) -{ - int maj, min; - EGLContext ctx; - EGLSurface pbuffer, screen_surf; - EGLConfig configs[10]; - EGLint numConfigs, i; - EGLBoolean b; - const EGLint pbufAttribs[] = { - EGL_WIDTH, 500, - EGL_HEIGHT, 500, - EGL_NONE - }; - EGLint screenAttribs[32]; - EGLModeMESA mode; - EGLScreenMESA screen; - EGLint count; - - EGLDisplay d = eglGetDisplay(EGL_DEFAULT_DISPLAY); - assert(d); - - if (!eglInitialize(d, &maj, &min)) { - printf("demo: eglInitialize failed\n"); - exit(1); - } - - printf("EGL version = %d.%d\n", maj, min); - printf("EGL_VENDOR = %s\n", eglQueryString(d, EGL_VENDOR)); - if (!strstr(eglQueryString(d, EGL_EXTENSIONS), - "EGL_MESA_screen_surface")) { - printf("EGL_MESA_screen_surface is not supported\n"); - exit(1); - } - - eglGetConfigs(d, configs, 10, &numConfigs); - printf("Got %d EGL configs:\n", numConfigs); - for (i = 0; i < numConfigs; i++) { - EGLint id, red, depth; - eglGetConfigAttrib(d, configs[i], EGL_CONFIG_ID, &id); - eglGetConfigAttrib(d, configs[i], EGL_RED_SIZE, &red); - eglGetConfigAttrib(d, configs[i], EGL_DEPTH_SIZE, &depth); - printf("%2d: Red Size = %d Depth Size = %d\n", id, red, depth); - } - - eglGetScreensMESA(d, &screen, 1, &count); - eglGetModesMESA(d, screen, &mode, 1, &count); - - eglBindAPI(EGL_OPENGL_API); - ctx = eglCreateContext(d, configs[0], EGL_NO_CONTEXT, NULL); - if (ctx == EGL_NO_CONTEXT) { - printf("failed to create context\n"); - return 0; - } - - pbuffer = eglCreatePbufferSurface(d, configs[0], pbufAttribs); - if (pbuffer == EGL_NO_SURFACE) { - printf("failed to create pbuffer\n"); - return 0; - } - - b = eglMakeCurrent(d, pbuffer, pbuffer, ctx); - if (!b) { - printf("make current failed\n"); - return 0; - } - - b = eglMakeCurrent(d, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); - - i = 0; - screenAttribs[i++] = EGL_WIDTH; - eglGetModeAttribMESA(d, mode, EGL_WIDTH, &screenAttribs[i++]); - screenAttribs[i++] = EGL_HEIGHT; - eglGetModeAttribMESA(d, mode, EGL_HEIGHT, &screenAttribs[i++]); - screenAttribs[i] = EGL_NONE; - - screen_surf = eglCreateScreenSurfaceMESA(d, configs[0], screenAttribs); - if (screen_surf == EGL_NO_SURFACE) { - printf("failed to create screen surface\n"); - return 0; - } - - eglShowScreenSurfaceMESA(d, screen, screen_surf, mode); - - b = eglMakeCurrent(d, screen_surf, screen_surf, ctx); - if (!b) { - printf("make current failed\n"); - return 0; - } - - glViewport(0, 0, 1024, 768); - - glClearColor( 0, - 1.0, - 0, - 1); - - glClear( GL_COLOR_BUFFER_BIT ); - - - TestScreens(d); - - glShadeModel( GL_FLAT ); - - for (i = 0; i < 6; i++) { - redraw(d, screen_surf, i*10 ); - - printf("sleep(1)\n"); - sleep(1); - } - - eglDestroySurface(d, pbuffer); - eglDestroyContext(d, ctx); - eglTerminate(d); - - return 0; -} diff --git a/progs/egl/opengl/demo3.c b/progs/egl/opengl/demo3.c deleted file mode 100644 index 64b9ee652c..0000000000 --- a/progs/egl/opengl/demo3.c +++ /dev/null @@ -1,647 +0,0 @@ -/* - * Exercise EGL API functions - */ - -#define EGL_EGLEXT_PROTOTYPES - -#include <EGL/egl.h> -#include <EGL/eglext.h> -#include <GL/gl.h> -#include <assert.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> - - - -#define PIXEL_CENTER(x) ((long)(x) + 0.5) - -#define GAP 10 -#define ROWS 3 -#define COLS 4 - -#define OPENGL_WIDTH 48 -#define OPENGL_HEIGHT 13 - - -GLenum rgb, doubleBuffer, windType; -GLint windW, windH; - -GLenum mode1, mode2; -GLint boxW, boxH; -GLubyte OpenGL_bits[] = { - 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, - 0x7f, 0xfb, 0xff, 0xff, 0xff, 0x01, - 0x7f, 0xfb, 0xff, 0xff, 0xff, 0x01, - 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, - 0x3e, 0x8f, 0xb7, 0xf9, 0xfc, 0x01, - 0x63, 0xdb, 0xb0, 0x8d, 0x0d, 0x00, - 0x63, 0xdb, 0xb7, 0x8d, 0x0d, 0x00, - 0x63, 0xdb, 0xb6, 0x8d, 0x0d, 0x00, - 0x63, 0x8f, 0xf3, 0xcc, 0x0d, 0x00, - 0x63, 0x00, 0x00, 0x0c, 0x4c, 0x0a, - 0x63, 0x00, 0x00, 0x0c, 0x4c, 0x0e, - 0x63, 0x00, 0x00, 0x8c, 0xed, 0x0e, - 0x3e, 0x00, 0x00, 0xf8, 0x0c, 0x00, -}; - - -static void Init(void) -{ - - mode1 = GL_TRUE; - mode2 = GL_TRUE; -} - -static void Reshape(int width, int height) -{ - - windW = (GLint)width; - windH = (GLint)height; -} - -#if 0 -static void RotateColorMask(void) -{ - static GLint rotation = 0; - - rotation = (rotation + 1) & 0x3; - switch (rotation) { - case 0: - glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); - glIndexMask( 0xff ); - break; - case 1: - glColorMask(GL_FALSE, GL_TRUE, GL_TRUE, GL_TRUE); - glIndexMask(0xFE); - break; - case 2: - glColorMask(GL_TRUE, GL_FALSE, GL_TRUE, GL_TRUE); - glIndexMask(0xFD); - break; - case 3: - glColorMask(GL_TRUE, GL_TRUE, GL_FALSE, GL_TRUE); - glIndexMask(0xFB); - break; - } -} -#endif - -static void Viewport(GLint row, GLint column) -{ - GLint x, y; - - boxW = (windW - (COLS + 1) * GAP) / COLS; - boxH = (windH - (ROWS + 1) * GAP) / ROWS; - - x = GAP + column * (boxW + GAP); - y = GAP + row * (boxH + GAP); - - glViewport(x, y, boxW, boxH); - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glOrtho(-boxW/2, boxW/2, -boxH/2, boxH/2, 0.0, 1.0); - glMatrixMode(GL_MODELVIEW); - - glEnable(GL_SCISSOR_TEST); - glScissor(x, y, boxW, boxH); -} - -enum { - COLOR_BLACK = 0, - COLOR_RED, - COLOR_GREEN, - COLOR_YELLOW, - COLOR_BLUE, - COLOR_MAGENTA, - COLOR_CYAN, - COLOR_WHITE -}; - -static float RGBMap[9][3] = { - {0, 0, 0}, - {1, 0, 0}, - {0, 1, 0}, - {1, 1, 0}, - {0, 0, 1}, - {1, 0, 1}, - {0, 1, 1}, - {1, 1, 1}, - {0.5, 0.5, 0.5} -}; - -static void SetColor(int c) -{ - glColor3fv(RGBMap[c]); -} - -static void Point(void) -{ - GLint i; - - glBegin(GL_POINTS); - SetColor(COLOR_WHITE); - glVertex2i(0, 0); - for (i = 1; i < 8; i++) { - GLint j = i * 2; - SetColor(COLOR_BLACK+i); - glVertex2i(-j, -j); - glVertex2i(-j, 0); - glVertex2i(-j, j); - glVertex2i(0, j); - glVertex2i(j, j); - glVertex2i(j, 0); - glVertex2i(j, -j); - glVertex2i(0, -j); - } - glEnd(); -} - -static void Lines(void) -{ - GLint i; - - glPushMatrix(); - - glTranslatef(-12, 0, 0); - for (i = 1; i < 8; i++) { - SetColor(COLOR_BLACK+i); - glBegin(GL_LINES); - glVertex2i(-boxW/4, -boxH/4); - glVertex2i(boxW/4, boxH/4); - glEnd(); - glTranslatef(4, 0, 0); - } - - glPopMatrix(); - - glBegin(GL_LINES); - glVertex2i(0, 0); - glEnd(); -} - -static void LineStrip(void) -{ - - glBegin(GL_LINE_STRIP); - SetColor(COLOR_RED); - glVertex2f(PIXEL_CENTER(-boxW/4), PIXEL_CENTER(-boxH/4)); - SetColor(COLOR_GREEN); - glVertex2f(PIXEL_CENTER(-boxW/4), PIXEL_CENTER(boxH/4)); - SetColor(COLOR_BLUE); - glVertex2f(PIXEL_CENTER(boxW/4), PIXEL_CENTER(boxH/4)); - SetColor(COLOR_WHITE); - glVertex2f(PIXEL_CENTER(boxW/4), PIXEL_CENTER(-boxH/4)); - glEnd(); - - glBegin(GL_LINE_STRIP); - glVertex2i(0, 0); - glEnd(); -} - -static void LineLoop(void) -{ - - glBegin(GL_LINE_LOOP); - SetColor(COLOR_RED); - glVertex2f(PIXEL_CENTER(-boxW/4), PIXEL_CENTER(-boxH/4)); - SetColor(COLOR_GREEN); - glVertex2f(PIXEL_CENTER(-boxW/4), PIXEL_CENTER(boxH/4)); - SetColor(COLOR_BLUE); - glVertex2f(PIXEL_CENTER(boxW/4), PIXEL_CENTER(boxH/4)); - SetColor(COLOR_WHITE); - glVertex2f(PIXEL_CENTER(boxW/4), PIXEL_CENTER(-boxH/4)); - glEnd(); - - glEnable(GL_LOGIC_OP); - glLogicOp(GL_XOR); - - glEnable(GL_BLEND); - glBlendFunc(GL_ONE, GL_ONE); - - SetColor(COLOR_MAGENTA); - glBegin(GL_LINE_LOOP); - glVertex2f(PIXEL_CENTER(-boxW/8), PIXEL_CENTER(-boxH/8)); - glVertex2f(PIXEL_CENTER(-boxW/8), PIXEL_CENTER(boxH/8)); - glEnd(); - glBegin(GL_LINE_LOOP); - glVertex2f(PIXEL_CENTER(-boxW/8), PIXEL_CENTER(boxH/8+5)); - glVertex2f(PIXEL_CENTER(boxW/8), PIXEL_CENTER(boxH/8+5)); - glEnd(); - glDisable(GL_LOGIC_OP); - glDisable(GL_BLEND); - - SetColor(COLOR_GREEN); - glBegin(GL_POINTS); - glVertex2i(0, 0); - glEnd(); - - glBegin(GL_LINE_LOOP); - glVertex2i(0, 0); - glEnd(); -} - -static void Bitmap(void) -{ - - glBegin(GL_LINES); - SetColor(COLOR_GREEN); - glVertex2i(-boxW/2, 0); - glVertex2i(boxW/2, 0); - glVertex2i(0, -boxH/2); - glVertex2i(0, boxH/2); - SetColor(COLOR_RED); - glVertex2i(0, -3); - glVertex2i(0, -3+OPENGL_HEIGHT); - SetColor(COLOR_BLUE); - glVertex2i(0, -3); - glVertex2i(OPENGL_WIDTH, -3); - glEnd(); - - SetColor(COLOR_GREEN); - - glPixelStorei(GL_UNPACK_LSB_FIRST, GL_TRUE); - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - - glRasterPos2i(0, 0); - glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, 0, 3, 0.0, 0.0, OpenGL_bits); -} - -static void Triangles(void) -{ - - glBegin(GL_TRIANGLES); - SetColor(COLOR_GREEN); - glVertex2i(-boxW/4, -boxH/4); - SetColor(COLOR_RED); - glVertex2i(-boxW/8, -boxH/16); - SetColor(COLOR_BLUE); - glVertex2i(boxW/8, -boxH/16); - - SetColor(COLOR_GREEN); - glVertex2i(-boxW/4, boxH/4); - SetColor(COLOR_RED); - glVertex2i(-boxW/8, boxH/16); - SetColor(COLOR_BLUE); - glVertex2i(boxW/8, boxH/16); - glEnd(); - - glBegin(GL_TRIANGLES); - glVertex2i(0, 0); - glVertex2i(-100, 100); - glEnd(); -} - -static void TriangleStrip(void) -{ - - glBegin(GL_TRIANGLE_STRIP); - SetColor(COLOR_GREEN); - glVertex2i(-boxW/4, -boxH/4); - SetColor(COLOR_RED); - glVertex2i(-boxW/4, boxH/4); - SetColor(COLOR_BLUE); - glVertex2i(0, -boxH/4); - SetColor(COLOR_WHITE); - glVertex2i(0, boxH/4); - SetColor(COLOR_CYAN); - glVertex2i(boxW/4, -boxH/4); - SetColor(COLOR_YELLOW); - glVertex2i(boxW/4, boxH/4); - glEnd(); - - glBegin(GL_TRIANGLE_STRIP); - glVertex2i(0, 0); - glVertex2i(-100, 100); - glEnd(); -} - -static void TriangleFan(void) -{ - GLint vx[8][2]; - GLint x0, y0, x1, y1, x2, y2, x3, y3; - GLint i; - - y0 = -boxH/4; - y1 = y0 + boxH/2/3; - y2 = y1 + boxH/2/3; - y3 = boxH/4; - x0 = -boxW/4; - x1 = x0 + boxW/2/3; - x2 = x1 + boxW/2/3; - x3 = boxW/4; - - vx[0][0] = x0; vx[0][1] = y1; - vx[1][0] = x0; vx[1][1] = y2; - vx[2][0] = x1; vx[2][1] = y3; - vx[3][0] = x2; vx[3][1] = y3; - vx[4][0] = x3; vx[4][1] = y2; - vx[5][0] = x3; vx[5][1] = y1; - vx[6][0] = x2; vx[6][1] = y0; - vx[7][0] = x1; vx[7][1] = y0; - - glBegin(GL_TRIANGLE_FAN); - SetColor(COLOR_WHITE); - glVertex2i(0, 0); - for (i = 0; i < 8; i++) { - SetColor(COLOR_WHITE-i); - glVertex2iv(vx[i]); - } - glEnd(); - - glBegin(GL_TRIANGLE_FAN); - glVertex2i(0, 0); - glVertex2i(-100, 100); - glEnd(); -} - -static void Rect(void) -{ - - SetColor(COLOR_GREEN); - glRecti(-boxW/4, -boxH/4, boxW/4, boxH/4); -} - -static void PolygonFunc(void) -{ - GLint vx[8][2]; - GLint x0, y0, x1, y1, x2, y2, x3, y3; - GLint i; - - y0 = -boxH/4; - y1 = y0 + boxH/2/3; - y2 = y1 + boxH/2/3; - y3 = boxH/4; - x0 = -boxW/4; - x1 = x0 + boxW/2/3; - x2 = x1 + boxW/2/3; - x3 = boxW/4; - - vx[0][0] = x0; vx[0][1] = y1; - vx[1][0] = x0; vx[1][1] = y2; - vx[2][0] = x1; vx[2][1] = y3; - vx[3][0] = x2; vx[3][1] = y3; - vx[4][0] = x3; vx[4][1] = y2; - vx[5][0] = x3; vx[5][1] = y1; - vx[6][0] = x2; vx[6][1] = y0; - vx[7][0] = x1; vx[7][1] = y0; - - glBegin(GL_POLYGON); - for (i = 0; i < 8; i++) { - SetColor(COLOR_WHITE-i); - glVertex2iv(vx[i]); - } - glEnd(); - - glBegin(GL_POLYGON); - glVertex2i(0, 0); - glVertex2i(100, 100); - glEnd(); -} - -static void Quads(void) -{ - - glBegin(GL_QUADS); - SetColor(COLOR_GREEN); - glVertex2i(-boxW/4, -boxH/4); - SetColor(COLOR_RED); - glVertex2i(-boxW/8, -boxH/16); - SetColor(COLOR_BLUE); - glVertex2i(boxW/8, -boxH/16); - SetColor(COLOR_WHITE); - glVertex2i(boxW/4, -boxH/4); - - SetColor(COLOR_GREEN); - glVertex2i(-boxW/4, boxH/4); - SetColor(COLOR_RED); - glVertex2i(-boxW/8, boxH/16); - SetColor(COLOR_BLUE); - glVertex2i(boxW/8, boxH/16); - SetColor(COLOR_WHITE); - glVertex2i(boxW/4, boxH/4); - glEnd(); - - glBegin(GL_QUADS); - glVertex2i(0, 0); - glVertex2i(100, 100); - glVertex2i(-100, 100); - glEnd(); -} - -static void QuadStrip(void) -{ - - glBegin(GL_QUAD_STRIP); - SetColor(COLOR_GREEN); - glVertex2i(-boxW/4, -boxH/4); - SetColor(COLOR_RED); - glVertex2i(-boxW/4, boxH/4); - SetColor(COLOR_BLUE); - glVertex2i(0, -boxH/4); - SetColor(COLOR_WHITE); - glVertex2i(0, boxH/4); - SetColor(COLOR_CYAN); - glVertex2i(boxW/4, -boxH/4); - SetColor(COLOR_YELLOW); - glVertex2i(boxW/4, boxH/4); - glEnd(); - - glBegin(GL_QUAD_STRIP); - glVertex2i(0, 0); - glVertex2i(100, 100); - glVertex2i(-100, 100); - glEnd(); -} - -static void Draw(EGLDisplay dpy, EGLSurface surf) -{ - - glViewport(0, 0, windW, windH); - glDisable(GL_SCISSOR_TEST); - - glPushAttrib(GL_COLOR_BUFFER_BIT); - - glColorMask(1, 1, 1, 1); - glIndexMask(~0); - - glClearColor(0.0, 0.0, 0.0, 0.0); - glClear(GL_COLOR_BUFFER_BIT); - - glPopAttrib(); - - if (mode1) { - glShadeModel(GL_SMOOTH); - } else { - glShadeModel(GL_FLAT); - } - - if (mode2) { - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); - } else { - glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); - } - - Viewport(0, 0); Point(); - Viewport(0, 1); Lines(); - Viewport(0, 2); LineStrip(); - Viewport(0, 3); LineLoop(); - - Viewport(1, 0); Bitmap(); - - Viewport(1, 1); TriangleFan(); - Viewport(1, 2); Triangles(); - Viewport(1, 3); TriangleStrip(); - - Viewport(2, 0); Rect(); - Viewport(2, 1); PolygonFunc(); - Viewport(2, 2); Quads(); - Viewport(2, 3); QuadStrip(); - - glFlush(); - - if (doubleBuffer) { - eglSwapBuffers(dpy, surf); - } -} - -static void -write_ppm(const char *filename, const GLubyte *buffer, int width, int height) -{ - const int binary = 0; - FILE *f = fopen( filename, "w" ); - if (f) { - int i, x, y; - const GLubyte *ptr = buffer; - if (binary) { - fprintf(f,"P6\n"); - fprintf(f,"# ppm-file created by osdemo.c\n"); - fprintf(f,"%i %i\n", width,height); - fprintf(f,"255\n"); - fclose(f); - f = fopen( filename, "ab" ); /* reopen in binary append mode */ - for (y=height-1; y>=0; y--) { - for (x=0; x<width; x++) { - i = (y*width + x) * 4; - fputc(ptr[i], f); /* write red */ - fputc(ptr[i+1], f); /* write green */ - fputc(ptr[i+2], f); /* write blue */ - } - } - } - else { - /*ASCII*/ - int counter = 0; - fprintf(f,"P3\n"); - fprintf(f,"# ascii ppm file created by osdemo.c\n"); - fprintf(f,"%i %i\n", width, height); - fprintf(f,"255\n"); - for (y=height-1; y>=0; y--) { - for (x=0; x<width; x++) { - i = (y*width + x) * 4; - fprintf(f, " %3d %3d %3d", ptr[i], ptr[i+1], ptr[i+2]); - counter++; - if (counter % 5 == 0) - fprintf(f, "\n"); - } - } - } - fclose(f); - } -} - -int -main(int argc, char *argv[]) -{ - int maj, min; - EGLContext ctx; - EGLSurface screen_surf; - EGLConfig configs[10]; - EGLScreenMESA screen; - EGLModeMESA mode; - EGLint numConfigs, count; - EGLBoolean b; - const GLubyte *bitmap; - EGLint screenAttribs[32]; - EGLint i; - - EGLDisplay d = eglGetDisplay(EGL_DEFAULT_DISPLAY); - assert(d); - - if (!eglInitialize(d, &maj, &min)) { - printf("demo: eglInitialize failed\n"); - exit(1); - } - - printf("EGL version = %d.%d\n", maj, min); - printf("EGL_VENDOR = %s\n", eglQueryString(d, EGL_VENDOR)); - if (!strstr(eglQueryString(d, EGL_EXTENSIONS), - "EGL_MESA_screen_surface")) { - printf("EGL_MESA_screen_surface is not supported\n"); - exit(1); - } - - eglGetConfigs(d, configs, 10, &numConfigs); - eglGetScreensMESA(d, &screen, 1, &count); - eglGetModesMESA(d, screen, &mode, 1, &count); - - eglBindAPI(EGL_OPENGL_API); - ctx = eglCreateContext(d, configs[0], EGL_NO_CONTEXT, NULL); - if (ctx == EGL_NO_CONTEXT) { - printf("failed to create context\n"); - return 0; - } - - i = 0; - screenAttribs[i++] = EGL_WIDTH; - eglGetModeAttribMESA(d, mode, EGL_WIDTH, &screenAttribs[i++]); - screenAttribs[i++] = EGL_HEIGHT; - eglGetModeAttribMESA(d, mode, EGL_HEIGHT, &screenAttribs[i++]); - screenAttribs[i] = EGL_NONE; - - screen_surf = eglCreateScreenSurfaceMESA(d, configs[0], screenAttribs); - if (screen_surf == EGL_NO_SURFACE) { - printf("failed to create screen surface\n"); - return 0; - } - - eglShowScreenSurfaceMESA(d, screen, screen_surf, mode); - - b = eglMakeCurrent(d, screen_surf, screen_surf, ctx); - if (!b) { - printf("make current failed\n"); - return 0; - } - glViewport(0, 0, 1024, 768); - - - Init(); - Reshape(1024, 768); - - /* some drivers crash when rendering to front buffer */ -#if 0 - glDrawBuffer( GL_FRONT ); - glClearColor( 0, 1.0, 0, 1); - - glClear( GL_COLOR_BUFFER_BIT ); -#endif - - doubleBuffer = 1; - glDrawBuffer( GL_BACK ); - - Draw(d, screen_surf); - sleep(2); - - /* TODO EGL_KHR_lock_surface */ - bitmap = NULL; - if (bitmap) - write_ppm("dump.ppm", bitmap, 1024, 768); - - eglDestroySurface(d, screen_surf); - eglDestroyContext(d, ctx); - eglTerminate(d); - - return 0; -} diff --git a/progs/egl/opengl/eglgears.c b/progs/egl/opengl/eglgears.c deleted file mode 100644 index 430deb26e5..0000000000 --- a/progs/egl/opengl/eglgears.c +++ /dev/null @@ -1,305 +0,0 @@ -/* - * 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 - */ - -#include <math.h> -#include <GL/gl.h> -#include <EGL/egl.h> - -#include "eglut.h" - -#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; - -/* - * - * 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(); -} - - -static void -idle(void) -{ - static double t0 = -1.; - double dt, t = eglutGet(EGLUT_ELAPSED_TIME) / 1000.0; - if (t0 < 0.0) - t0 = t; - dt = t - t0; - t0 = t; - - angle += 70.0 * dt; /* 70 degrees per second */ - angle = fmod(angle, 360.0); /* prevents eventual overflow */ - - eglutPostRedisplay(); -} - -/* new window size or exposure */ -static void -reshape(int width, int height) -{ - GLfloat h = (GLfloat) height / (GLfloat) width; - - glViewport(0, 0, (GLint) width, (GLint) height); - - 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); -} - -int -main(int argc, char *argv[]) -{ - eglutInitWindowSize(300, 300); - eglutInitAPIMask(EGLUT_OPENGL_BIT); - eglutInit(argc, argv); - - eglutCreateWindow("eglgears"); - - eglutIdleFunc(idle); - eglutReshapeFunc(reshape); - eglutDisplayFunc(draw); - - init(); - glDrawBuffer(GL_BACK); - - eglutMainLoop(); - - return 0; -} diff --git a/progs/egl/opengl/eglinfo.c b/progs/egl/opengl/eglinfo.c deleted file mode 100644 index 961fd9ccc7..0000000000 --- a/progs/egl/opengl/eglinfo.c +++ /dev/null @@ -1,223 +0,0 @@ -/* - * eglinfo - like glxinfo but for EGL - * - * Brian Paul - * 11 March 2005 - * - * Copyright (C) 2005 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. - */ - -#define EGL_EGLEXT_PROTOTYPES - -#include <EGL/egl.h> -#include <EGL/eglext.h> -#include <assert.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#define MAX_CONFIGS 1000 -#define MAX_MODES 1000 -#define MAX_SCREENS 10 - -/* These are X visual types, so if you're running eglinfo under - * something not X, they probably don't make sense. */ -static const char *vnames[] = { "SG", "GS", "SC", "PC", "TC", "DC" }; - -/** - * Print table of all available configurations. - */ -static void -PrintConfigs(EGLDisplay d) -{ - EGLConfig configs[MAX_CONFIGS]; - EGLint numConfigs, i; - - eglGetConfigs(d, configs, MAX_CONFIGS, &numConfigs); - - printf("Configurations:\n"); - printf(" bf lv colorbuffer dp st ms vis cav bi renderable supported\n"); - printf(" id sz l r g b a th cl ns b id eat nd gl es es2 vg surfaces \n"); - printf("---------------------------------------------------------------------\n"); - for (i = 0; i < numConfigs; i++) { - EGLint id, size, level; - EGLint red, green, blue, alpha; - EGLint depth, stencil; - EGLint renderable, surfaces; - EGLint vid, vtype, caveat, bindRgb, bindRgba; - EGLint samples, sampleBuffers; - char surfString[100] = ""; - - eglGetConfigAttrib(d, configs[i], EGL_CONFIG_ID, &id); - eglGetConfigAttrib(d, configs[i], EGL_BUFFER_SIZE, &size); - eglGetConfigAttrib(d, configs[i], EGL_LEVEL, &level); - - eglGetConfigAttrib(d, configs[i], EGL_RED_SIZE, &red); - eglGetConfigAttrib(d, configs[i], EGL_GREEN_SIZE, &green); - eglGetConfigAttrib(d, configs[i], EGL_BLUE_SIZE, &blue); - 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_NATIVE_VISUAL_TYPE, &vtype); - - eglGetConfigAttrib(d, configs[i], EGL_CONFIG_CAVEAT, &caveat); - eglGetConfigAttrib(d, configs[i], EGL_BIND_TO_TEXTURE_RGB, &bindRgb); - eglGetConfigAttrib(d, configs[i], EGL_BIND_TO_TEXTURE_RGBA, &bindRgba); - eglGetConfigAttrib(d, configs[i], EGL_RENDERABLE_TYPE, &renderable); - 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) - strcat(surfString, "pb,"); - if (surfaces & EGL_PIXMAP_BIT) - strcat(surfString, "pix,"); -#ifdef EGL_MESA_screen_surface - if (surfaces & EGL_SCREEN_BIT_MESA) - strcat(surfString, "scrn,"); -#endif - if (strlen(surfString) > 0) - surfString[strlen(surfString) - 1] = 0; - - printf("0x%02x %2d %2d %2d %2d %2d %2d %2d %2d %2d%2d 0x%02x%s ", - id, size, level, - red, green, blue, alpha, - depth, stencil, - samples, sampleBuffers, vid, vtype < 6 ? vnames[vtype] : "--"); - printf(" %c %c %c %c %c %c %s\n", - (caveat != EGL_NONE) ? 'y' : ' ', - (bindRgba) ? 'a' : (bindRgb) ? 'y' : ' ', - (renderable & EGL_OPENGL_BIT) ? 'y' : ' ', - (renderable & EGL_OPENGL_ES_BIT) ? 'y' : ' ', - (renderable & EGL_OPENGL_ES2_BIT) ? 'y' : ' ', - (renderable & EGL_OPENVG_BIT) ? 'y' : ' ', - surfString); - } -} - - -/** - * Print table of all available configurations. - */ -static void -PrintModes(EGLDisplay d) -{ -#ifdef EGL_MESA_screen_surface - const char *extensions = eglQueryString(d, EGL_EXTENSIONS); - if (strstr(extensions, "EGL_MESA_screen_surface")) { - EGLScreenMESA screens[MAX_SCREENS]; - EGLint numScreens = 1, scrn; - EGLModeMESA modes[MAX_MODES]; - - eglGetScreensMESA(d, screens, MAX_SCREENS, &numScreens); - printf("Number of Screens: %d\n\n", numScreens); - - for (scrn = 0; scrn < numScreens; scrn++) { - EGLint numModes, i; - - eglGetModesMESA(d, screens[scrn], modes, MAX_MODES, &numModes); - - printf("Screen %d Modes:\n", scrn); - printf(" id width height refresh name\n"); - printf("-----------------------------------------\n"); - for (i = 0; i < numModes; i++) { - EGLint id, w, h, r; - const char *str; - eglGetModeAttribMESA(d, modes[i], EGL_MODE_ID_MESA, &id); - eglGetModeAttribMESA(d, modes[i], EGL_WIDTH, &w); - eglGetModeAttribMESA(d, modes[i], EGL_HEIGHT, &h); - eglGetModeAttribMESA(d, modes[i], EGL_REFRESH_RATE_MESA, &r); - str = eglQueryModeStringMESA(d, modes[i]); - printf("0x%02x %5d %5d %.3f %s\n", id, w, h, r / 1000.0, str); - } - } - } -#endif -} - -static void -PrintExtensions(EGLDisplay d) -{ - const char *extensions, *p, *end, *next; - int column; - - printf("EGL extensions string:\n"); - - extensions = eglQueryString(d, EGL_EXTENSIONS); - - column = 0; - end = extensions + strlen(extensions); - - for (p = extensions; p < end; p = next + 1) { - next = strchr(p, ' '); - if (next == NULL) - next = end; - - if (column > 0 && column + next - p + 1 > 70) { - printf("\n"); - column = 0; - } - if (column == 0) - printf(" "); - else - printf(" "); - column += next - p + 1; - - printf("%.*s", (int) (next - p), p); - - p = next + 1; - } - - if (column > 0) - printf("\n"); -} - -int -main(int argc, char *argv[]) -{ - int maj, min; - EGLDisplay d = eglGetDisplay(EGL_DEFAULT_DISPLAY); - - if (!eglInitialize(d, &maj, &min)) { - printf("eglinfo: eglInitialize failed\n"); - exit(1); - } - - 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 - - PrintExtensions(d); - - PrintConfigs(d); - - PrintModes(d); - - eglTerminate(d); - - return 0; -} diff --git a/progs/egl/opengl/eglscreen.c b/progs/egl/opengl/eglscreen.c deleted file mode 100644 index 520f76ea03..0000000000 --- a/progs/egl/opengl/eglscreen.c +++ /dev/null @@ -1,120 +0,0 @@ -/* - * 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 <assert.h> -#include <math.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <unistd.h> -#include <GL/gl.h> -#include <EGL/egl.h> -#include <EGL/eglext.h> - -#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; - EGLint chosenMode = 0; - EGLint width = 0, height = 0; - - d = eglGetDisplay(EGL_DEFAULT_DISPLAY); - 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; - } - - usleep(5000000); - - eglDestroySurface(d, screen_surf); - eglTerminate(d); - - return 0; -} diff --git a/progs/egl/opengl/egltri.c b/progs/egl/opengl/egltri.c deleted file mode 100644 index fb1dde3529..0000000000 --- a/progs/egl/opengl/egltri.c +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright (C) 2008 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -/* - * Draw a triangle with X/EGL. - * Brian Paul - * 3 June 2008 - */ - - -#include <math.h> -#include <stdlib.h> -#include <string.h> -#include <GL/gl.h> - -#include "eglut.h" - - -static GLfloat view_rotx = 0.0, view_roty = 0.0, view_rotz = 0.0; - - -static void -draw(void) -{ - static const GLfloat verts[3][2] = { - { -1, -1 }, - { 1, -1 }, - { 0, 1 } - }; - static const GLfloat colors[3][3] = { - { 1, 0, 0 }, - { 0, 1, 0 }, - { 0, 0, 1 } - }; - - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - glPushMatrix(); - glRotatef(view_rotx, 1, 0, 0); - glRotatef(view_roty, 0, 1, 0); - glRotatef(view_rotz, 0, 0, 1); - - { - glVertexPointer(2, GL_FLOAT, 0, verts); - glColorPointer(3, GL_FLOAT, 0, colors); - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_COLOR_ARRAY); - - glDrawArrays(GL_TRIANGLES, 0, 3); - - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - } - - glPopMatrix(); -} - - -/* new window size or exposure */ -static void -reshape(int width, int height) -{ - GLfloat ar = (GLfloat) width / (GLfloat) height; - - glViewport(0, 0, (GLint) width, (GLint) height); - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glFrustum(-ar, ar, -1, 1, 5.0, 60.0); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glTranslatef(0.0, 0.0, -10.0); -} - - -static void -init(void) -{ - glClearColor(0.4, 0.4, 0.4, 0.0); -} - - -static void -special_key(int special) -{ - switch (special) { - case EGLUT_KEY_LEFT: - view_roty += 5.0; - break; - case EGLUT_KEY_RIGHT: - view_roty -= 5.0; - break; - case EGLUT_KEY_UP: - view_rotx += 5.0; - break; - case EGLUT_KEY_DOWN: - view_rotx -= 5.0; - break; - default: - break; - } -} - -int -main(int argc, char *argv[]) -{ - eglutInitWindowSize(300, 300); - eglutInitAPIMask(EGLUT_OPENGL_BIT); - eglutInit(argc, argv); - - eglutCreateWindow("egltri"); - - eglutReshapeFunc(reshape); - eglutDisplayFunc(draw); - eglutSpecialFunc(special_key); - - init(); - - eglutMainLoop(); - - return 0; -} diff --git a/progs/egl/opengl/peglgears.c b/progs/egl/opengl/peglgears.c deleted file mode 100644 index 212d1acf69..0000000000 --- a/progs/egl/opengl/peglgears.c +++ /dev/null @@ -1,451 +0,0 @@ -/* - * 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 <assert.h> -#include <math.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <GL/gl.h> -#include <EGL/egl.h> -#include <EGL/eglext.h> - -#define MAX_CONFIGS 10 -#define MAX_MODES 100 - -#define BENCHMARK - -#ifdef BENCHMARK - -/* XXX this probably isn't very portable */ - -#include <sys/time.h> -#include <unistd.h> - -/* return current time (in seconds) */ -static double -current_time(void) -{ - struct timeval tv; -#ifdef __VMS - (void) gettimeofday(&tv, NULL ); -#else - struct timezone tz; - (void) gettimeofday(&tv, &tz); -#endif - return (double) tv.tv_sec + tv.tv_usec / 1000000.0; -} - -#else /*BENCHMARK*/ - -/* dummy */ -static double -current_time(void) -{ - /* update this function for other platforms! */ - static double t = 0.0; - static int warn = 1; - if (warn) { - fprintf(stderr, "Warning: current_time() not implemented!!\n"); - warn = 0; - } - return t += 1.0; -} - -#endif /*BENCHMARK*/ - - -#ifndef M_PI -#define M_PI 3.14159265 -#endif - - -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) -{ - GLfloat h = (GLfloat) height / (GLfloat) width; - - glViewport(0, 0, (GLint) width, (GLint) height); - - 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; - GLfloat seconds, fps; - - while (ct - st < ttr) - { - double tt = current_time(); - double dt = tt - ct; - ct = tt; - - /* advance rotation for next frame */ - angle += 70.0 * dt; /* 70 degrees per second */ - if (angle > 3600.0) - angle -= 3600.0; - - draw(); - - eglSwapBuffers(dpy, surf); - - - frames++; - } - - seconds = ct - st; - fps = frames / seconds; - printf("%d frames in %3.1f seconds = %6.3f FPS\n", frames, seconds, fps); - -} - - -int -main(int argc, char *argv[]) -{ - int 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(EGL_DEFAULT_DISPLAY); - 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; -} diff --git a/progs/egl/opengl/xeglgears.c b/progs/egl/opengl/xeglgears.c deleted file mode 100644 index a6a977d9ff..0000000000 --- a/progs/egl/opengl/xeglgears.c +++ /dev/null @@ -1,954 +0,0 @@ -/* - * 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 - * - */ - - -#define GL_GLEXT_PROTOTYPES -#define EGL_EGLEXT_PROTOTYPES - -#include <math.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <X11/Xlib.h> -#include <X11/Xutil.h> -#include <X11/keysym.h> -#include <GL/gl.h> -#include <EGL/egl.h> - -#include <EGL/eglext.h> - - -#define BENCHMARK - -#ifdef BENCHMARK - -/* XXX this probably isn't very portable */ - -#include <sys/time.h> -#include <unistd.h> - -/* return current time (in seconds) */ -static double -current_time(void) -{ - struct timeval tv; -#ifdef __VMS - (void) gettimeofday(&tv, NULL ); -#else - struct timezone tz; - (void) gettimeofday(&tv, &tz); -#endif - return (double) tv.tv_sec + tv.tv_usec / 1000000.0; -} - -#else /*BENCHMARK*/ - -/* dummy */ -static double -current_time(void) -{ - /* update this function for other platforms! */ - static double t = 0.0; - static int warn = 1; - if (warn) { - fprintf(stderr, "Warning: current_time() not implemented!!\n"); - warn = 0; - } - return t += 1.0; -} - -#endif /*BENCHMARK*/ - - - -#ifndef M_PI -#define M_PI 3.14159265 -#endif - - -static GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0; -static GLint gear1, gear2, gear3; -static GLfloat angle = 0.0; - -/* - * - * Draw a gear wheel. You'll probably want to call this function when - * building a display list since we do a lot of trig here. - * - * Input: inner_radius - radius of hole at center - * outer_radius - radius at center of teeth - * width - width of gear - * teeth - number of teeth - * tooth_depth - depth of tooth - */ -static void -gear(GLfloat inner_radius, GLfloat outer_radius, GLfloat width, - GLint teeth, GLfloat tooth_depth) -{ - GLint i; - GLfloat r0, r1, r2; - GLfloat angle, da; - GLfloat u, v, len; - - r0 = inner_radius; - r1 = outer_radius - tooth_depth / 2.0; - r2 = outer_radius + tooth_depth / 2.0; - - da = 2.0 * M_PI / teeth / 4.0; - - glShadeModel(GL_FLAT); - - glNormal3f(0.0, 0.0, 1.0); - - /* draw front face */ - glBegin(GL_QUAD_STRIP); - for (i = 0; i <= teeth; i++) { - angle = i * 2.0 * M_PI / teeth; - glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5); - glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5); - if (i < teeth) { - glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5); - glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), - width * 0.5); - } - } - glEnd(); - - /* draw front sides of teeth */ - glBegin(GL_QUADS); - da = 2.0 * M_PI / teeth / 4.0; - for (i = 0; i < teeth; i++) { - angle = i * 2.0 * M_PI / teeth; - - glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5); - glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5); - glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), - width * 0.5); - glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), - width * 0.5); - } - glEnd(); - - glNormal3f(0.0, 0.0, -1.0); - - /* draw back face */ - glBegin(GL_QUAD_STRIP); - for (i = 0; i <= teeth; i++) { - angle = i * 2.0 * M_PI / teeth; - glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5); - glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5); - if (i < teeth) { - glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), - -width * 0.5); - glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5); - } - } - glEnd(); - - /* draw back sides of teeth */ - glBegin(GL_QUADS); - da = 2.0 * M_PI / teeth / 4.0; - for (i = 0; i < teeth; i++) { - angle = i * 2.0 * M_PI / teeth; - - glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), - -width * 0.5); - glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), - -width * 0.5); - glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5); - glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5); - } - glEnd(); - - /* draw outward faces of teeth */ - glBegin(GL_QUAD_STRIP); - for (i = 0; i < teeth; i++) { - angle = i * 2.0 * M_PI / teeth; - - glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5); - glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5); - u = r2 * cos(angle + da) - r1 * cos(angle); - v = r2 * sin(angle + da) - r1 * sin(angle); - len = sqrt(u * u + v * v); - u /= len; - v /= len; - glNormal3f(v, -u, 0.0); - glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5); - glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5); - glNormal3f(cos(angle), sin(angle), 0.0); - glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), - width * 0.5); - glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), - -width * 0.5); - u = r1 * cos(angle + 3 * da) - r2 * cos(angle + 2 * da); - v = r1 * sin(angle + 3 * da) - r2 * sin(angle + 2 * da); - glNormal3f(v, -u, 0.0); - glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), - width * 0.5); - glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), - -width * 0.5); - glNormal3f(cos(angle), sin(angle), 0.0); - } - - glVertex3f(r1 * cos(0), r1 * sin(0), width * 0.5); - glVertex3f(r1 * cos(0), r1 * sin(0), -width * 0.5); - - glEnd(); - - glShadeModel(GL_SMOOTH); - - /* draw inside radius cylinder */ - glBegin(GL_QUAD_STRIP); - for (i = 0; i <= teeth; i++) { - angle = i * 2.0 * M_PI / teeth; - glNormal3f(-cos(angle), -sin(angle), 0.0); - glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5); - glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5); - } - glEnd(); -} - - -static void -draw(void) -{ - glClearColor(0.2, 0.2, 0.2, 0.2); - 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); -} - - -struct egl_manager { - EGLNativeDisplayType xdpy; - EGLNativeWindowType xwin; - EGLNativePixmapType xpix; - - EGLDisplay dpy; - EGLConfig conf; - EGLContext ctx; - - EGLSurface win; - EGLSurface pix; - EGLSurface pbuf; - EGLImageKHR image; - - EGLBoolean verbose; - EGLint major, minor; - - GC gc; - GLuint fbo; -}; - -static struct egl_manager * -egl_manager_new(EGLNativeDisplayType xdpy, const EGLint *attrib_list, - EGLBoolean verbose) -{ - struct egl_manager *eman; - const char *ver; - EGLint num_conf; - - eman = calloc(1, sizeof(*eman)); - if (!eman) - return NULL; - - eman->verbose = verbose; - eman->xdpy = xdpy; - - eman->dpy = eglGetDisplay(eman->xdpy); - if (eman->dpy == EGL_NO_DISPLAY) { - printf("eglGetDisplay() failed\n"); - free(eman); - return NULL; - } - - if (!eglInitialize(eman->dpy, &eman->major, &eman->minor)) { - printf("eglInitialize() failed\n"); - free(eman); - return NULL; - } - - ver = eglQueryString(eman->dpy, EGL_VERSION); - printf("EGL_VERSION = %s\n", ver); - - if (!eglChooseConfig(eman->dpy, attrib_list, &eman->conf, 1, &num_conf) || - !num_conf) { - printf("eglChooseConfig() failed\n"); - eglTerminate(eman->dpy); - free(eman); - return NULL; - } - - eman->ctx = eglCreateContext(eman->dpy, eman->conf, EGL_NO_CONTEXT, NULL); - if (eman->ctx == EGL_NO_CONTEXT) { - printf("eglCreateContext() failed\n"); - eglTerminate(eman->dpy); - free(eman); - return NULL; - } - - return eman; -} - -static EGLBoolean -egl_manager_create_window(struct egl_manager *eman, const char *name, - EGLint w, EGLint h, EGLBoolean need_surface, - EGLBoolean fullscreen, const EGLint *attrib_list) -{ - XVisualInfo vinfo_template, *vinfo = NULL; - EGLint val, num_vinfo; - Window root; - XSetWindowAttributes attrs; - unsigned long mask; - EGLint x = 0, y = 0; - - if (!eglGetConfigAttrib(eman->dpy, eman->conf, - EGL_NATIVE_VISUAL_ID, &val)) { - printf("eglGetConfigAttrib() failed\n"); - return EGL_FALSE; - } - if (val) { - vinfo_template.visualid = (VisualID) val; - vinfo = XGetVisualInfo(eman->xdpy, VisualIDMask, &vinfo_template, &num_vinfo); - } - /* try harder if window surface is not needed */ - if (!vinfo && !need_surface && - eglGetConfigAttrib(eman->dpy, eman->conf, EGL_BUFFER_SIZE, &val)) { - if (val == 32) - val = 24; - vinfo_template.depth = val; - vinfo = XGetVisualInfo(eman->xdpy, VisualDepthMask, &vinfo_template, &num_vinfo); - } - - if (!vinfo) { - printf("XGetVisualInfo() failed\n"); - return EGL_FALSE; - } - - root = DefaultRootWindow(eman->xdpy); - if (fullscreen) { - x = y = 0; - w = DisplayWidth(eman->xdpy, DefaultScreen(eman->xdpy)); - h = DisplayHeight(eman->xdpy, DefaultScreen(eman->xdpy)); - } - - /* window attributes */ - attrs.background_pixel = 0; - attrs.border_pixel = 0; - attrs.colormap = XCreateColormap(eman->xdpy, root, vinfo->visual, AllocNone); - attrs.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask; - attrs.override_redirect = fullscreen; - mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect; - - eman->xwin = XCreateWindow(eman->xdpy, root, x, y, w, h, - 0, vinfo->depth, InputOutput, - vinfo->visual, mask, &attrs); - XFree(vinfo); - - /* set hints and properties */ - { - XSizeHints sizehints; - sizehints.x = x; - sizehints.y = y; - sizehints.width = w; - sizehints.height = h; - sizehints.flags = USSize | USPosition; - XSetNormalHints(eman->xdpy, eman->xwin, &sizehints); - XSetStandardProperties(eman->xdpy, eman->xwin, name, name, - None, (char **)NULL, 0, &sizehints); - } - - if (need_surface) { - eman->win = eglCreateWindowSurface(eman->dpy, eman->conf, - eman->xwin, attrib_list); - if (eman->win == EGL_NO_SURFACE) { - printf("eglCreateWindowSurface() failed\n"); - XDestroyWindow(eman->xdpy, eman->xwin); - eman->xwin = None; - return EGL_FALSE; - } - } - - eman->gc = XCreateGC(eman->xdpy, eman->xwin, 0, NULL); - - XMapWindow(eman->xdpy, eman->xwin); - - return EGL_TRUE; -} - -static EGLBoolean -egl_manager_create_pixmap(struct egl_manager *eman, EGLNativeWindowType xwin, - EGLBoolean need_surface, const EGLint *attrib_list) -{ - XWindowAttributes attrs; - - if (!XGetWindowAttributes(eman->xdpy, xwin, &attrs)) { - printf("XGetWindowAttributes() failed\n"); - return EGL_FALSE; - } - - eman->xpix = XCreatePixmap(eman->xdpy, xwin, - attrs.width, attrs.height, attrs.depth); - - if (need_surface) { - eman->pix = eglCreatePixmapSurface(eman->dpy, eman->conf, - eman->xpix, attrib_list); - if (eman->pix == EGL_NO_SURFACE) { - printf("eglCreatePixmapSurface() failed\n"); - XFreePixmap(eman->xdpy, eman->xpix); - eman->xpix = None; - return EGL_FALSE; - } - } - - return EGL_TRUE; -} - -static EGLBoolean -egl_manager_create_pbuffer(struct egl_manager *eman, const EGLint *attrib_list) -{ - eman->pbuf = eglCreatePbufferSurface(eman->dpy, eman->conf, attrib_list); - if (eman->pbuf == EGL_NO_SURFACE) { - printf("eglCreatePbufferSurface() failed\n"); - return EGL_FALSE; - } - - return EGL_TRUE; -} - -static void -egl_manager_destroy(struct egl_manager *eman) -{ - eglMakeCurrent(eman->dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); - eglTerminate(eman->dpy); - - if (eman->xwin != None) - XDestroyWindow(eman->xdpy, eman->xwin); - if (eman->xpix != None) - XFreePixmap(eman->xdpy, eman->xpix); - - XFreeGC(eman->xdpy, eman->gc); - - free(eman); -} - -enum { - GEARS_WINDOW, - GEARS_PIXMAP, - GEARS_PIXMAP_TEXTURE, - GEARS_PBUFFER, - GEARS_PBUFFER_TEXTURE, - GEARS_RENDERBUFFER -}; - -static void -texture_gears(struct egl_manager *eman, int surface_type) -{ - static const GLint verts[12] = - { -5, -6, -10, 5, -6, -10, -5, 4, 10, 5, 4, 10 }; - static const GLint tex_coords[8] = { 0, 0, 1, 0, 0, 1, 1, 1 }; - - eglMakeCurrent(eman->dpy, eman->win, eman->win, eman->ctx); - - glClearColor(0, 0, 0, 0); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - glEnable(GL_TEXTURE_2D); - glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glVertexPointer(3, GL_INT, 0, verts); - glTexCoordPointer(2, GL_INT, 0, tex_coords); - - if (surface_type == GEARS_PBUFFER_TEXTURE) - eglBindTexImage(eman->dpy, eman->pbuf, EGL_BACK_BUFFER); - - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - glDisable(GL_TEXTURE_2D); - - if (surface_type == GEARS_PBUFFER_TEXTURE) - eglReleaseTexImage(eman->dpy, eman->pbuf, EGL_BACK_BUFFER); - - eglSwapBuffers(eman->dpy, eman->win); -} - -static void -copy_gears(struct egl_manager *eman, - EGLint tile_w, EGLint tile_h, EGLint w, EGLint h) -{ - int x, y; - - eglWaitClient(); - - for (x = 0; x < w; x += tile_w) { - for (y = 0; y < h; y += tile_h) { - - XCopyArea(eman->xdpy, eman->xpix, eman->xwin, eman->gc, - 0, 0, tile_w, tile_h, x, y); - } - } -} - -static void -event_loop(struct egl_manager *eman, EGLint surface_type, EGLint w, EGLint h) -{ - int window_w = w, window_h = h; - - if (surface_type == EGL_PBUFFER_BIT) - printf("there will be no screen update if " - "eglCopyBuffers() is not implemented\n"); - - while (1) { - while (XPending(eman->xdpy) > 0) { - XEvent event; - XNextEvent(eman->xdpy, &event); - switch (event.type) { - case Expose: - /* we'll redraw below */ - break; - case ConfigureNotify: - window_w = event.xconfigure.width; - window_h = event.xconfigure.height; - if (surface_type == EGL_WINDOW_BIT) - reshape(window_w, window_h); - 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; - - switch (surface_type) { - case GEARS_WINDOW: - draw(); - eglSwapBuffers(eman->dpy, eman->win); - break; - - case GEARS_PBUFFER: - draw(); - if (!eglCopyBuffers(eman->dpy, eman->pbuf, eman->xpix)) - break; - copy_gears(eman, w, h, window_w, window_h); - break; - - case GEARS_PBUFFER_TEXTURE: - eglMakeCurrent(eman->dpy, eman->pbuf, eman->pbuf, eman->ctx); - draw(); - texture_gears(eman, surface_type); - break; - - case GEARS_PIXMAP: - draw(); - copy_gears(eman, w, h, window_w, window_h); - break; - - case GEARS_PIXMAP_TEXTURE: - eglMakeCurrent(eman->dpy, eman->pix, eman->pix, eman->ctx); - draw(); - texture_gears(eman, surface_type); - break; - - case GEARS_RENDERBUFFER: - glBindFramebuffer(GL_FRAMEBUFFER_EXT, eman->fbo); - draw(); - glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0); - texture_gears(eman, surface_type); - break; - } - - 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 <displayname> set the display to run on\n"); - printf(" -fullscreen run in fullscreen mode\n"); - printf(" -info display OpenGL renderer info\n"); - printf(" -pixmap use pixmap surface\n"); - printf(" -pixmap-texture use pixmap surface and texture using EGLImage\n"); - printf(" -pbuffer use pbuffer surface and eglCopyBuffers\n"); - printf(" -pbuffer-texture use pbuffer surface and eglBindTexImage\n"); - printf(" -renderbuffer renderbuffer as EGLImage and bind as texture from\n"); -} - -static const char *names[] = { - "window", - "pixmap", - "pixmap_texture", - "pbuffer", - "pbuffer_texture", - "renderbuffer" -}; - -int -main(int argc, char *argv[]) -{ - const int winWidth = 300, winHeight = 300; - Display *x_dpy; - char *dpyName = NULL; - struct egl_manager *eman; - EGLint attribs[] = { - EGL_SURFACE_TYPE, EGL_WINDOW_BIT, /* may be changed later */ - EGL_RED_SIZE, 1, - EGL_GREEN_SIZE, 1, - EGL_BLUE_SIZE, 1, - EGL_DEPTH_SIZE, 1, - EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT, - EGL_NONE - }; - char win_title[] = "xeglgears (window/pixmap/pbuffer)"; - EGLint surface_type = GEARS_WINDOW; - GLboolean printInfo = GL_FALSE; - GLboolean fullscreen = GL_FALSE; - EGLBoolean ret; - GLuint texture, color_rb, depth_rb; - int i; - - 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 if (strcmp(argv[i], "-pixmap") == 0) { - surface_type = GEARS_PIXMAP; - attribs[1] = EGL_PIXMAP_BIT; - } - else if (strcmp(argv[i], "-pixmap-texture") == 0) { - surface_type = GEARS_PIXMAP_TEXTURE; - attribs[1] = EGL_PIXMAP_BIT; - } - else if (strcmp(argv[i], "-pbuffer") == 0) { - surface_type = GEARS_PBUFFER; - attribs[1] = EGL_PBUFFER_BIT; - } - else if (strcmp(argv[i], "-pbuffer-texture") == 0) { - surface_type = GEARS_PBUFFER_TEXTURE; - attribs[1] = EGL_PBUFFER_BIT; - } - else if (strcmp(argv[i], "-renderbuffer") == 0) { - surface_type = GEARS_RENDERBUFFER; - } - 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; - } - - eglBindAPI(EGL_OPENGL_API); - - eman = egl_manager_new(x_dpy, attribs, printInfo); - if (!eman) { - XCloseDisplay(x_dpy); - return -1; - } - - snprintf(win_title, sizeof(win_title), - "xeglgears (%s)", names[surface_type]); - - ret = egl_manager_create_window(eman, win_title, winWidth, winHeight, - EGL_TRUE, fullscreen, NULL); - if (!ret) - return -1; - - /* create surface(s) */ - switch (surface_type) { - case GEARS_WINDOW: - if (ret) - ret = eglMakeCurrent(eman->dpy, eman->win, eman->win, eman->ctx); - break; - case GEARS_PIXMAP: - case GEARS_PIXMAP_TEXTURE: - ret = egl_manager_create_pixmap(eman, eman->xwin, EGL_TRUE, NULL); - if (surface_type == GEARS_PIXMAP_TEXTURE) - eman->image = eglCreateImageKHR (eman->dpy, eman->ctx, - EGL_NATIVE_PIXMAP_KHR, - (EGLClientBuffer) eman->xpix, NULL); - if (ret) - ret = eglMakeCurrent(eman->dpy, eman->pix, eman->pix, eman->ctx); - break; - case GEARS_PBUFFER: - case GEARS_PBUFFER_TEXTURE: - { - EGLint pbuf_attribs[] = { - EGL_WIDTH, winWidth, - EGL_HEIGHT, winHeight, - EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGB, - EGL_TEXTURE_TARGET, EGL_TEXTURE_2D, - EGL_NONE - }; - ret = (egl_manager_create_pixmap(eman, eman->xwin, - EGL_TRUE, NULL) && - egl_manager_create_pbuffer(eman, pbuf_attribs)); - if (ret) - ret = eglMakeCurrent(eman->dpy, eman->pbuf, eman->pbuf, eman->ctx); - } - break; - - - case GEARS_RENDERBUFFER: - ret = eglMakeCurrent(eman->dpy, eman->win, eman->win, eman->ctx); - if (ret == EGL_FALSE) - printf("failed to make context current\n"); - - glGenFramebuffers(1, &eman->fbo); - glBindFramebuffer(GL_FRAMEBUFFER_EXT, eman->fbo); - - glGenRenderbuffers(1, &color_rb); - glBindRenderbuffer(GL_RENDERBUFFER_EXT, color_rb); - glRenderbufferStorage(GL_RENDERBUFFER_EXT, GL_RGBA, winWidth, winHeight); - glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, - GL_COLOR_ATTACHMENT0_EXT, - GL_RENDERBUFFER_EXT, - color_rb); - - eman->image = eglCreateImageKHR(eman->dpy, eman->ctx, - EGL_GL_RENDERBUFFER_KHR, - (EGLClientBuffer) color_rb, NULL); - - glGenRenderbuffers(1, &depth_rb); - glBindRenderbuffer(GL_RENDERBUFFER_EXT, depth_rb); - glRenderbufferStorage(GL_RENDERBUFFER_EXT, - GL_DEPTH_COMPONENT, winWidth, winHeight); - glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, - GL_DEPTH_ATTACHMENT_EXT, - GL_RENDERBUFFER_EXT, - depth_rb); - - if (glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) != GL_FRAMEBUFFER_COMPLETE) { - printf("framebuffer not complete\n"); - exit(1); - } - - break; - - default: - ret = EGL_FALSE; - break; - } - - switch (surface_type) { - case GEARS_PIXMAP_TEXTURE: - case GEARS_RENDERBUFFER: - glGenTextures(1, &texture); - glBindTexture(GL_TEXTURE_2D, texture); - glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, eman->image); - break; - case GEARS_PBUFFER_TEXTURE: - glGenTextures(1, &texture); - glBindTexture(GL_TEXTURE_2D, texture); - break; - } - - if (!ret) { - egl_manager_destroy(eman); - XCloseDisplay(x_dpy); - 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(eman, surface_type, winWidth, winHeight); - - glDeleteLists(gear1, 1); - glDeleteLists(gear2, 1); - glDeleteLists(gear3, 1); - - egl_manager_destroy(eman); - XCloseDisplay(x_dpy); - - return 0; -} diff --git a/progs/egl/opengl/xeglthreads.c b/progs/egl/opengl/xeglthreads.c deleted file mode 100644 index 5787faecb9..0000000000 --- a/progs/egl/opengl/xeglthreads.c +++ /dev/null @@ -1,775 +0,0 @@ -/* - * Copyright (C) 2000 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * Ported to EGL by Chia-I Wu <olvaffe@gmail.com> - */ - - -/* - * This program tests EGL thread safety. - * Command line options: - * -p Open a display connection for each thread - * -l Enable application-side locking - * -n <num threads> Number of threads to create (default is 2) - * -display <display name> Specify X display (default is $DISPLAY) - * -t Use texture mapping - * - * Brian Paul 20 July 2000 - */ - - -/* - * Notes: - * - Each thread gets its own EGL context. - * - * - The EGL contexts share texture objects. - * - * - When 't' is pressed to update the texture image, the window/thread which - * has input focus is signalled to change the texture. The other threads - * should see the updated texture the next time they call glBindTexture. - */ - - -#if defined(PTHREADS) /* defined by Mesa on Linux and other platforms */ - -#include <assert.h> -#include <X11/Xlib.h> -#include <X11/Xutil.h> -#include <GL/gl.h> -#include <EGL/egl.h> -#include <math.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <pthread.h> - - -/* - * Each window/thread/context: - */ -struct winthread { - Display *Dpy; - int Index; - pthread_t Thread; - Window Win; - EGLDisplay Display; - EGLContext Context; - EGLSurface Surface; - float Angle; - int WinWidth, WinHeight; - GLboolean NewSize; - GLboolean Initialized; - GLboolean MakeNewTexture; -}; - - -#define MAX_WINTHREADS 100 -static struct winthread WinThreads[MAX_WINTHREADS]; -static int NumWinThreads = 0; -static volatile GLboolean ExitFlag = GL_FALSE; - -static GLboolean MultiDisplays = 0; -static GLboolean Locking = 0; -static GLboolean Texture = GL_FALSE; -static GLuint TexObj = 12; -static GLboolean Animate = GL_TRUE; - -static pthread_mutex_t Mutex; -static pthread_cond_t CondVar; -static pthread_mutex_t CondMutex; - - -static void -Error(const char *msg) -{ - fprintf(stderr, "Error: %s\n", msg); - exit(1); -} - - -static void -signal_redraw(void) -{ - pthread_mutex_lock(&CondMutex); - pthread_cond_broadcast(&CondVar); - pthread_mutex_unlock(&CondMutex); -} - - -static void -MakeNewTexture(struct winthread *wt) -{ -#define TEX_SIZE 128 - static float step = 0.0; - GLfloat image[TEX_SIZE][TEX_SIZE][4]; - GLint width; - int i, j; - - for (j = 0; j < TEX_SIZE; j++) { - for (i = 0; i < TEX_SIZE; i++) { - float dt = 5.0 * (j - 0.5 * TEX_SIZE) / TEX_SIZE; - float ds = 5.0 * (i - 0.5 * TEX_SIZE) / TEX_SIZE; - float r = dt * dt + ds * ds + step; - image[j][i][0] = - image[j][i][1] = - image[j][i][2] = 0.75 + 0.25 * cos(r); - image[j][i][3] = 1.0; - } - } - - step += 0.5; - - glBindTexture(GL_TEXTURE_2D, TexObj); - - glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width); - if (width) { - assert(width == TEX_SIZE); - /* sub-tex replace */ - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, TEX_SIZE, TEX_SIZE, - GL_RGBA, GL_FLOAT, image); - } - else { - /* create new */ - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TEX_SIZE, TEX_SIZE, 0, - GL_RGBA, GL_FLOAT, image); - } -} - - - -/* draw a colored cube */ -static void -draw_object(void) -{ - glPushMatrix(); - glScalef(0.75, 0.75, 0.75); - - glColor3f(1, 0, 0); - - if (Texture) { - glBindTexture(GL_TEXTURE_2D, TexObj); - glEnable(GL_TEXTURE_2D); - } - else { - glDisable(GL_TEXTURE_2D); - } - - glBegin(GL_QUADS); - - /* -X */ - glColor3f(0, 1, 1); - glTexCoord2f(0, 0); glVertex3f(-1, -1, -1); - glTexCoord2f(1, 0); glVertex3f(-1, 1, -1); - glTexCoord2f(1, 1); glVertex3f(-1, 1, 1); - glTexCoord2f(0, 1); glVertex3f(-1, -1, 1); - - /* +X */ - glColor3f(1, 0, 0); - glTexCoord2f(0, 0); glVertex3f(1, -1, -1); - glTexCoord2f(1, 0); glVertex3f(1, 1, -1); - glTexCoord2f(1, 1); glVertex3f(1, 1, 1); - glTexCoord2f(0, 1); glVertex3f(1, -1, 1); - - /* -Y */ - glColor3f(1, 0, 1); - glTexCoord2f(0, 0); glVertex3f(-1, -1, -1); - glTexCoord2f(1, 0); glVertex3f( 1, -1, -1); - glTexCoord2f(1, 1); glVertex3f( 1, -1, 1); - glTexCoord2f(0, 1); glVertex3f(-1, -1, 1); - - /* +Y */ - glColor3f(0, 1, 0); - glTexCoord2f(0, 0); glVertex3f(-1, 1, -1); - glTexCoord2f(1, 0); glVertex3f( 1, 1, -1); - glTexCoord2f(1, 1); glVertex3f( 1, 1, 1); - glTexCoord2f(0, 1); glVertex3f(-1, 1, 1); - - /* -Z */ - glColor3f(1, 1, 0); - glTexCoord2f(0, 0); glVertex3f(-1, -1, -1); - glTexCoord2f(1, 0); glVertex3f( 1, -1, -1); - glTexCoord2f(1, 1); glVertex3f( 1, 1, -1); - glTexCoord2f(0, 1); glVertex3f(-1, 1, -1); - - /* +Y */ - glColor3f(0, 0, 1); - glTexCoord2f(0, 0); glVertex3f(-1, -1, 1); - glTexCoord2f(1, 0); glVertex3f( 1, -1, 1); - glTexCoord2f(1, 1); glVertex3f( 1, 1, 1); - glTexCoord2f(0, 1); glVertex3f(-1, 1, 1); - - glEnd(); - - glPopMatrix(); -} - - -/* signal resize of given window */ -static void -resize(struct winthread *wt, int w, int h) -{ - wt->NewSize = GL_TRUE; - wt->WinWidth = w; - wt->WinHeight = h; - if (!Animate) - signal_redraw(); -} - - -/* - * We have an instance of this for each thread. - */ -static void -draw_loop(struct winthread *wt) -{ - while (!ExitFlag) { - - if (Locking) - pthread_mutex_lock(&Mutex); - - if (!wt->Initialized) { - eglMakeCurrent(wt->Display, wt->Surface, wt->Surface, wt->Context); - printf("xeglthreads: %d: GL_RENDERER = %s\n", wt->Index, - (char *) glGetString(GL_RENDERER)); - if (Texture /*&& wt->Index == 0*/) { - MakeNewTexture(wt); - } - wt->Initialized = GL_TRUE; - } - - if (Locking) - pthread_mutex_unlock(&Mutex); - - eglBindAPI(EGL_OPENGL_API); - if (eglGetCurrentContext() != wt->Context) { - printf("xeglthreads: current context %p != %p\n", - eglGetCurrentContext(), wt->Context); - } - - glEnable(GL_DEPTH_TEST); - - if (wt->NewSize) { - GLfloat w = (float) wt->WinWidth / (float) wt->WinHeight; - glViewport(0, 0, wt->WinWidth, wt->WinHeight); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glFrustum(-w, w, -1.0, 1.0, 1.5, 10); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glTranslatef(0, 0, -2.5); - wt->NewSize = GL_FALSE; - } - - if (wt->MakeNewTexture) { - MakeNewTexture(wt); - wt->MakeNewTexture = GL_FALSE; - } - - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - glPushMatrix(); - glRotatef(wt->Angle, 0, 1, 0); - glRotatef(wt->Angle, 1, 0, 0); - glScalef(0.7, 0.7, 0.7); - draw_object(); - glPopMatrix(); - - if (Locking) - pthread_mutex_lock(&Mutex); - - eglSwapBuffers(wt->Display, wt->Surface); - - if (Locking) - pthread_mutex_unlock(&Mutex); - - if (Animate) { - usleep(5000); - } - else { - /* wait for signal to draw */ - pthread_mutex_lock(&CondMutex); - pthread_cond_wait(&CondVar, &CondMutex); - pthread_mutex_unlock(&CondMutex); - } - wt->Angle += 1.0; - } - eglMakeCurrent(wt->Display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); -} - - -static void -keypress(XEvent *event, struct winthread *wt) -{ - char buf[100]; - KeySym keySym; - XComposeStatus stat; - - XLookupString(&event->xkey, buf, sizeof(buf), &keySym, &stat); - - switch (keySym) { - case XK_Escape: - /* tell all threads to exit */ - if (!Animate) { - signal_redraw(); - } - ExitFlag = GL_TRUE; - /*printf("exit draw_loop %d\n", wt->Index);*/ - return; - case XK_t: - case XK_T: - if (Texture) { - wt->MakeNewTexture = GL_TRUE; - if (!Animate) - signal_redraw(); - } - break; - case XK_a: - case XK_A: - Animate = !Animate; - if (Animate) /* yes, prev Animate state! */ - signal_redraw(); - break; - case XK_s: - case XK_S: - if (!Animate) - signal_redraw(); - break; - default: - ; /* nop */ - } -} - - -/* - * The main process thread runs this loop. - * Single display connection for all threads. - */ -static void -event_loop(Display *dpy) -{ - XEvent event; - int i; - - assert(!MultiDisplays); - - while (!ExitFlag) { - - if (Locking) { - while (1) { - int k; - pthread_mutex_lock(&Mutex); - k = XPending(dpy); - if (k) { - XNextEvent(dpy, &event); - pthread_mutex_unlock(&Mutex); - break; - } - pthread_mutex_unlock(&Mutex); - usleep(5000); - } - } - else { - XNextEvent(dpy, &event); - } - - switch (event.type) { - case ConfigureNotify: - /* Find winthread for this event's window */ - for (i = 0; i < NumWinThreads; i++) { - struct winthread *wt = &WinThreads[i]; - if (event.xconfigure.window == wt->Win) { - resize(wt, event.xconfigure.width, - event.xconfigure.height); - break; - } - } - break; - case KeyPress: - for (i = 0; i < NumWinThreads; i++) { - struct winthread *wt = &WinThreads[i]; - if (event.xkey.window == wt->Win) { - keypress(&event, wt); - break; - } - } - break; - default: - /*no-op*/ ; - } - } -} - - -/* - * Separate display connection for each thread. - */ -static void -event_loop_multi(void) -{ - XEvent event; - int w = 0; - - assert(MultiDisplays); - - while (!ExitFlag) { - struct winthread *wt = &WinThreads[w]; - if (XPending(wt->Dpy)) { - XNextEvent(wt->Dpy, &event); - switch (event.type) { - case ConfigureNotify: - resize(wt, event.xconfigure.width, event.xconfigure.height); - break; - case KeyPress: - keypress(&event, wt); - break; - default: - ; /* nop */ - } - } - w = (w + 1) % NumWinThreads; - usleep(5000); - } -} - - - -/* - * we'll call this once for each thread, before the threads are created. - */ -static void -create_window(struct winthread *wt, EGLContext shareCtx) -{ - Window win; - EGLContext ctx; - EGLSurface surf; - EGLint attribs[] = { EGL_RED_SIZE, 1, - EGL_GREEN_SIZE, 1, - EGL_BLUE_SIZE, 1, - EGL_DEPTH_SIZE, 1, - EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT, - 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) || - !num_configs) { - Error("Unable to choose an EGL config"); - } - - assert(config); - assert(num_configs > 0); - - if (!eglGetConfigAttrib(wt->Display, config, EGL_NATIVE_VISUAL_ID, &vid)) { - Error("Unable to get visual id of EGL config\n"); - } - - visTemplate.visualid = vid; - visinfo = XGetVisualInfo(wt->Dpy, VisualIDMask, - &visTemplate, &num_visuals); - if (!visinfo) { - Error("Unable to find RGB, Z, double-buffered visual"); - } - - /* window attributes */ - attr.background_pixel = 0; - attr.border_pixel = 0; - attr.colormap = XCreateColormap(wt->Dpy, root, visinfo->visual, AllocNone); - attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask; - mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; - - win = XCreateWindow(wt->Dpy, root, xpos, ypos, width, height, - 0, visinfo->depth, InputOutput, - visinfo->visual, mask, &attr); - if (!win) { - Error("Couldn't create window"); - } - - XFree(visinfo); - - { - XSizeHints sizehints; - sizehints.x = xpos; - sizehints.y = ypos; - sizehints.width = width; - sizehints.height = height; - sizehints.flags = USSize | USPosition; - XSetNormalHints(wt->Dpy, win, &sizehints); - XSetStandardProperties(wt->Dpy, win, "xeglthreads", "xeglthreads", - None, (char **)NULL, 0, &sizehints); - } - - eglBindAPI(EGL_OPENGL_API); - - ctx = eglCreateContext(wt->Display, config, shareCtx, NULL); - if (!ctx) { - Error("Couldn't create EGL context"); - } - surf = eglCreateWindowSurface(wt->Display, config, win, NULL); - if (!surf) { - Error("Couldn't create EGL surface"); - } - - XMapWindow(wt->Dpy, win); - XSync(wt->Dpy, 0); - - /* save the info for this window/context */ - wt->Win = win; - wt->Context = ctx; - wt->Surface = surf; - wt->Angle = 0.0; - wt->WinWidth = width; - wt->WinHeight = height; - wt->NewSize = GL_TRUE; -} - - -/* - * Called by pthread_create() - */ -static void * -thread_function(void *p) -{ - struct winthread *wt = (struct winthread *) p; - draw_loop(wt); - return NULL; -} - - -/* - * called before exit to wait for all threads to finish - */ -static void -clean_up(void) -{ - int i; - - /* wait for threads to finish */ - for (i = 0; i < NumWinThreads; i++) { - pthread_join(WinThreads[i].Thread, NULL); - } - - for (i = 0; i < NumWinThreads; i++) { - eglDestroyContext(WinThreads[i].Display, WinThreads[i].Context); - XDestroyWindow(WinThreads[i].Dpy, WinThreads[i].Win); - } -} - - -static void -usage(void) -{ - printf("xeglthreads: test of EGL/GL thread safety (any key = exit)\n"); - printf("Usage:\n"); - printf(" xeglthreads [options]\n"); - printf("Options:\n"); - printf(" -display DISPLAYNAME Specify display string\n"); - printf(" -n NUMTHREADS Number of threads to create\n"); - printf(" -p Use a separate display connection for each thread\n"); - printf(" -l Use application-side locking\n"); - printf(" -t Enable texturing\n"); - printf("Keyboard:\n"); - printf(" Esc Exit\n"); - printf(" t Change texture image (requires -t option)\n"); - printf(" a Toggle animation\n"); - printf(" s Step rotation (when not animating)\n"); -} - - -int -main(int argc, char *argv[]) -{ - char *displayName = NULL; - int numThreads = 2; - Display *dpy = NULL; - EGLDisplay *egl_dpy = NULL; - int i; - Status threadStat; - - if (argc == 1) { - usage(); - } - else { - int i; - for (i = 1; i < argc; i++) { - if (strcmp(argv[i], "-display") == 0 && i + 1 < argc) { - displayName = argv[i + 1]; - i++; - } - else if (strcmp(argv[i], "-p") == 0) { - MultiDisplays = 1; - } - else if (strcmp(argv[i], "-l") == 0) { - Locking = 1; - } - else if (strcmp(argv[i], "-t") == 0) { - Texture = 1; - } - else if (strcmp(argv[i], "-n") == 0 && i + 1 < argc) { - numThreads = atoi(argv[i + 1]); - if (numThreads < 1) - numThreads = 1; - else if (numThreads > MAX_WINTHREADS) - numThreads = MAX_WINTHREADS; - i++; - } - else { - usage(); - exit(1); - } - } - } - - if (Locking) - printf("xeglthreads: Using explicit locks around Xlib calls.\n"); - else - printf("xeglthreads: No explict locking.\n"); - - if (MultiDisplays) - printf("xeglthreads: Per-thread display connections.\n"); - else - printf("xeglthreads: Single display connection.\n"); - - /* - * VERY IMPORTANT: call XInitThreads() before any other Xlib functions. - */ - if (!MultiDisplays) { - if (!Locking) { - threadStat = XInitThreads(); - if (threadStat) { - printf("XInitThreads() returned %d (success)\n", - (int) threadStat); - } - else { - printf("XInitThreads() returned 0 " - "(failure- this program may fail)\n"); - } - } - - dpy = XOpenDisplay(displayName); - if (!dpy) { - fprintf(stderr, "Unable to open display %s\n", - XDisplayName(displayName)); - return -1; - } - egl_dpy = eglGetDisplay(dpy); - if (!egl_dpy) { - fprintf(stderr, "Unable to get EGL display\n"); - XCloseDisplay(dpy); - return -1; - } - if (!eglInitialize(egl_dpy, NULL, NULL)) { - fprintf(stderr, "Unable to initialize EGL display\n"); - return -1; - } - } - - pthread_mutex_init(&Mutex, NULL); - pthread_mutex_init(&CondMutex, NULL); - pthread_cond_init(&CondVar, NULL); - - printf("xeglthreads: creating windows\n"); - - NumWinThreads = numThreads; - - /* Create the EGL windows and contexts */ - for (i = 0; i < numThreads; i++) { - EGLContext share; - - if (MultiDisplays) { - WinThreads[i].Dpy = XOpenDisplay(displayName); - assert(WinThreads[i].Dpy); - WinThreads[i].Display = eglGetDisplay(WinThreads[i].Dpy); - assert(eglInitialize(WinThreads[i].Display, NULL, NULL)); - } - else { - WinThreads[i].Dpy = dpy; - WinThreads[i].Display = egl_dpy; - } - WinThreads[i].Index = i; - WinThreads[i].Initialized = GL_FALSE; - - share = (Texture && i > 0) ? WinThreads[0].Context : 0; - - create_window(&WinThreads[i], share); - } - - printf("xeglthreads: creating threads\n"); - - /* Create the threads */ - for (i = 0; i < numThreads; i++) { - pthread_create(&WinThreads[i].Thread, NULL, thread_function, - (void*) &WinThreads[i]); - printf("xeglthreads: Created thread %p\n", - (void *) WinThreads[i].Thread); - } - - if (MultiDisplays) - event_loop_multi(); - else - event_loop(dpy); - - clean_up(); - - if (MultiDisplays) { - for (i = 0; i < numThreads; i++) { - eglTerminate(WinThreads[i].Display); - XCloseDisplay(WinThreads[i].Dpy); - } - } - else { - eglTerminate(egl_dpy); - XCloseDisplay(dpy); - } - - return 0; -} - - -#else /* PTHREADS */ - - -#include <stdio.h> - -int -main(int argc, char *argv[]) -{ - printf("Sorry, this program wasn't compiled with PTHREADS defined.\n"); - return 0; -} - - -#endif /* PTHREADS */ diff --git a/progs/egl/opengles1/.gitignore b/progs/egl/opengles1/.gitignore deleted file mode 100644 index 135e3deb35..0000000000 --- a/progs/egl/opengles1/.gitignore +++ /dev/null @@ -1,15 +0,0 @@ -bindtex -drawtex_x11 -drawtex_screen -es1_info -gears_x11 -gears_screen -msaa -pbuffer -render_tex -texture_from_pixmap -torus_x11 -torus_screen -tri_x11 -tri_screen -two_win diff --git a/progs/egl/opengles1/Makefile b/progs/egl/opengles1/Makefile deleted file mode 100644 index e7802f8003..0000000000 --- a/progs/egl/opengles1/Makefile +++ /dev/null @@ -1,99 +0,0 @@ -# progs/egl/opengles1/Makefile - -TOP = ../../.. -include $(TOP)/configs/current - - -INCLUDE_DIRS = \ - -I$(TOP)/include \ - $(X11_CFLAGS) - -HEADERS = $(TOP)/include/GLES/egl.h - - -ES1_LIB_DEPS = \ - $(TOP)/$(LIB_DIR)/$(EGL_LIB_NAME) \ - $(TOP)/$(LIB_DIR)/$(GLESv1_CM_LIB_NAME) - - -ES1_LIBS = \ - -L$(TOP)/$(LIB_DIR) -l$(EGL_LIB) -l$(GLESv1_CM_LIB) \ - $(LIBDRM_LIB) $(X11_LIBS) - -EGLUT_DIR = $(TOP)/progs/egl/eglut - -EGLUT_DEMOS = \ - drawtex \ - gears \ - torus \ - tri - -EGLUT_X11_DEMOS := $(addsuffix _x11,$(EGLUT_DEMOS)) -EGLUT_SCREEN_DEMOS := $(addsuffix _screen,$(EGLUT_DEMOS)) - -PROGRAMS = \ - bindtex \ - es1_info \ - msaa \ - pbuffer \ - render_tex \ - texture_from_pixmap \ - two_win - - -.c.o: - $(CC) -c $(INCLUDE_DIRS) -I$(EGLUT_DIR) $(CFLAGS) $< -o $@ - - - -default: $(PROGRAMS) $(EGLUT_X11_DEMOS) $(EGLUT_SCREEN_DEMOS) - - - -bindtex: bindtex.o $(ES1_LIB_DEPS) - $(CC) $(CFLAGS) bindtex.o $(ES1_LIBS) -o $@ - - -es1_info: es1_info.o $(ES1_LIB_DEPS) - $(CC) $(CFLAGS) es1_info.o $(ES1_LIBS) -o $@ - - -msaa: msaa.o $(ES1_LIB_DEPS) - $(CC) $(CFLAGS) msaa.o $(ES1_LIBS) -o $@ - - -pbuffer: pbuffer.o $(ES1_LIB_DEPS) - $(CC) $(CFLAGS) pbuffer.o $(ES1_LIBS) -o $@ - - -render_tex: render_tex.o $(ES1_LIB_DEPS) - $(CC) $(CFLAGS) render_tex.o $(ES1_LIBS) -o $@ - - -texture_from_pixmap: texture_from_pixmap.o $(ES1_LIB_DEPS) - $(CC) $(CFLAGS) texture_from_pixmap.o $(ES1_LIBS) -o $@ - -torus: torus.o $(ES1_LIB_DEPS) - $(CC) $(CFLAGS) torus.o $(ES1_LIBS) -o $@ - - -two_win: two_win.o $(ES1_LIB_DEPS) - $(CC) $(CFLAGS) two_win.o $(ES1_LIBS) -o $@ - - -# define the rules for EGLUT demos -define eglut-demo-rule -$(1)_x11 $(1)_screen: $(1)_%: $(1).o $(EGLUT_DIR)/libeglut-%.a $(ES1_LIB_DEPS) -endef -$(foreach demo, $(EGLUT_DEMOS), $(eval $(call eglut-demo-rule,$(demo)))) - -# build EGLUT demos -$(EGLUT_X11_DEMOS): - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -L$(EGLUT_DIR) -leglut-$* $(ES1_LIBS) $(X11_LIBS) -$(EGLUT_SCREEN_DEMOS): - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -L$(EGLUT_DIR) -leglut-$* $(ES1_LIBS) - - -clean: - -rm -f *.o *~ - -rm -f $(PROGRAMS) $(EGLUT_X11_DEMOS) $(EGLUT_SCREEN_DEMOS) diff --git a/progs/egl/opengles1/bindtex.c b/progs/egl/opengles1/bindtex.c deleted file mode 100644 index c243b5941b..0000000000 --- a/progs/egl/opengles1/bindtex.c +++ /dev/null @@ -1,474 +0,0 @@ -/* - * Simple demo for eglBindTexImage. Based on xegl_tri.c by - * - * Copyright (C) 2008 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -/* - * The spec says that eglBindTexImage supports only OpenGL ES context, but this - * demo uses OpenGL context. Keep in mind that this is non-standard. - */ - -#include <math.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <X11/Xlib.h> -#include <X11/Xutil.h> -#include <X11/keysym.h> -#include <GLES/gl.h> -#include <EGL/egl.h> - -static EGLDisplay dpy; -static EGLContext ctx_win, ctx_pbuf; -static EGLSurface surf_win, surf_pbuf; -static GLuint tex_pbuf; - -static GLfloat view_rotx = 0.0, view_roty = 0.0, view_rotz = 0.0; -static GLboolean blend = GL_TRUE; -static GLuint color_flow; - -static void -make_pbuffer(int width, int height) -{ - static const EGLint config_attribs[] = { - EGL_RED_SIZE, 8, - EGL_GREEN_SIZE, 8, - EGL_BLUE_SIZE, 8, - EGL_BIND_TO_TEXTURE_RGB, EGL_TRUE, - EGL_NONE - }; - EGLint pbuf_attribs[] = { - EGL_WIDTH, width, - EGL_HEIGHT, height, - EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGB, - EGL_TEXTURE_TARGET, EGL_TEXTURE_2D, - EGL_NONE - }; - EGLConfig config; - EGLint num_configs; - - if (!eglChooseConfig(dpy, config_attribs, &config, 1, &num_configs) || - !num_configs) { - printf("Error: couldn't get an EGL visual config for pbuffer\n"); - exit(1); - } - - 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); - } -} - -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(); - glFrustumf(-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); - - glGenTextures(1, &tex_pbuf); - } -} - -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) || - !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); - } - - ctx_win = eglCreateContext(dpy, config, EGL_NO_CONTEXT, NULL ); - if (!ctx_win) { - printf("Error: eglCreateContext 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][4] = { - { 1, 0, 0, 1 }, - { 0, 1, 0, 1 }, - { 0, 0, 1, 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(4, 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(); - glFrustumf(-ar, ar, -1, 1, 5.0, 60.0); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glTranslatef(0.0, 0.0, -40.0); -} - -static void -event_loop(Display *x_dpy, Window win) -{ - while (1) { - int redraw = 1; - - if (XPending(x_dpy) > 0) { - XEvent event; - XNextEvent(x_dpy, &event); - - switch (event.type) { - case Expose: - redraw = 1; - break; - case ConfigureNotify: - reshape(event.xconfigure.width, event.xconfigure.height); - break; - case KeyPress: - { - char buffer[10]; - int r, code; - code = XLookupKeysym(&event.xkey, 0); - if (code == XK_Left) { - view_roty += 5.0; - } - else if (code == XK_Right) { - view_roty -= 5.0; - } - else if (code == XK_Up) { - view_rotx += 5.0; - } - else if (code == XK_Down) { - view_rotx -= 5.0; - } - else if (code == XK_b) { - blend = !blend; - } - else { - r = XLookupString(&event.xkey, buffer, sizeof(buffer), - NULL, NULL); - if (buffer[0] == 27) { - /* escape */ - return; - } - } - } - redraw = 1; - break; - default: - ; /*no-op*/ - } - } - - if (redraw) { - view_rotx += 1.0; - view_roty += 2.0; - view_rotz += 1.5; - color_flow += 20; - draw(); - eglSwapBuffers(dpy, surf_win); - } - } -} - -int -main(int argc, char *argv[]) -{ - const int winWidth = 300, winHeight = 300; - Display *x_dpy; - Window win; - char *dpyName = NULL; - EGLint egl_major, egl_minor; - const char *s; - - x_dpy = XOpenDisplay(dpyName); - if (!x_dpy) { - printf("Error: couldn't open display %s\n", - dpyName ? dpyName : getenv("DISPLAY")); - return -1; - } - - dpy = eglGetDisplay(x_dpy); - if (!dpy) { - printf("Error: eglGetDisplay() failed\n"); - return -1; - } - - if (!eglInitialize(dpy, &egl_major, &egl_minor)) { - printf("Error: eglInitialize() failed\n"); - return -1; - } - - s = eglQueryString(dpy, EGL_VERSION); - printf("EGL_VERSION = %s\n", s); - - make_window(x_dpy, "color flow", 0, 0, winWidth, winHeight, &win); - make_pbuffer(winWidth, winHeight); - - XMapWindow(x_dpy, win); - - reshape(winWidth, winHeight); - event_loop(x_dpy, win); - - glDeleteTextures(1, &tex_pbuf); - - eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); - eglTerminate(dpy); - - XDestroyWindow(x_dpy, win); - XCloseDisplay(x_dpy); - - return 0; -} diff --git a/progs/egl/opengles1/drawtex.c b/progs/egl/opengles1/drawtex.c deleted file mode 100644 index e9ac015340..0000000000 --- a/progs/egl/opengles1/drawtex.c +++ /dev/null @@ -1,217 +0,0 @@ -/* - * Copyright (C) 2008 Tunsgten Graphics,Inc. All Rights Reserved. - */ - -/* - * Test GL_OES_draw_texture - * Brian Paul - * August 2008 - */ - -#define GL_GLEXT_PROTOTYPES - -#include <math.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <GLES/gl.h> -#include <GLES/glext.h> - -#include "eglut.h" - - -static GLfloat view_posx = 10.0, view_posy = 20.0; -static GLfloat width = 200, height = 200; -static GLboolean animate = GL_FALSE; -static int win; - - -static void -draw(void) -{ - glClear(GL_COLOR_BUFFER_BIT); - - glDrawTexfOES(view_posx, view_posy, 0.0, width, height); -} - - -/* new window size or exposure */ -static void -reshape(int width, int height) -{ - GLfloat ar = (GLfloat) width / (GLfloat) height; - - glViewport(0, 0, (GLint) width, (GLint) height); - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - -#ifdef GL_VERSION_ES_CM_1_0 - glFrustumf(-ar, ar, -1, 1, 5.0, 60.0); -#else - glFrustum(-ar, ar, -1, 1, 5.0, 60.0); -#endif - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glTranslatef(0.0, 0.0, -15.0); -} - - -static float -dist(GLuint i, GLuint j, float x, float y) -{ - return sqrt((i-x) * (i-x) + (j-y) * (j-y)); -} - -static void -make_smile_texture(void) -{ -#define SZ 128 - GLenum Filter = GL_LINEAR; - GLubyte image[SZ][SZ][4]; - GLuint i, j; - GLint cropRect[4]; - - for (i = 0; i < SZ; i++) { - for (j = 0; j < SZ; j++) { - GLfloat d_mouth = dist(i, j, SZ/2, SZ/2); - GLfloat d_rt_eye = dist(i, j, SZ*3/4, SZ*3/4); - GLfloat d_lt_eye = dist(i, j, SZ*3/4, SZ*1/4); - if (d_rt_eye < SZ / 8 || d_lt_eye < SZ / 8) { - image[i][j][0] = 20; - image[i][j][1] = 50; - image[i][j][2] = 255; - image[i][j][3] = 255; - } - else if (i < SZ/2 && d_mouth < SZ/3) { - image[i][j][0] = 255; - image[i][j][1] = 20; - image[i][j][2] = 20; - image[i][j][3] = 255; - } - else { - image[i][j][0] = 200; - image[i][j][1] = 200; - image[i][j][2] = 200; - image[i][j][3] = 255; - } - } - } - - glActiveTexture(GL_TEXTURE0); /* unit 0 */ - glBindTexture(GL_TEXTURE_2D, 42); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, SZ, SZ, 0, - GL_RGBA, GL_UNSIGNED_BYTE, image); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, Filter); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, Filter); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); - - cropRect[0] = 0; - cropRect[1] = 0; - cropRect[2] = SZ; - cropRect[3] = SZ; - glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, cropRect); -#undef SZ -} - - - -static void -init(void) -{ - const char *ext = (char *) glGetString(GL_EXTENSIONS); - - if (!strstr(ext, "GL_OES_draw_texture")) { - fprintf(stderr, "Sorry, this program requires GL_OES_draw_texture"); - exit(1); - } - - glClearColor(0.4, 0.4, 0.4, 0.0); - - make_smile_texture(); - glEnable(GL_TEXTURE_2D); -} - - -static void -idle(void) -{ - if (animate) { - view_posx += 1.0; - view_posy += 2.0; - eglutPostRedisplay(); - } -} - -static void -key(unsigned char key) -{ - switch (key) { - case ' ': - animate = !animate; - break; - case 'w': - width -= 1.0f; - break; - case 'W': - width += 1.0f; - break; - case 'h': - height -= 1.0f; - break; - case 'H': - height += 1.0f; - break; - case 27: - eglutDestroyWindow(win); - exit(0); - break; - default: - break; - } -} - -static void -special_key(int key) -{ - switch (key) { - case EGLUT_KEY_LEFT: - view_posx -= 1.0; - break; - case EGLUT_KEY_RIGHT: - view_posx += 1.0; - break; - case EGLUT_KEY_UP: - view_posy += 1.0; - break; - case EGLUT_KEY_DOWN: - view_posy -= 1.0; - break; - default: - break; - } -} - -int -main(int argc, char *argv[]) -{ - eglutInitWindowSize(400, 300); - eglutInitAPIMask(EGLUT_OPENGL_ES1_BIT); - eglutInit(argc, argv); - - win = eglutCreateWindow("drawtex"); - - eglutIdleFunc(idle); - eglutReshapeFunc(reshape); - eglutDisplayFunc(draw); - eglutKeyboardFunc(key); - eglutSpecialFunc(special_key); - - init(); - - eglutMainLoop(); - - return 0; -} diff --git a/progs/egl/opengles1/es1_info.c b/progs/egl/opengles1/es1_info.c deleted file mode 100644 index 93816b5215..0000000000 --- a/progs/egl/opengles1/es1_info.c +++ /dev/null @@ -1,289 +0,0 @@ -/* - * Copyright (C) 2008 Tunsgten Graphics,Inc. All Rights Reserved. - */ - -/* - * List OpenGL ES extensions. - * Print ES 1 or ES 2 extensions depending on which library we're - * linked with: libGLESv1_CM.so vs libGLESv2.so - */ - -#define GL_GLEXT_PROTOTYPES - -#include <assert.h> -#include <math.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <X11/Xlib.h> -#include <X11/Xutil.h> -#include <X11/keysym.h> -#include <GLES/gl.h> -#include <GLES/glext.h> -#include <EGL/egl.h> - - -/* - * Print a list of extensions, with word-wrapping. - */ -static void -print_extension_list(const char *ext) -{ - const char *indentString = " "; - const int indent = 4; - const int max = 79; - int width, i, j; - - if (!ext || !ext[0]) - return; - - width = indent; - printf(indentString); - i = j = 0; - while (1) { - if (ext[j] == ' ' || ext[j] == 0) { - /* found end of an extension name */ - const int len = j - i; - if (width + len > max) { - /* start a new line */ - printf("\n"); - width = indent; - printf(indentString); - } - /* print the extension name between ext[i] and ext[j] */ - while (i < j) { - printf("%c", ext[i]); - i++; - } - /* either we're all done, or we'll continue with next extension */ - width += len + 1; - if (ext[j] == 0) { - break; - } - else { - i++; - j++; - if (ext[j] == 0) - break; - printf(", "); - width += 2; - } - } - j++; - } - printf("\n"); -} - - -static void -info(EGLDisplay egl_dpy) -{ - const char *s; - - s = eglQueryString(egl_dpy, EGL_VERSION); - printf("EGL_VERSION = %s\n", s); - - s = eglQueryString(egl_dpy, EGL_VENDOR); - printf("EGL_VENDOR = %s\n", s); - - s = eglQueryString(egl_dpy, EGL_EXTENSIONS); - printf("EGL_EXTENSIONS = %s\n", s); - - s = eglQueryString(egl_dpy, EGL_CLIENT_APIS); - printf("EGL_CLIENT_APIS = %s\n", s); - - printf("GL_VERSION: %s\n", (char *) glGetString(GL_VERSION)); - printf("GL_RENDERER: %s\n", (char *) glGetString(GL_RENDERER)); - printf("GL_EXTENSIONS:\n"); - print_extension_list((char *) glGetString(GL_EXTENSIONS)); -} - - -/* - * 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, int es_ver, - Window *winRet, - EGLContext *ctxRet, - EGLSurface *surfRet) -{ - EGLint attribs[] = { - EGL_RENDERABLE_TYPE, 0x0, - EGL_RED_SIZE, 1, - EGL_GREEN_SIZE, 1, - EGL_BLUE_SIZE, 1, - EGL_NONE - }; - EGLint ctx_attribs[] = { - EGL_CONTEXT_CLIENT_VERSION, 0, - 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 (es_ver == 1) - attribs[1] = EGL_OPENGL_ES_BIT; - else - attribs[1] = EGL_OPENGL_ES2_BIT; - ctx_attribs[1] = es_ver; - - if (!eglChooseConfig( egl_dpy, attribs, &config, 1, &num_configs)) { - printf("Error: couldn't get an EGL visual config\n"); - exit(1); - } - - assert(config); - assert(num_configs > 0); - - if (!eglGetConfigAttrib(egl_dpy, config, EGL_NATIVE_VISUAL_ID, &vid)) { - printf("Error: eglGetConfigAttrib() failed\n"); - exit(1); - } - - /* The X window visual must match the EGL config */ - visTemplate.visualid = vid; - visInfo = XGetVisualInfo(x_dpy, VisualIDMask, &visTemplate, &num_visuals); - if (!visInfo) { - printf("Error: couldn't get X visual\n"); - exit(1); - } - - /* window attributes */ - attr.background_pixel = 0; - attr.border_pixel = 0; - attr.colormap = XCreateColormap( x_dpy, root, visInfo->visual, AllocNone); - attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask; - mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; - - win = XCreateWindow( x_dpy, root, 0, 0, width, height, - 0, visInfo->depth, InputOutput, - visInfo->visual, mask, &attr ); - - /* set hints and properties */ - { - XSizeHints sizehints; - sizehints.x = x; - sizehints.y = y; - sizehints.width = width; - sizehints.height = height; - sizehints.flags = USSize | USPosition; - XSetNormalHints(x_dpy, win, &sizehints); - XSetStandardProperties(x_dpy, win, name, name, - None, (char **)NULL, 0, &sizehints); - } - - eglBindAPI(EGL_OPENGL_ES_API); - - ctx = eglCreateContext(egl_dpy, config, EGL_NO_CONTEXT, ctx_attribs ); - if (!ctx) { - printf("Error: eglCreateContext failed\n"); - exit(1); - } - - *surfRet = eglCreateWindowSurface(egl_dpy, config, win, NULL); - - if (!*surfRet) { - printf("Error: eglCreateWindowSurface failed\n"); - exit(1); - } - - XFree(visInfo); - - *winRet = win; - *ctxRet = ctx; -} - - -static void -usage(void) -{ - printf("Usage:\n"); - printf(" -display <displayname> set the display to run on\n"); -} - - -int -main(int argc, char *argv[]) -{ - const int winWidth = 400, winHeight = 300; - Display *x_dpy; - Window win; - EGLSurface egl_surf; - EGLContext egl_ctx; - EGLDisplay egl_dpy; - char *dpyName = NULL; - EGLint egl_major, egl_minor, es_ver; - int i; - - for (i = 1; i < argc; i++) { - if (strcmp(argv[i], "-display") == 0) { - dpyName = argv[i+1]; - i++; - } - 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; - } - - es_ver = 1; - /* decide the version from the executable's name */ - if (argc > 0 && argv[0] && strstr(argv[0], "es2")) - es_ver = 2; - make_x_window(x_dpy, egl_dpy, - "ES info", 0, 0, winWidth, winHeight, es_ver, - &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; - } - - info(egl_dpy); - - eglDestroyContext(egl_dpy, egl_ctx); - eglDestroySurface(egl_dpy, egl_surf); - eglTerminate(egl_dpy); - - - XDestroyWindow(x_dpy, win); - XCloseDisplay(x_dpy); - - return 0; -} diff --git a/progs/egl/opengles1/gears.c b/progs/egl/opengles1/gears.c deleted file mode 100644 index 8462a4871a..0000000000 --- a/progs/egl/opengles1/gears.c +++ /dev/null @@ -1,383 +0,0 @@ -/* - * Copyright (C) 2009 Chia-I Wu <olv@0xlab.org> - * - * Based on eglgears by - * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -#include <stdlib.h> -#include <stdio.h> -#include <math.h> -#include <assert.h> - -#include <GLES/gl.h> -#include "eglut.h" - -#ifndef M_PI -#define M_PI 3.14159265 -#endif - - -struct gear { - GLuint vbo; - GLfloat *vertices; - GLsizei stride; - - GLint num_teeth; -}; - -static GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0; -static struct gear gears[3]; -static GLfloat angle = 0.0; - -/* - * Initialize a gear wheel. - * - * Input: gear - gear to initialize - * 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 -init_gear(struct gear *gear, GLfloat inner_radius, GLfloat outer_radius, - GLfloat width, GLint teeth, GLfloat tooth_depth) -{ - GLfloat r0, r1, r2; - GLfloat a0, da; - GLint verts_per_tooth, total_verts, total_size; - GLint count, i; - GLfloat *verts; - - r0 = inner_radius; - r1 = outer_radius - tooth_depth / 2.0; - r2 = outer_radius + tooth_depth / 2.0; - - a0 = 2.0 * M_PI / teeth; - da = a0 / 4.0; - - gear->vbo = 0; - gear->vertices = NULL; - gear->stride = sizeof(GLfloat) * 6; /* XYZ + normal */ - gear->num_teeth = teeth; - - verts_per_tooth = 10 + 4; - total_verts = teeth * verts_per_tooth; - total_size = total_verts * gear->stride; - - verts = malloc(total_size); - if (!verts) { - printf("failed to allocate vertices\n"); - return; - } - -#define GEAR_VERT(r, n, sign) \ - do { \ - verts[count * 6 + 0] = (r) * vx[n]; \ - verts[count * 6 + 1] = (r) * vy[n]; \ - verts[count * 6 + 2] = (sign) * width * 0.5; \ - verts[count * 6 + 3] = normal[0]; \ - verts[count * 6 + 4] = normal[1]; \ - verts[count * 6 + 5] = normal[2]; \ - count++; \ - } while (0) - - count = 0; - for (i = 0; i < teeth; i++) { - GLfloat normal[3]; - GLfloat vx[5], vy[5]; - GLfloat u, v; - - normal[0] = 0.0; - normal[1] = 0.0; - normal[2] = 0.0; - - vx[0] = cos(i * a0 + 0 * da); - vy[0] = sin(i * a0 + 0 * da); - vx[1] = cos(i * a0 + 1 * da); - vy[1] = sin(i * a0 + 1 * da); - vx[2] = cos(i * a0 + 2 * da); - vy[2] = sin(i * a0 + 2 * da); - vx[3] = cos(i * a0 + 3 * da); - vy[3] = sin(i * a0 + 3 * da); - vx[4] = cos(i * a0 + 4 * da); - vy[4] = sin(i * a0 + 4 * da); - - /* outward faces of a tooth, 10 verts */ - normal[0] = vx[0]; - normal[1] = vy[0]; - GEAR_VERT(r1, 0, 1); - GEAR_VERT(r1, 0, -1); - - u = r2 * vx[1] - r1 * vx[0]; - v = r2 * vy[1] - r1 * vy[0]; - normal[0] = v; - normal[1] = -u; - GEAR_VERT(r2, 1, 1); - GEAR_VERT(r2, 1, -1); - - normal[0] = vx[0]; - normal[1] = vy[0]; - GEAR_VERT(r2, 2, 1); - GEAR_VERT(r2, 2, -1); - - u = r1 * vx[3] - r2 * vx[2]; - v = r1 * vy[3] - r2 * vy[2]; - normal[0] = v; - normal[1] = -u; - GEAR_VERT(r1, 3, 1); - GEAR_VERT(r1, 3, -1); - - normal[0] = vx[0]; - normal[1] = vy[0]; - GEAR_VERT(r1, 4, 1); - GEAR_VERT(r1, 4, -1); - - /* inside radius cylinder, 4 verts */ - normal[0] = -vx[4]; - normal[1] = -vy[4]; - GEAR_VERT(r0, 4, 1); - GEAR_VERT(r0, 4, -1); - - normal[0] = -vx[0]; - normal[1] = -vy[0]; - GEAR_VERT(r0, 0, 1); - GEAR_VERT(r0, 0, -1); - - assert(count % verts_per_tooth == 0); - } - assert(count == total_verts); -#undef GEAR_VERT - - gear->vertices = verts; - - /* setup VBO */ - glGenBuffers(1, &gear->vbo); - if (gear->vbo) { - glBindBuffer(GL_ARRAY_BUFFER, gear->vbo); - glBufferData(GL_ARRAY_BUFFER, total_size, verts, GL_STATIC_DRAW); - } -} - - -static void -draw_gear(const struct gear *gear) -{ - GLint i; - - if (!gear->vbo && !gear->vertices) { - printf("nothing to be drawn\n"); - return; - } - - if (gear->vbo) { - glBindBuffer(GL_ARRAY_BUFFER, gear->vbo); - glVertexPointer(3, GL_FLOAT, gear->stride, (const GLvoid *) 0); - glNormalPointer(GL_FLOAT, gear->stride, (const GLvoid *) (sizeof(GLfloat) * 3)); - } else { - glBindBuffer(GL_ARRAY_BUFFER, 0); - glVertexPointer(3, GL_FLOAT, gear->stride, gear->vertices); - glNormalPointer(GL_FLOAT, gear->stride, gear->vertices + 3); - } - - glEnableClientState(GL_VERTEX_ARRAY); - - for (i = 0; i < gear->num_teeth; i++) { - const GLint base = (10 + 4) * i; - GLushort indices[7]; - - glShadeModel(GL_FLAT); - - /* front face */ - indices[0] = base + 12; - indices[1] = base + 0; - indices[2] = base + 2; - indices[3] = base + 4; - indices[4] = base + 6; - indices[5] = base + 8; - indices[6] = base + 10; - - glNormal3f(0.0, 0.0, 1.0); - glDrawElements(GL_TRIANGLE_FAN, 7, GL_UNSIGNED_SHORT, indices); - - /* back face */ - indices[0] = base + 13; - indices[1] = base + 11; - indices[2] = base + 9; - indices[3] = base + 7; - indices[4] = base + 5; - indices[5] = base + 3; - indices[6] = base + 1; - - glNormal3f(0.0, 0.0, -1.0); - glDrawElements(GL_TRIANGLE_FAN, 7, GL_UNSIGNED_SHORT, indices); - - glEnableClientState(GL_NORMAL_ARRAY); - - /* outward face of a tooth */ - glDrawArrays(GL_TRIANGLE_STRIP, base, 10); - - /* inside radius cylinder */ - glShadeModel(GL_SMOOTH); - glDrawArrays(GL_TRIANGLE_STRIP, base + 10, 4); - - glDisableClientState(GL_NORMAL_ARRAY); - } - - glDisableClientState(GL_VERTEX_ARRAY); -} - - -static void -gears_draw(void) -{ - static const GLfloat red[4] = { 0.8, 0.1, 0.0, 1.0 }; - static const GLfloat green[4] = { 0.0, 0.8, 0.2, 1.0 }; - static const GLfloat blue[4] = { 0.2, 0.2, 1.0, 1.0 }; - - 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); - - glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, red); - draw_gear(&gears[0]); - - glPopMatrix(); - - glPushMatrix(); - glTranslatef(3.1, -2.0, 0.0); - glRotatef(-2.0 * angle - 9.0, 0.0, 0.0, 1.0); - - glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, green); - draw_gear(&gears[1]); - - glPopMatrix(); - - glPushMatrix(); - glTranslatef(-3.1, 4.2, 0.0); - glRotatef(-2.0 * angle - 25.0, 0.0, 0.0, 1.0); - - glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, blue); - draw_gear(&gears[2]); - - glPopMatrix(); - - glPopMatrix(); -} - - -static void gears_fini(void) -{ - GLint i; - for (i = 0; i < 3; i++) { - struct gear *gear = &gears[i]; - if (gear->vbo) { - glDeleteBuffers(1, &gear->vbo); - gear->vbo = 0; - } - if (gear->vertices) { - free(gear->vertices); - gear->vertices = NULL; - } - } -} - - -static void gears_init(void) -{ - static const GLfloat pos[4] = { 5.0, 5.0, 10.0, 0.0 }; - - glLightfv(GL_LIGHT0, GL_POSITION, pos); - glEnable(GL_CULL_FACE); - glEnable(GL_LIGHTING); - glEnable(GL_LIGHT0); - glEnable(GL_DEPTH_TEST); - glEnable(GL_NORMALIZE); - - init_gear(&gears[0], 1.0, 4.0, 1.0, 20, 0.7); - init_gear(&gears[1], 0.5, 2.0, 2.0, 10, 0.7); - init_gear(&gears[2], 1.3, 2.0, 0.5, 10, 0.7); -} - - -/* new window size or exposure */ -static void -gears_reshape(int width, int height) -{ - GLfloat h = (GLfloat) height / (GLfloat) width; - - glViewport(0, 0, (GLint) width, (GLint) height); - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glFrustumf(-1.0, 1.0, -h, h, 5.0, 60.0); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glTranslatef(0.0, 0.0, -40.0); -} - - -static void -gears_idle(void) -{ - static double t0 = -1.; - double dt, t = eglutGet(EGLUT_ELAPSED_TIME) / 1000.0; - if (t0 < 0.0) - t0 = t; - dt = t - t0; - t0 = t; - - angle += 70.0 * dt; /* 70 degrees per second */ - angle = fmod(angle, 360.0); /* prevents eventual overflow */ - - eglutPostRedisplay(); -} - - -int -main(int argc, char *argv[]) -{ - eglutInitWindowSize(300, 300); - eglutInitAPIMask(EGLUT_OPENGL_ES1_BIT); - eglutInit(argc, argv); - - eglutCreateWindow("gears"); - - eglutIdleFunc(gears_idle); - eglutReshapeFunc(gears_reshape); - eglutDisplayFunc(gears_draw); - - gears_init(); - - eglutMainLoop(); - - gears_fini(); - - return 0; -} diff --git a/progs/egl/opengles1/msaa.c b/progs/egl/opengles1/msaa.c deleted file mode 100644 index b4c6c63217..0000000000 --- a/progs/egl/opengles1/msaa.c +++ /dev/null @@ -1,442 +0,0 @@ -/* - * Copyright (C) 2008 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -/* - * Test MSAA with X/EGL and OpenGL ES 1.x - * Brian Paul - * 15 September 2008 - */ - -#define USE_FULL_GL 0 - - -#include <assert.h> -#include <math.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <X11/Xlib.h> -#include <X11/Xutil.h> -#include <X11/keysym.h> -#if USE_FULL_GL -#include <GL/gl.h> /* use full OpenGL */ -#else -#include <GLES/gl.h> /* use OpenGL ES 1.x */ -#include <GLES/glext.h> -#endif -#include <EGL/egl.h> - - - -static GLfloat view_rotx = 0.0, view_roty = 0.0, view_rotz = 0.0; -static GLboolean AA = 0*GL_TRUE; - - -static void -draw(void) -{ - float a; - - static const GLfloat verts[4][2] = { - { -1, -.1 }, - { 1, -.1 }, - { -1, .1 }, - { 1, .1 } - }; - static const GLfloat colors[4][4] = { - { 1, 0, 0, 1 }, - { 0, 1, 0, 1 }, - { 0, 0, 1, 1 }, - { 1, 0, 1, 1 } - }; - - if (AA) { - printf("MSAA enabled\n"); - glEnable(GL_MULTISAMPLE); - } - else { - printf("MSAA disabled\n"); - glDisable(GL_MULTISAMPLE); - } - - 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(4, GL_FLOAT, 0, colors); - - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_COLOR_ARRAY); - - for (a = 0; a < 360; a += 20.0) { - glPushMatrix(); - - glRotatef(a, 0, 0, 1); - glTranslatef(1.5, 0, 0); - - /* draw triangle */ - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - - glPopMatrix(); - } - - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - } - - glPopMatrix(); -} - - -/* new window size or exposure */ -static void -reshape(int width, int height) -{ - GLfloat ary = 3.0; - GLfloat arx = ary * (GLfloat) width / (GLfloat) height; - - glViewport(0, 0, (GLint) width, (GLint) height); - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); -#ifdef GL_VERSION_ES_CM_1_0 - glOrthof(-arx, arx, -ary, ary, -1.0, 1.0); -#else - glOrtho(-arx, arx, -ary, ary, -1.0, 1.0); -#endif - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); -} - - - -static void -init(void) -{ - printf("Press 'a' to toggle multisample antialiasing\n"); - printf("Press 'Esc' to exit\n"); -} - - -/* - * 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_SAMPLES, 1, - EGL_SAMPLE_BUFFERS, 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); - } - - if (num_configs < 1) { - printf("Error: Unable to find multisample pixel format.\n"); - printf("Try running glxinfo to see if your server supports MSAA.\n"); - exit(1); - } - - if (!eglGetConfigAttrib(egl_dpy, config, EGL_NATIVE_VISUAL_ID, &vid)) { - printf("Error: eglGetConfigAttrib() failed\n"); - exit(1); - } - - /* The X window visual must match the EGL config */ - visTemplate.visualid = vid; - visInfo = XGetVisualInfo(x_dpy, VisualIDMask, &visTemplate, &num_visuals); - if (!visInfo) { - printf("Error: couldn't get X visual\n"); - exit(1); - } - - /* window attributes */ - attr.background_pixel = 0; - attr.border_pixel = 0; - attr.colormap = XCreateColormap( x_dpy, root, visInfo->visual, AllocNone); - attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask; - mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; - - win = XCreateWindow( x_dpy, root, 0, 0, width, height, - 0, visInfo->depth, InputOutput, - visInfo->visual, mask, &attr ); - - /* set hints and properties */ - { - XSizeHints sizehints; - sizehints.x = x; - sizehints.y = y; - sizehints.width = width; - sizehints.height = height; - sizehints.flags = USSize | USPosition; - XSetNormalHints(x_dpy, win, &sizehints); - XSetStandardProperties(x_dpy, win, name, name, - None, (char **)NULL, 0, &sizehints); - } - -#if USE_FULL_GL - eglBindAPI(EGL_OPENGL_API); -#else - eglBindAPI(EGL_OPENGL_ES_API); -#endif - - ctx = eglCreateContext(egl_dpy, config, EGL_NO_CONTEXT, NULL ); - if (!ctx) { - printf("Error: eglCreateContext failed\n"); - exit(1); - } - - *surfRet = eglCreateWindowSurface(egl_dpy, config, win, NULL); - - if (!*surfRet) { - printf("Error: eglCreateWindowSurface failed\n"); - exit(1); - } - - XFree(visInfo); - - *winRet = win; - *ctxRet = ctx; -} - - -static void -event_loop(Display *dpy, Window win, - EGLDisplay egl_dpy, EGLSurface egl_surf) -{ - while (1) { - int redraw = 0; - XEvent event; - - XNextEvent(dpy, &event); - - switch (event.type) { - case Expose: - redraw = 1; - break; - case ConfigureNotify: - reshape(event.xconfigure.width, event.xconfigure.height); - break; - case KeyPress: - { - char buffer[10]; - int r, code; - code = XLookupKeysym(&event.xkey, 0); - if (code == XK_Left) { - view_roty += 5.0; - } - else if (code == XK_Right) { - view_roty -= 5.0; - } - else if (code == XK_Up) { - view_rotx += 5.0; - } - else if (code == XK_Down) { - view_rotx -= 5.0; - } - else { - r = XLookupString(&event.xkey, buffer, sizeof(buffer), - NULL, NULL); - if (buffer[0] == 'a') { - AA = !AA; - redraw = 1; - } - else if (buffer[0] == 27) { - /* escape */ - return; - } - } - } - redraw = 1; - break; - default: - ; /*no-op*/ - } - - if (redraw) { - draw(); - eglSwapBuffers(egl_dpy, egl_surf); - } - } -} - - -static void -usage(void) -{ - printf("Usage:\n"); - printf(" -display <displayname> set the display to run on\n"); - printf(" -info display OpenGL renderer info\n"); -} - - -int -main(int argc, char *argv[]) -{ - const int winWidth = 600, winHeight = 600; - Display *x_dpy; - Window win; - EGLSurface egl_surf; - EGLContext egl_ctx; - EGLDisplay egl_dpy; - char *dpyName = NULL; - GLboolean printInfo = GL_FALSE; - EGLint egl_major, egl_minor; - int i; - const char *s; - - static struct { - char *name; - GLenum value; - enum {GetString, GetInteger} type; - } info_items[] = { - {"GL_RENDERER", GL_RENDERER, GetString}, - {"GL_VERSION", GL_VERSION, GetString}, - {"GL_VENDOR", GL_VENDOR, GetString}, - {"GL_EXTENSIONS", GL_EXTENSIONS, GetString}, - {"GL_MAX_PALETTE_MATRICES_OES", GL_MAX_PALETTE_MATRICES_OES, GetInteger}, - {"GL_MAX_VERTEX_UNITS_OES", GL_MAX_VERTEX_UNITS_OES, GetInteger}, - }; - - for (i = 1; i < argc; i++) { - if (strcmp(argv[i], "-display") == 0) { - dpyName = argv[i+1]; - i++; - } - else if (strcmp(argv[i], "-info") == 0) { - printInfo = GL_TRUE; - } - else { - usage(); - return -1; - } - } - - x_dpy = XOpenDisplay(dpyName); - if (!x_dpy) { - printf("Error: couldn't open display %s\n", - dpyName ? dpyName : getenv("DISPLAY")); - return -1; - } - - egl_dpy = eglGetDisplay(x_dpy); - if (!egl_dpy) { - printf("Error: eglGetDisplay() failed\n"); - return -1; - } - - if (!eglInitialize(egl_dpy, &egl_major, &egl_minor)) { - printf("Error: eglInitialize() failed\n"); - return -1; - } - - s = eglQueryString(egl_dpy, EGL_VERSION); - printf("EGL_VERSION = %s\n", s); - - s = eglQueryString(egl_dpy, EGL_VENDOR); - printf("EGL_VENDOR = %s\n", s); - - s = eglQueryString(egl_dpy, EGL_EXTENSIONS); - printf("EGL_EXTENSIONS = %s\n", s); - - s = eglQueryString(egl_dpy, EGL_CLIENT_APIS); - printf("EGL_CLIENT_APIS = %s\n", s); - - make_x_window(x_dpy, egl_dpy, - "msaa", 0, 0, winWidth, winHeight, - &win, &egl_ctx, &egl_surf); - - XMapWindow(x_dpy, win); - if (!eglMakeCurrent(egl_dpy, egl_surf, egl_surf, egl_ctx)) { - printf("Error: eglMakeCurrent() failed\n"); - return -1; - } - - if (printInfo) { - for (i = 0; i < sizeof(info_items)/sizeof(info_items[0]); i++) { - switch (info_items[i].type) { - case GetString: - printf("%s = %s\n", info_items[i].name, (char *)glGetString(info_items[i].value)); - break; - case GetInteger: { - GLint rv = -1; - glGetIntegerv(info_items[i].value, &rv); - printf("%s = %d\n", info_items[i].name, rv); - break; - } - } - } - }; - init(); - - /* Set initial projection/viewing transformation. - * We can't be sure we'll get a ConfigureNotify event when the window - * first appears. - */ - reshape(winWidth, winHeight); - - event_loop(x_dpy, win, egl_dpy, egl_surf); - - eglDestroyContext(egl_dpy, egl_ctx); - eglDestroySurface(egl_dpy, egl_surf); - eglTerminate(egl_dpy); - - - XDestroyWindow(x_dpy, win); - XCloseDisplay(x_dpy); - - return 0; -} diff --git a/progs/egl/opengles1/pbuffer.c b/progs/egl/opengles1/pbuffer.c deleted file mode 100644 index 1b4dbb666f..0000000000 --- a/progs/egl/opengles1/pbuffer.c +++ /dev/null @@ -1,611 +0,0 @@ -/* - * Copyright (C) 2008 Tunsgten Graphics,Inc. All Rights Reserved. - */ - -/* - * Test EGL Pbuffers - * Brian Paul - * August 2008 - */ - - -#include <assert.h> -#include <math.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <X11/Xlib.h> -#include <X11/Xutil.h> -#include <X11/keysym.h> -#include <GLES/gl.h> -#include <GLES/glext.h> -#include <EGL/egl.h> - - -#ifndef M_PI -#define M_PI 3.14159265 -#endif - -static int WinWidth = 300, WinHeight = 300; - -static GLfloat view_rotx = 0.0, view_roty = 0.0, view_rotz = 0.0; - - -static void -Normal(GLfloat *n, GLfloat nx, GLfloat ny, GLfloat nz) -{ - n[0] = nx; - n[1] = ny; - n[2] = nz; -} - -static void -Vertex(GLfloat *v, GLfloat vx, GLfloat vy, GLfloat vz) -{ - v[0] = vx; - v[1] = vy; - v[2] = vz; -} - -static void -Texcoord(GLfloat *v, GLfloat s, GLfloat t) -{ - v[0] = s; - v[1] = t; -} - - -/* Borrowed from glut, adapted */ -static void -draw_torus(GLfloat r, GLfloat R, GLint nsides, GLint rings) -{ - int i, j; - GLfloat theta, phi, theta1; - GLfloat cosTheta, sinTheta; - GLfloat cosTheta1, sinTheta1; - GLfloat ringDelta, sideDelta; - GLfloat varray[100][3], narray[100][3], tarray[100][2]; - int vcount; - - glVertexPointer(3, GL_FLOAT, 0, varray); - glNormalPointer(GL_FLOAT, 0, narray); - glTexCoordPointer(2, GL_FLOAT, 0, tarray); - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_NORMAL_ARRAY); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - - ringDelta = 2.0 * M_PI / rings; - sideDelta = 2.0 * M_PI / nsides; - - theta = 0.0; - cosTheta = 1.0; - sinTheta = 0.0; - for (i = rings - 1; i >= 0; i--) { - theta1 = theta + ringDelta; - cosTheta1 = cos(theta1); - sinTheta1 = sin(theta1); - - vcount = 0; /* glBegin(GL_QUAD_STRIP); */ - - phi = 0.0; - for (j = nsides; j >= 0; j--) { - GLfloat s0, s1, t; - GLfloat cosPhi, sinPhi, dist; - - phi += sideDelta; - cosPhi = cos(phi); - sinPhi = sin(phi); - dist = R + r * cosPhi; - - s0 = 20.0 * theta / (2.0 * M_PI); - s1 = 20.0 * theta1 / (2.0 * M_PI); - t = 8.0 * phi / (2.0 * M_PI); - - Normal(narray[vcount], cosTheta1 * cosPhi, -sinTheta1 * cosPhi, sinPhi); - Texcoord(tarray[vcount], s1, t); - Vertex(varray[vcount], cosTheta1 * dist, -sinTheta1 * dist, r * sinPhi); - vcount++; - - Normal(narray[vcount], cosTheta * cosPhi, -sinTheta * cosPhi, sinPhi); - Texcoord(tarray[vcount], s0, t); - Vertex(varray[vcount], cosTheta * dist, -sinTheta * dist, r * sinPhi); - vcount++; - } - - /*glEnd();*/ - assert(vcount <= 100); - glDrawArrays(GL_TRIANGLE_STRIP, 0, vcount); - - theta = theta1; - cosTheta = cosTheta1; - sinTheta = sinTheta1; - } - - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_NORMAL_ARRAY); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); -} - - -static void -draw(void) -{ - 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); - glScalef(0.5, 0.5, 0.5); - - draw_torus(1.0, 3.0, 30, 60); - - glPopMatrix(); - - glFinish(); -} - - -/** - * Draw to both the window and pbuffer and compare results. - */ -static void -draw_both(EGLDisplay egl_dpy, EGLSurface egl_surf, EGLSurface egl_pbuf, - EGLContext egl_ctx) -{ - unsigned *wbuf, *pbuf; - int x = 100, y = 110; - int i, dif; - - wbuf = (unsigned *) malloc(WinWidth * WinHeight * 4); - pbuf = (unsigned *) malloc(WinWidth * WinHeight * 4); - - glPixelStorei(GL_PACK_ALIGNMENT, 1); - - /* first draw to window */ - if (!eglMakeCurrent(egl_dpy, egl_surf, egl_surf, egl_ctx)) { - printf("Error: eglMakeCurrent(window) failed\n"); - return; - } - draw(); - glReadPixels(0, 0, WinWidth, WinHeight, GL_RGBA, GL_UNSIGNED_BYTE, wbuf); - printf("Window[%d,%d] = 0x%08x\n", x, y, wbuf[y*WinWidth+x]); - - eglSwapBuffers(egl_dpy, egl_surf); - - /* then draw to pbuffer */ - if (!eglMakeCurrent(egl_dpy, egl_pbuf, egl_pbuf, egl_ctx)) { - printf("Error: eglMakeCurrent(pbuffer) failed\n"); - return; - } - draw(); - glReadPixels(0, 0, WinWidth, WinHeight, GL_RGBA, GL_UNSIGNED_BYTE, pbuf); - printf("Pbuffer[%d,%d] = 0x%08x\n", x, y, pbuf[y*WinWidth+x]); - - - /* compare renderings */ - for (dif = i = 0; i < WinWidth * WinHeight; i++) { - if (wbuf[i] != pbuf[i]) { - dif = 1; - break; - } - } - - if (dif) - printf("Difference at %d: 0x%08x vs. 0x%08x\n", i, wbuf[i], pbuf[i]); - else - printf("Window rendering matches Pbuffer rendering!\n"); - - free(wbuf); - free(pbuf); -} - - -/* new window size or exposure */ -static void -reshape(int width, int height) -{ - GLfloat ar = (GLfloat) width / (GLfloat) height; - - WinWidth = width; - WinHeight = height; - - glViewport(0, 0, (GLint) width, (GLint) height); - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - -#ifdef GL_VERSION_ES_CM_1_0 - glFrustumf(-ar, ar, -1, 1, 5.0, 60.0); -#else - glFrustum(-ar, ar, -1, 1, 5.0, 60.0); -#endif - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glTranslatef(0.0, 0.0, -15.0); -} - - -static void -make_texture(void) -{ -#define SZ 64 - GLenum Filter = GL_LINEAR; - GLubyte image[SZ][SZ][4]; - GLuint i, j; - - for (i = 0; i < SZ; i++) { - for (j = 0; j < SZ; j++) { - GLfloat d = (i - SZ/2) * (i - SZ/2) + (j - SZ/2) * (j - SZ/2); - d = sqrt(d); - if (d < SZ/3) { - image[i][j][0] = 255; - image[i][j][1] = 255; - image[i][j][2] = 255; - image[i][j][3] = 255; - } - else { - image[i][j][0] = 127; - image[i][j][1] = 127; - image[i][j][2] = 127; - image[i][j][3] = 255; - } - } - } - - glActiveTexture(GL_TEXTURE0); /* unit 0 */ - glBindTexture(GL_TEXTURE_2D, 42); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, SZ, SZ, 0, - GL_RGBA, GL_UNSIGNED_BYTE, image); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, Filter); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, Filter); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); -#undef SZ -} - - - -static void -init(void) -{ - static const GLfloat red[4] = {1, 0, 0, 0}; - static const GLfloat white[4] = {1.0, 1.0, 1.0, 1.0}; - static const GLfloat diffuse[4] = {0.7, 0.7, 0.7, 1.0}; - static const GLfloat specular[4] = {0.001, 0.001, 0.001, 1.0}; - static const GLfloat pos[4] = {20, 20, 50, 1}; - - glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, red); - glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, white); - glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 9.0); - - glEnable(GL_LIGHTING); - glEnable(GL_LIGHT0); - glLightfv(GL_LIGHT0, GL_POSITION, pos); - glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); - glLightfv(GL_LIGHT0, GL_SPECULAR, specular); - - glClearColor(0.4, 0.4, 0.4, 0.0); - glEnable(GL_DEPTH_TEST); - - make_texture(); - glEnable(GL_TEXTURE_2D); -} - - -/* - * Create an RGB, double-buffered X window. - * Return the window and context handles. - */ -static void -make_x_window(Display *x_dpy, EGLDisplay egl_dpy, - const char *name, - int x, int y, int width, int height, - Window *winRet, - EGLContext *ctxRet, - EGLSurface *surfRet) -{ - static const EGLint attribs[] = { - EGL_RED_SIZE, 1, - EGL_GREEN_SIZE, 1, - EGL_BLUE_SIZE, 1, - EGL_DEPTH_SIZE, 1, - EGL_NONE - }; - - int scrnum; - XSetWindowAttributes attr; - unsigned long mask; - Window root; - Window win; - XVisualInfo *visInfo, visTemplate; - int num_visuals; - EGLContext ctx; - EGLConfig config; - EGLint num_configs; - EGLint vid; - - scrnum = DefaultScreen( x_dpy ); - root = RootWindow( x_dpy, scrnum ); - - if (!eglChooseConfig( egl_dpy, attribs, &config, 1, &num_configs)) { - printf("Error: couldn't get an EGL visual config\n"); - exit(1); - } - - assert(config); - assert(num_configs > 0); - - if (!eglGetConfigAttrib(egl_dpy, config, EGL_NATIVE_VISUAL_ID, &vid)) { - printf("Error: eglGetConfigAttrib() failed\n"); - exit(1); - } - - /* The X window visual must match the EGL config */ - visTemplate.visualid = vid; - visInfo = XGetVisualInfo(x_dpy, VisualIDMask, &visTemplate, &num_visuals); - if (!visInfo) { - printf("Error: couldn't get X visual\n"); - exit(1); - } - - /* window attributes */ - attr.background_pixel = 0; - attr.border_pixel = 0; - attr.colormap = XCreateColormap( x_dpy, root, visInfo->visual, AllocNone); - attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask; - mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; - - win = XCreateWindow( x_dpy, root, 0, 0, width, height, - 0, visInfo->depth, InputOutput, - visInfo->visual, mask, &attr ); - - /* set hints and properties */ - { - XSizeHints sizehints; - sizehints.x = x; - sizehints.y = y; - sizehints.width = width; - sizehints.height = height; - sizehints.flags = USSize | USPosition; - XSetNormalHints(x_dpy, win, &sizehints); - XSetStandardProperties(x_dpy, win, name, name, - None, (char **)NULL, 0, &sizehints); - } - - eglBindAPI(EGL_OPENGL_ES_API); - - ctx = eglCreateContext(egl_dpy, config, EGL_NO_CONTEXT, NULL ); - if (!ctx) { - printf("Error: eglCreateContext failed\n"); - exit(1); - } - - *surfRet = eglCreateWindowSurface(egl_dpy, config, win, NULL); - - if (!*surfRet) { - printf("Error: eglCreateWindowSurface failed\n"); - exit(1); - } - - XFree(visInfo); - - *winRet = win; - *ctxRet = ctx; -} - - -static EGLSurface -make_pbuffer(Display *x_dpy, EGLDisplay egl_dpy, int width, int height) -{ - static const EGLint config_attribs[] = { - EGL_RED_SIZE, 1, - EGL_GREEN_SIZE, 1, - EGL_BLUE_SIZE, 1, - EGL_DEPTH_SIZE, 1, - EGL_NONE - }; - EGLConfig config; - EGLSurface pbuf; - EGLint num_configs; - EGLint pbuf_attribs[5]; - - pbuf_attribs[0] = EGL_WIDTH; - pbuf_attribs[1] = width; - pbuf_attribs[2] = EGL_HEIGHT; - pbuf_attribs[3] = height; - pbuf_attribs[4] = EGL_NONE; - - if (!eglChooseConfig( egl_dpy, config_attribs, &config, 1, &num_configs)) { - printf("Error: couldn't get an EGL config for pbuffer\n"); - exit(1); - } - - pbuf = eglCreatePbufferSurface(egl_dpy, config, pbuf_attribs); - - return pbuf; -} - - -static void -event_loop(Display *dpy, Window win, - EGLDisplay egl_dpy, EGLSurface egl_surf, EGLSurface egl_pbuf, - EGLContext egl_ctx) -{ - int anim = 0; - - while (1) { - int redraw = 0; - - if (!anim || XPending(dpy)) { - XEvent event; - XNextEvent(dpy, &event); - - switch (event.type) { - case Expose: - redraw = 1; - break; - case ConfigureNotify: - if (event.xconfigure.window == win) - 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] == ' ') { - anim = !anim; - } - else if (buffer[0] == 27) { - /* escape */ - return; - } - } - } - redraw = 1; - break; - default: - ; /*no-op*/ - } - } - - if (anim) { - view_rotx += 1.0; - view_roty += 2.0; - redraw = 1; - } - - if (redraw) { - draw_both(egl_dpy, egl_surf, egl_pbuf, egl_ctx); - } - } -} - - -static void -usage(void) -{ - printf("Usage:\n"); - printf(" -display <displayname> set the display to run on\n"); - printf(" -info display OpenGL renderer info\n"); -} - - -int -main(int argc, char *argv[]) -{ - Display *x_dpy; - Window win; - EGLSurface egl_surf, egl_pbuf; - EGLContext egl_ctx; - EGLDisplay egl_dpy; - char *dpyName = NULL; - GLboolean printInfo = GL_FALSE; - EGLint egl_major, egl_minor; - int i; - const char *s; - - for (i = 1; i < argc; i++) { - if (strcmp(argv[i], "-display") == 0) { - dpyName = argv[i+1]; - i++; - } - else if (strcmp(argv[i], "-info") == 0) { - printInfo = GL_TRUE; - } - else { - usage(); - return -1; - } - } - - x_dpy = XOpenDisplay(dpyName); - if (!x_dpy) { - printf("Error: couldn't open display %s\n", - dpyName ? dpyName : getenv("DISPLAY")); - return -1; - } - - egl_dpy = eglGetDisplay(x_dpy); - if (!egl_dpy) { - printf("Error: eglGetDisplay() failed\n"); - return -1; - } - - if (!eglInitialize(egl_dpy, &egl_major, &egl_minor)) { - printf("Error: eglInitialize() failed\n"); - return -1; - } - - s = eglQueryString(egl_dpy, EGL_VERSION); - printf("EGL_VERSION = %s\n", s); - - s = eglQueryString(egl_dpy, EGL_VENDOR); - printf("EGL_VENDOR = %s\n", s); - - s = eglQueryString(egl_dpy, EGL_EXTENSIONS); - printf("EGL_EXTENSIONS = %s\n", s); - - s = eglQueryString(egl_dpy, EGL_CLIENT_APIS); - printf("EGL_CLIENT_APIS = %s\n", s); - - make_x_window(x_dpy, egl_dpy, - "pbuffer", 0, 0, WinWidth, WinHeight, - &win, &egl_ctx, &egl_surf); - - egl_pbuf = make_pbuffer(x_dpy, egl_dpy, WinWidth, WinHeight); - if (!egl_pbuf) { - printf("Error: eglCreatePBufferSurface() failed\n"); - return -1; - } - - XMapWindow(x_dpy, win); - if (!eglMakeCurrent(egl_dpy, egl_surf, egl_surf, egl_ctx)) { - printf("Error: eglMakeCurrent() failed\n"); - return -1; - } - - if (printInfo) { - printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); - printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); - printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); - printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS)); - } - - init(); - - /* Set initial projection/viewing transformation. - * We can't be sure we'll get a ConfigureNotify event when the window - * first appears. - */ - reshape(WinWidth, WinHeight); - - event_loop(x_dpy, win, egl_dpy, egl_surf, egl_pbuf, egl_ctx); - - eglDestroyContext(egl_dpy, egl_ctx); - eglDestroySurface(egl_dpy, egl_surf); - eglTerminate(egl_dpy); - - - XDestroyWindow(x_dpy, win); - XCloseDisplay(x_dpy); - - return 0; -} diff --git a/progs/egl/opengles1/render_tex.c b/progs/egl/opengles1/render_tex.c deleted file mode 100644 index cd2abbd51b..0000000000 --- a/progs/egl/opengles1/render_tex.c +++ /dev/null @@ -1,663 +0,0 @@ -/* - * Copyright (C) 2008 Tunsgten Graphics,Inc. All Rights Reserved. - */ - -/* - * Test EGL render to texture. - * Brian Paul - * August 2008 - */ - - -#include <assert.h> -#include <math.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <X11/Xlib.h> -#include <X11/Xutil.h> -#include <X11/keysym.h> -#include <GLES/gl.h> -#include <GLES/glext.h> -#include <EGL/egl.h> - - -#ifndef M_PI -#define M_PI 3.14159265 -#endif - -static int TexWidth = 256, TexHeight = 256; - -static int WinWidth = 300, WinHeight = 300; - -static GLfloat view_rotx = 0.0, view_roty = 0.0, view_rotz = 0.0; - -static GLuint DotTexture, RenderTexture; - - -static void -Normal(GLfloat *n, GLfloat nx, GLfloat ny, GLfloat nz) -{ - n[0] = nx; - n[1] = ny; - n[2] = nz; -} - -static void -Vertex(GLfloat *v, GLfloat vx, GLfloat vy, GLfloat vz) -{ - v[0] = vx; - v[1] = vy; - v[2] = vz; -} - -static void -Texcoord(GLfloat *v, GLfloat s, GLfloat t) -{ - v[0] = s; - v[1] = t; -} - - -/* Borrowed from glut, adapted */ -static void -draw_torus(GLfloat r, GLfloat R, GLint nsides, GLint rings) -{ - int i, j; - GLfloat theta, phi, theta1; - GLfloat cosTheta, sinTheta; - GLfloat cosTheta1, sinTheta1; - GLfloat ringDelta, sideDelta; - GLfloat varray[100][3], narray[100][3], tarray[100][2]; - int vcount; - - glVertexPointer(3, GL_FLOAT, 0, varray); - glNormalPointer(GL_FLOAT, 0, narray); - glTexCoordPointer(2, GL_FLOAT, 0, tarray); - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_NORMAL_ARRAY); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - - ringDelta = 2.0 * M_PI / rings; - sideDelta = 2.0 * M_PI / nsides; - - theta = 0.0; - cosTheta = 1.0; - sinTheta = 0.0; - for (i = rings - 1; i >= 0; i--) { - theta1 = theta + ringDelta; - cosTheta1 = cos(theta1); - sinTheta1 = sin(theta1); - - vcount = 0; /* glBegin(GL_QUAD_STRIP); */ - - phi = 0.0; - for (j = nsides; j >= 0; j--) { - GLfloat s0, s1, t; - GLfloat cosPhi, sinPhi, dist; - - phi += sideDelta; - cosPhi = cos(phi); - sinPhi = sin(phi); - dist = R + r * cosPhi; - - s0 = 20.0 * theta / (2.0 * M_PI); - s1 = 20.0 * theta1 / (2.0 * M_PI); - t = 8.0 * phi / (2.0 * M_PI); - - Normal(narray[vcount], cosTheta1 * cosPhi, -sinTheta1 * cosPhi, sinPhi); - Texcoord(tarray[vcount], s1, t); - Vertex(varray[vcount], cosTheta1 * dist, -sinTheta1 * dist, r * sinPhi); - vcount++; - - Normal(narray[vcount], cosTheta * cosPhi, -sinTheta * cosPhi, sinPhi); - Texcoord(tarray[vcount], s0, t); - Vertex(varray[vcount], cosTheta * dist, -sinTheta * dist, r * sinPhi); - vcount++; - } - - /*glEnd();*/ - assert(vcount <= 100); - glDrawArrays(GL_TRIANGLE_STRIP, 0, vcount); - - theta = theta1; - cosTheta = cosTheta1; - sinTheta = sinTheta1; - } - - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_NORMAL_ARRAY); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); -} - - -static void -draw_torus_to_texture(void) -{ - glViewport(0, 0, TexWidth, TexHeight); - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glFrustumf(-1, 1, -1, 1, 5.0, 60.0); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glTranslatef(0.0, 0.0, -15.0); - - glClearColor(0.4, 0.4, 0.4, 0.0); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - glBindTexture(GL_TEXTURE_2D, DotTexture); - - glEnable(GL_LIGHTING); - - glPushMatrix(); - glRotatef(view_roty, 0, 1, 0); - glScalef(0.5, 0.5, 0.5); - - draw_torus(1.0, 3.0, 30, 60); - - glPopMatrix(); - - glDisable(GL_LIGHTING); - -#if 0 - glBindTexture(GL_TEXTURE_2D, RenderTexture); - glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, TexWidth, TexHeight); -#endif - - glFinish(); -} - - -static void -draw_textured_quad(void) -{ - GLfloat ar = (GLfloat) WinWidth / (GLfloat) WinHeight; - - glViewport(0, 0, WinWidth, WinHeight); - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glFrustumf(-ar, ar, -1, 1, 5.0, 60.0); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glTranslatef(0.0, 0.0, -8.0); - - glClearColor(0.4, 0.4, 1.0, 0.0); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - glBindTexture(GL_TEXTURE_2D, RenderTexture); - - glPushMatrix(); - glRotatef(view_rotx, 1, 0, 0); - glRotatef(view_rotz, 0, 0, 1); - - { - static const GLfloat texcoord[4][2] = { - { 0, 0 }, { 1, 0 }, { 0, 1 }, { 1, 1 } - }; - static const GLfloat vertex[4][2] = { - { -1, -1 }, { 1, -1 }, { -1, 1 }, { 1, 1 } - }; - - glVertexPointer(2, GL_FLOAT, 0, vertex); - glTexCoordPointer(2, GL_FLOAT, 0, texcoord); - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - } - - glPopMatrix(); -} - - - -static void -draw(EGLDisplay egl_dpy, EGLSurface egl_surf, EGLSurface egl_pbuf, - EGLContext egl_ctx) -{ - /*printf("Begin draw\n");*/ - - /* first draw torus to pbuffer /texture */ -#if 01 - if (!eglMakeCurrent(egl_dpy, egl_pbuf, egl_pbuf, egl_ctx)) { -#else - if (!eglMakeCurrent(egl_dpy, egl_surf, egl_surf, egl_ctx)) { -#endif - printf("Error: eglMakeCurrent(pbuf) failed\n"); - return; - } - draw_torus_to_texture(); - - /* draw textured quad to window */ - if (!eglMakeCurrent(egl_dpy, egl_surf, egl_surf, egl_ctx)) { - printf("Error: eglMakeCurrent(pbuffer) failed\n"); - return; - } - - glBindTexture(GL_TEXTURE_2D, RenderTexture); - eglBindTexImage(egl_dpy, egl_pbuf, EGL_BACK_BUFFER); - draw_textured_quad(); - eglReleaseTexImage(egl_dpy, egl_pbuf, EGL_BACK_BUFFER); - - eglSwapBuffers(egl_dpy, egl_surf); - - /*printf("End draw\n");*/ -} - - - -static void -make_dot_texture(void) -{ -#define SZ 64 - GLenum Filter = GL_LINEAR; - GLubyte image[SZ][SZ][4]; - GLuint i, j; - - for (i = 0; i < SZ; i++) { - for (j = 0; j < SZ; j++) { - GLfloat d = (i - SZ/2) * (i - SZ/2) + (j - SZ/2) * (j - SZ/2); - d = sqrt(d); - if (d < SZ/3) { - image[i][j][0] = 255; - image[i][j][1] = 255; - image[i][j][2] = 255; - image[i][j][3] = 255; - } - else { - image[i][j][0] = 127; - image[i][j][1] = 127; - image[i][j][2] = 127; - image[i][j][3] = 255; - } - } - } - - glGenTextures(1, &DotTexture); - glBindTexture(GL_TEXTURE_2D, DotTexture); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, SZ, SZ, 0, - GL_RGBA, GL_UNSIGNED_BYTE, image); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, Filter); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, Filter); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); -#undef SZ -} - - -static void -make_render_texture(void) -{ - GLenum Filter = GL_LINEAR; - glGenTextures(1, &RenderTexture); - glBindTexture(GL_TEXTURE_2D, RenderTexture); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TexWidth, TexHeight, 0, - GL_RGBA, GL_UNSIGNED_BYTE, NULL); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, Filter); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, Filter); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); -} - - -static void -init(void) -{ - static const GLfloat red[4] = {1, 0, 0, 0}; - static const GLfloat white[4] = {1.0, 1.0, 1.0, 1.0}; - static const GLfloat diffuse[4] = {0.7, 0.7, 0.7, 1.0}; - static const GLfloat specular[4] = {0.001, 0.001, 0.001, 1.0}; - static const GLfloat pos[4] = {20, 20, 50, 1}; - - glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, red); - glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, white); - glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 9.0); - - glEnable(GL_LIGHT0); - glLightfv(GL_LIGHT0, GL_POSITION, pos); - glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); - glLightfv(GL_LIGHT0, GL_SPECULAR, specular); - - glEnable(GL_DEPTH_TEST); - - make_dot_texture(); - make_render_texture(); - - printf("DotTexture=%u RenderTexture=%u\n", DotTexture, RenderTexture); - - glEnable(GL_TEXTURE_2D); -} - - -/* - * Create an RGB, double-buffered X window. - * Return the window and context handles. - */ -static void -make_x_window(Display *x_dpy, EGLDisplay egl_dpy, - const char *name, - int x, int y, int width, int height, - Window *winRet, - EGLContext *ctxRet, - EGLSurface *surfRet) -{ - static const EGLint attribs[] = { - EGL_RED_SIZE, 1, - EGL_GREEN_SIZE, 1, - EGL_BLUE_SIZE, 1, - EGL_DEPTH_SIZE, 1, - EGL_NONE - }; - - int scrnum; - XSetWindowAttributes attr; - unsigned long mask; - Window root; - Window win; - XVisualInfo *visInfo, visTemplate; - int num_visuals; - EGLContext ctx; - EGLConfig config; - EGLint num_configs; - EGLint vid; - - scrnum = DefaultScreen( x_dpy ); - root = RootWindow( x_dpy, scrnum ); - - if (!eglChooseConfig( egl_dpy, attribs, &config, 1, &num_configs)) { - printf("Error: couldn't get an EGL visual config\n"); - exit(1); - } - - assert(config); - assert(num_configs > 0); - - if (!eglGetConfigAttrib(egl_dpy, config, EGL_NATIVE_VISUAL_ID, &vid)) { - printf("Error: eglGetConfigAttrib() failed\n"); - exit(1); - } - - /* The X window visual must match the EGL config */ - visTemplate.visualid = vid; - visInfo = XGetVisualInfo(x_dpy, VisualIDMask, &visTemplate, &num_visuals); - if (!visInfo) { - printf("Error: couldn't get X visual\n"); - exit(1); - } - - /* window attributes */ - attr.background_pixel = 0; - attr.border_pixel = 0; - attr.colormap = XCreateColormap( x_dpy, root, visInfo->visual, AllocNone); - attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask; - mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; - - win = XCreateWindow( x_dpy, root, 0, 0, width, height, - 0, visInfo->depth, InputOutput, - visInfo->visual, mask, &attr ); - - /* set hints and properties */ - { - XSizeHints sizehints; - sizehints.x = x; - sizehints.y = y; - sizehints.width = width; - sizehints.height = height; - sizehints.flags = USSize | USPosition; - XSetNormalHints(x_dpy, win, &sizehints); - XSetStandardProperties(x_dpy, win, name, name, - None, (char **)NULL, 0, &sizehints); - } - - eglBindAPI(EGL_OPENGL_ES_API); - - ctx = eglCreateContext(egl_dpy, config, EGL_NO_CONTEXT, NULL ); - if (!ctx) { - printf("Error: eglCreateContext failed\n"); - exit(1); - } - - *surfRet = eglCreateWindowSurface(egl_dpy, config, win, NULL); - - if (!*surfRet) { - printf("Error: eglCreateWindowSurface failed\n"); - exit(1); - } - - XFree(visInfo); - - *winRet = win; - *ctxRet = ctx; -} - - -static EGLSurface -make_pbuffer(Display *x_dpy, EGLDisplay egl_dpy, int width, int height) -{ - static const EGLint config_attribs[] = { - EGL_RED_SIZE, 1, - EGL_GREEN_SIZE, 1, - EGL_BLUE_SIZE, 1, - EGL_DEPTH_SIZE, 1, - EGL_NONE - }; - EGLConfig config; - EGLSurface pbuf; - EGLint num_configs; - EGLint pbuf_attribs[15]; - int i = 0; - - pbuf_attribs[i++] = EGL_WIDTH; - pbuf_attribs[i++] = width; - pbuf_attribs[i++] = EGL_HEIGHT; - pbuf_attribs[i++] = height; - pbuf_attribs[i++] = EGL_TEXTURE_FORMAT; - pbuf_attribs[i++] = EGL_TEXTURE_RGBA; - pbuf_attribs[i++] = EGL_TEXTURE_TARGET; - pbuf_attribs[i++] = EGL_TEXTURE_2D; - pbuf_attribs[i++] = EGL_MIPMAP_TEXTURE; - pbuf_attribs[i++] = EGL_FALSE; - pbuf_attribs[i++] = EGL_NONE; - assert(i <= 15); - - if (!eglChooseConfig( egl_dpy, config_attribs, &config, 1, &num_configs)) { - printf("Error: couldn't get an EGL config for pbuffer\n"); - exit(1); - } - - pbuf = eglCreatePbufferSurface(egl_dpy, config, pbuf_attribs); - - return pbuf; -} - - -static void -event_loop(Display *dpy, Window win, - EGLDisplay egl_dpy, EGLSurface egl_surf, EGLSurface egl_pbuf, - EGLContext egl_ctx) -{ - int anim = 0; - - while (1) { - int redraw = 0; - - if (!anim || XPending(dpy)) { - XEvent event; - XNextEvent(dpy, &event); - - switch (event.type) { - case Expose: - redraw = 1; - break; - case ConfigureNotify: - if (event.xconfigure.window == win) { - WinWidth = event.xconfigure.width; - WinHeight = 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] == ' ') { - anim = !anim; - } - else if (buffer[0] == 'z') { - view_rotz += 5.0; - } - else if (buffer[0] == 'Z') { - view_rotz -= 5.0; - } - else if (buffer[0] == 27) { - /* escape */ - return; - } - } - } - redraw = 1; - break; - default: - ; /*no-op*/ - } - } - - if (anim) { - view_rotx += 1.0; - view_roty += 2.0; - redraw = 1; - } - - if (redraw) { - draw(egl_dpy, egl_surf, egl_pbuf, egl_ctx); - } - } -} - - -static void -usage(void) -{ - printf("Usage:\n"); - printf(" -display <displayname> set the display to run on\n"); - printf(" -info display OpenGL renderer info\n"); -} - - -int -main(int argc, char *argv[]) -{ - Display *x_dpy; - Window win; - EGLSurface egl_surf, egl_pbuf; - EGLContext egl_ctx; - EGLDisplay egl_dpy; - char *dpyName = NULL; - GLboolean printInfo = GL_FALSE; - EGLint egl_major, egl_minor; - int i; - const char *s; - - for (i = 1; i < argc; i++) { - if (strcmp(argv[i], "-display") == 0) { - dpyName = argv[i+1]; - i++; - } - else if (strcmp(argv[i], "-info") == 0) { - printInfo = GL_TRUE; - } - else { - usage(); - return -1; - } - } - - x_dpy = XOpenDisplay(dpyName); - if (!x_dpy) { - printf("Error: couldn't open display %s\n", - dpyName ? dpyName : getenv("DISPLAY")); - return -1; - } - - egl_dpy = eglGetDisplay(x_dpy); - if (!egl_dpy) { - printf("Error: eglGetDisplay() failed\n"); - return -1; - } - - if (!eglInitialize(egl_dpy, &egl_major, &egl_minor)) { - printf("Error: eglInitialize() failed\n"); - return -1; - } - - s = eglQueryString(egl_dpy, EGL_VERSION); - printf("EGL_VERSION = %s\n", s); - - s = eglQueryString(egl_dpy, EGL_VENDOR); - printf("EGL_VENDOR = %s\n", s); - - s = eglQueryString(egl_dpy, EGL_EXTENSIONS); - printf("EGL_EXTENSIONS = %s\n", s); - - s = eglQueryString(egl_dpy, EGL_CLIENT_APIS); - printf("EGL_CLIENT_APIS = %s\n", s); - - make_x_window(x_dpy, egl_dpy, - "render_tex", 0, 0, WinWidth, WinHeight, - &win, &egl_ctx, &egl_surf); - - egl_pbuf = make_pbuffer(x_dpy, egl_dpy, TexWidth, TexHeight); - if (!egl_pbuf) { - printf("Error: eglCreatePBufferSurface() failed\n"); - return -1; - } - - XMapWindow(x_dpy, win); - if (!eglMakeCurrent(egl_dpy, egl_surf, egl_surf, egl_ctx)) { - printf("Error: eglMakeCurrent() failed\n"); - return -1; - } - - if (printInfo) { - printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); - printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); - printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); - printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS)); - } - - init(); - - event_loop(x_dpy, win, egl_dpy, egl_surf, egl_pbuf, egl_ctx); - - eglDestroyContext(egl_dpy, egl_ctx); - eglDestroySurface(egl_dpy, egl_surf); - eglTerminate(egl_dpy); - - - XDestroyWindow(x_dpy, win); - XCloseDisplay(x_dpy); - - return 0; -} diff --git a/progs/egl/opengles1/texture_from_pixmap.c b/progs/egl/opengles1/texture_from_pixmap.c deleted file mode 100644 index 8e7e803d78..0000000000 --- a/progs/egl/opengles1/texture_from_pixmap.c +++ /dev/null @@ -1,579 +0,0 @@ -/* - * Mesa 3-D graphics library - * Version: 7.9 - * - * Copyright (C) 2010 LunarG Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * Authors: - * Chia-I Wu <olv@lunarg.com> - */ - -/* - * This demo uses EGL_KHR_image_pixmap and GL_OES_EGL_image to demonstrate - * texture-from-pixmap. - */ - -#include <assert.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <unistd.h> /* for usleep */ -#include <sys/time.h> /* for gettimeofday */ -#include <X11/Xlib.h> -#include <X11/Xutil.h> -#include <X11/keysym.h> -#include <GLES/gl.h> -#include <GLES/glext.h> -#include <EGL/egl.h> -#include <EGL/eglext.h> - -struct app_data { - /* native */ - Display *xdpy; - Window canvas, cube; - Pixmap pix; - unsigned int width, height, depth; - GC fg, bg; - - /* EGL */ - EGLDisplay dpy; - EGLContext ctx; - EGLSurface surf; - EGLImageKHR img; - - /* OpenGL ES */ - GLuint texture; - - PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR; - PFNEGLDESTROYIMAGEKHRPROC eglDestroyImageKHR; - PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES; - - /* app state */ - Bool loop; - Bool redraw, reshape; - - struct { - Bool active; - unsigned long next_frame; /* in ms */ - float view_rotx; - float view_roty; - float view_rotz; - - } animate; - - struct { - Bool active; - int x1, y1; - int x2, y2; - } paint; -}; - -static void -gl_redraw(void) -{ - const GLfloat verts[4][2] = { - { -1, -1 }, - { 1, -1 }, - { 1, 1 }, - { -1, 1 } - }; - const GLfloat texcoords[4][2] = { - { 0, 1 }, - { 1, 1 }, - { 1, 0 }, - { 0, 0 } - }; - const GLfloat faces[6][4] = { - { 0, 0, 1, 0 }, - { 90, 0, 1, 0 }, - { 180, 0, 1, 0 }, - { 270, 0, 1, 0 }, - { 90, 1, 0, 0 }, - { -90, 1, 0, 0 } - }; - GLint i; - - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - glVertexPointer(2, GL_FLOAT, 0, verts); - glTexCoordPointer(2, GL_FLOAT, 0, texcoords); - - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - - for (i = 0; i < 6; i++) { - glPushMatrix(); - glRotatef(faces[i][0], faces[i][1], faces[i][2], faces[i][3]); - glTranslatef(0, 0, 1.0); - glDrawArrays(GL_TRIANGLE_FAN, 0, 4); - glPopMatrix(); - } - - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); -} - -static void -gl_reshape(int width, int height) -{ - GLfloat ar = (GLfloat) width / (GLfloat) height; - - glViewport(0, 0, width, height); - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glFrustumf(-ar, ar, -1, 1, 5.0, 60.0); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glTranslatef(0.0, 0.0, -10.0); -} - -static void -app_redraw(struct app_data *data) -{ - /* pixmap has changed */ - if (data->reshape || data->paint.active) { - eglWaitNative(EGL_CORE_NATIVE_ENGINE); - - if (data->reshape) { - data->glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, - (GLeglImageOES) data->img); - } - } - - XCopyArea(data->xdpy, data->pix, data->canvas, data->fg, - 0, 0, data->width, data->height, 0, 0); - - glPushMatrix(); - glRotatef(data->animate.view_rotx, 1, 0, 0); - glRotatef(data->animate.view_roty, 0, 1, 0); - glRotatef(data->animate.view_rotz, 0, 0, 1); - gl_redraw(); - glPopMatrix(); - - eglSwapBuffers(data->dpy, data->surf); -} - -static void -app_reshape(struct app_data *data) -{ - const EGLint img_attribs[] = { - EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, - EGL_NONE - }; - - XResizeWindow(data->xdpy, data->cube, data->width, data->height); - XMoveWindow(data->xdpy, data->cube, data->width, 0); - - if (data->img) - data->eglDestroyImageKHR(data->dpy, data->img); - if (data->pix) - XFreePixmap(data->xdpy, data->pix); - - data->pix = XCreatePixmap(data->xdpy, data->canvas, data->width, data->height, data->depth); - XFillRectangle(data->xdpy, data->pix, data->bg, 0, 0, data->width, data->height); - - data->img = data->eglCreateImageKHR(data->dpy, EGL_NO_CONTEXT, - EGL_NATIVE_PIXMAP_KHR, (EGLClientBuffer) data->pix, img_attribs); - - gl_reshape(data->width, data->height); -} - -static void -app_toggle_animate(struct app_data *data) -{ - data->animate.active = !data->animate.active; - - if (data->animate.active) { - struct timeval tv; - - gettimeofday(&tv, NULL); - data->animate.next_frame = tv.tv_sec * 1000 + tv.tv_usec / 1000; - } -} - -static void -app_next_event(struct app_data *data) -{ - XEvent event; - - data->reshape = False; - data->redraw = False; - data->paint.active = False; - - if (data->animate.active) { - struct timeval tv; - unsigned long now; - - gettimeofday(&tv, NULL); - now = tv.tv_sec * 1000 + tv.tv_usec / 1000; - - /* wait for next frame */ - if (!XPending(data->xdpy) && now < data->animate.next_frame) { - usleep((data->animate.next_frame - now) * 1000); - gettimeofday(&tv, NULL); - now = tv.tv_sec * 1000 + tv.tv_usec / 1000; - } - - while (now >= data->animate.next_frame) { - data->animate.view_rotx += 1.0; - data->animate.view_roty += 2.0; - data->animate.view_rotz += 1.5; - - /* 30fps */ - data->animate.next_frame += 1000 / 30; - } - - /* check again in case there were events when sleeping */ - if (!XPending(data->xdpy)) { - data->redraw = True; - return; - } - } - - XNextEvent(data->xdpy, &event); - - switch (event.type) { - case ConfigureNotify: - data->width = event.xconfigure.width / 2; - data->height = event.xconfigure.height; - data->reshape = True; - break; - case Expose: - data->redraw = True; - break; - case KeyPress: - { - int code; - - code = XLookupKeysym(&event.xkey, 0); - switch (code) { - case XK_a: - app_toggle_animate(data); - break; - case XK_Escape: - data->loop = False; - break; - default: - break; - } - } - break; - case ButtonPress: - data->paint.x1 = data->paint.x2 = event.xbutton.x; - data->paint.y1 = data->paint.y2 = event.xbutton.y; - break; - case ButtonRelease: - data->paint.active = False; - break; - case MotionNotify: - data->paint.x1 = data->paint.x2; - data->paint.y1 = data->paint.y2; - data->paint.x2 = event.xmotion.x; - data->paint.y2 = event.xmotion.y; - data->paint.active = True; - break; - default: - break; - } - - if (data->paint.active || data->reshape) - data->redraw = True; -} - -static void -app_init_gl(struct app_data *data) -{ - glClearColor(0.1, 0.1, 0.3, 0.0); - glColor4f(1.0, 1.0, 1.0, 1.0); - - glGenTextures(1, &data->texture); - - glBindTexture(GL_TEXTURE_2D, data->texture); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - - glEnable(GL_TEXTURE_2D); - glEnable(GL_DEPTH_TEST); -} - -static Bool -app_init_exts(struct app_data *data) -{ - const char *exts; - - exts = eglQueryString(data->dpy, EGL_EXTENSIONS); - data->eglCreateImageKHR = - (PFNEGLCREATEIMAGEKHRPROC) eglGetProcAddress("eglCreateImageKHR"); - data->eglDestroyImageKHR = - (PFNEGLDESTROYIMAGEKHRPROC) eglGetProcAddress("eglDestroyImageKHR"); - if (!exts || !strstr(exts, "EGL_KHR_image_pixmap") || - !data->eglCreateImageKHR || !data->eglDestroyImageKHR) { - printf("EGL does not support EGL_KHR_image_pixmap\n"); - return False; - } - - exts = (const char *) glGetString(GL_EXTENSIONS); - data->glEGLImageTargetTexture2DOES = (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC) - eglGetProcAddress("glEGLImageTargetTexture2DOES"); - if (!exts || !strstr(exts, "GL_OES_EGL_image") || - !data->glEGLImageTargetTexture2DOES) { - printf("OpenGL ES does not support GL_OES_EGL_image\n"); - return False; - } - - return True; -} - -static void -app_run(struct app_data *data) -{ - Window root; - int x, y; - unsigned int border; - - if (!eglMakeCurrent(data->dpy, data->surf, data->surf, data->ctx)) - return; - - if (!app_init_exts(data)) - return; - - printf("Draw something on the left with the mouse!\n"); - - app_init_gl(data); - - if (!XGetGeometry(data->xdpy, data->canvas, &root, &x, &y, - &data->width, &data->height, &border, &data->depth)) - return; - data->width /= 2; - - app_reshape(data); - - XMapWindow(data->xdpy, data->canvas); - XMapWindow(data->xdpy, data->cube); - - app_toggle_animate(data); - data->loop = True; - - while (data->loop) { - app_next_event(data); - - if (data->reshape) - app_reshape(data); - if (data->paint.active) { - XDrawLine(data->xdpy, data->pix, data->fg, - data->paint.x1, data->paint.y1, - data->paint.x2, data->paint.y2); - } - - if (data->redraw) - app_redraw(data); - } - - eglMakeCurrent(data->dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); -} - -static Bool -make_x_window(struct app_data *data, const char *name, - int x, int y, int width, int height) -{ - static const EGLint attribs[] = { - EGL_RED_SIZE, 1, - EGL_GREEN_SIZE, 1, - EGL_BLUE_SIZE, 1, - EGL_DEPTH_SIZE, 1, - EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT, - EGL_NONE - }; - static const EGLint ctx_attribs[] = { - EGL_CONTEXT_CLIENT_VERSION, 1, - EGL_NONE - }; - int scrnum; - XSetWindowAttributes attr; - unsigned long mask; - Window root; - Window win; - XVisualInfo *visInfo, visTemplate; - int num_visuals; - EGLConfig config; - EGLint num_configs; - EGLint vid; - - scrnum = DefaultScreen( data->xdpy ); - root = RootWindow( data->xdpy, scrnum ); - - if (!eglChooseConfig( data->dpy, attribs, &config, 1, &num_configs)) { - printf("Error: couldn't get an EGL visual config\n"); - exit(1); - } - - assert(config); - assert(num_configs > 0); - - if (!eglGetConfigAttrib(data->dpy, config, EGL_NATIVE_VISUAL_ID, &vid)) { - printf("Error: eglGetConfigAttrib() failed\n"); - exit(1); - } - - /* The X window visual must match the EGL config */ - visTemplate.visualid = vid; - visInfo = XGetVisualInfo(data->xdpy, VisualIDMask, &visTemplate, &num_visuals); - if (!visInfo) { - printf("Error: couldn't get X visual\n"); - exit(1); - } - - /* window attributes */ - attr.background_pixel = 0; - attr.border_pixel = 0; - attr.colormap = XCreateColormap( data->xdpy, root, visInfo->visual, AllocNone); - attr.event_mask = StructureNotifyMask | ExposureMask | - KeyPressMask | ButtonPressMask | ButtonMotionMask; - mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; - - win = XCreateWindow( data->xdpy, root, 0, 0, width * 2, height, - 0, visInfo->depth, InputOutput, - visInfo->visual, mask, &attr ); - - /* set hints and properties */ - { - XSizeHints sizehints; - sizehints.x = x; - sizehints.y = y; - sizehints.width = width; - sizehints.height = height; - sizehints.flags = USSize | USPosition; - XSetNormalHints(data->xdpy, win, &sizehints); - XSetStandardProperties(data->xdpy, win, name, name, - None, (char **)NULL, 0, &sizehints); - } - - data->canvas = win; - - attr.event_mask = 0x0; - win = XCreateWindow( data->xdpy, win, width, 0, width, height, - 0, visInfo->depth, InputOutput, - visInfo->visual, mask, &attr ); - data->cube = win; - - eglBindAPI(EGL_OPENGL_ES_API); - - data->ctx = eglCreateContext(data->dpy, config, EGL_NO_CONTEXT, ctx_attribs ); - if (!data->ctx) { - printf("Error: eglCreateContext failed\n"); - exit(1); - } - - data->surf = eglCreateWindowSurface(data->dpy, config, data->cube, NULL); - if (!data->surf) { - printf("Error: eglCreateWindowSurface failed\n"); - exit(1); - } - - XFree(visInfo); - - return (data->canvas && data->cube && data->ctx && data->surf); -} - -static void -app_fini(struct app_data *data) -{ - if (data->img) - data->eglDestroyImageKHR(data->dpy, data->img); - if (data->pix) - XFreePixmap(data->xdpy, data->pix); - - if (data->fg) - XFreeGC(data->xdpy, data->fg); - if (data->bg) - XFreeGC(data->xdpy, data->bg); - - if (data->surf) - eglDestroySurface(data->dpy, data->surf); - if (data->ctx) - eglDestroyContext(data->dpy, data->ctx); - - if (data->cube) - XDestroyWindow(data->xdpy, data->cube); - if (data->canvas) - XDestroyWindow(data->xdpy, data->canvas); - - if (data->dpy) - eglTerminate(data->dpy); - if (data->xdpy) - XCloseDisplay(data->xdpy); -} - -static Bool -app_init(struct app_data *data, int argc, char **argv) -{ - XGCValues gc_vals; - - memset(data, 0, sizeof(*data)); - - data->xdpy = XOpenDisplay(NULL); - if (!data->xdpy) - goto fail; - - data->dpy = eglGetDisplay(data->xdpy); - if (!data->dpy || !eglInitialize(data->dpy, NULL, NULL)) - goto fail; - - if (!make_x_window(data, "EGLImage TFP", 0, 0, 300, 300)) - goto fail; - - gc_vals.function = GXcopy; - gc_vals.foreground = WhitePixel(data->xdpy, DefaultScreen(data->xdpy)); - gc_vals.line_width = 3; - gc_vals.line_style = LineSolid; - gc_vals.fill_style = FillSolid; - - data->fg = XCreateGC(data->xdpy, data->canvas, - GCFunction | GCForeground | GCLineWidth | GCLineStyle | GCFillStyle, - &gc_vals); - gc_vals.foreground = BlackPixel(data->xdpy, DefaultScreen(data->xdpy)); - data->bg = XCreateGC(data->xdpy, data->canvas, - GCFunction | GCForeground | GCLineWidth | GCLineStyle | GCFillStyle, - &gc_vals); - if (!data->fg || !data->bg) - goto fail; - - return True; - -fail: - app_fini(data); - return False; -} - -int -main(int argc, char **argv) -{ - struct app_data data; - - if (app_init(&data, argc, argv)) { - app_run(&data); - app_fini(&data); - } - - return 0; -} diff --git a/progs/egl/opengles1/torus.c b/progs/egl/opengles1/torus.c deleted file mode 100644 index 18ddff3fe4..0000000000 --- a/progs/egl/opengles1/torus.c +++ /dev/null @@ -1,452 +0,0 @@ -/* - * Copyright (C) 2008 Tunsgten Graphics,Inc. All Rights Reserved. - */ - -/* - * Draw a lit, textured torus with X/EGL and OpenGL ES 1.x - * Brian Paul - * July 2008 - */ - - -#include <assert.h> -#include <math.h> -#include <stdlib.h> -#include <stdio.h> -#include <GLES/gl.h> - -#include "eglut.h" - -#ifndef M_PI -#define M_PI 3.14159265 -#endif - -static const struct { - GLenum internalFormat; - const char *name; - GLuint num_entries; - GLuint size; -} cpal_formats[] = { - { GL_PALETTE4_RGB8_OES, "GL_PALETTE4_RGB8_OES", 16, 3 }, - { GL_PALETTE4_RGBA8_OES, "GL_PALETTE4_RGBA8_OES", 16, 4 }, - { GL_PALETTE4_R5_G6_B5_OES, "GL_PALETTE4_R5_G6_B5_OES", 16, 2 }, - { GL_PALETTE4_RGBA4_OES, "GL_PALETTE4_RGBA4_OES", 16, 2 }, - { GL_PALETTE4_RGB5_A1_OES, "GL_PALETTE4_RGB5_A1_OES", 16, 2 }, - { GL_PALETTE8_RGB8_OES, "GL_PALETTE8_RGB8_OES", 256, 3 }, - { GL_PALETTE8_RGBA8_OES, "GL_PALETTE8_RGBA8_OES", 256, 4 }, - { GL_PALETTE8_R5_G6_B5_OES, "GL_PALETTE8_R5_G6_B5_OES", 256, 2 }, - { GL_PALETTE8_RGBA4_OES, "GL_PALETTE8_RGBA4_OES", 256, 2 }, - { GL_PALETTE8_RGB5_A1_OES, "GL_PALETTE8_RGB5_A1_OES", 256, 2 } -}; -#define NUM_CPAL_FORMATS (sizeof(cpal_formats) / sizeof(cpal_formats[0])) - -static GLfloat view_rotx = 0.0, view_roty = 0.0, view_rotz = 0.0; -static GLint tex_format = NUM_CPAL_FORMATS; -static GLboolean animate = GL_TRUE; -static int win; - - -static void -Normal(GLfloat *n, GLfloat nx, GLfloat ny, GLfloat nz) -{ - n[0] = nx; - n[1] = ny; - n[2] = nz; -} - -static void -Vertex(GLfloat *v, GLfloat vx, GLfloat vy, GLfloat vz) -{ - v[0] = vx; - v[1] = vy; - v[2] = vz; -} - -static void -Texcoord(GLfloat *v, GLfloat s, GLfloat t) -{ - v[0] = s; - v[1] = t; -} - - -/* Borrowed from glut, adapted */ -static void -draw_torus(GLfloat r, GLfloat R, GLint nsides, GLint rings) -{ - int i, j; - GLfloat theta, phi, theta1; - GLfloat cosTheta, sinTheta; - GLfloat cosTheta1, sinTheta1; - GLfloat ringDelta, sideDelta; - GLfloat varray[100][3], narray[100][3], tarray[100][2]; - int vcount; - - glVertexPointer(3, GL_FLOAT, 0, varray); - glNormalPointer(GL_FLOAT, 0, narray); - glTexCoordPointer(2, GL_FLOAT, 0, tarray); - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_NORMAL_ARRAY); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - - ringDelta = 2.0 * M_PI / rings; - sideDelta = 2.0 * M_PI / nsides; - - theta = 0.0; - cosTheta = 1.0; - sinTheta = 0.0; - for (i = rings - 1; i >= 0; i--) { - theta1 = theta + ringDelta; - cosTheta1 = cos(theta1); - sinTheta1 = sin(theta1); - - vcount = 0; /* glBegin(GL_QUAD_STRIP); */ - - phi = 0.0; - for (j = nsides; j >= 0; j--) { - GLfloat s0, s1, t; - GLfloat cosPhi, sinPhi, dist; - - phi += sideDelta; - cosPhi = cos(phi); - sinPhi = sin(phi); - dist = R + r * cosPhi; - - s0 = 20.0 * theta / (2.0 * M_PI); - s1 = 20.0 * theta1 / (2.0 * M_PI); - t = 8.0 * phi / (2.0 * M_PI); - - Normal(narray[vcount], cosTheta1 * cosPhi, -sinTheta1 * cosPhi, sinPhi); - Texcoord(tarray[vcount], s1, t); - Vertex(varray[vcount], cosTheta1 * dist, -sinTheta1 * dist, r * sinPhi); - vcount++; - - Normal(narray[vcount], cosTheta * cosPhi, -sinTheta * cosPhi, sinPhi); - Texcoord(tarray[vcount], s0, t); - Vertex(varray[vcount], cosTheta * dist, -sinTheta * dist, r * sinPhi); - vcount++; - } - - /*glEnd();*/ - assert(vcount <= 100); - glDrawArrays(GL_TRIANGLE_STRIP, 0, vcount); - - theta = theta1; - cosTheta = cosTheta1; - sinTheta = sinTheta1; - } - - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_NORMAL_ARRAY); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); -} - - -static void -draw(void) -{ - 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); - glScalef(0.5, 0.5, 0.5); - - draw_torus(1.0, 3.0, 30, 60); - - glPopMatrix(); -} - - -/* new window size or exposure */ -static void -reshape(int width, int height) -{ - GLfloat ar = (GLfloat) width / (GLfloat) height; - - glViewport(0, 0, (GLint) width, (GLint) height); - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - -#ifdef GL_VERSION_ES_CM_1_0 - glFrustumf(-ar, ar, -1, 1, 5.0, 60.0); -#else - glFrustum(-ar, ar, -1, 1, 5.0, 60.0); -#endif - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glTranslatef(0.0, 0.0, -15.0); -} - - -static GLint -make_cpal_texture(GLint idx) -{ -#define SZ 64 - GLenum internalFormat = GL_PALETTE4_RGB8_OES + idx; - GLenum Filter = GL_LINEAR; - GLubyte palette[256 * 4 + SZ * SZ]; - GLubyte *indices; - GLsizei image_size; - GLuint i, j; - GLuint packed_indices = 0; - - assert(cpal_formats[idx].internalFormat == internalFormat); - - /* init palette */ - switch (internalFormat) { - case GL_PALETTE4_RGB8_OES: - case GL_PALETTE8_RGB8_OES: - /* first entry */ - palette[0] = 255; - palette[1] = 255; - palette[2] = 255; - /* second entry */ - palette[3] = 127; - palette[4] = 127; - palette[5] = 127; - break; - case GL_PALETTE4_RGBA8_OES: - case GL_PALETTE8_RGBA8_OES: - /* first entry */ - palette[0] = 255; - palette[1] = 255; - palette[2] = 255; - palette[3] = 255; - /* second entry */ - palette[4] = 127; - palette[5] = 127; - palette[6] = 127; - palette[7] = 255; - break; - case GL_PALETTE4_R5_G6_B5_OES: - case GL_PALETTE8_R5_G6_B5_OES: - { - GLushort *pal = (GLushort *) palette; - /* first entry */ - pal[0] = (31 << 11 | 63 << 5 | 31); - /* second entry */ - pal[1] = (15 << 11 | 31 << 5 | 15); - } - break; - case GL_PALETTE4_RGBA4_OES: - case GL_PALETTE8_RGBA4_OES: - { - GLushort *pal = (GLushort *) palette; - /* first entry */ - pal[0] = (15 << 12 | 15 << 8 | 15 << 4 | 15); - /* second entry */ - pal[1] = (7 << 12 | 7 << 8 | 7 << 4 | 15); - } - break; - case GL_PALETTE4_RGB5_A1_OES: - case GL_PALETTE8_RGB5_A1_OES: - { - GLushort *pal = (GLushort *) palette; - /* first entry */ - pal[0] = (31 << 11 | 31 << 6 | 31 << 1 | 1); - /* second entry */ - pal[1] = (15 << 11 | 15 << 6 | 15 << 1 | 1); - } - break; - } - - image_size = cpal_formats[idx].size * cpal_formats[idx].num_entries; - indices = palette + image_size; - for (i = 0; i < SZ; i++) { - for (j = 0; j < SZ; j++) { - GLfloat d; - GLint index; - d = (i - SZ/2) * (i - SZ/2) + (j - SZ/2) * (j - SZ/2); - d = sqrt(d); - index = (d < SZ / 3) ? 0 : 1; - - if (cpal_formats[idx].num_entries == 16) { - /* 4-bit indices packed in GLubyte */ - packed_indices |= index << (4 * (1 - (j % 2))); - if (j % 2) { - *(indices + (i * SZ + j - 1) / 2) = packed_indices & 0xff; - packed_indices = 0; - image_size += 1; - } - } - else { - /* 8-bit indices */ - *(indices + i * SZ + j) = index; - image_size += 1; - } - } - } - - glActiveTexture(GL_TEXTURE0); /* unit 0 */ - glBindTexture(GL_TEXTURE_2D, 42); - glCompressedTexImage2D(GL_TEXTURE_2D, 0, internalFormat, SZ, SZ, 0, - image_size, palette); - - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, Filter); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, Filter); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); -#undef SZ - - return image_size; -} - - -static GLint -make_texture(void) -{ -#define SZ 64 - GLenum Filter = GL_LINEAR; - GLubyte image[SZ][SZ][4]; - GLuint i, j; - - for (i = 0; i < SZ; i++) { - for (j = 0; j < SZ; j++) { - GLfloat d = (i - SZ/2) * (i - SZ/2) + (j - SZ/2) * (j - SZ/2); - d = sqrt(d); - if (d < SZ/3) { - image[i][j][0] = 255; - image[i][j][1] = 255; - image[i][j][2] = 255; - image[i][j][3] = 255; - } - else { - image[i][j][0] = 127; - image[i][j][1] = 127; - image[i][j][2] = 127; - image[i][j][3] = 255; - } - } - } - - glActiveTexture(GL_TEXTURE0); /* unit 0 */ - glBindTexture(GL_TEXTURE_2D, 42); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, SZ, SZ, 0, - GL_RGBA, GL_UNSIGNED_BYTE, image); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, Filter); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, Filter); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); -#undef SZ - - return sizeof(image); -} - - - -static void -init(void) -{ - static const GLfloat red[4] = {1, 0, 0, 0}; - static const GLfloat white[4] = {1.0, 1.0, 1.0, 1.0}; - static const GLfloat diffuse[4] = {0.7, 0.7, 0.7, 1.0}; - static const GLfloat specular[4] = {0.001, 0.001, 0.001, 1.0}; - static const GLfloat pos[4] = {20, 20, 50, 1}; - - glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, red); - glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, white); - glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 9.0); - - glEnable(GL_LIGHTING); - glEnable(GL_LIGHT0); - glLightfv(GL_LIGHT0, GL_POSITION, pos); - glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); - glLightfv(GL_LIGHT0, GL_SPECULAR, specular); - - glClearColor(0.4, 0.4, 0.4, 0.0); - glEnable(GL_DEPTH_TEST); - - make_texture(); - glEnable(GL_TEXTURE_2D); -} - - -static void -idle(void) -{ - if (animate) { - view_rotx += 1.0; - view_roty += 2.0; - eglutPostRedisplay(); - } -} - -static void -key(unsigned char key) -{ - switch (key) { - case ' ': - animate = !animate; - break; - case 't': - { - GLint size; - tex_format = (tex_format + 1) % (NUM_CPAL_FORMATS + 1); - if (tex_format < NUM_CPAL_FORMATS) { - size = make_cpal_texture(tex_format); - printf("Using %s (%d bytes)\n", - cpal_formats[tex_format].name, size); - } - else { - size = make_texture(); - printf("Using uncompressed texture (%d bytes)\n", size); - } - - eglutPostRedisplay(); - } - break; - case 27: - eglutDestroyWindow(win); - exit(0); - break; - default: - break; - } -} - -static void -special_key(int key) -{ - switch (key) { - case EGLUT_KEY_LEFT: - view_roty += 5.0; - break; - case EGLUT_KEY_RIGHT: - view_roty -= 5.0; - break; - case EGLUT_KEY_UP: - view_rotx += 5.0; - break; - case EGLUT_KEY_DOWN: - view_rotx -= 5.0; - break; - default: - break; - } -} - -int -main(int argc, char *argv[]) -{ - eglutInitWindowSize(300, 300); - eglutInitAPIMask(EGLUT_OPENGL_ES1_BIT); - eglutInit(argc, argv); - - win = eglutCreateWindow("torus"); - - eglutIdleFunc(idle); - eglutReshapeFunc(reshape); - eglutDisplayFunc(draw); - eglutKeyboardFunc(key); - eglutSpecialFunc(special_key); - - init(); - - eglutMainLoop(); - - return 0; -} diff --git a/progs/egl/opengles1/tri.c b/progs/egl/opengles1/tri.c deleted file mode 100644 index 01ad9bd37e..0000000000 --- a/progs/egl/opengles1/tri.c +++ /dev/null @@ -1,211 +0,0 @@ -/* - * Copyright (C) 2008 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -/* - * Draw a triangle with X/EGL and OpenGL ES 1.x - * Brian Paul - * 5 June 2008 - */ - -#define USE_FIXED_POINT 0 - - -#include <assert.h> -#include <math.h> -#include <stdio.h> -#include <GLES/gl.h> /* use OpenGL ES 1.x */ -#include <GLES/glext.h> -#include <EGL/egl.h> - -#include "eglut.h" - - -#define FLOAT_TO_FIXED(X) ((X) * 65535.0) - - - -static GLfloat view_rotx = 0.0, view_roty = 0.0, view_rotz = 0.0; - - -static void -draw(void) -{ -#if USE_FIXED_POINT - static const GLfixed verts[3][2] = { - { -65536, -65536 }, - { 65536, -65536 }, - { 0, 65536 } - }; - static const GLfixed colors[3][4] = { - { 65536, 0, 0, 65536 }, - { 0, 65536, 0 , 65536}, - { 0, 0, 65536 , 65536} - }; -#else - static const GLfloat verts[3][2] = { - { -1, -1 }, - { 1, -1 }, - { 0, 1 } - }; - static const GLfloat colors[3][4] = { - { 1, 0, 0, 1 }, - { 0, 1, 0, 1 }, - { 0, 0, 1, 1 } - }; -#endif - - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - glPushMatrix(); - glRotatef(view_rotx, 1, 0, 0); - glRotatef(view_roty, 0, 1, 0); - glRotatef(view_rotz, 0, 0, 1); - - { -#if USE_FIXED_POINT - glVertexPointer(2, GL_FIXED, 0, verts); - glColorPointer(4, GL_FIXED, 0, colors); -#else - glVertexPointer(2, GL_FLOAT, 0, verts); - glColorPointer(4, GL_FLOAT, 0, colors); -#endif - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_COLOR_ARRAY); - - /* draw triangle */ - glDrawArrays(GL_TRIANGLES, 0, 3); - - /* draw some points */ - glPointSizex(FLOAT_TO_FIXED(15.5)); - glDrawArrays(GL_POINTS, 0, 3); - - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - } - - if (0) { - /* test code */ - GLfixed size; - glGetFixedv(GL_POINT_SIZE, &size); - printf("GL_POINT_SIZE = 0x%x %f\n", size, size / 65536.0); - } - - glPopMatrix(); -} - - -/* new window size or exposure */ -static void -reshape(int width, int height) -{ - GLfloat ar = (GLfloat) width / (GLfloat) height; - - glViewport(0, 0, (GLint) width, (GLint) height); - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); -#ifdef GL_VERSION_ES_CM_1_0 - glFrustumf(-ar, ar, -1, 1, 5.0, 60.0); -#else - glFrustum(-ar, ar, -1, 1, 5.0, 60.0); -#endif - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glTranslatef(0.0, 0.0, -10.0); -} - - -static void -test_query_matrix(void) -{ - PFNGLQUERYMATRIXXOESPROC procQueryMatrixx; - typedef void (*voidproc)(); - GLfixed mantissa[16]; - GLint exponent[16]; - GLbitfield rv; - int i; - - procQueryMatrixx = (PFNGLQUERYMATRIXXOESPROC) eglGetProcAddress("glQueryMatrixxOES"); - assert(procQueryMatrixx); - /* Actually try out this one */ - rv = (*procQueryMatrixx)(mantissa, exponent); - for (i = 0; i < 16; i++) { - if (rv & (1<<i)) { - printf("matrix[%d] invalid\n", i); - } - else { - printf("matrix[%d] = %f * 2^(%d)\n", i, mantissa[i]/65536.0, exponent[i]); - } - } - assert(!eglGetProcAddress("glFoo")); -} - - -static void -init(void) -{ - glClearColor(0.4, 0.4, 0.4, 0.0); - - if (0) - test_query_matrix(); -} - -static void -special_key(int special) -{ - switch (special) { - case EGLUT_KEY_LEFT: - view_roty += 5.0; - break; - case EGLUT_KEY_RIGHT: - view_roty -= 5.0; - break; - case EGLUT_KEY_UP: - view_rotx += 5.0; - break; - case EGLUT_KEY_DOWN: - view_rotx -= 5.0; - break; - default: - break; - } -} - -int -main(int argc, char *argv[]) -{ - eglutInitWindowSize(300, 300); - eglutInitAPIMask(EGLUT_OPENGL_ES1_BIT); - eglutInit(argc, argv); - - eglutCreateWindow("tri"); - - eglutReshapeFunc(reshape); - eglutDisplayFunc(draw); - eglutSpecialFunc(special_key); - - init(); - - eglutMainLoop(); - - return 0; -} diff --git a/progs/egl/opengles1/two_win.c b/progs/egl/opengles1/two_win.c deleted file mode 100644 index 4785e5304d..0000000000 --- a/progs/egl/opengles1/two_win.c +++ /dev/null @@ -1,433 +0,0 @@ -/* - * Copyright (C) 2008 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -/* - * Test drawing to two windows. - * Brian Paul - * August 2008 - */ - - -#include <assert.h> -#include <math.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <X11/Xlib.h> -#include <X11/Xutil.h> -#include <X11/keysym.h> -#include <GLES/gl.h> -#include <GLES/glext.h> -#include <EGL/egl.h> - - -static int WinWidth[2] = {150, 300}, WinHeight[2] = {150, 300}; - - -static GLfloat view_rotx = 0.0, view_roty = 0.0, view_rotz = 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(); -#ifdef GL_VERSION_ES_CM_1_0 - glFrustumf(-ar, ar, -1, 1, 5.0, 60.0); -#else - glFrustum(-ar, ar, -1, 1, 5.0, 60.0); -#endif - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glTranslatef(0.0, 0.0, -10.0); -} - - -static void -draw(int win) -{ - static const GLfloat verts[3][2] = { - { -1, -1 }, - { 1, -1 }, - { 0, 1 } - }; - static const GLfloat colors[3][4] = { - { 1, 0, 0, 1 }, - { 0, 1, 0, 1 }, - { 0, 0, 1, 1 } - }; - - assert(win == 0 || win == 1); - - reshape(WinWidth[win], WinHeight[win]); - - 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); - - /* draw triangle */ - { - glVertexPointer(2, GL_FLOAT, 0, verts); - glColorPointer(4, 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(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, x, y, width, height, - 0, visInfo->depth, InputOutput, - visInfo->visual, mask, &attr ); - - /* set hints and properties */ - { - XSizeHints sizehints; - sizehints.x = x; - sizehints.y = y; - sizehints.width = width; - sizehints.height = height; - sizehints.flags = USSize | USPosition; - XSetNormalHints(x_dpy, win, &sizehints); - XSetStandardProperties(x_dpy, win, name, name, - None, (char **)NULL, 0, &sizehints); - } - -#if USE_FULL_GL - eglBindAPI(EGL_OPENGL_API); -#else - eglBindAPI(EGL_OPENGL_ES_API); -#endif - - if (ctxRet) { - ctx = eglCreateContext(egl_dpy, config, EGL_NO_CONTEXT, NULL ); - if (!ctx) { - printf("Error: eglCreateContext failed\n"); - exit(1); - } - *ctxRet = ctx; - } - - *surfRet = eglCreateWindowSurface(egl_dpy, config, win, NULL); - - if (!*surfRet) { - printf("Error: eglCreateWindowSurface failed\n"); - exit(1); - } - - XFree(visInfo); - - *winRet = win; -} - - -static void -event_loop(Display *dpy, Window win1, Window win2, - EGLDisplay egl_dpy, EGLSurface egl_surf1, EGLSurface egl_surf2, - EGLContext egl_ctx) -{ - while (1) { - int redraw = 0; - int win; - XEvent event; - - XNextEvent(dpy, &event); - - switch (event.type) { - case Expose: - redraw = 1; - break; - case ConfigureNotify: - if (event.xconfigure.window == win1) - win = 0; - else - win = 1; - WinWidth[win] = event.xconfigure.width; - WinHeight[win] = 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) { - /* win 1 */ - if (!eglMakeCurrent(egl_dpy, egl_surf1, egl_surf1, egl_ctx)) { - printf("Error: eglMakeCurrent(1) failed\n"); - return; - } - draw(0); - eglSwapBuffers(egl_dpy, egl_surf1); - - /* win 2 */ - if (!eglMakeCurrent(egl_dpy, egl_surf2, egl_surf2, egl_ctx)) { - printf("Error: eglMakeCurrent(2) failed\n"); - return; - } - draw(1); - eglSwapBuffers(egl_dpy, egl_surf2); - } - } -} - - -static void -usage(void) -{ - printf("Usage:\n"); - printf(" -display <displayname> set the display to run on\n"); - printf(" -info display OpenGL renderer info\n"); -} - - -int -main(int argc, char *argv[]) -{ - Display *x_dpy; - Window win1, win2; - EGLSurface egl_surf1, egl_surf2; - EGLContext egl_ctx; - EGLDisplay egl_dpy; - char *dpyName = NULL; - GLboolean printInfo = GL_FALSE; - EGLint egl_major, egl_minor; - int i; - const char *s; - - static struct { - char *name; - GLenum value; - enum {GetString, GetInteger} type; - } info_items[] = { - {"GL_RENDERER", GL_RENDERER, GetString}, - {"GL_VERSION", GL_VERSION, GetString}, - {"GL_VENDOR", GL_VENDOR, GetString}, - {"GL_EXTENSIONS", GL_EXTENSIONS, GetString}, - {"GL_MAX_PALETTE_MATRICES_OES", GL_MAX_PALETTE_MATRICES_OES, GetInteger}, - {"GL_MAX_VERTEX_UNITS_OES", GL_MAX_VERTEX_UNITS_OES, GetInteger}, - }; - - for (i = 1; i < argc; i++) { - if (strcmp(argv[i], "-display") == 0) { - dpyName = argv[i+1]; - i++; - } - else if (strcmp(argv[i], "-info") == 0) { - printInfo = GL_TRUE; - } - else { - usage(); - return -1; - } - } - - x_dpy = XOpenDisplay(dpyName); - if (!x_dpy) { - printf("Error: couldn't open display %s\n", - dpyName ? dpyName : getenv("DISPLAY")); - return -1; - } - - egl_dpy = eglGetDisplay(x_dpy); - if (!egl_dpy) { - printf("Error: eglGetDisplay() failed\n"); - return -1; - } - - if (!eglInitialize(egl_dpy, &egl_major, &egl_minor)) { - printf("Error: eglInitialize() failed\n"); - return -1; - } - - s = eglQueryString(egl_dpy, EGL_VERSION); - printf("EGL_VERSION = %s\n", s); - - s = eglQueryString(egl_dpy, EGL_VENDOR); - printf("EGL_VENDOR = %s\n", s); - - s = eglQueryString(egl_dpy, EGL_EXTENSIONS); - printf("EGL_EXTENSIONS = %s\n", s); - - s = eglQueryString(egl_dpy, EGL_CLIENT_APIS); - printf("EGL_CLIENT_APIS = %s\n", s); - - make_x_window(x_dpy, egl_dpy, - "xegl_two_win #1", 0, 0, WinWidth[0], WinHeight[0], - &win1, &egl_ctx, &egl_surf1); - - make_x_window(x_dpy, egl_dpy, - "xegl_two_win #2", WinWidth[0] + 50, 0, - WinWidth[1], WinHeight[1], - &win2, NULL, &egl_surf2); - - XMapWindow(x_dpy, win1); - - XMapWindow(x_dpy, win2); - - if (!eglMakeCurrent(egl_dpy, egl_surf1, egl_surf1, egl_ctx)) { - printf("Error: eglMakeCurrent() failed\n"); - return -1; - } - - if (printInfo) { - for (i = 0; i < sizeof(info_items)/sizeof(info_items[0]); i++) { - switch (info_items[i].type) { - case GetString: - printf("%s = %s\n", info_items[i].name, (char *)glGetString(info_items[i].value)); - break; - case GetInteger: { - GLint rv = -1; - glGetIntegerv(info_items[i].value, &rv); - printf("%s = %d\n", info_items[i].name, rv); - break; - } - } - } - }; - - init(); - - event_loop(x_dpy, win1, win2, egl_dpy, egl_surf1, egl_surf2, egl_ctx); - - eglDestroyContext(egl_dpy, egl_ctx); - eglDestroySurface(egl_dpy, egl_surf1); - eglDestroySurface(egl_dpy, egl_surf2); - eglTerminate(egl_dpy); - - XDestroyWindow(x_dpy, win1); - XDestroyWindow(x_dpy, win2); - XCloseDisplay(x_dpy); - - return 0; -} diff --git a/progs/egl/opengles2/.gitignore b/progs/egl/opengles2/.gitignore deleted file mode 100644 index 6158cc6e68..0000000000 --- a/progs/egl/opengles2/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -es2_info.c -es2_info -tri diff --git a/progs/egl/opengles2/Makefile b/progs/egl/opengles2/Makefile deleted file mode 100644 index bf14513d7f..0000000000 --- a/progs/egl/opengles2/Makefile +++ /dev/null @@ -1,56 +0,0 @@ -# progs/egl/opengles2/Makefile - -TOP = ../../.. -include $(TOP)/configs/current - - -INCLUDE_DIRS = \ - -I$(TOP)/include \ - -I$(TOP)/progs/egl/eglut \ - $(X11_CFLAGS) \ - - -HEADERS = $(TOP)/include/GLES/egl.h - - -ES2_LIB_DEPS = \ - $(TOP)/$(LIB_DIR)/$(EGL_LIB_NAME) \ - $(TOP)/$(LIB_DIR)/$(GLESv2_LIB_NAME) - - -ES2_LIBS = \ - -L$(TOP)/$(LIB_DIR) -l$(EGL_LIB) -l$(GLESv2_LIB) \ - $(LIBDRM_LIB) $(X11_LIBS) - -PROGRAMS = \ - es2_info \ - tri \ - es2gears - - -.c.o: - $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $< -o $@ - - - -default: $(PROGRAMS) - - - -es2_info.c: ../opengles1/es1_info.c - cp -f $^ $@ - -es2_info: es2_info.o $(ES2_LIB_DEPS) - $(CC) $(CFLAGS) es2_info.o $(ES2_LIBS) -o $@ - -tri: tri.o $(ES2_LIB_DEPS) - $(CC) $(CFLAGS) tri.o $(ES2_LIBS) -o $@ - -es2gears: es2gears.o $(ES2_LIB_DEPS) - $(CC) $(CFLAGS) es2gears.o ../eglut/libeglut-x11.a $(ES2_LIBS) -lm -o $@ - -clean: - rm -f *.o *~ - rm -f $(PROGRAMS) - rm -f es2_info.c - diff --git a/progs/egl/opengles2/es2gears.c b/progs/egl/opengles2/es2gears.c deleted file mode 100644 index 6bd6594320..0000000000 --- a/progs/egl/opengles2/es2gears.c +++ /dev/null @@ -1,425 +0,0 @@ -/* - * 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 GLES2. - * Kristian Høgsberg <krh@bitplanet.net> - * May 3, 2010 - */ - -/* - * Command line options: - * -info print GL implementation information - * - */ - - -#define GL_GLEXT_PROTOTYPES -#define EGL_EGLEXT_PROTOTYPES - -#include <math.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <sys/time.h> -#include <unistd.h> -#include <GLES2/gl2.h> -#include <EGL/egl.h> -#include <EGL/eglext.h> -#include "eglut.h" - -#ifndef M_PI -#define M_PI 3.14159265 -#endif - -struct gear { - GLfloat *vertices; - GLuint vbo; - int count; -}; - -static GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0; -static struct gear *gear1, *gear2, *gear3; -static GLfloat angle = 0.0; -static GLuint proj_location, light_location, color_location; -static GLfloat proj[16]; - -static GLfloat * -vert(GLfloat *p, GLfloat x, GLfloat y, GLfloat z, GLfloat *n) -{ - p[0] = x; - p[1] = y; - p[2] = z; - p[3] = n[0]; - p[4] = n[1]; - p[5] = n[2]; - - return p + 6; -} - -/* 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 struct gear * -gear(GLfloat inner_radius, GLfloat outer_radius, GLfloat width, - GLint teeth, GLfloat tooth_depth) -{ - GLint i; - GLfloat r0, r1, r2; - GLfloat da; - GLfloat *p, *v; - struct gear *gear; - double s[5], c[5]; - GLfloat verts[3 * 14], normal[3]; - const int tris_per_tooth = 20; - - gear = malloc(sizeof *gear); - if (gear == NULL) - return NULL; - - 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; - - gear->vertices = calloc(teeth * tris_per_tooth * 3 * 6, - sizeof *gear->vertices); - s[4] = 0; - c[4] = 1; - v = gear->vertices; - for (i = 0; i < teeth; i++) { - s[0] = s[4]; - c[0] = c[4]; - sincos(i * 2.0 * M_PI / teeth + da, &s[1], &c[1]); - sincos(i * 2.0 * M_PI / teeth + da * 2, &s[2], &c[2]); - sincos(i * 2.0 * M_PI / teeth + da * 3, &s[3], &c[3]); - sincos(i * 2.0 * M_PI / teeth + da * 4, &s[4], &c[4]); - - normal[0] = 0.0; - normal[1] = 0.0; - normal[2] = 1.0; - - v = vert(v, r2 * c[1], r2 * s[1], width * 0.5, normal); - - v = vert(v, r2 * c[1], r2 * s[1], width * 0.5, normal); - v = vert(v, r2 * c[2], r2 * s[2], width * 0.5, normal); - v = vert(v, r1 * c[0], r1 * s[0], width * 0.5, normal); - v = vert(v, r1 * c[3], r1 * s[3], width * 0.5, normal); - v = vert(v, r0 * c[0], r0 * s[0], width * 0.5, normal); - v = vert(v, r1 * c[4], r1 * s[4], width * 0.5, normal); - v = vert(v, r0 * c[4], r0 * s[4], width * 0.5, normal); - - v = vert(v, r0 * c[4], r0 * s[4], width * 0.5, normal); - v = vert(v, r0 * c[0], r0 * s[0], width * 0.5, normal); - v = vert(v, r0 * c[4], r0 * s[4], -width * 0.5, normal); - v = vert(v, r0 * c[0], r0 * s[0], -width * 0.5, normal); - - normal[0] = 0.0; - normal[1] = 0.0; - normal[2] = -1.0; - - v = vert(v, r0 * c[4], r0 * s[4], -width * 0.5, normal); - - v = vert(v, r0 * c[4], r0 * s[4], -width * 0.5, normal); - v = vert(v, r1 * c[4], r1 * s[4], -width * 0.5, normal); - v = vert(v, r0 * c[0], r0 * s[0], -width * 0.5, normal); - v = vert(v, r1 * c[3], r1 * s[3], -width * 0.5, normal); - v = vert(v, r1 * c[0], r1 * s[0], -width * 0.5, normal); - v = vert(v, r2 * c[2], r2 * s[2], -width * 0.5, normal); - v = vert(v, r2 * c[1], r2 * s[1], -width * 0.5, normal); - - v = vert(v, r1 * c[0], r1 * s[0], width * 0.5, normal); - - v = vert(v, r1 * c[0], r1 * s[0], width * 0.5, normal); - v = vert(v, r1 * c[0], r1 * s[0], -width * 0.5, normal); - v = vert(v, r2 * c[1], r2 * s[1], width * 0.5, normal); - v = vert(v, r2 * c[1], r2 * s[1], -width * 0.5, normal); - v = vert(v, r2 * c[2], r2 * s[2], width * 0.5, normal); - v = vert(v, r2 * c[2], r2 * s[2], -width * 0.5, normal); - v = vert(v, r1 * c[3], r1 * s[3], width * 0.5, normal); - v = vert(v, r1 * c[3], r1 * s[3], -width * 0.5, normal); - v = vert(v, r1 * c[4], r1 * s[4], width * 0.5, normal); - v = vert(v, r1 * c[4], r1 * s[4], -width * 0.5, normal); - - v = vert(v, r1 * c[4], r1 * s[4], -width * 0.5, normal); - } - - gear->count = (v - gear->vertices) / 6; - - glGenBuffers(1, &gear->vbo); - glBindBuffer(GL_ARRAY_BUFFER, gear->vbo); - glBufferData(GL_ARRAY_BUFFER, gear->count * 6 * 4, - gear->vertices, GL_STATIC_DRAW); - - return gear; -} - -static void -multiply(GLfloat *m, const GLfloat *n) -{ - GLfloat tmp[16]; - const GLfloat *row, *column; - div_t d; - int i, j; - - for (i = 0; i < 16; i++) { - tmp[i] = 0; - d = div(i, 4); - row = n + d.quot * 4; - column = m + d.rem; - for (j = 0; j < 4; j++) - tmp[i] += row[j] * column[j * 4]; - } - memcpy(m, &tmp, sizeof tmp); -} - -static void -rotate(GLfloat *m, GLfloat angle, GLfloat x, GLfloat y, GLfloat z) -{ - double s, c; - - sincos(angle, &s, &c); - GLfloat r[16] = { - x * x * (1 - c) + c, y * x * (1 - c) + z * s, x * z * (1 - c) - y * s, 0, - x * y * (1 - c) - z * s, y * y * (1 - c) + c, y * z * (1 - c) + x * s, 0, - x * z * (1 - c) + y * s, y * z * (1 - c) - x * s, z * z * (1 - c) + c, 0, - 0, 0, 0, 1 - }; - - multiply(m, r); -} - -static void -translate(GLfloat *m, GLfloat x, GLfloat y, GLfloat z) -{ - GLfloat t[16] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, x, y, z, 1 }; - - multiply(m, t); -} - -static const GLfloat light[3] = { 1.0, 1.0, -1.0 }; - -static void -draw_gear(struct gear *gear, GLfloat *m, - GLfloat x, GLfloat y, GLfloat angle, const GLfloat *color) -{ - GLfloat tmp[16]; - - memcpy(tmp, m, sizeof tmp); - translate(tmp, x, y, 0); - rotate(tmp, 2 * M_PI * angle / 360.0, 0, 0, 1); - glUniformMatrix4fv(proj_location, 1, GL_FALSE, tmp); - glUniform3fv(light_location, 1, light); - glUniform4fv(color_location, 1, color); - - glBindBuffer(GL_ARRAY_BUFFER, gear->vbo); - - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, - 6 * sizeof(GLfloat), NULL); - glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, - 6 * sizeof(GLfloat), (GLfloat *) 0 + 3); - glEnableVertexAttribArray(0); - glEnableVertexAttribArray(1); - glDrawArrays(GL_TRIANGLE_STRIP, 0, gear->count); -} - -static void -gears_draw(void) -{ - const static GLfloat red[4] = { 0.8, 0.1, 0.0, 1.0 }; - const static GLfloat green[4] = { 0.0, 0.8, 0.2, 1.0 }; - const static GLfloat blue[4] = { 0.2, 0.2, 1.0, 1.0 }; - GLfloat m[16]; - - glClearColor(0.0, 0.0, 0.0, 0.0); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - memcpy(m, proj, sizeof m); - rotate(m, 2 * M_PI * view_rotx / 360.0, 1, 0, 0); - rotate(m, 2 * M_PI * view_roty / 360.0, 0, 1, 0); - rotate(m, 2 * M_PI * view_rotz / 360.0, 0, 0, 1); - - draw_gear(gear1, m, -3.0, -2.0, angle, red); - draw_gear(gear2, m, 3.1, -2.0, -2 * angle - 9.0, green); - draw_gear(gear3, m, -3.1, 4.2, -2 * angle - 25.0, blue); -} - -/* new window size or exposure */ -static void -gears_reshape(int width, int height) -{ - GLfloat ar, m[16] = { - 1.0, 0.0, 0.0, 0.0, - 0.0, 1.0, 0.0, 0.0, - 0.0, 0.0, 0.1, 0.0, - 0.0, 0.0, 0.0, 1.0, - }; - - if (width < height) - ar = width; - else - ar = height; - - m[0] = 0.1 * ar / width; - m[5] = 0.1 * ar / height; - memcpy(proj, m, sizeof proj); - glViewport(0, 0, (GLint) width, (GLint) height); -} - -static void -gears_special(int special) -{ - switch (special) { - case EGLUT_KEY_LEFT: - view_roty += 5.0; - break; - case EGLUT_KEY_RIGHT: - view_roty -= 5.0; - break; - case EGLUT_KEY_UP: - view_rotx += 5.0; - break; - case EGLUT_KEY_DOWN: - view_rotx -= 5.0; - break; - } -} - -static void -gears_idle(void) -{ - static double tRot0 = -1.0; - double dt, t = eglutGet(EGLUT_ELAPSED_TIME) / 1000.0; - - 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; - - eglutPostRedisplay(); -} - -static const char vertex_shader[] = - "uniform mat4 proj;\n" - "attribute vec4 position;\n" - "attribute vec4 normal;\n" - "varying vec3 rotated_normal;\n" - "varying vec3 rotated_position;\n" - "vec4 tmp;\n" - "void main()\n" - "{\n" - " gl_Position = proj * position;\n" - " rotated_position = gl_Position.xyz;\n" - " tmp = proj * normal;\n" - " rotated_normal = tmp.xyz;\n" - "}\n"; - - static const char fragment_shader[] = - //"precision mediump float;\n" - "uniform vec4 color;\n" - "uniform vec3 light;\n" - "varying vec3 rotated_normal;\n" - "varying vec3 rotated_position;\n" - "vec3 light_direction;\n" - "vec4 white = vec4(1.0, 1.0, 1.0, 1.0);\n" - "void main()\n" - "{\n" - " light_direction = normalize(light - rotated_position);\n" - " gl_FragColor = color + white * dot(light_direction, rotated_normal);\n" - "}\n"; - -static void -gears_init(void) -{ - GLuint v, f, program; - const char *p; - char msg[512]; - - glEnable(GL_CULL_FACE); - glEnable(GL_DEPTH_TEST); - - p = vertex_shader; - v = glCreateShader(GL_VERTEX_SHADER); - glShaderSource(v, 1, &p, NULL); - glCompileShader(v); - glGetShaderInfoLog(v, sizeof msg, NULL, msg); - printf("vertex shader info: %s\n", msg); - - p = fragment_shader; - f = glCreateShader(GL_FRAGMENT_SHADER); - glShaderSource(f, 1, &p, NULL); - glCompileShader(f); - glGetShaderInfoLog(f, sizeof msg, NULL, msg); - printf("fragment shader info: %s\n", msg); - - program = glCreateProgram(); - glAttachShader(program, v); - glAttachShader(program, f); - glBindAttribLocation(program, 0, "position"); - glBindAttribLocation(program, 1, "normal"); - - glLinkProgram(program); - glGetProgramInfoLog(program, sizeof msg, NULL, msg); - printf("info: %s\n", msg); - - glUseProgram(program); - proj_location = glGetUniformLocation(program, "proj"); - light_location = glGetUniformLocation(program, "light"); - color_location = glGetUniformLocation(program, "color"); - - /* make the gears */ - gear1 = gear(1.0, 4.0, 1.0, 20, 0.7); - gear2 = gear(0.5, 2.0, 2.0, 10, 0.7); - gear3 = gear(1.3, 2.0, 0.5, 10, 0.7); -} - -int -main(int argc, char *argv[]) -{ - eglutInitWindowSize(300, 300); - eglutInitAPIMask(EGLUT_OPENGL_ES2_BIT); - eglutInit(argc, argv); - - eglutCreateWindow("es2gears"); - - eglutIdleFunc(gears_idle); - eglutReshapeFunc(gears_reshape); - eglutDisplayFunc(gears_draw); - eglutSpecialFunc(gears_special); - - gears_init(); - - eglutMainLoop(); - - return 0; -} diff --git a/progs/egl/opengles2/tri.c b/progs/egl/opengles2/tri.c deleted file mode 100644 index 812dbf031e..0000000000 --- a/progs/egl/opengles2/tri.c +++ /dev/null @@ -1,520 +0,0 @@ -/************************************************************************** - * - * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. - * All Rights Reserved. - * - **************************************************************************/ - -/* - * Draw a triangle with X/EGL and OpenGL ES 2.x - */ - -#define USE_FULL_GL 0 - - - -#include <assert.h> -#include <math.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <X11/Xlib.h> -#include <X11/Xutil.h> -#include <X11/keysym.h> -#if USE_FULL_GL -#include <GL/gl.h> /* use full OpenGL */ -#else -#include <GLES2/gl2.h> /* use OpenGL ES 2.x */ -#endif -#include <EGL/egl.h> - - -#ifndef M_PI -#define M_PI 3.14159265 -#endif - -#define FLOAT_TO_FIXED(X) ((X) * 65535.0) - - - -static GLfloat view_rotx = 0.0, view_roty = 0.0; - -static GLint u_matrix = -1; -static GLint attr_pos = 0, attr_color = 1; - - -static void -make_z_rot_matrix(GLfloat angle, GLfloat *m) -{ - float c = cos(angle * M_PI / 180.0); - float s = sin(angle * M_PI / 180.0); - int i; - for (i = 0; i < 16; i++) - m[i] = 0.0; - m[0] = m[5] = m[10] = m[15] = 1.0; - - m[0] = c; - m[1] = s; - m[4] = -s; - m[5] = c; -} - -static void -make_scale_matrix(GLfloat xs, GLfloat ys, GLfloat zs, GLfloat *m) -{ - int i; - for (i = 0; i < 16; i++) - m[i] = 0.0; - m[0] = xs; - m[5] = ys; - m[10] = zs; - m[15] = 1.0; -} - - -static void -mul_matrix(GLfloat *prod, const GLfloat *a, const GLfloat *b) -{ -#define A(row,col) a[(col<<2)+row] -#define B(row,col) b[(col<<2)+row] -#define P(row,col) p[(col<<2)+row] - GLfloat p[16]; - GLint i; - for (i = 0; i < 4; i++) { - const GLfloat ai0=A(i,0), ai1=A(i,1), ai2=A(i,2), ai3=A(i,3); - P(i,0) = ai0 * B(0,0) + ai1 * B(1,0) + ai2 * B(2,0) + ai3 * B(3,0); - P(i,1) = ai0 * B(0,1) + ai1 * B(1,1) + ai2 * B(2,1) + ai3 * B(3,1); - P(i,2) = ai0 * B(0,2) + ai1 * B(1,2) + ai2 * B(2,2) + ai3 * B(3,2); - P(i,3) = ai0 * B(0,3) + ai1 * B(1,3) + ai2 * B(2,3) + ai3 * B(3,3); - } - memcpy(prod, p, sizeof(p)); -#undef A -#undef B -#undef PROD -} - - -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 } - }; - GLfloat mat[16], rot[16], scale[16]; - - /* Set modelview/projection matrix */ - make_z_rot_matrix(view_rotx, rot); - make_scale_matrix(0.5, 0.5, 0.5, scale); - mul_matrix(mat, rot, scale); - glUniformMatrix4fv(u_matrix, 1, GL_FALSE, mat); - - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - { - glVertexAttribPointer(attr_pos, 2, GL_FLOAT, GL_FALSE, 0, verts); - glVertexAttribPointer(attr_color, 3, GL_FLOAT, GL_FALSE, 0, colors); - glEnableVertexAttribArray(attr_pos); - glEnableVertexAttribArray(attr_color); - - glDrawArrays(GL_TRIANGLES, 0, 3); - - glDisableVertexAttribArray(attr_pos); - glDisableVertexAttribArray(attr_color); - } -} - - -/* new window size or exposure */ -static void -reshape(int width, int height) -{ - glViewport(0, 0, (GLint) width, (GLint) height); -} - - -static void -create_shaders(void) -{ - static const char *fragShaderText = - "varying vec4 v_color;\n" - "void main() {\n" - " gl_FragColor = v_color;\n" - "}\n"; - static const char *vertShaderText = - "uniform mat4 modelviewProjection;\n" - "attribute vec4 pos;\n" - "attribute vec4 color;\n" - "varying vec4 v_color;\n" - "void main() {\n" - " gl_Position = modelviewProjection * pos;\n" - " v_color = color;\n" - "}\n"; - - GLuint fragShader, vertShader, program; - GLint stat; - - fragShader = glCreateShader(GL_FRAGMENT_SHADER); - glShaderSource(fragShader, 1, (const char **) &fragShaderText, NULL); - glCompileShader(fragShader); - glGetShaderiv(fragShader, GL_COMPILE_STATUS, &stat); - if (!stat) { - printf("Error: fragment shader did not compile!\n"); - exit(1); - } - - vertShader = glCreateShader(GL_VERTEX_SHADER); - glShaderSource(vertShader, 1, (const char **) &vertShaderText, NULL); - glCompileShader(vertShader); - glGetShaderiv(vertShader, GL_COMPILE_STATUS, &stat); - if (!stat) { - printf("Error: vertex shader did not compile!\n"); - exit(1); - } - - program = glCreateProgram(); - glAttachShader(program, fragShader); - glAttachShader(program, vertShader); - glLinkProgram(program); - - glGetProgramiv(program, GL_LINK_STATUS, &stat); - if (!stat) { - char log[1000]; - GLsizei len; - glGetProgramInfoLog(program, 1000, &len, log); - printf("Error: linking:\n%s\n", log); - exit(1); - } - - glUseProgram(program); - - if (1) { - /* test setting attrib locations */ - glBindAttribLocation(program, attr_pos, "pos"); - glBindAttribLocation(program, attr_color, "color"); - glLinkProgram(program); /* needed to put attribs into effect */ - } - else { - /* test automatic attrib locations */ - attr_pos = glGetAttribLocation(program, "pos"); - attr_color = glGetAttribLocation(program, "color"); - } - - u_matrix = glGetUniformLocation(program, "modelviewProjection"); - printf("Uniform modelviewProjection at %d\n", u_matrix); - printf("Attrib pos at %d\n", attr_pos); - printf("Attrib color at %d\n", attr_color); -} - - -static void -init(void) -{ - typedef void (*proc)(); - -#if 1 /* test code */ - proc p = eglGetProcAddress("glMapBufferOES"); - assert(p); -#endif - - glClearColor(0.4, 0.4, 0.4, 0.0); - - create_shaders(); -} - - -/* - * Create an RGB, double-buffered X window. - * Return the window and context handles. - */ -static void -make_x_window(Display *x_dpy, EGLDisplay egl_dpy, - const char *name, - int x, int y, int width, int height, - Window *winRet, - EGLContext *ctxRet, - EGLSurface *surfRet) -{ - static const EGLint attribs[] = { - EGL_RED_SIZE, 1, - EGL_GREEN_SIZE, 1, - EGL_BLUE_SIZE, 1, - EGL_DEPTH_SIZE, 1, - EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, - EGL_NONE - }; - static const EGLint ctx_attribs[] = { - EGL_CONTEXT_CLIENT_VERSION, 2, - EGL_NONE - }; - int scrnum; - XSetWindowAttributes attr; - unsigned long mask; - Window root; - Window win; - XVisualInfo *visInfo, visTemplate; - int num_visuals; - EGLContext ctx; - EGLConfig config; - EGLint num_configs; - EGLint vid; - - scrnum = DefaultScreen( x_dpy ); - root = RootWindow( x_dpy, scrnum ); - - if (!eglChooseConfig( egl_dpy, attribs, &config, 1, &num_configs)) { - printf("Error: couldn't get an EGL visual config\n"); - exit(1); - } - - assert(config); - assert(num_configs > 0); - - if (!eglGetConfigAttrib(egl_dpy, config, EGL_NATIVE_VISUAL_ID, &vid)) { - printf("Error: eglGetConfigAttrib() failed\n"); - exit(1); - } - - /* The X window visual must match the EGL config */ - visTemplate.visualid = vid; - visInfo = XGetVisualInfo(x_dpy, VisualIDMask, &visTemplate, &num_visuals); - if (!visInfo) { - printf("Error: couldn't get X visual\n"); - exit(1); - } - - /* window attributes */ - attr.background_pixel = 0; - attr.border_pixel = 0; - attr.colormap = XCreateColormap( x_dpy, root, visInfo->visual, AllocNone); - attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask; - mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; - - win = XCreateWindow( x_dpy, root, 0, 0, width, height, - 0, visInfo->depth, InputOutput, - visInfo->visual, mask, &attr ); - - /* set hints and properties */ - { - XSizeHints sizehints; - sizehints.x = x; - sizehints.y = y; - sizehints.width = width; - sizehints.height = height; - sizehints.flags = USSize | USPosition; - XSetNormalHints(x_dpy, win, &sizehints); - XSetStandardProperties(x_dpy, win, name, name, - None, (char **)NULL, 0, &sizehints); - } - -#if USE_FULL_GL /* XXX fix this when eglBindAPI() works */ - eglBindAPI(EGL_OPENGL_API); -#else - eglBindAPI(EGL_OPENGL_ES_API); -#endif - - ctx = eglCreateContext(egl_dpy, config, EGL_NO_CONTEXT, ctx_attribs ); - if (!ctx) { - printf("Error: eglCreateContext failed\n"); - exit(1); - } - - /* test eglQueryContext() */ - { - EGLint val; - eglQueryContext(egl_dpy, ctx, EGL_CONTEXT_CLIENT_VERSION, &val); - assert(val == 2); - } - - *surfRet = eglCreateWindowSurface(egl_dpy, config, win, NULL); - if (!*surfRet) { - printf("Error: eglCreateWindowSurface failed\n"); - exit(1); - } - - /* sanity checks */ - { - EGLint val; - eglQuerySurface(egl_dpy, *surfRet, EGL_WIDTH, &val); - assert(val == width); - eglQuerySurface(egl_dpy, *surfRet, EGL_HEIGHT, &val); - assert(val == height); - assert(eglGetConfigAttrib(egl_dpy, config, EGL_SURFACE_TYPE, &val)); - assert(val & EGL_WINDOW_BIT); - } - - XFree(visInfo); - - *winRet = win; - *ctxRet = ctx; -} - - -static void -event_loop(Display *dpy, Window win, - EGLDisplay egl_dpy, EGLSurface egl_surf) -{ - while (1) { - int redraw = 0; - XEvent event; - - XNextEvent(dpy, &event); - - switch (event.type) { - case Expose: - redraw = 1; - break; - case ConfigureNotify: - reshape(event.xconfigure.width, event.xconfigure.height); - break; - case KeyPress: - { - char buffer[10]; - int r, code; - code = XLookupKeysym(&event.xkey, 0); - if (code == XK_Left) { - view_roty += 5.0; - } - else if (code == XK_Right) { - view_roty -= 5.0; - } - else if (code == XK_Up) { - view_rotx += 5.0; - } - else if (code == XK_Down) { - view_rotx -= 5.0; - } - else { - r = XLookupString(&event.xkey, buffer, sizeof(buffer), - NULL, NULL); - if (buffer[0] == 27) { - /* escape */ - return; - } - } - } - redraw = 1; - break; - default: - ; /*no-op*/ - } - - if (redraw) { - draw(); - eglSwapBuffers(egl_dpy, egl_surf); - } - } -} - - -static void -usage(void) -{ - printf("Usage:\n"); - printf(" -display <displayname> set the display to run on\n"); - printf(" -info display OpenGL renderer info\n"); -} - - -int -main(int argc, char *argv[]) -{ - const int winWidth = 300, winHeight = 300; - Display *x_dpy; - Window win; - EGLSurface egl_surf; - EGLContext egl_ctx; - EGLDisplay egl_dpy; - char *dpyName = NULL; - GLboolean printInfo = GL_FALSE; - EGLint egl_major, egl_minor; - int i; - const char *s; - - for (i = 1; i < argc; i++) { - if (strcmp(argv[i], "-display") == 0) { - dpyName = argv[i+1]; - i++; - } - else if (strcmp(argv[i], "-info") == 0) { - printInfo = GL_TRUE; - } - else { - usage(); - return -1; - } - } - - x_dpy = XOpenDisplay(dpyName); - if (!x_dpy) { - printf("Error: couldn't open display %s\n", - dpyName ? dpyName : getenv("DISPLAY")); - return -1; - } - - egl_dpy = eglGetDisplay(x_dpy); - if (!egl_dpy) { - printf("Error: eglGetDisplay() failed\n"); - return -1; - } - - if (!eglInitialize(egl_dpy, &egl_major, &egl_minor)) { - printf("Error: eglInitialize() failed\n"); - return -1; - } - - s = eglQueryString(egl_dpy, EGL_VERSION); - printf("EGL_VERSION = %s\n", s); - - s = eglQueryString(egl_dpy, EGL_VENDOR); - printf("EGL_VENDOR = %s\n", s); - - s = eglQueryString(egl_dpy, EGL_EXTENSIONS); - printf("EGL_EXTENSIONS = %s\n", s); - - s = eglQueryString(egl_dpy, EGL_CLIENT_APIS); - printf("EGL_CLIENT_APIS = %s\n", s); - - make_x_window(x_dpy, egl_dpy, - "OpenGL ES 2.x tri", 0, 0, winWidth, winHeight, - &win, &egl_ctx, &egl_surf); - - XMapWindow(x_dpy, win); - if (!eglMakeCurrent(egl_dpy, egl_surf, egl_surf, egl_ctx)) { - printf("Error: eglMakeCurrent() failed\n"); - return -1; - } - - if (printInfo) { - printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); - printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); - printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); - printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS)); - } - - init(); - - /* Set initial projection/viewing transformation. - * We can't be sure we'll get a ConfigureNotify event when the window - * first appears. - */ - reshape(winWidth, winHeight); - - event_loop(x_dpy, win, egl_dpy, egl_surf); - - eglDestroyContext(egl_dpy, egl_ctx); - eglDestroySurface(egl_dpy, egl_surf); - eglTerminate(egl_dpy); - - - XDestroyWindow(x_dpy, win); - XCloseDisplay(x_dpy); - - return 0; -} |