diff options
| author | Chia-I Wu <olv@lunarg.com> | 2010-04-01 14:03:30 +0800 | 
|---|---|---|
| committer | Chia-I Wu <olv@lunarg.com> | 2010-04-01 22:25:49 +0800 | 
| commit | 7b48d88407655dc135d7a3c2c47d9df3e8dff01e (patch) | |
| tree | 9c006f6b4ddb2f084528faca04d516dbfc2215ec /progs/egl/opengles1 | |
| parent | dd7276f494f81e57450fac93434ed6d9abfe8e41 (diff) | |
progs/egl: Port ES1 gears to eglut.
As gears in the last demo under "screen" subdirectory, this also removes
the directory.
Diffstat (limited to 'progs/egl/opengles1')
| -rw-r--r-- | progs/egl/opengles1/.gitignore | 3 | ||||
| -rw-r--r-- | progs/egl/opengles1/Makefile | 1 | ||||
| -rw-r--r-- | progs/egl/opengles1/gears.c (renamed from progs/egl/opengles1/screen/gears.c) | 43 | ||||
| -rw-r--r-- | progs/egl/opengles1/screen/Makefile | 28 | ||||
| -rw-r--r-- | progs/egl/opengles1/screen/winsys.c | 272 | ||||
| -rw-r--r-- | progs/egl/opengles1/screen/winsys.h | 36 | 
6 files changed, 28 insertions, 355 deletions
| diff --git a/progs/egl/opengles1/.gitignore b/progs/egl/opengles1/.gitignore index 8c1c9a8ef9..e95e393b00 100644 --- a/progs/egl/opengles1/.gitignore +++ b/progs/egl/opengles1/.gitignore @@ -1,8 +1,7 @@ -screen/gears -screen/tri  bindtex  drawtex  es1_info +gears  msaa  pbuffer  render_tex diff --git a/progs/egl/opengles1/Makefile b/progs/egl/opengles1/Makefile index d6c09c6abe..27caa0cd0f 100644 --- a/progs/egl/opengles1/Makefile +++ b/progs/egl/opengles1/Makefile @@ -22,6 +22,7 @@ ES1_LIBS = \  EGLUT_DIR = $(TOP)/progs/egl/eglut  EGLUT_DEMOS = \ +	gears \  	tri  EGLUT_X11_DEMOS := $(addsuffix _x11,$(EGLUT_DEMOS)) diff --git a/progs/egl/opengles1/screen/gears.c b/progs/egl/opengles1/gears.c index c7625826b9..8462a4871a 100644 --- a/progs/egl/opengles1/screen/gears.c +++ b/progs/egl/opengles1/gears.c @@ -28,7 +28,7 @@  #include <assert.h>  #include <GLES/gl.h> -#include "winsys.h" +#include "eglut.h"  #ifndef M_PI  #define M_PI 3.14159265 @@ -247,7 +247,7 @@ draw_gear(const struct gear *gear)  static void -gears_draw(void *data) +gears_draw(void)  {     static const GLfloat red[4] = { 0.8, 0.1, 0.0, 1.0 };     static const GLfloat green[4] = { 0.0, 0.8, 0.2, 1.0 }; @@ -288,11 +288,6 @@ gears_draw(void *data)     glPopMatrix();     glPopMatrix(); - -   /* advance rotation for next frame */ -   angle += 0.5; /* 0.5 degree per frame */ -   if (angle > 3600.0) -      angle -= 3600.0;  } @@ -348,27 +343,41 @@ gears_reshape(int width, int height)  } -static void gears_run(void) +static void +gears_idle(void)  { -   winsysRun(5.0, gears_draw, NULL); +  static double t0 = -1.; +  double dt, t = eglutGet(EGLUT_ELAPSED_TIME) / 1000.0; +  if (t0 < 0.0) +    t0 = t; +  dt = t - t0; +  t0 = t; + +  angle += 70.0 * dt;  /* 70 degrees per second */ +  angle = fmod(angle, 360.0); /* prevents eventual overflow */ + +  eglutPostRedisplay();  }  int  main(int argc, char *argv[])  { -   EGLint width, height; +   eglutInitWindowSize(300, 300); +   eglutInitAPIMask(EGLUT_OPENGL_ES1_BIT); +   eglutInit(argc, argv); -   if (!winsysInitScreen()) -      exit(1); -   winsysQueryScreenSize(&width, &height); +   eglutCreateWindow("gears"); + +   eglutIdleFunc(gears_idle); +   eglutReshapeFunc(gears_reshape); +   eglutDisplayFunc(gears_draw);     gears_init(); -   gears_reshape(width, height); -   gears_run(); -   gears_fini(); -   winsysFiniScreen(); +   eglutMainLoop(); + +   gears_fini();     return 0;  } diff --git a/progs/egl/opengles1/screen/Makefile b/progs/egl/opengles1/screen/Makefile deleted file mode 100644 index 0c3c136ff2..0000000000 --- a/progs/egl/opengles1/screen/Makefile +++ /dev/null @@ -1,28 +0,0 @@ -# progs/egl/opengles1/screen/Makefile - -TOP = ../../../.. -include $(TOP)/configs/current - -ES1_CFLAGS = -I$(TOP)/include -ES1_LIBS = -L$(TOP)/$(LIB_DIR) -lEGL -lGLESv1_CM - -ES1_LIB_DEPS = \ -	$(TOP)/$(LIB_DIR)/libEGL.so \ -	$(TOP)/$(LIB_DIR)/libGLESv1_CM.so - -WINSYS_OBJS = winsys.o - -PROGRAMS = \ -	gears - -.c.o: -	$(CC) -c $(ES1_CFLAGS) $(CFLAGS) $< -o $@ - -default: $(PROGRAMS) - -gears: gears.o $(WINSYS_OBJS) $(ES1_LIB_DEPS) -	$(CC) $(CFLAGS) -o $@ $@.o $(WINSYS_OBJS) $(ES1_LIBS) - -clean: -	-rm -f *.o *~ -	-rm -f $(PROGRAMS) diff --git a/progs/egl/opengles1/screen/winsys.c b/progs/egl/opengles1/screen/winsys.c deleted file mode 100644 index 84d00471eb..0000000000 --- a/progs/egl/opengles1/screen/winsys.c +++ /dev/null @@ -1,272 +0,0 @@ -/* - * Copyright (C) 2009 Chia-I Wu <olv@0xlab.org> - * - * Based on eglgears by - * Copyright (C) 1999-2001  Brian Paul   All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <assert.h> -#include <sys/time.h> - -#define EGL_EGLEXT_PROTOTYPES - -#include <EGL/egl.h> -#include <EGL/eglext.h> - -#include "winsys.h" - -#define MAX_MODES 100 - -static struct { -   EGLBoolean verbose; - -   EGLDisplay dpy; -   EGLConfig conf; - -   EGLScreenMESA screen; -   EGLModeMESA mode; -   EGLint width, height; - -   EGLContext ctx; -   EGLSurface surf; -} screen; - - -static EGLBoolean -init_screen(void) -{ -   EGLModeMESA modes[MAX_MODES]; -   EGLint num_screens, num_modes; -   EGLint width, height, best_mode; -   EGLint i; - -   if (!eglGetScreensMESA(screen.dpy, &screen.screen, 1, &num_screens) || -       !num_screens) { -      printf("eglGetScreensMESA failed\n"); -      return EGL_FALSE; -   } - -   if (!eglGetModesMESA(screen.dpy, screen.screen, modes, MAX_MODES, -                        &num_modes) || -       !num_modes) { -      printf("eglGetModesMESA failed!\n"); -      return EGL_FALSE; -   } - -   printf("Found %d modes:\n", num_modes); - -   best_mode = 0; -   width = 0; -   height = 0; -   for (i = 0; i < num_modes; i++) { -      EGLint w, h; -      eglGetModeAttribMESA(screen.dpy, modes[i], EGL_WIDTH, &w); -      eglGetModeAttribMESA(screen.dpy, modes[i], EGL_HEIGHT, &h); -      printf("%3d: %d x %d\n", i, w, h); -      if (w > width && h > height) { -         width = w; -         height = h; -         best_mode = i; -      } -   } - -   screen.mode = modes[best_mode]; -   screen.width = width; -   screen.height = height; - -   return EGL_TRUE; -} - - -static EGLBoolean -init_display(void) -{ -   EGLint maj, min; -   const char *exts; -   const EGLint attribs[] = { -      EGL_SURFACE_TYPE, 0x0,    /* should be EGL_SCREEN_BIT_MESA */ -      EGL_RENDERABLE_TYPE, 0x0, /* should be EGL_OPENGL_ES_BIT */ -      EGL_NONE -   }; -   EGLint num_configs; - -   screen.dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); -   if (!screen.dpy) { -      printf("eglGetDisplay failed\n"); -      return EGL_FALSE; -   } - -   if (!eglInitialize(screen.dpy, &maj, &min)) { -      printf("eglInitialize failed\n"); -      return EGL_FALSE; -   } - -   printf("EGL_VERSION = %s\n", eglQueryString(screen.dpy, EGL_VERSION)); -   printf("EGL_VENDOR = %s\n", eglQueryString(screen.dpy, EGL_VENDOR)); - -   exts = eglQueryString(screen.dpy, EGL_EXTENSIONS); -   assert(exts); - -   if (!strstr(exts, "EGL_MESA_screen_surface")) { -      printf("EGL_MESA_screen_surface is not supported\n"); -      return EGL_FALSE; -   } - -   if (!eglChooseConfig(screen.dpy, attribs, &screen.conf, 1, -                        &num_configs) || -       !num_configs) { -      printf("eglChooseConfig failed\n"); -      return EGL_FALSE; -   } - -   return EGL_TRUE; -} - - -EGLBoolean -winsysInitScreen(void) -{ -        EGLint surf_attribs[20]; -        EGLint i; -        EGLBoolean ok; - -        if (!init_display()) -           goto fail; -        if (!init_screen()) -           goto fail; - -        /* create context */ -	screen.ctx = eglCreateContext(screen.dpy, screen.conf, -                                      EGL_NO_CONTEXT, NULL); -	if (screen.ctx == EGL_NO_CONTEXT) { -		printf("eglCreateContext failed\n"); -                goto fail; -	} - -	i = 0; -	surf_attribs[i++] = EGL_WIDTH; -	surf_attribs[i++] = screen.width; -	surf_attribs[i++] = EGL_HEIGHT; -	surf_attribs[i++] = screen.height; -	surf_attribs[i++] = EGL_NONE; - -        /* create surface */ -        printf("Using screen size: %d x %d\n", screen.width, screen.height); -        screen.surf = eglCreateScreenSurfaceMESA(screen.dpy, screen.conf, -                                                 surf_attribs); -	if (screen.surf == EGL_NO_SURFACE) { -		printf("eglCreateScreenSurfaceMESA failed\n"); -                goto fail; -	} - -	ok = eglMakeCurrent(screen.dpy, screen.surf, screen.surf, screen.ctx); -	if (!ok) { -		printf("eglMakeCurrent failed\n"); -		goto fail; -	} - -	ok = eglShowScreenSurfaceMESA(screen.dpy, screen.screen, -                                      screen.surf, screen.mode); -	if (!ok) { -		printf("eglShowScreenSurfaceMESA failed\n"); -                goto fail; -	} - -        return EGL_TRUE; - -fail: -        winsysFiniScreen(); -        return EGL_FALSE; -} - - -EGLBoolean -winsysQueryScreenSize(EGLint *width, EGLint *height) -{ -   if (!screen.dpy) -      return EGL_FALSE; - -   if (width) -      *width = screen.width; -   if (height) -      *height = screen.height; - -   return EGL_TRUE; -} - - -void -winsysFiniScreen(void) -{ -   if (screen.dpy) { -      eglMakeCurrent(screen.dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, -                     EGL_NO_CONTEXT); -      if (screen.surf != EGL_NO_SURFACE) -         eglDestroySurface(screen.dpy, screen.surf); -      if (screen.ctx != EGL_NO_CONTEXT) -         eglDestroyContext(screen.dpy, screen.ctx); -      eglTerminate(screen.dpy); - -      memset(&screen, 0, sizeof(screen)); -   } -} - - -void -winsysSwapBuffers(void) -{ -   eglSwapBuffers(screen.dpy, screen.surf); -} - - -/* return current time (in seconds) */ -double -winsysNow(void) -{ -   struct timeval tv; -   gettimeofday(&tv, NULL); -   return (double) tv.tv_sec + tv.tv_usec / 1000000.0; -} - - -void -winsysRun(double seconds, void (*draw_frame)(void *data), void *data) -{ -        double begin, end, last_frame, duration; -	EGLint num_frames = 0; - -        begin = winsysNow(); -        end = begin + seconds; - -        last_frame = begin; -        while (last_frame < end) { -           draw_frame(data); -           winsysSwapBuffers(); -           last_frame = winsysNow(); -           num_frames++; -        } - -        duration = last_frame - begin; -	printf("%d frames in %3.1f seconds = %6.3f FPS\n", -               num_frames, duration, (double) num_frames / duration); -} diff --git a/progs/egl/opengles1/screen/winsys.h b/progs/egl/opengles1/screen/winsys.h deleted file mode 100644 index 679c7e0bd6..0000000000 --- a/progs/egl/opengles1/screen/winsys.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2009 Chia-I Wu <olv@0xlab.org> - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -#ifndef _WINSYS_H_ -#define _WINSYS_H_ - -#include <EGL/egl.h> - -EGLBoolean winsysInitScreen(void); -EGLBoolean winsysQueryScreenSize(EGLint *width, EGLint *height); -void winsysFiniScreen(void); - -void winsysSwapBuffers(void); -double winsysNow(void); - -void winsysRun(double seconds, void (*draw_frame)(void *data), void *data); - -#endif /* _WINSYS_H_ */ | 
