From: Dave Airlie
Date: Thu, 8 Apr 2010 06:48:41 +0000 (+1000)
Subject: Merge remote branch 'origin/7.8'
X-Git-Url: https://git.libre-soc.org/?p=mesa.git;a=commitdiff_plain;h=dff50ff592da7cb1d784fae794dd1647a5445bca;hp=4b39a0da89f5b07d4a24bc9ce52693e6c2acfe99
Merge remote branch 'origin/7.8'
Conflicts:
Makefile
configs/default
src/mesa/main/version.h
---
diff --git a/Makefile b/Makefile
index c81a2ec2d9e..411130bc272 100644
--- a/Makefile
+++ b/Makefile
@@ -180,7 +180,7 @@ ultrix-gcc:
# Rules for making release tarballs
-VERSION=7.8.1
+VERSION=7.9-devel
DIRECTORY = Mesa-$(VERSION)
LIB_NAME = MesaLib-$(VERSION)
DEMO_NAME = MesaDemos-$(VERSION)
@@ -215,7 +215,6 @@ MAIN_FILES = \
$(DIRECTORY)/include/GL/glx_mangle.h \
$(DIRECTORY)/include/GL/glfbdev.h \
$(DIRECTORY)/include/GL/mesa_wgl.h \
- $(DIRECTORY)/include/GL/mglmesa.h \
$(DIRECTORY)/include/GL/osmesa.h \
$(DIRECTORY)/include/GL/vms_x_fix.h \
$(DIRECTORY)/include/GL/wglext.h \
@@ -321,6 +320,8 @@ GALLIUM_FILES = \
$(DIRECTORY)/src/gallium/Makefile \
$(DIRECTORY)/src/gallium/Makefile.template \
$(DIRECTORY)/src/gallium/SConscript \
+ $(DIRECTORY)/src/gallium/targets/Makefile.dri \
+ $(DIRECTORY)/src/gallium/targets/Makefile.egl \
$(DIRECTORY)/src/gallium/*/Makefile \
$(DIRECTORY)/src/gallium/*/SConscript \
$(DIRECTORY)/src/gallium/*/*/Makefile \
@@ -408,14 +409,18 @@ DEMO_FILES = \
$(DIRECTORY)/progs/demos/*.cxx \
$(DIRECTORY)/progs/demos/*.dat \
$(DIRECTORY)/progs/demos/README \
- $(DIRECTORY)/progs/egl/Makefile \
- $(DIRECTORY)/progs/egl/*.[ch] \
- $(DIRECTORY)/progs/es1/*/Makefile \
- $(DIRECTORY)/progs/es1/*/*.[ch] \
- $(DIRECTORY)/progs/es2/*/Makefile \
- $(DIRECTORY)/progs/es2/*/*.[ch] \
- $(DIRECTORY)/progs/openvg/*/Makefile \
- $(DIRECTORY)/progs/openvg/*/*.[ch] \
+ $(DIRECTORY)/progs/egl/eglut/Makefile \
+ $(DIRECTORY)/progs/egl/eglut/*.[ch] \
+ $(DIRECTORY)/progs/egl/opengl/Makefile \
+ $(DIRECTORY)/progs/egl/opengl/*.[ch] \
+ $(DIRECTORY)/progs/egl/opengles1/Makefile \
+ $(DIRECTORY)/progs/egl/opengles1/*.[ch] \
+ $(DIRECTORY)/progs/egl/opengles2/Makefile \
+ $(DIRECTORY)/progs/egl/opengles2/*.[ch] \
+ $(DIRECTORY)/progs/egl/openvg/Makefile \
+ $(DIRECTORY)/progs/egl/openvg/*.[ch] \
+ $(DIRECTORY)/progs/egl/openvg/*/Makefile \
+ $(DIRECTORY)/progs/egl/openvg/*/*.[ch] \
$(DIRECTORY)/progs/fbdev/Makefile \
$(DIRECTORY)/progs/fbdev/glfbdevtest.c \
$(DIRECTORY)/progs/objviewer/*.[ch] \
diff --git a/SConstruct b/SConstruct
index e1c4a1898ce..56d88cc1cc0 100644
--- a/SConstruct
+++ b/SConstruct
@@ -52,7 +52,7 @@ opts.Add(ListVariable('statetrackers', 'state trackers to build', default_statet
opts.Add(ListVariable('drivers', 'pipe drivers to build', default_drivers,
['softpipe', 'failover', 'svga', 'i915', 'i965', 'trace', 'r300', 'identity', 'llvmpipe']))
opts.Add(ListVariable('winsys', 'winsys drivers to build', default_winsys,
- ['xlib', 'vmware', 'intel', 'i965', 'gdi', 'radeon']))
+ ['xlib', 'vmware', 'i915', 'i965', 'gdi', 'radeon', 'graw-xlib']))
opts.Add(EnumVariable('MSVS_VERSION', 'MS Visual C++ version', None, allowed_values=('7.1', '8.0', '9.0')))
@@ -88,6 +88,8 @@ if drawllvm:
env.Tool('llvm')
if not env.has_key('LLVM_VERSION'):
drawllvm = False
+if drawllvm:
+ env.Append(CFLAGS = ['-DDRAW_LLVM=1'])
# derived options
x86 = machine == 'x86'
@@ -110,9 +112,11 @@ Export([
#######################################################################
# Environment setup
-# Always build trace driver
+# Always build trace and identity drivers
if 'trace' not in env['drivers']:
env['drivers'].append('trace')
+if 'identity' not in env['drivers']:
+ env['drivers'].append('identity')
# Includes
env.Append(CPPPATH = [
@@ -120,6 +124,7 @@ env.Append(CPPPATH = [
'#/src/gallium/include',
'#/src/gallium/auxiliary',
'#/src/gallium/drivers',
+ '#/src/gallium/winsys',
])
if env['msvc']:
@@ -156,12 +161,9 @@ if platform in ('posix', 'linux', 'freebsd', 'darwin'):
])
if platform == 'darwin':
env.Append(CPPDEFINES = ['_DARWIN_C_SOURCE'])
- env.Append(CPPPATH = ['/usr/X11R6/include'])
- env.Append(LIBPATH = ['/usr/X11R6/lib'])
env.Append(LIBS = [
'm',
'pthread',
- 'expat',
'dl',
])
@@ -179,16 +181,6 @@ if dri:
if drawllvm:
env.Append(CPPDEFINES = ['DRAW_LLVM'])
-# libGL
-if platform in ('linux', 'freebsd', 'darwin'):
- env.Append(LIBS = [
- 'X11',
- 'Xext',
- 'Xxf86vm',
- 'Xdamage',
- 'Xfixes',
- ])
-
# for debugging
#print env.Dump()
diff --git a/bin/mklib b/bin/mklib
index 08ef99ec105..c2760e5d892 100755
--- a/bin/mklib
+++ b/bin/mklib
@@ -494,13 +494,16 @@ case $ARCH in
OPTS="${OPTS} -Wl,-Mmapfile.scope"
fi
- # Check if objects are SPARC v9
+ # Check if objects are 64-bit
# file says: ELF 64-bit MSB relocatable SPARCV9 Version 1
set ${OBJECTS}
if [ ${LINK} = "cc" -o ${LINK} = "CC" ] ; then
- SPARCV9=`file $1 | grep SPARCV9`
- if [ "${SPARCV9}" ] ; then
- OPTS="${OPTS} -xarch=v9"
+ ABI64=`file $1 | grep "ELF 64-bit"`
+ if [ "${ABI64}" ] ; then
+ case `uname -p` in
+ sparc) OPTS="${OPTS} -xarch=v9" ;;
+ i386) OPTS="${OPTS} -xarch=amd64" ;;
+ esac
fi
fi
if [ "${ALTOPTS}" ] ; then
diff --git a/common.py b/common.py
index 928a4496f78..97389ed5001 100644
--- a/common.py
+++ b/common.py
@@ -60,7 +60,6 @@ def AddOptions(opts):
allowed_values=('generic', 'ppc', 'x86', 'x86_64')))
opts.Add(EnumOption('platform', 'target platform', default_platform,
allowed_values=('linux', 'cell', 'windows', 'winddk', 'wince', 'darwin', 'embedded')))
- opts.Add(EnumOption('toolchain', 'compiler toolchain', 'default',
- allowed_values=('default', 'crossmingw', 'winsdk', 'winddk')))
+ opts.Add('toolchain', 'compiler toolchain', 'default')
opts.Add(BoolOption('llvm', 'use LLVM', 'no'))
opts.Add(BoolOption('dri', 'build DRI drivers', default_dri))
diff --git a/configs/autoconf.in b/configs/autoconf.in
index 30637877f3b..b6cc9b3b73e 100644
--- a/configs/autoconf.in
+++ b/configs/autoconf.in
@@ -24,6 +24,8 @@ RADEON_CFLAGS = @RADEON_CFLAGS@
RADEON_LDFLAGS = @RADEON_LDFLAGS@
INTEL_LIBS = @INTEL_LIBS@
INTEL_CFLAGS = @INTEL_CFLAGS@
+X11_LIBS = @X11_LIBS@
+X11_CFLAGS = @X11_CFLAGS@
# Assembler
MESA_ASM_SOURCES = @MESA_ASM_SOURCES@
@@ -73,7 +75,7 @@ EGL_DRIVERS_DIRS = @EGL_DRIVERS_DIRS@
GALLIUM_DIRS = @GALLIUM_DIRS@
GALLIUM_DRIVERS_DIRS = @GALLIUM_DRIVERS_DIRS@
GALLIUM_WINSYS_DIRS = @GALLIUM_WINSYS_DIRS@
-GALLIUM_WINSYS_DRM_DIRS = @GALLIUM_WINSYS_DRM_DIRS@
+GALLIUM_TARGET_DIRS = @GALLIUM_TARGET_DIRS@
GALLIUM_STATE_TRACKERS_DIRS = @GALLIUM_STATE_TRACKERS_DIRS@
GALLIUM_AUXILIARIES = $(TOP)/src/gallium/auxiliary/libgallium.a
GALLIUM_DRIVERS = $(foreach DIR,$(GALLIUM_DRIVERS_DIRS),$(TOP)/src/gallium/drivers/$(DIR)/lib$(DIR).a)
@@ -83,7 +85,6 @@ PROGRAM_DIRS = @PROGRAM_DIRS@
# Driver specific build vars
DRI_DIRS = @DRI_DIRS@
-WINDOW_SYSTEM = @WINDOW_SYSTEM@
EGL_DISPLAYS = @EGL_DISPLAYS@
# Dependencies
diff --git a/configs/default b/configs/default
index 47d6923f019..593fc32b7d6 100644
--- a/configs/default
+++ b/configs/default
@@ -9,8 +9,8 @@ CONFIG_NAME = default
# Version info
MESA_MAJOR=7
-MESA_MINOR=8
-MESA_TINY=1
+MESA_MINOR=9
+MESA_TINY=0
MESA_VERSION = $(MESA_MAJOR).$(MESA_MINOR).$(MESA_TINY)
# external projects. This should be useless now that we use libdrm.
@@ -86,7 +86,7 @@ MOTIF_CFLAGS = -I/usr/include/Motif1.2
# Directories to build
LIB_DIR = lib
-SRC_DIRS = glsl mesa gallium egl gallium/winsys glu glut/glx glew glw
+SRC_DIRS = glsl mesa gallium egl gallium/winsys gallium/targets glu glut/glx glew glw
GLU_DIRS = sgi
DRIVER_DIRS = x11 osmesa
# Which subdirs under $(TOP)/progs/ to enter:
@@ -100,8 +100,8 @@ GALLIUM_DIRS = auxiliary drivers state_trackers
GALLIUM_AUXILIARIES = $(TOP)/src/gallium/auxiliary/libgallium.a
GALLIUM_DRIVERS_DIRS = softpipe failover svga i915 i965 r300 trace identity
GALLIUM_DRIVERS = $(foreach DIR,$(GALLIUM_DRIVERS_DIRS),$(TOP)/src/gallium/drivers/$(DIR)/lib$(DIR).a)
-GALLIUM_WINSYS_DIRS = drm xlib
-GALLIUM_WINSYS_DRM_DIRS = swrast
+GALLIUM_WINSYS_DIRS = sw sw/xlib
+GALLIUM_TARGET_DIRS = libgl-xlib
GALLIUM_STATE_TRACKERS_DIRS = glx vega
# native displays EGL should support
@@ -119,7 +119,7 @@ APP_LIB_DEPS = $(EXTRA_LIB_PATH) -L$(TOP)/$(LIB_DIR) -l$(GLUT_LIB) -l$(GLU_LI
# Program dependencies - specific GL/glut libraries added in Makefiles
APP_LIB_DEPS = -lm
-
+X11_LIBS = -lX11
# Installation directories (for make install)
INSTALL_DIR = /usr/local
diff --git a/configs/freebsd-dri b/configs/freebsd-dri
index 0b91cfc37e9..2c697e1c6e4 100644
--- a/configs/freebsd-dri
+++ b/configs/freebsd-dri
@@ -44,7 +44,6 @@ GLW_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -L/usr/local/lib -lGL -lXt -lX11
SRC_DIRS = glx gallium mesa glu glut/glx glew glw
DRIVER_DIRS = dri
PROGRAM_DIRS =
-WINDOW_SYSTEM=dri
DRM_SOURCE_PATH=$(TOP)/../drm
diff --git a/configs/linux-cell b/configs/linux-cell
index e89a08cd934..0908dba9e05 100644
--- a/configs/linux-cell
+++ b/configs/linux-cell
@@ -6,7 +6,7 @@ CONFIG_NAME = linux-cell
# Omiting other gallium drivers:
-GALLIUM_DRIVERS_DIRS = cell softpipe trace
+GALLIUM_DRIVERS_DIRS = cell softpipe trace identity
# Compiler and flags
@@ -37,7 +37,7 @@ CXXFLAGS = $(COMMON_C_CPP_FLAGS)
# Omitting glw here:
-SRC_DIRS = glsl mesa gallium gallium/winsys glu glut/glx glew
+SRC_DIRS = glsl mesa gallium gallium/winsys gallium/targets glu glut/glx glew
# Build no traditional Mesa drivers:
DRIVER_DIRS =
diff --git a/configs/linux-dri b/configs/linux-dri
index e8e8ccfcf94..9017becdafe 100644
--- a/configs/linux-dri
+++ b/configs/linux-dri
@@ -52,15 +52,14 @@ GL_LIB_DEPS = $(EXTRA_LIB_PATH) -lX11 -lXext -lXxf86vm -lXdamage -lXfixes \
# Directories
SRC_DIRS := glx egl $(SRC_DIRS)
-PROGRAM_DIRS := egl $(PROGRAM_DIRS)
+PROGRAM_DIRS := egl/opengl $(PROGRAM_DIRS)
# EGL directories
EGL_DRIVERS_DIRS = glx
DRIVER_DIRS = dri
-WINDOW_SYSTEM = dri
-GALLIUM_WINSYS_DIRS = drm
-GALLIUM_WINSYS_DRM_DIRS = vmware intel i965
+GALLIUM_WINSYS_DIRS = sw sw/xlib drm/vmware drm/intel drm/i965
+GALLIUM_TARGET_DIRS = egl-swrast
GALLIUM_STATE_TRACKERS_DIRS = egl
DRI_DIRS = i810 i915 i965 mach64 mga r128 r200 r300 radeon \
diff --git a/configs/linux-dri-xcb b/configs/linux-dri-xcb
index c5ed89c4b34..1ed980aa36e 100644
--- a/configs/linux-dri-xcb
+++ b/configs/linux-dri-xcb
@@ -51,7 +51,5 @@ SRC_DIRS = glx gallium mesa glu glut/glx glew glw
PROGRAM_DIRS = xdemos
DRIVER_DIRS = dri
-WINDOW_SYSTEM=dri
-
DRI_DIRS = i810 i915 mach64 mga r128 r200 r300 radeon \
savage sis tdfx unichrome
diff --git a/configs/linux-egl b/configs/linux-egl
index 2c2834b81d7..cd664b4171f 100644
--- a/configs/linux-egl
+++ b/configs/linux-egl
@@ -47,11 +47,11 @@ GL_LIB_DEPS = $(EXTRA_LIB_PATH) -lX11 -lXext -lXxf86vm -lXdamage -lXfixes \
# Directories
-SRC_DIRS = gallium mesa gallium/winsys glu egl
-PROGRAM_DIRS = egl
+SRC_DIRS = gallium mesa gallium/winsys gallium/targets glu egl
+PROGRAM_DIRS = egl/opengl
DRIVER_DIRS = dri
-WINDOW_SYSTEM = dri
GALLIUM_WINSYS_DIRS = egl_drm
+GALLIUM_TARGET_DIRS =
DRI_DIRS = intel
diff --git a/configs/linux-i965 b/configs/linux-i965
index e66abc347bb..7656a2adc5e 100644
--- a/configs/linux-i965
+++ b/configs/linux-i965
@@ -6,3 +6,4 @@ CONFIG_NAME = linux-i965
GALLIUM_DRIVER_DIRS = i965
GALLIUM_WINSYS_DIRS = drm/i965/xlib
+GALLIUM_TARGET_DIRS =
diff --git a/configs/linux-indirect b/configs/linux-indirect
index 0914fba19bc..1c7dd857db6 100644
--- a/configs/linux-indirect
+++ b/configs/linux-indirect
@@ -50,4 +50,3 @@ GL_LIB_DEPS = $(EXTRA_LIB_PATH) -lX11 -lXext -lXxf86vm -lm -lpthread -ldl
SRC_DIRS = glx glu glut/glx glew glw
DRIVER_DIRS =
PROGRAM_DIRS =
-WINDOW_SYSTEM=dri
diff --git a/configs/linux-llvm b/configs/linux-llvm
index 27e082ebf7e..3a15f1d6d8b 100644
--- a/configs/linux-llvm
+++ b/configs/linux-llvm
@@ -10,7 +10,7 @@ CONFIG_NAME = linux-llvm
GALLIUM_DRIVERS_DIRS += llvmpipe
OPT_FLAGS = -O3 -ansi -pedantic
-ARCH_FLAGS = -m32 -mmmx -msse -msse2 -mstackrealign
+ARCH_FLAGS = -mmmx -msse -msse2 -mstackrealign
DEFINES += -DNDEBUG -DGALLIUM_LLVMPIPE -DDRAW_LLVM -DHAVE_UDIS86
@@ -24,6 +24,8 @@ ifeq ($(LLVM_VERSION),)
MESA_LLVM=0
else
MESA_LLVM=1
+ HAVE_LLVM := 0x0$(subst .,0,$(LLVM_VERSION:svn=))
+ DEFINES += -DHAVE_LLVM=$(HAVE_LLVM)
# $(info Using LLVM version: $(LLVM_VERSION))
endif
diff --git a/configs/linux-opengl-es b/configs/linux-opengl-es
index 259c26a931b..ead47136f4a 100644
--- a/configs/linux-opengl-es
+++ b/configs/linux-opengl-es
@@ -6,8 +6,8 @@ CONFIG_NAME = linux-opengl-es
# Directories to build
LIB_DIR = lib
-SRC_DIRS = egl glsl mesa/es gallium gallium/winsys
-PROGRAM_DIRS = es1/screen es1/xegl es2/xegl
+SRC_DIRS = egl glsl mesa/es gallium gallium/winsys gallium/targets
+PROGRAM_DIRS = egl/opengles1 egl/opengles2
# egl st needs this
DEFINES += -DGLX_DIRECT_RENDERING
@@ -24,5 +24,5 @@ GALLIUM_STATE_TRACKERS_DIRS = es
# build egl_x11_{swrast,i915}.so
GALLIUM_DRIVERS_DIRS += trace i915
GALLIUM_STATE_TRACKERS_DIRS += egl
-GALLIUM_WINSYS_DIRS += drm
-GALLIUM_WINSYS_DRM_DIRS += intel swrast
+GALLIUM_WINSYS_DIRS += drm/intel
+GALLIUM_TARGET_DIRS += egl-swrast egl-i915
diff --git a/configure.ac b/configure.ac
index 61487c3905e..5647442ea17 100644
--- a/configure.ac
+++ b/configure.ac
@@ -459,23 +459,22 @@ CORE_DIRS="glsl mesa"
SRC_DIRS="glew"
GLU_DIRS="sgi"
-WINDOW_SYSTEM=""
GALLIUM_DIRS="auxiliary drivers state_trackers"
-GALLIUM_WINSYS_DIRS=""
-GALLIUM_WINSYS_DRM_DIRS=""
+GALLIUM_TARGET_DIRS=""
+GALLIUM_WINSYS_DIRS="sw"
GALLIUM_DRIVERS_DIRS="softpipe failover trace identity"
GALLIUM_STATE_TRACKERS_DIRS=""
case "$mesa_driver" in
xlib)
DRIVER_DIRS="x11"
- GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS xlib"
+ GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS sw/xlib"
+ GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS libgl-xlib"
;;
dri)
SRC_DIRS="$SRC_DIRS glx"
DRIVER_DIRS="dri"
- WINDOW_SYSTEM="dri"
- GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS drm"
+ GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS sw/xlib sw/dri sw/drm"
;;
osmesa)
DRIVER_DIRS="osmesa"
@@ -484,10 +483,9 @@ esac
AC_SUBST([SRC_DIRS])
AC_SUBST([GLU_DIRS])
AC_SUBST([DRIVER_DIRS])
-AC_SUBST([WINDOW_SYSTEM])
AC_SUBST([GALLIUM_DIRS])
+AC_SUBST([GALLIUM_TARGET_DIRS])
AC_SUBST([GALLIUM_WINSYS_DIRS])
-AC_SUBST([GALLIUM_WINSYS_DRM_DIRS])
AC_SUBST([GALLIUM_DRIVERS_DIRS])
AC_SUBST([GALLIUM_STATE_TRACKERS_DIRS])
@@ -547,8 +545,14 @@ else
x11_pkgconfig=no
fi
dnl Use the autoconf macro if no pkg-config files
-if test "$x11_pkgconfig" = no; then
+if test "$x11_pkgconfig" = yes; then
+ PKG_CHECK_MODULES([X11], [x11])
+else
AC_PATH_XTRA
+ test -z "$X11_CFLAGS" && X11_CFLAGS="$X_CFLAGS"
+ test -z "$X11_LIBS" && X11_LIBS="$X_LIBS -lX11"
+ AC_SUBST([X11_CFLAGS])
+ AC_SUBST([X11_LIBS])
fi
dnl Try to tell the user that the --x-* options are only used when
@@ -950,7 +954,7 @@ if test "x$enable_egl" = xyes; then
fi
if test "$with_demos" = yes; then
- PROGRAM_DIRS="$PROGRAM_DIRS egl"
+ PROGRAM_DIRS="$PROGRAM_DIRS egl/opengl"
fi
fi
AC_SUBST([EGL_LIB_DEPS])
@@ -1176,7 +1180,7 @@ AC_ARG_ENABLE([gallium],
[enable_gallium="$enableval"],
[enable_gallium=yes])
if test "x$enable_gallium" = xyes; then
- SRC_DIRS="$SRC_DIRS gallium gallium/winsys"
+ SRC_DIRS="$SRC_DIRS gallium gallium/winsys gallium/targets"
fi
dnl
@@ -1201,13 +1205,15 @@ yes)
;;
dri)
GALLIUM_STATE_TRACKERS_DIRS="dri"
+ HAVE_ST_DRI="yes"
if test "x$enable_egl" = xyes; then
GALLIUM_STATE_TRACKERS_DIRS="$GALLIUM_STATE_TRACKERS_DIRS egl"
+ HAVE_ST_EGL="yes"
fi
# Have only tested st/xorg on 1.6.0 servers
PKG_CHECK_MODULES(XORG, [xorg-server >= 1.6.0 libdrm >= $LIBDRM_XORG_REQUIRED libkms >= $LIBKMS_XORG_REQUIRED],
- HAVE_XORG="yes"; GALLIUM_STATE_TRACKERS_DIRS="$GALLIUM_STATE_TRACKERS_DIRS xorg",
- HAVE_XORG="no")
+ HAVE_ST_XORG="yes"; GALLIUM_STATE_TRACKERS_DIRS="$GALLIUM_STATE_TRACKERS_DIRS xorg",
+ HAVE_ST_XORG="no")
;;
esac
;;
@@ -1219,15 +1225,22 @@ yes)
AC_MSG_ERROR([state tracker '$tracker' doesn't exist])
case "$tracker" in
+ dri)
+ if test "x$mesa_driver" != xdri; then
+ AC_MSG_ERROR([cannot build dri state tracker without mesa driver set to dri])
+ fi
+ HAVE_ST_DRI="yes"
+ ;;
egl)
if test "x$enable_egl" != xyes; then
AC_MSG_ERROR([cannot build egl state tracker without EGL library])
fi
+ HAVE_ST_EGL="yes"
;;
xorg)
PKG_CHECK_MODULES([LIBDRM_XORG], [libdrm >= $LIBDRM_XORG_REQUIRED])
PKG_CHECK_MODULES([LIBKMS_XORG], [libkms >= $LIBKMS_XORG_REQUIRED])
- HAVE_XORG="yes"
+ HAVE_ST_XORG="yes"
;;
es)
# mesa/es is required to build es state tracker
@@ -1239,7 +1252,7 @@ yes)
;;
esac
-if test "x$HAVE_XORG" = xyes; then
+if test "x$HAVE_ST_XORG" = xyes; then
PKG_CHECK_MODULES(XEXT, [xextproto >= 7.0.99.1],
HAVE_XEXTPROTO_71="yes"; DEFINES="$DEFINES -DHAVE_XEXTPROTO_71",
HAVE_XEXTPROTO_71="no")
@@ -1303,6 +1316,25 @@ AC_ARG_WITH([max-height],
[AC_MSG_WARN([Large framebuffer: see s_tritemp.h comments.])])]
)
+dnl
+dnl Gallium helper functions
+dnl
+gallium_check_st() {
+ if test "x$HAVE_ST_DRI" = xyes || test "x$HAVE_ST_EGL" = xyes || test "x$HAVE_ST_XORG" = xyes; then
+ GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS $1"
+ fi
+ if test "x$HAVE_ST_DRI" = xyes && test "x$2" != x; then
+ GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS $2"
+ fi
+ if test "x$HAVE_ST_EGL" = xyes && test "x$3" != x; then
+ GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS $3"
+ fi
+ if test "x$HAVE_ST_XORG" = xyes && test "x$4" != x; then
+ GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS $4"
+ fi
+}
+
+
dnl
dnl Gallium SVGA configuration
dnl
@@ -1312,8 +1344,8 @@ AC_ARG_ENABLE([gallium-svga],
[enable_gallium_svga="$enableval"],
[enable_gallium_svga=auto])
if test "x$enable_gallium_svga" = xyes; then
- GALLIUM_WINSYS_DRM_DIRS="$GALLIUM_WINSYS_DRM_DIRS vmware"
GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS svga"
+ gallium_check_st "svga/drm" "dri-vmwgfx" "egl-vmwgfx" "xorg-vmwgfx"
elif test "x$enable_gallium_svga" = xauto; then
GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS svga"
fi
@@ -1327,8 +1359,8 @@ AC_ARG_ENABLE([gallium-intel],
[enable_gallium_intel="$enableval"],
[enable_gallium_intel=auto])
if test "x$enable_gallium_intel" = xyes; then
- GALLIUM_WINSYS_DRM_DIRS="$GALLIUM_WINSYS_DRM_DIRS intel i965"
GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS i915 i965"
+ gallium_check_st "i915/drm i965/drm" "dri-i915 dri-i965" "egl-i915 egl-i965" "xorg-i915 xorg-i965"
elif test "x$enable_gallium_intel" = xauto; then
GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS i915 i965"
fi
@@ -1342,8 +1374,8 @@ AC_ARG_ENABLE([gallium-radeon],
[enable_gallium_radeon="$enableval"],
[enable_gallium_radeon=auto])
if test "x$enable_gallium_radeon" = xyes; then
- GALLIUM_WINSYS_DRM_DIRS="$GALLIUM_WINSYS_DRM_DIRS radeon"
GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS r300"
+ gallium_check_st "radeon/drm" "dri-radeong" "egl-radeon" "xorg-radeon"
elif test "x$enable_gallium_radeon" = xauto; then
GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS r300"
fi
@@ -1357,8 +1389,8 @@ AC_ARG_ENABLE([gallium-nouveau],
[enable_gallium_nouveau="$enableval"],
[enable_gallium_nouveau=no])
if test "x$enable_gallium_nouveau" = xyes; then
- GALLIUM_WINSYS_DRM_DIRS="$GALLIUM_WINSYS_DRM_DIRS nouveau"
- GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS nouveau nv30 nv40 nv50"
+ GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS nouveau nvfx nv50"
+ gallium_check_st "nouveau/drm" "dri-nouveau" "egl-nouveau" "xorg-nouveau"
fi
dnl
@@ -1366,11 +1398,16 @@ dnl Gallium swrast configuration
dnl
AC_ARG_ENABLE([gallium-swrast],
[AS_HELP_STRING([--enable-gallium-swrast],
- [build gallium swrast @<:@default=disabled@:>@])],
+ [build gallium swrast @<:@default=auto@:>@])],
[enable_gallium_swrast="$enableval"],
[enable_gallium_swrast=auto])
-if test "x$enable_gallium_swrast" = xyes; then
- GALLIUM_WINSYS_DRM_DIRS="$GALLIUM_WINSYS_DRM_DIRS swrast"
+if test "x$enable_gallium_swrast" = xyes || test "x$enable_gallium_swrast" = xauto; then
+ if test "x$HAVE_ST_DRI" = xyes; then
+ GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS dri-swrast"
+ fi
+ if test "x$HAVE_ST_EGL" = xyes; then
+ GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS egl-swrast"
+ fi
fi
dnl prepend CORE_DIRS to SRC_DIRS
@@ -1426,8 +1463,8 @@ echo ""
if echo "$SRC_DIRS" | grep 'gallium' >/dev/null 2>&1; then
echo " Gallium: yes"
echo " Gallium dirs: $GALLIUM_DIRS"
+ echo " Target dirs: $GALLIUM_TARGET_DIRS"
echo " Winsys dirs: $GALLIUM_WINSYS_DIRS"
- echo " Winsys drm dirs:$GALLIUM_WINSYS_DRM_DIRS"
echo " Driver dirs: $GALLIUM_DRIVERS_DIRS"
echo " Trackers dirs: $GALLIUM_STATE_TRACKERS_DIRS"
else
diff --git a/docs/GL3.txt b/docs/GL3.txt
index 889edefbce1..78ac6e852dd 100644
--- a/docs/GL3.txt
+++ b/docs/GL3.txt
@@ -16,6 +16,7 @@ GLSL changes (GL_EXT_gpu_shader4, etc) not started
Conditional rendering (GL_NV_conditional_render) DONE (swrast & softpipe)
Map buffer subranges (GL_APPLE_flush_buffer_range) not started
Float textures, renderbuffers some infrastructure done
+ (incl. GL_EXT_packed_float, GL_EXT_shared_exponent)
Framebuffer objects (GL_EXT_framebuffer_object) DONE
Half-float some infrastructure done
Multisample blit DONE
@@ -25,7 +26,7 @@ Packed depth/stencil formats DONE
Per-buffer blend and masks (GL_EXT_draw_buffers2) DONE
GL_EXT_texture_compression_rgtc not started
Red and red/green texture formats Ian?
-Transform feedback (GL_EXT_transform_feedback) not started
+Transform feedback (GL_EXT_transform_feedback) ~50% done
Vertex array objects (GL_APPLE_vertex_array_object) DONE
sRGB framebuffer format (GL_EXT_framebuffer_sRGB) not started
glClearBuffer commands DONE, except for dispatch
@@ -39,7 +40,7 @@ glBindBufferRange, glBindBufferBase commands not started
GL 3.1:
GLSL 1.30 and 1.40 not started
-Instanced drawing (GL_ARB_draw_instanced) not started
+Instanced drawing (GL_ARB_draw_instanced) ~50% done
Buffer copying (GL_ARB_copy_buffer) DONE
Primitive restart (GL_NV_primitive_restart) not started
16 vertex texture image units not started
@@ -56,7 +57,7 @@ GLSL 1.50 not started
Geometry shaders (GL_ARB_geometry_shader4) partially done (Zack)
BGRA vertex order (GL_ARB_vertex_array_bgra) DONE
Base vertex offset(GL_ARB_draw_elements_base_vertex) DONE
-Frag shader coord (GL_ARB_fragment_coord_conventions) not started
+Frag shader coord (GL_ARB_fragment_coord_conventions) DONE (swrast, gallium)
Provoking vertex (GL_ARB_provoking_vertex) DONE
Seamless cubemaps (GL_ARB_seamless_cube_map) DONE, mostly?
Multisample textures (GL_ARB_texture_multisample) not started
diff --git a/docs/egl.html b/docs/egl.html
index 55907f6cfac..e960309fc47 100644
--- a/docs/egl.html
+++ b/docs/egl.html
@@ -106,11 +106,11 @@ noted that the classic libGL
is not a state tracker and cannot be
used with EGL (unless the EGL driver in use is egl_glx
). To build
the OpenGL state tracker, one may append glx
to
--with-state-trackers
and manually build
-src/gallium/winsys/xlib/
.
+src/gallium/targets/libgl-xlib/
.
Use EGL
- The demos for OpenGL ES and OpenVG can be found in progs/es1/
,
+
The demos for OpenGL ES and OpenVG can be found in progs/es1/
,
progs/es2/
and progs/openvg/
. You can use them to
test your build. For example,
diff --git a/docs/install.html b/docs/install.html
index 5aea92e0b51..3962ea5c91e 100644
--- a/docs/install.html
+++ b/docs/install.html
@@ -361,7 +361,7 @@ To build Mesa with SCons for Windows on Linux using the MinGW crosscompiler tool
This will create:
-build/windows-x86-debug/gallium/winsys/gdi/opengl32.dll — Mesa + Gallium + softpipe, binary compatible with Windows's opengl32.dll
+ build/windows-x86-debug/gallium/targets/libgl-gdi/opengl32.dll — Mesa + Gallium + softpipe, binary compatible with Windows's opengl32.dll
build/windows-x86-debug/glut/glx/glut32.dll
progs/build/windows-x86-debug/wgl/wglinfo.exe
progs/build/windows-x86-debug/trivial/tri.exe
diff --git a/docs/relnotes-7.9.html b/docs/relnotes-7.9.html
new file mode 100644
index 00000000000..f7d5016dc69
--- /dev/null
+++ b/docs/relnotes-7.9.html
@@ -0,0 +1,50 @@
+
+
+Mesa Release Notes
+
+
+
+
+
+
+
+Mesa 7.9 Release Notes / date TBD
+
+
+Mesa 7.9 is a new development release.
+People who are concerned with stability and reliability should stick
+with a previous release or wait for Mesa 7.9.1.
+
+
+Mesa 7.9 implements the OpenGL 2.1 API, but the version reported by
+glGetString(GL_VERSION) depends on the particular driver being used.
+Some drivers don't support all the features required in OpenGL 2.1.
+
+
+See the Compiling/Installing page for prerequisites
+for DRI hardware acceleration.
+
+
+
+MD5 checksums
+
+tbd
+
+
+
+New features
+
+
+
+Bug fixes
+
+
+
+Changes
+
+
+
+
diff --git a/include/GL/glut_h.dja b/include/GL/glut_h.dja
deleted file mode 100644
index e76dcb985e3..00000000000
--- a/include/GL/glut_h.dja
+++ /dev/null
@@ -1,340 +0,0 @@
-
-/*
- * Mesa 3-D graphics library
- * Version: 3.1
- * Copyright (C) 1995-1998 Brian Paul
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the Free
- * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-
-/*
- * This header file is based on the REAL glut.h by Mark J. Kilgard.
- *
- * The DJGPP/ALLEGRO (DJA) GLUT implementation was written by
- * Bernhard Tschirren (bernie-t@geocities.com) for the sole purpose
- * of compiling all the sample programs (which use GLUT). Therefore,
- * is NOT AT ALL a complete version of GLUT!
- */
-
-
-#ifndef __AGLUT_H__
-#define __AGLUT_H__
-
-#include
-#include
-
-#define GLUTCALLBACK
-#define APIENTRY
-#define GLUTAPI extern
-
-#define GLUT_RGB 0
-#define GLUT_RGBA GLUT_RGB
-#define GLUT_INDEX 1
-#define GLUT_SINGLE 0
-#define GLUT_DOUBLE 2
-#define GLUT_ACCUM 4
-#define GLUT_ALPHA 8
-#define GLUT_DEPTH 16
-#define GLUT_STENCIL 32
-
-/* Mouse buttons. */
-#define GLUT_LEFT_BUTTON 0
-#define GLUT_MIDDLE_BUTTON 1
-#define GLUT_RIGHT_BUTTON 2
-
-/* Mouse button state. */
-#define GLUT_DOWN 0
-#define GLUT_UP 1
-
-/* function keys */
-#define GLUT_KEY_F1 1
-#define GLUT_KEY_F2 2
-#define GLUT_KEY_F3 3
-#define GLUT_KEY_F4 4
-#define GLUT_KEY_F5 5
-#define GLUT_KEY_F6 6
-#define GLUT_KEY_F7 7
-#define GLUT_KEY_F8 8
-#define GLUT_KEY_F9 9
-#define GLUT_KEY_F10 10
-#define GLUT_KEY_F11 11
-#define GLUT_KEY_F12 12
-
-/* directional keys */
-#define GLUT_KEY_LEFT 100
-#define GLUT_KEY_UP 101
-#define GLUT_KEY_RIGHT 102
-#define GLUT_KEY_DOWN 103
-#define GLUT_KEY_PAGE_UP 104
-#define GLUT_KEY_PAGE_DOWN 105
-#define GLUT_KEY_HOME 106
-#define GLUT_KEY_END 107
-#define GLUT_KEY_INSERT 108
-
-/* Entry/exit state. */
-#define GLUT_LEFT 0
-#define GLUT_ENTERED 1
-
-/* Visibility state. */
-#define GLUT_NOT_VISIBLE 0
-#define GLUT_VISIBLE 1
-
-/* Color index component selection values. */
-#define GLUT_RED 0
-#define GLUT_GREEN 1
-#define GLUT_BLUE 2
-
-/* Layers for use. */
-#define GLUT_NORMAL 0
-#define GLUT_OVERLAY 1
-
-/* Stroke font constants (use these in GLUT program). */
-#define GLUT_STROKE_ROMAN ((void*)0)
-#define GLUT_STROKE_MONO_ROMAN ((void*)1)
-
-/* Bitmap font constants (use these in GLUT program). */
-#define GLUT_BITMAP_9_BY_15 ((void*)2)
-#define GLUT_BITMAP_8_BY_13 ((void*)3)
-#define GLUT_BITMAP_TIMES_ROMAN_10 ((void*)4)
-#define GLUT_BITMAP_TIMES_ROMAN_24 ((void*)5)
-#define GLUT_BITMAP_HELVETICA_10 ((void*)6)
-#define GLUT_BITMAP_HELVETICA_12 ((void*)7)
-#define GLUT_BITMAP_HELVETICA_18 ((void*)8)
-
-/* glutGet parameters. */
-#define GLUT_WINDOW_X 100
-#define GLUT_WINDOW_Y 101
-#define GLUT_WINDOW_WIDTH 102
-#define GLUT_WINDOW_HEIGHT 103
-#define GLUT_WINDOW_BUFFER_SIZE 104
-#define GLUT_WINDOW_STENCIL_SIZE 105
-#define GLUT_WINDOW_DEPTH_SIZE 106
-#define GLUT_WINDOW_RED_SIZE 107
-#define GLUT_WINDOW_GREEN_SIZE 108
-#define GLUT_WINDOW_BLUE_SIZE 109
-#define GLUT_WINDOW_ALPHA_SIZE 110
-#define GLUT_WINDOW_ACCUM_RED_SIZE 111
-#define GLUT_WINDOW_ACCUM_GREEN_SIZE 112
-#define GLUT_WINDOW_ACCUM_BLUE_SIZE 113
-#define GLUT_WINDOW_ACCUM_ALPHA_SIZE 114
-#define GLUT_WINDOW_DOUBLEBUFFER 115
-#define GLUT_WINDOW_RGBA 116
-#define GLUT_WINDOW_PARENT 117
-#define GLUT_WINDOW_NUM_CHILDREN 118
-#define GLUT_WINDOW_COLORMAP_SIZE 119
-#define GLUT_WINDOW_NUM_SAMPLES 120
-#define GLUT_WINDOW_STEREO 121
-#define GLUT_WINDOW_CURSOR 122
-#define GLUT_SCREEN_WIDTH 200
-#define GLUT_SCREEN_HEIGHT 201
-#define GLUT_SCREEN_WIDTH_MM 202
-#define GLUT_SCREEN_HEIGHT_MM 203
-#define GLUT_MENU_NUM_ITEMS 300
-#define GLUT_DISPLAY_MODE_POSSIBLE 400
-#define GLUT_INIT_WINDOW_X 500
-#define GLUT_INIT_WINDOW_Y 501
-#define GLUT_INIT_WINDOW_WIDTH 502
-#define GLUT_INIT_WINDOW_HEIGHT 503
-#define GLUT_INIT_DISPLAY_MODE 504
-#define GLUT_ELAPSED_TIME 700
-#define GLUT_WINDOW_FORMAT_ID 123
-
-/* glutDeviceGet parameters. */
-#define GLUT_HAS_KEYBOARD 600
-#define GLUT_HAS_MOUSE 601
-#define GLUT_HAS_SPACEBALL 602
-#define GLUT_HAS_DIAL_AND_BUTTON_BOX 603
-#define GLUT_HAS_TABLET 604
-#define GLUT_NUM_MOUSE_BUTTONS 605
-#define GLUT_NUM_SPACEBALL_BUTTONS 606
-#define GLUT_NUM_BUTTON_BOX_BUTTONS 607
-#define GLUT_NUM_DIALS 608
-#define GLUT_NUM_TABLET_BUTTONS 609
-#define GLUT_DEVICE_IGNORE_KEY_REPEAT 610
-#define GLUT_DEVICE_KEY_REPEAT 611
-#define GLUT_HAS_JOYSTICK 612
-#define GLUT_OWNS_JOYSTICK 613
-#define GLUT_JOYSTICK_BUTTONS 614
-#define GLUT_JOYSTICK_AXES 615
-#define GLUT_JOYSTICK_POLL_RATE 616
-
-/* glutLayerGet parameters. */
-#define GLUT_OVERLAY_POSSIBLE 800
-#define GLUT_LAYER_IN_USE 801
-#define GLUT_HAS_OVERLAY 802
-#define GLUT_TRANSPARENT_INDEX 803
-#define GLUT_NORMAL_DAMAGED 804
-#define GLUT_OVERLAY_DAMAGED 805
-
-/* glutVideoResizeGet parameters. */
-#define GLUT_VIDEO_RESIZE_POSSIBLE 900
-#define GLUT_VIDEO_RESIZE_IN_USE 901
-#define GLUT_VIDEO_RESIZE_X_DELTA 902
-#define GLUT_VIDEO_RESIZE_Y_DELTA 903
-#define GLUT_VIDEO_RESIZE_WIDTH_DELTA 904
-#define GLUT_VIDEO_RESIZE_HEIGHT_DELTA 905
-#define GLUT_VIDEO_RESIZE_X 906
-#define GLUT_VIDEO_RESIZE_Y 907
-#define GLUT_VIDEO_RESIZE_WIDTH 908
-#define GLUT_VIDEO_RESIZE_HEIGHT 909
-
-/* glutUseLayer parameters. */
-#define GLUT_NORMAL 0
-#define GLUT_OVERLAY 1
-
-/* glutGetModifiers return mask. */
-#define GLUT_ACTIVE_SHIFT 1
-#define GLUT_ACTIVE_CTRL 2
-#define GLUT_ACTIVE_ALT 4
-
-/* glutSetCursor parameters. */
-/* Basic arrows. */
-#define GLUT_CURSOR_RIGHT_ARROW 0
-#define GLUT_CURSOR_LEFT_ARROW 1
-/* Symbolic cursor shapes. */
-#define GLUT_CURSOR_INFO 2
-#define GLUT_CURSOR_DESTROY 3
-#define GLUT_CURSOR_HELP 4
-#define GLUT_CURSOR_CYCLE 5
-#define GLUT_CURSOR_SPRAY 6
-#define GLUT_CURSOR_WAIT 7
-#define GLUT_CURSOR_TEXT 8
-#define GLUT_CURSOR_CROSSHAIR 9
-/* Directional cursors. */
-#define GLUT_CURSOR_UP_DOWN 10
-#define GLUT_CURSOR_LEFT_RIGHT 11
-/* Sizing cursors. */
-#define GLUT_CURSOR_TOP_SIDE 12
-#define GLUT_CURSOR_BOTTOM_SIDE 13
-#define GLUT_CURSOR_LEFT_SIDE 14
-#define GLUT_CURSOR_RIGHT_SIDE 15
-#define GLUT_CURSOR_TOP_LEFT_CORNER 16
-#define GLUT_CURSOR_TOP_RIGHT_CORNER 17
-#define GLUT_CURSOR_BOTTOM_RIGHT_CORNER 18
-#define GLUT_CURSOR_BOTTOM_LEFT_CORNER 19
-/* Inherit from parent window. */
-#define GLUT_CURSOR_INHERIT 100
-/* Blank cursor. */
-#define GLUT_CURSOR_NONE 101
-/* Fullscreen crosshair (if available). */
-#define GLUT_CURSOR_FULL_CROSSHAIR 102
-
-/* GLUT initialization sub-API. */
-GLUTAPI void APIENTRY glutInit(int *argcp, char **argv);
-GLUTAPI void APIENTRY glutInitDisplayMode(unsigned int mode);
-GLUTAPI void APIENTRY glutInitWindowPosition(int x, int y);
-GLUTAPI void APIENTRY glutInitWindowSize(int width, int height);
-GLUTAPI void APIENTRY glutMainLoop(void);
-
-/* GLUT window sub-API. */
-GLUTAPI int APIENTRY glutCreateWindow(const char *title);
-GLUTAPI int APIENTRY glutCreateSubWindow(int win, int x, int y, int width, int height);
-GLUTAPI void APIENTRY glutDestroyWindow(int win);
-GLUTAPI void APIENTRY glutPostRedisplay(void);
-GLUTAPI void APIENTRY glutSwapBuffers(void);
-GLUTAPI int APIENTRY glutGetWindow(void);
-GLUTAPI void APIENTRY glutSetWindow(int win);
-GLUTAPI void APIENTRY glutSetWindowTitle(const char *title);
-GLUTAPI void APIENTRY glutSetIconTitle(const char *title);
-GLUTAPI void APIENTRY glutPositionWindow(int x, int y);
-GLUTAPI void APIENTRY glutReshapeWindow(int width, int height);
-GLUTAPI void APIENTRY glutPopWindow(void);
-GLUTAPI void APIENTRY glutPushWindow(void);
-GLUTAPI void APIENTRY glutIconifyWindow(void);
-GLUTAPI void APIENTRY glutShowWindow(void);
-GLUTAPI void APIENTRY glutHideWindow(void);
-
-/* GLUT overlay sub-API. */
-GLUTAPI void APIENTRY glutEstablishOverlay(void);
-GLUTAPI void APIENTRY glutRemoveOverlay(void);
-GLUTAPI void APIENTRY glutUseLayer(GLenum layer);
-GLUTAPI void APIENTRY glutPostOverlayRedisplay(void);
-GLUTAPI void APIENTRY glutShowOverlay(void);
-GLUTAPI void APIENTRY glutHideOverlay(void);
-
-/* GLUT menu sub-API. */
-GLUTAPI int APIENTRY glutCreateMenu(void (GLUTCALLBACK *)(int));
-GLUTAPI void APIENTRY glutDestroyMenu(int menu);
-GLUTAPI int APIENTRY glutGetMenu(void);
-GLUTAPI void APIENTRY glutSetMenu(int menu);
-GLUTAPI void APIENTRY glutAddMenuEntry(const char *label, int value);
-GLUTAPI void APIENTRY glutAddSubMenu(const char *label, int submenu);
-GLUTAPI void APIENTRY glutChangeToMenuEntry(int item, const char *label, int value);
-GLUTAPI void APIENTRY glutChangeToSubMenu(int item, const char *label, int submenu);
-GLUTAPI void APIENTRY glutRemoveMenuItem(int item);
-GLUTAPI void APIENTRY glutAttachMenu(int button);
-GLUTAPI void APIENTRY glutDetachMenu(int button);
-
-/* GLUT window callback sub-API. */
-GLUTAPI void APIENTRY glutDisplayFunc(void (GLUTCALLBACK * func)(void));
-GLUTAPI void APIENTRY glutReshapeFunc(void (GLUTCALLBACK * func)(int width, int height));
-GLUTAPI void APIENTRY glutKeyboardFunc(void (GLUTCALLBACK * func)(unsigned char key, int x, int y));
-GLUTAPI void APIENTRY glutMouseFunc(void (GLUTCALLBACK * func)(int button, int state, int x, int y));
-GLUTAPI void APIENTRY glutMotionFunc(void (GLUTCALLBACK * func)(int x, int y));
-GLUTAPI void APIENTRY glutPassiveMotionFunc(void (GLUTCALLBACK * func)(int x, int y));
-GLUTAPI void APIENTRY glutEntryFunc(void (GLUTCALLBACK * func)(int state));
-GLUTAPI void APIENTRY glutVisibilityFunc(void (GLUTCALLBACK * func)(int state));
-GLUTAPI void APIENTRY glutIdleFunc(void (GLUTCALLBACK * func)(void));
-GLUTAPI void APIENTRY glutTimerFunc(unsigned int millis, void (GLUTCALLBACK * func)(int value), int value);
-GLUTAPI void APIENTRY glutMenuStateFunc(void (GLUTCALLBACK * func)(int state));
-GLUTAPI void APIENTRY glutSpecialFunc(void (GLUTCALLBACK * func)(int key, int x, int y));
-GLUTAPI void APIENTRY glutSpaceballMotionFunc(void (GLUTCALLBACK * func)(int x, int y, int z));
-GLUTAPI void APIENTRY glutSpaceballRotateFunc(void (GLUTCALLBACK * func)(int x, int y, int z));
-GLUTAPI void APIENTRY glutSpaceballButtonFunc(void (GLUTCALLBACK * func)(int button, int state));
-GLUTAPI void APIENTRY glutButtonBoxFunc(void (GLUTCALLBACK * func)(int button, int state));
-GLUTAPI void APIENTRY glutDialsFunc(void (GLUTCALLBACK * func)(int dial, int value));
-GLUTAPI void APIENTRY glutTabletMotionFunc(void (GLUTCALLBACK * func)(int x, int y));
-GLUTAPI void APIENTRY glutTabletButtonFunc(void (GLUTCALLBACK * func)(int button, int state, int x, int y));
-GLUTAPI void APIENTRY glutMenuStatusFunc(void (GLUTCALLBACK * func)(int status, int x, int y));
-GLUTAPI void APIENTRY glutOverlayDisplayFunc(void (GLUTCALLBACK * func)(void));
-GLUTAPI void APIENTRY glutWindowStatusFunc(void (GLUTCALLBACK * func)(int state));
-
-/* GLUT color index sub-API. */
-GLUTAPI void APIENTRY glutSetColor(int, GLfloat red, GLfloat green, GLfloat blue);
-GLUTAPI GLfloat APIENTRY glutGetColor(int ndx, int component);
-GLUTAPI void APIENTRY glutCopyColormap(int win);
-
-/* GLUT state retrieval sub-API. */
-GLUTAPI int APIENTRY glutGet(GLenum type);
-GLUTAPI int APIENTRY glutDeviceGet(GLenum type);
-
-/* GLUT font sub-API */
-GLUTAPI void APIENTRY glutBitmapCharacter(void *font, int character);
-GLUTAPI int APIENTRY glutBitmapWidth(void *font, int character);
-GLUTAPI void APIENTRY glutStrokeCharacter(void *font, int character);
-GLUTAPI int APIENTRY glutStrokeWidth(void *font, int character);
-
-/* GLUT pre-built models sub-API */
-GLUTAPI void APIENTRY glutWireSphere(GLdouble radius, GLint slices, GLint stacks);
-GLUTAPI void APIENTRY glutSolidSphere(GLdouble radius, GLint slices, GLint stacks);
-GLUTAPI void APIENTRY glutWireCone(GLdouble base, GLdouble height, GLint slices, GLint stacks);
-GLUTAPI void APIENTRY glutSolidCone(GLdouble base, GLdouble height, GLint slices, GLint stacks);
-GLUTAPI void APIENTRY glutWireCube(GLdouble size);
-GLUTAPI void APIENTRY glutSolidCube(GLdouble size);
-GLUTAPI void APIENTRY glutWireTorus(GLdouble innerRadius, GLdouble outerRadius, GLint sides, GLint rings);
-GLUTAPI void APIENTRY glutSolidTorus(GLdouble innerRadius, GLdouble outerRadius, GLint sides, GLint rings);
-GLUTAPI void APIENTRY glutWireDodecahedron(void);
-GLUTAPI void APIENTRY glutSolidDodecahedron(void);
-GLUTAPI void APIENTRY glutWireTeapot(GLdouble size);
-GLUTAPI void APIENTRY glutSolidTeapot(GLdouble size);
-GLUTAPI void APIENTRY glutWireOctahedron(void);
-GLUTAPI void APIENTRY glutSolidOctahedron(void);
-GLUTAPI void APIENTRY glutWireTetrahedron(void);
-GLUTAPI void APIENTRY glutSolidTetrahedron(void);
-GLUTAPI void APIENTRY glutWireIcosahedron(void);
-GLUTAPI void APIENTRY glutSolidIcosahedron(void);
-
-#endif /* __AGLUT_H__ */
diff --git a/include/GL/internal/dri_interface.h b/include/GL/internal/dri_interface.h
index 1d4e82e154a..fa9b7c4bf21 100644
--- a/include/GL/internal/dri_interface.h
+++ b/include/GL/internal/dri_interface.h
@@ -41,7 +41,13 @@
#define DRI_INTERFACE_H
/* For archs with no drm.h */
-#if !defined(__APPLE__) && !defined(__CYGWIN__) && !defined(__GNU__)
+#if defined(__APPLE__) || defined(__CYGWIN__) || defined(__GNU__)
+#ifndef __NOT_HAVE_DRM_H
+#define __NOT_HAVE_DRM_H
+#endif
+#endif
+
+#ifndef __NOT_HAVE_DRM_H
#include
#else
typedef unsigned int drm_context_t;
@@ -410,15 +416,15 @@ struct __DRIswrastLoaderExtensionRec {
* Put image to drawable
*/
void (*putImage)(__DRIdrawable *drawable, int op,
- int x, int y, int width, int height, char *data,
- void *loaderPrivate);
+ int x, int y, int width, int height,
+ char *data, void *loaderPrivate);
/**
- * Get image from drawable
+ * Get image from readable
*/
- void (*getImage)(__DRIdrawable *drawable,
- int x, int y, int width, int height, char *data,
- void *loaderPrivate);
+ void (*getImage)(__DRIdrawable *readable,
+ int x, int y, int width, int height,
+ char *data, void *loaderPrivate);
};
/**
diff --git a/include/GL/mglmesa.h b/include/GL/mglmesa.h
deleted file mode 100644
index 0f9f7895714..00000000000
--- a/include/GL/mglmesa.h
+++ /dev/null
@@ -1,79 +0,0 @@
-/****************************************************************************
-*
-* Mesa bindings for SciTech MGL
-*
-* Copyright (C) 1996 SciTech Software.
-* All rights reserved.
-*
-* Filename: mglmesa.h
-* Version: Revision: 1.1.1.1
-*
-* Language: ANSI C
-* Environment: Any
-*
-* Description: Header file for the Mesa/OpenGL interface bindings for the
-* SciTech MGL graphics library. Uses the MGL internal
-* device context structures to get direct access to the
-* high performance MGL rasterization functions for maximum
-* performance. Utilizes the VESA VBE/AF Accelerator Functions
-* via the MGL's accelerated device driver functions, as well
-* as basic DirectDraw accelerated functions provided by the
-* MGL.
-*
-* This library is free software; you can redistribute it and/or
-* modify it under the terms of the GNU Library General Public
-* License as published by the Free Software Foundation; either
-* version 2 of the License, or (at your option) any later version.
-*
-* This library is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Library General Public License for more details.
-*
-* You should have received a copy of the GNU Library General Public
-* License along with this library; if not, write to the Free
-* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*
-*
-****************************************************************************/
-
-#ifndef __MGLMESA_H
-#define __MGLMESA_H
-
-#include "mgraph.h"
-
-/*------------------------- Function Prototypes ---------------------------*/
-
-#ifdef __cplusplus
-extern "C" { /* Use "C" linkage when in C++ mode */
-#endif
-
-#ifndef __WINDOWS__
-#define GLAPIENTRY
-#endif
-
-#ifdef __WINDOWS__
-bool GLAPIENTRY MGLMesaInitDLL(MGLCallbacks *cb,char *version);
-#endif
-void GLAPIENTRY MGLMesaChooseVisual(MGLDC *dc,MGLVisual *visual);
-bool GLAPIENTRY MGLMesaSetVisual(MGLDC *dc,MGLVisual *visual);
-bool GLAPIENTRY MGLMesaCreateContext(MGLDC *dc,bool forceMemDC);
-void GLAPIENTRY MGLMesaDestroyContext(MGLDC *dc);
-void GLAPIENTRY MGLMesaMakeCurrent(MGLDC *dc);
-void GLAPIENTRY MGLMesaSwapBuffers(MGLDC *dc,bool waitVRT);
-
-/* Palette manipulation support. The reason we provide palette manipulation
- * routines is so that when rendering in double buffered modes with a
- * software backbuffer, the palette for the backbuffer is kept consistent
- * with the hardware front buffer.
- */
-
-void GLAPIENTRY MGLMesaSetPaletteEntry(MGLDC *dc,int entry,uchar red,uchar green,uchar blue);
-void GLAPIENTRY MGLMesaSetPalette(MGLDC *dc,palette_t *pal,int numColors,int startIndex);
-void GLAPIENTRY MGLMesaRealizePalette(MGLDC *dc,int numColors,int startIndex,int waitVRT);
-
-#ifdef __cplusplus
-} /* End of "C" linkage for C++ */
-#endif /* __cplusplus */
-
-#endif /* __MGLMESA_H */
diff --git a/progs/SConscript b/progs/SConscript
index aa6640cf7a6..4cd35fec646 100644
--- a/progs/SConscript
+++ b/progs/SConscript
@@ -24,6 +24,7 @@ if progs_env['platform'] == 'windows':
if progs_env['platform'] == 'windows':
progs_env.Prepend(LIBS = ['glu32', 'opengl32'])
else:
+ progs_env.Tool('x11')
progs_env.Prepend(LIBS = ['GLU', 'GL'])
# Glut
@@ -56,4 +57,5 @@ SConscript([
'wgl/SConscript',
'perf/SConscript',
'gallium/unit/SConscript',
+# 'gallium/raw/SConscript',
])
diff --git a/progs/demos/dissolve.c b/progs/demos/dissolve.c
index 0b8df1bb669..8ab5242d91c 100644
--- a/progs/demos/dissolve.c
+++ b/progs/demos/dissolve.c
@@ -1,5 +1,5 @@
/**
- * Dissolve between two images using randomized stencil buffer
+ * Dissolve between two images using randomized/patterned stencil buffer
* and varying stencil ref.
*
* Brian Paul
@@ -9,6 +9,7 @@
#include
#include
+#include
#include
#include
#include "readtex.h"
@@ -28,6 +29,8 @@ static GLfloat ScaleX[2], ScaleY[2];
static GLubyte StencilRef = 0;
+static int Mode = 0;
+
static void
Idle(void)
@@ -38,13 +41,114 @@ Idle(void)
static void
-RandomizeStencilBuffer(void)
+FillRandomPixels(GLubyte *b)
{
- GLubyte *b = malloc(WinWidth * WinHeight);
int i;
for (i = 0; i < WinWidth * WinHeight; i++) {
b[i] = rand() & 0xff;
}
+}
+
+
+static void
+FillRandomRects(GLubyte *b)
+{
+ int i;
+
+ memset(b, 0, WinWidth * WinHeight);
+
+ for (i = 0; i < 256; i++) {
+ int x = rand() % WinWidth;
+ int y = rand() % WinHeight;
+ int w = rand() % 60;
+ int h = rand() % 60;
+ int ix, iy;
+
+ if (x + w > WinWidth)
+ w = WinWidth - x;
+ if (y + h > WinHeight)
+ h = WinHeight - y;
+
+ for (iy = 0; iy < h; iy++) {
+ for (ix = 0; ix < w; ix++) {
+ int p = (y + iy) * WinWidth + x + ix;
+ b[p] = i;
+ }
+ }
+ }
+}
+
+
+static void
+FillWipe(GLubyte *b)
+{
+ int iy, ix;
+
+ memset(b, 0, WinWidth * WinHeight);
+
+ for (iy = 0; iy < WinHeight; iy++) {
+ for (ix = 0; ix < WinWidth; ix++) {
+ int p = iy * WinWidth + ix;
+ b[p] = 2 * ix + iy / 2;
+ }
+ }
+}
+
+
+static void
+FillMoire(GLubyte *b)
+{
+ int iy, ix;
+
+ memset(b, 0, WinWidth * WinHeight);
+
+ for (iy = 0; iy < WinHeight; iy++) {
+ for (ix = 0; ix < WinWidth; ix++) {
+ int p = iy * WinWidth + ix;
+ b[p] = (ix / 2) * (ix / 2) - (iy / 2) * (iy / 2);
+ }
+ }
+}
+
+
+static void
+FillWaves(GLubyte *b)
+{
+ int iy, ix;
+
+ memset(b, 0, WinWidth * WinHeight);
+
+ for (iy = 0; iy < WinHeight; iy++) {
+ for (ix = 0; ix < WinWidth; ix++) {
+ int p = iy * WinWidth + ix;
+ float x = 8.0 * 3.1415 * ix / (float) WinWidth;
+ b[p] = (int) (25.0 * sin(x) ) - iy*2;
+ }
+ }
+}
+
+
+typedef void (*FillFunc)(GLubyte *b);
+
+
+static FillFunc Funcs[] = {
+ FillRandomPixels,
+ FillRandomRects,
+ FillWipe,
+ FillMoire,
+ FillWaves
+};
+
+#define NUM_MODES (sizeof(Funcs) / sizeof(Funcs[0]))
+
+
+
+static void
+InitStencilBuffer(void)
+{
+ GLubyte *b = malloc(WinWidth * WinHeight);
+
+ Funcs[Mode](b);
glStencilFunc(GL_ALWAYS, 0, ~0);
glPixelZoom(1.0, 1.0);
@@ -54,7 +158,6 @@ RandomizeStencilBuffer(void)
}
-
static void
Draw(void)
{
@@ -85,7 +188,7 @@ Reshape(int width, int height)
glLoadIdentity();
glTranslatef(0.0, 0.0, -15.0);
- RandomizeStencilBuffer();
+ InitStencilBuffer();
ScaleX[0] = (float) width / ImgWidth[0];
ScaleY[0] = (float) height / ImgHeight[0];
@@ -102,12 +205,26 @@ Key(unsigned char key, int x, int y)
(void) y;
switch (key) {
case 'a':
+ case ' ':
Anim = !Anim;
if (Anim)
glutIdleFunc(Idle);
else
glutIdleFunc(NULL);
break;
+ case 'i':
+ InitStencilBuffer();
+ break;
+ case '-':
+ StencilRef--;
+ break;
+ case '+':
+ StencilRef++;
+ break;
+ case 'm':
+ Mode = (Mode + 1) % NUM_MODES;
+ InitStencilBuffer();
+ break;
case 27:
glutDestroyWindow(Win);
exit(0);
@@ -143,8 +260,8 @@ Init(void)
int
main(int argc, char *argv[])
{
- glutInit(&argc, argv);
glutInitWindowSize(WinWidth, WinHeight);
+ glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_STENCIL);
Win = glutCreateWindow(argv[0]);
glutReshapeFunc(Reshape);
@@ -153,6 +270,14 @@ main(int argc, char *argv[])
if (Anim)
glutIdleFunc(Idle);
Init();
+
+ printf("Keys:\n");
+ printf(" a/SPACE toggle animation\n");
+ printf(" +/- single step\n");
+ printf(" i re-init pattern\n");
+ printf(" m change pattern/dissolve mode\n");
+ printf(" ESC exit\n");
+
glutMainLoop();
return 0;
}
diff --git a/progs/demos/stex3d.c b/progs/demos/stex3d.c
index c0bbea0960f..de18480c25e 100644
--- a/progs/demos/stex3d.c
+++ b/progs/demos/stex3d.c
@@ -36,6 +36,7 @@ static int tex_width=64, tex_height=64, tex_depth=64;
static float angx=0, angy=0, angz=0;
static int texgen = 2, animate = 1, smooth = 1, wireframe = 0;
static int CurTexture = NOISE_TEXTURE, CurObject = TORUS;
+static GLenum Filter = GL_LINEAR;
static void
@@ -298,8 +299,6 @@ create3Dtexture(void)
printf("setting up 3d texture...\n");
glBindTexture(GL_TEXTURE_3D, NOISE_TEXTURE);
- glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_REPEAT);
@@ -406,6 +405,9 @@ drawScene(void)
glDisable(GL_TEXTURE_GEN_R);
}
+ glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, Filter);
+ glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, Filter);
+
glCallList(CurObject);
glPopMatrix();
@@ -505,6 +507,12 @@ KeyHandler(unsigned char key, int x, int y)
else
CurObject = TORUS;
break;
+ case 'f':
+ if (Filter == GL_LINEAR)
+ Filter = GL_NEAREST;
+ else
+ Filter = GL_LINEAR;
+ break;
case 'i':
if (CurTexture == NOISE_TEXTURE)
CurTexture = GRADIENT_TEXTURE;
@@ -513,6 +521,7 @@ KeyHandler(unsigned char key, int x, int y)
glBindTexture(GL_TEXTURE_3D, CurTexture);
break;
case 'a':
+ case ' ':
animate = !animate;
if (animate)
glutIdleFunc(Idle);
@@ -559,8 +568,6 @@ create3Dgradient(void)
glBindTexture(GL_TEXTURE_3D, GRADIENT_TEXTURE);
- glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_REPEAT);
diff --git a/progs/egl/.gitignore b/progs/egl/.gitignore
deleted file mode 100644
index 7a13d4686a0..00000000000
--- a/progs/egl/.gitignore
+++ /dev/null
@@ -1,12 +0,0 @@
-demo1
-demo2
-demo3
-eglgears
-eglinfo
-eglscreen
-egltri
-peglgears
-xeglbindtex
-xeglgears
-xeglthreads
-xegl_tri
diff --git a/progs/egl/Makefile b/progs/egl/Makefile
deleted file mode 100644
index 25de6e1f703..00000000000
--- a/progs/egl/Makefile
+++ /dev/null
@@ -1,70 +0,0 @@
-# progs/egl/Makefile
-
-TOP = ../..
-include $(TOP)/configs/current
-
-
-INCLUDE_DIRS = -I$(TOP)/include
-
-HEADERS = $(TOP)/include/GLES/egl.h
-LIB_DEP = $(TOP)/$(LIB_DIR)/libEGL.so
-
-LIBS = -L$(TOP)/$(LIB_DIR) -lEGL -lGL
-
-PROGRAMS = \
- demo1 \
- demo2 \
- demo3 \
- egltri \
- eglinfo \
- eglgears \
- eglscreen \
- peglgears \
- xeglgears \
- xeglthreads \
- xegl_tri
-
-
-.c.o:
- $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $< -o $@
-
-
-
-default: $(PROGRAMS)
-
-demo1: demo1.o $(HEADERS) $(LIB_DEP)
- $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB)
-
-demo2: demo2.o $(HEADERS) $(LIB_DEP)
- $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB)
-
-demo3: demo3.o $(HEADERS) $(LIB_DEP)
- $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB)
-
-egltri: egltri.o $(HEADERS) $(LIB_DEP)
- $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB)
-
-eglinfo: eglinfo.o $(HEADERS) $(LIB_DEP)
- $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS)
-
-eglgears: eglgears.o $(HEADERS) $(LIB_DEP)
- $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB) -lm
-
-eglscreen: eglscreen.o $(HEADERS) $(LIB_DEP)
- $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB)
-
-peglgears: peglgears.o $(HEADERS) $(LIB_DEP)
- $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB) -lm
-
-xeglgears: xeglgears.o $(HEADERS) $(LIB_DEP)
- $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lm -L$(libdir) -lX11
-
-xeglthreads: xeglthreads.o $(HEADERS) $(LIB_DEP)
- $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lm -L$(libdir) -lX11
-
-xegl_tri: xegl_tri.o $(HEADERS) $(LIB_DEP)
- $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lm -L$(libdir) -lX11
-
-clean:
- -rm -f *.o *~
- -rm -f $(PROGRAMS)
diff --git a/progs/egl/demo1.c b/progs/egl/demo1.c
deleted file mode 100644
index d892734ee55..00000000000
--- a/progs/egl/demo1.c
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * Exercise EGL API functions
- */
-
-#define EGL_EGLEXT_PROTOTYPES
-
-#include
-#include
-#include
-#include
-#include
-#include
-
-
-/**
- * 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/demo2.c b/progs/egl/demo2.c
deleted file mode 100644
index b9e92f62ac2..00000000000
--- a/progs/egl/demo2.c
+++ /dev/null
@@ -1,216 +0,0 @@
-/*
- * Exercise EGL API functions
- */
-
-#define EGL_EGLEXT_PROTOTYPES
-
-#include
-#include
-#include
-#include
-#include
-
-#include
-#include
-#include
-
-/*#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/demo3.c b/progs/egl/demo3.c
deleted file mode 100644
index 64b9ee652cd..00000000000
--- a/progs/egl/demo3.c
+++ /dev/null
@@ -1,647 +0,0 @@
-/*
- * Exercise EGL API functions
- */
-
-#define EGL_EGLEXT_PROTOTYPES
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-
-
-#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=0; y--) {
- for (x=0; x
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#define MAX_CONFIGS 10
-#define MAX_MODES 100
-
-#define BENCHMARK
-
-#ifdef BENCHMARK
-
-/* XXX this probably isn't very portable */
-
-#include
-#include
-
-/* return current time (in seconds) */
-static double
-current_time(void)
-{
- struct timeval tv;
-#ifdef __VMS
- (void) gettimeofday(&tv, NULL );
-#else
- struct timezone tz;
- (void) gettimeofday(&tv, &tz);
-#endif
- return (double) tv.tv_sec + tv.tv_usec / 1000000.0;
-}
-
-#else /*BENCHMARK*/
-
-/* dummy */
-static double
-current_time(void)
-{
- /* update this function for other platforms! */
- static double t = 0.0;
- static int warn = 1;
- if (warn) {
- fprintf(stderr, "Warning: current_time() not implemented!!\n");
- warn = 0;
- }
- return t += 1.0;
-}
-
-#endif /*BENCHMARK*/
-
-
-#ifndef M_PI
-#define M_PI 3.14159265
-#endif
-
-
-static GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0;
-static GLint gear1, gear2, gear3;
-static GLfloat angle = 0.0;
-
-#if 0
-static GLfloat eyesep = 5.0; /* Eye separation. */
-static GLfloat fix_point = 40.0; /* Fixation point distance. */
-static GLfloat left, right, asp; /* Stereo frustum params. */
-#endif
-
-
-/*
- *
- * Draw a gear wheel. You'll probably want to call this function when
- * building a display list since we do a lot of trig here.
- *
- * Input: inner_radius - radius of hole at center
- * outer_radius - radius at center of teeth
- * width - width of gear
- * teeth - number of teeth
- * tooth_depth - depth of tooth
- */
-static void
-gear(GLfloat inner_radius, GLfloat outer_radius, GLfloat width,
- GLint teeth, GLfloat tooth_depth)
-{
- GLint i;
- GLfloat r0, r1, r2;
- GLfloat angle, da;
- GLfloat u, v, len;
-
- r0 = inner_radius;
- r1 = outer_radius - tooth_depth / 2.0;
- r2 = outer_radius + tooth_depth / 2.0;
-
- da = 2.0 * M_PI / teeth / 4.0;
-
- glShadeModel(GL_FLAT);
-
- glNormal3f(0.0, 0.0, 1.0);
-
- /* draw front face */
- glBegin(GL_QUAD_STRIP);
- for (i = 0; i <= teeth; i++) {
- angle = i * 2.0 * M_PI / teeth;
- glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
- glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
- if (i < teeth) {
- glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
- glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
- width * 0.5);
- }
- }
- glEnd();
-
- /* draw front sides of teeth */
- glBegin(GL_QUADS);
- da = 2.0 * M_PI / teeth / 4.0;
- for (i = 0; i < teeth; i++) {
- angle = i * 2.0 * M_PI / teeth;
-
- glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
- glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5);
- glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
- width * 0.5);
- glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
- width * 0.5);
- }
- glEnd();
-
- glNormal3f(0.0, 0.0, -1.0);
-
- /* draw back face */
- glBegin(GL_QUAD_STRIP);
- for (i = 0; i <= teeth; i++) {
- angle = i * 2.0 * M_PI / teeth;
- glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
- glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
- if (i < teeth) {
- glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
- -width * 0.5);
- glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
- }
- }
- glEnd();
-
- /* draw back sides of teeth */
- glBegin(GL_QUADS);
- da = 2.0 * M_PI / teeth / 4.0;
- for (i = 0; i < teeth; i++) {
- angle = i * 2.0 * M_PI / teeth;
-
- glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
- -width * 0.5);
- glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
- -width * 0.5);
- glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5);
- glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
- }
- glEnd();
-
- /* draw outward faces of teeth */
- glBegin(GL_QUAD_STRIP);
- for (i = 0; i < teeth; i++) {
- angle = i * 2.0 * M_PI / teeth;
-
- glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
- glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
- u = r2 * cos(angle + da) - r1 * cos(angle);
- v = r2 * sin(angle + da) - r1 * sin(angle);
- len = sqrt(u * u + v * v);
- u /= len;
- v /= len;
- glNormal3f(v, -u, 0.0);
- glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5);
- glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5);
- glNormal3f(cos(angle), sin(angle), 0.0);
- glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
- width * 0.5);
- glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
- -width * 0.5);
- u = r1 * cos(angle + 3 * da) - r2 * cos(angle + 2 * da);
- v = r1 * sin(angle + 3 * da) - r2 * sin(angle + 2 * da);
- glNormal3f(v, -u, 0.0);
- glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
- width * 0.5);
- glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
- -width * 0.5);
- glNormal3f(cos(angle), sin(angle), 0.0);
- }
-
- glVertex3f(r1 * cos(0), r1 * sin(0), width * 0.5);
- glVertex3f(r1 * cos(0), r1 * sin(0), -width * 0.5);
-
- glEnd();
-
- glShadeModel(GL_SMOOTH);
-
- /* draw inside radius cylinder */
- glBegin(GL_QUAD_STRIP);
- for (i = 0; i <= teeth; i++) {
- angle = i * 2.0 * M_PI / teeth;
- glNormal3f(-cos(angle), -sin(angle), 0.0);
- glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
- glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
- }
- glEnd();
-}
-
-
-static void
-draw(void)
-{
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- glPushMatrix();
- glRotatef(view_rotx, 1.0, 0.0, 0.0);
- glRotatef(view_roty, 0.0, 1.0, 0.0);
- glRotatef(view_rotz, 0.0, 0.0, 1.0);
-
- glPushMatrix();
- glTranslatef(-3.0, -2.0, 0.0);
- glRotatef(angle, 0.0, 0.0, 1.0);
- glCallList(gear1);
- glPopMatrix();
-
- glPushMatrix();
- glTranslatef(3.1, -2.0, 0.0);
- glRotatef(-2.0 * angle - 9.0, 0.0, 0.0, 1.0);
- glCallList(gear2);
- glPopMatrix();
-
- glPushMatrix();
- glTranslatef(-3.1, 4.2, 0.0);
- glRotatef(-2.0 * angle - 25.0, 0.0, 0.0, 1.0);
- glCallList(gear3);
- glPopMatrix();
-
- glPopMatrix();
-}
-
-
-/* new window size or exposure */
-static void
-reshape(int width, int height)
-{
- 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 maj, min;
- EGLContext ctx;
- EGLSurface screen_surf;
- EGLConfig configs[MAX_CONFIGS];
- EGLint numConfigs, i;
- EGLBoolean b;
- EGLDisplay d;
- EGLint screenAttribs[10];
- EGLModeMESA mode[MAX_MODES];
- EGLScreenMESA screen;
- EGLint count;
- EGLint chosenMode = 0;
- GLboolean printInfo = GL_FALSE;
- EGLint width = 0, height = 0;
-
- /* parse cmd line args */
- for (i = 1; i < argc; i++)
- {
- if (strcmp(argv[i], "-info") == 0)
- {
- printInfo = GL_TRUE;
- }
- else
- printf("Warning: unknown parameter: %s\n", argv[i]);
- }
-
- /* DBR : Create EGL context/surface etc */
- d = eglGetDisplay(EGL_DEFAULT_DISPLAY);
- assert(d);
-
- if (!eglInitialize(d, &maj, &min)) {
- printf("eglgears: eglInitialize failed\n");
- exit(1);
- }
-
- printf("eglgears: EGL version = %d.%d\n", maj, min);
- printf("eglgears: EGL_VENDOR = %s\n", eglQueryString(d, EGL_VENDOR));
-
- /* XXX use ChooseConfig */
- eglGetConfigs(d, configs, MAX_CONFIGS, &numConfigs);
- eglGetScreensMESA(d, &screen, 1, &count);
-
- if (!eglGetModesMESA(d, screen, mode, MAX_MODES, &count) || count == 0) {
- printf("eglgears: eglGetModesMESA failed!\n");
- return 0;
- }
-
- /* Print list of modes, and find the one to use */
- printf("eglgears: Found %d modes:\n", count);
- for (i = 0; i < count; i++) {
- EGLint w, h;
- eglGetModeAttribMESA(d, mode[i], EGL_WIDTH, &w);
- eglGetModeAttribMESA(d, mode[i], EGL_HEIGHT, &h);
- printf("%3d: %d x %d\n", i, w, h);
- if (w > width && h > height) {
- width = w;
- height = h;
- chosenMode = i;
- }
- }
- printf("eglgears: Using screen mode/size %d: %d x %d\n", chosenMode, width, height);
-
- eglBindAPI(EGL_OPENGL_API);
- ctx = eglCreateContext(d, configs[0], EGL_NO_CONTEXT, NULL);
- if (ctx == EGL_NO_CONTEXT) {
- printf("eglgears: failed to create context\n");
- return 0;
- }
-
- /* build up screenAttribs array */
- i = 0;
- screenAttribs[i++] = EGL_WIDTH;
- screenAttribs[i++] = width;
- screenAttribs[i++] = EGL_HEIGHT;
- screenAttribs[i++] = height;
- screenAttribs[i++] = EGL_NONE;
-
- screen_surf = eglCreateScreenSurfaceMESA(d, configs[0], screenAttribs);
- if (screen_surf == EGL_NO_SURFACE) {
- printf("eglgears: failed to create screen surface\n");
- return 0;
- }
-
- b = eglShowScreenSurfaceMESA(d, screen, screen_surf, mode[chosenMode]);
- if (!b) {
- printf("eglgears: show surface failed\n");
- return 0;
- }
-
- b = eglMakeCurrent(d, screen_surf, screen_surf, ctx);
- if (!b) {
- printf("eglgears: make current failed\n");
- return 0;
- }
-
- if (printInfo)
- {
- printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
- printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
- printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR));
- printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS));
- }
-
- init();
- reshape(width, height);
-
- glDrawBuffer( GL_BACK );
-
- run_gears(d, screen_surf, 5.0);
-
- eglDestroySurface(d, screen_surf);
- eglDestroyContext(d, ctx);
- eglTerminate(d);
-
- return 0;
-}
diff --git a/progs/egl/eglinfo.c b/progs/egl/eglinfo.c
deleted file mode 100644
index 961fd9ccc76..00000000000
--- a/progs/egl/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
-#include
-#include
-#include
-#include
-#include
-
-#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/eglscreen.c b/progs/egl/eglscreen.c
deleted file mode 100644
index 520f76ea036..00000000000
--- a/progs/egl/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
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#define MAX_CONFIGS 10
-#define MAX_MODES 100
-
-int
-main(int argc, char *argv[])
-{
- int maj, min;
- EGLSurface screen_surf;
- EGLConfig configs[MAX_CONFIGS];
- EGLint numConfigs, i;
- EGLBoolean b;
- EGLDisplay d;
- EGLint screenAttribs[10];
- EGLModeMESA mode[MAX_MODES];
- EGLScreenMESA screen;
- EGLint count;
- 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/egltri.c b/progs/egl/egltri.c
deleted file mode 100644
index 006e06eb03e..00000000000
--- a/progs/egl/egltri.c
+++ /dev/null
@@ -1,264 +0,0 @@
-/*
- * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
- * Copyright (C) 2008 Brian Paul All Rights Reserved.
- * Copyright (C) 2008 Jakob Bornecrantz All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-/*
- * This program is based on eglgears and xegl_tri.
- * Remixed by Jakob Bornecrantz
- *
- * No command line options.
- * Program runs for 5 seconds then exits, outputing framerate to console
- */
-
-#define EGL_EGLEXT_PROTOTYPES
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#define MAX_CONFIGS 10
-#define MAX_MODES 100
-
-
-/* XXX this probably isn't very portable */
-
-#include
-#include
-
-/* return current time (in seconds) */
-static double
-current_time(void)
-{
- struct timeval tv;
-#ifdef __VMS
- (void) gettimeofday(&tv, NULL );
-#else
- struct timezone tz;
- (void) gettimeofday(&tv, &tz);
-#endif
- return (double) tv.tv_sec + tv.tv_usec / 1000000.0;
-}
-
-
-static GLfloat view_rotx = 0.0, view_roty = 0.0, view_rotz = 0.0;
-
-static void draw()
-{
- static const GLfloat verts[3][2] = {
- { -1, -1 },
- { 1, -1 },
- { 0, 1 }
- };
- static const GLfloat colors[3][3] = {
- { 1, 0, 0 },
- { 0, 1, 0 },
- { 0, 0, 1 }
- };
-
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- glPushMatrix();
- glRotatef(view_rotx, 1, 0, 0);
- glRotatef(view_roty, 0, 1, 0);
- glRotatef(view_rotz, 0, 0, 1);
-
- {
- glVertexPointer(2, GL_FLOAT, 0, verts);
- glColorPointer(3, GL_FLOAT, 0, colors);
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_COLOR_ARRAY);
-
- glDrawArrays(GL_TRIANGLES, 0, 3);
-
- glDisableClientState(GL_VERTEX_ARRAY);
- glDisableClientState(GL_COLOR_ARRAY);
- }
-
- glPopMatrix();
-}
-
-static void init()
-{
- glClearColor(0.4, 0.4, 0.4, 0.0);
-}
-
-/* new window size or exposure */
-static void reshape(int width, int height)
-{
- GLfloat ar = (GLfloat) width / (GLfloat) height;
-
- glViewport(0, 0, (GLint) width, (GLint) height);
-
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glFrustum(-ar, ar, -1, 1, 5.0, 60.0);
-
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTranslatef(0.0, 0.0, -10.0);
-}
-
-static void run(EGLDisplay dpy, EGLSurface surf, int ttr)
-{
- double st = current_time();
- double ct = st;
- int frames = 0;
- GLfloat seconds, fps;
-
- while (ct - st < ttr)
- {
- ct = current_time();
-
- draw();
-
- eglSwapBuffers(dpy, surf);
-
- frames++;
- }
-
- seconds = ct - st;
- fps = frames / seconds;
- printf("%d frames in %3.1f seconds = %6.3f FPS\n", frames, seconds, fps);
-}
-
-int main(int argc, char *argv[])
-{
- int maj, min;
- EGLContext ctx;
- EGLSurface screen_surf;
- EGLConfig configs[MAX_CONFIGS];
- EGLint numConfigs, i;
- EGLBoolean b;
- EGLDisplay d;
- EGLint screenAttribs[10];
- EGLModeMESA mode[MAX_MODES];
- EGLScreenMESA screen;
- EGLint count, chosenMode = 0;
- GLboolean printInfo = GL_FALSE;
- EGLint width = 0, height = 0;
-
- /* parse cmd line args */
- for (i = 1; i < argc; i++)
- {
- if (strcmp(argv[i], "-info") == 0)
- {
- printInfo = GL_TRUE;
- }
- else
- printf("Warning: unknown parameter: %s\n", argv[i]);
- }
-
- /* DBR : Create EGL context/surface etc */
- d = eglGetDisplay(EGL_DEFAULT_DISPLAY);
- assert(d);
-
- if (!eglInitialize(d, &maj, &min)) {
- printf("egltri: eglInitialize failed\n");
- exit(1);
- }
-
- printf("egltri: EGL version = %d.%d\n", maj, min);
- printf("egltri: EGL_VENDOR = %s\n", eglQueryString(d, EGL_VENDOR));
-
- /* XXX use ChooseConfig */
- eglGetConfigs(d, configs, MAX_CONFIGS, &numConfigs);
- eglGetScreensMESA(d, &screen, 1, &count);
-
- if (!eglGetModesMESA(d, screen, mode, MAX_MODES, &count) || count == 0) {
- printf("egltri: eglGetModesMESA failed!\n");
- return 0;
- }
-
- /* Print list of modes, and find the one to use */
- printf("egltri: Found %d modes:\n", count);
- for (i = 0; i < count; i++) {
- EGLint w, h;
- eglGetModeAttribMESA(d, mode[i], EGL_WIDTH, &w);
- eglGetModeAttribMESA(d, mode[i], EGL_HEIGHT, &h);
- printf("%3d: %d x %d\n", i, w, h);
- if (w > width && h > height) {
- width = w;
- height = h;
- chosenMode = i;
- }
- }
- printf("egltri: Using screen mode/size %d: %d x %d\n", chosenMode, width, height);
-
- eglBindAPI(EGL_OPENGL_API);
- ctx = eglCreateContext(d, configs[0], EGL_NO_CONTEXT, NULL);
- if (ctx == EGL_NO_CONTEXT) {
- printf("egltri: failed to create context\n");
- return 0;
- }
-
- /* build up screenAttribs array */
- i = 0;
- screenAttribs[i++] = EGL_WIDTH;
- screenAttribs[i++] = width;
- screenAttribs[i++] = EGL_HEIGHT;
- screenAttribs[i++] = height;
- screenAttribs[i++] = EGL_NONE;
-
- screen_surf = eglCreateScreenSurfaceMESA(d, configs[0], screenAttribs);
- if (screen_surf == EGL_NO_SURFACE) {
- printf("egltri: failed to create screen surface\n");
- return 0;
- }
-
- b = eglShowScreenSurfaceMESA(d, screen, screen_surf, mode[chosenMode]);
- if (!b) {
- printf("egltri: show surface failed\n");
- return 0;
- }
-
- b = eglMakeCurrent(d, screen_surf, screen_surf, ctx);
- if (!b) {
- printf("egltri: make current failed\n");
- return 0;
- }
-
- if (printInfo)
- {
- printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
- printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
- printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR));
- printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS));
- }
-
- init();
- reshape(width, height);
-
- glDrawBuffer( GL_BACK );
-
- run(d, screen_surf, 5.0);
-
- eglDestroySurface(d, screen_surf);
- eglDestroyContext(d, ctx);
- eglTerminate(d);
-
- return 0;
-}
diff --git a/progs/egl/eglut/Makefile b/progs/egl/eglut/Makefile
new file mode 100644
index 00000000000..f5cafa70104
--- /dev/null
+++ b/progs/egl/eglut/Makefile
@@ -0,0 +1,35 @@
+# progs/egl/eglut
+
+TOP = ../../..
+include $(TOP)/configs/current
+
+INCLUDES = \
+ -I$(TOP)/include
+
+SOURCES = $(wildcard *.c)
+
+EGLUT_X11_OBJECTS = eglut.o eglut_x11.o
+EGLUT_SCREEN_OBJECTS = eglut.o eglut_screen.o
+
+default: depend libeglut-x11.a libeglut-screen.a
+
+libeglut-x11.a: $(EGLUT_X11_OBJECTS)
+ $(MKLIB) -o eglut-x11 -static $(EGLUT_X11_OBJECTS)
+
+libeglut-screen.a: $(EGLUT_SCREEN_OBJECTS)
+ $(MKLIB) -o eglut-screen -static $(EGLUT_SCREEN_OBJECTS)
+
+.c.o:
+ $(CC) -c -o $@ $< $(INCLUDES) $(DEFINES) $(CFLAGS)
+
+depend: $(SOURCES)
+ @rm -f depend
+ @touch depend
+ @$(MKDEP) $(MKDEP_OPTIONS) $(INCLUDES) $(SOURCES) \
+ > /dev/null 2>/dev/null
+
+clean:
+ rm -f *.o *.a
+ rm -f depend depend.bak
+
+sinclude depend
diff --git a/progs/egl/eglut/eglut.c b/progs/egl/eglut/eglut.c
new file mode 100644
index 00000000000..b9b5e6e5a8c
--- /dev/null
+++ b/progs/egl/eglut/eglut.c
@@ -0,0 +1,346 @@
+#include
+#include
+#include
+#include
+#include
+
+#include "EGL/egl.h"
+#include "EGL/eglext.h"
+
+#include "eglutint.h"
+
+static struct eglut_state _eglut_state = {
+ .api_mask = EGLUT_OPENGL_ES1_BIT,
+ .window_width = 300,
+ .window_height = 300,
+ .verbose = 0,
+ .num_windows = 0,
+};
+
+struct eglut_state *_eglut = &_eglut_state;
+
+void
+_eglutFatal(char *format, ...)
+{
+ va_list args;
+
+ va_start(args, format);
+
+ fprintf(stderr, "EGLUT: ");
+ vfprintf(stderr, format, args);
+ va_end(args);
+ putc('\n', stderr);
+
+ exit(1);
+}
+
+/* return current time (in milliseconds) */
+int
+_eglutNow(void)
+{
+ struct timeval tv;
+#ifdef __VMS
+ (void) gettimeofday(&tv, NULL );
+#else
+ struct timezone tz;
+ (void) gettimeofday(&tv, &tz);
+#endif
+ return tv.tv_sec * 1000 + tv.tv_usec / 1000;
+}
+
+static void
+_eglutDestroyWindow(struct eglut_window *win)
+{
+ if (_eglut->surface_type != EGL_PBUFFER_BIT &&
+ _eglut->surface_type != EGL_SCREEN_BIT_MESA)
+ eglDestroySurface(_eglut->dpy, win->surface);
+
+ _eglutNativeFiniWindow(win);
+
+ eglDestroyContext(_eglut->dpy, win->context);
+}
+
+static EGLConfig
+_eglutChooseConfig(void)
+{
+ EGLConfig config;
+ EGLint config_attribs[32];
+ EGLint renderable_type, num_configs, i;
+
+ i = 0;
+ config_attribs[i++] = EGL_RED_SIZE;
+ config_attribs[i++] = 1;
+ config_attribs[i++] = EGL_GREEN_SIZE;
+ config_attribs[i++] = 1;
+ config_attribs[i++] = EGL_BLUE_SIZE;
+ config_attribs[i++] = 1;
+ config_attribs[i++] = EGL_DEPTH_SIZE;
+ config_attribs[i++] = 1;
+
+ config_attribs[i++] = EGL_SURFACE_TYPE;
+ config_attribs[i++] = _eglut->surface_type;
+
+ config_attribs[i++] = EGL_RENDERABLE_TYPE;
+ renderable_type = 0x0;
+ if (_eglut->api_mask & EGLUT_OPENGL_BIT)
+ renderable_type |= EGL_OPENGL_BIT;
+ if (_eglut->api_mask & (EGLUT_OPENGL_ES1_BIT | EGLUT_OPENGL_ES2_BIT))
+ renderable_type |= EGL_OPENGL_ES_BIT;
+ if (_eglut->api_mask & EGLUT_OPENVG_BIT)
+ renderable_type |= EGL_OPENVG_BIT;
+ config_attribs[i++] = renderable_type;
+
+ config_attribs[i] = EGL_NONE;
+
+ if (!eglChooseConfig(_eglut->dpy,
+ config_attribs, &config, 1, &num_configs) || !num_configs)
+ _eglutFatal("failed to choose a config");
+
+ return config;
+}
+
+static struct eglut_window *
+_eglutCreateWindow(const char *title, int x, int y, int w, int h)
+{
+ struct eglut_window *win;
+ EGLint context_attribs[4];
+ EGLint api, i;
+
+ win = calloc(1, sizeof(*win));
+ if (!win)
+ _eglutFatal("failed to allocate window");
+
+ win->config = _eglutChooseConfig();
+
+ i = 0;
+ context_attribs[i] = EGL_NONE;
+
+ /* multiple APIs? */
+
+ api = EGL_OPENGL_ES_API;
+ if (_eglut->api_mask & EGLUT_OPENGL_BIT) {
+ api = EGL_OPENGL_API;
+ }
+ else if (_eglut->api_mask & EGLUT_OPENVG_BIT) {
+ api = EGL_OPENVG_API;
+ }
+ else if (_eglut->api_mask & EGLUT_OPENGL_ES2_BIT) {
+ context_attribs[i++] = EGL_CONTEXT_CLIENT_VERSION;
+ context_attribs[i++] = 2;
+ }
+
+ context_attribs[i] = EGL_NONE;
+
+ eglBindAPI(api);
+ win->context = eglCreateContext(_eglut->dpy,
+ win->config, EGL_NO_CONTEXT, context_attribs);
+ if (!win->context)
+ _eglutFatal("failed to create context");
+
+ _eglutNativeInitWindow(win, title, x, y, w, h);
+ switch (_eglut->surface_type) {
+ case EGL_WINDOW_BIT:
+ win->surface = eglCreateWindowSurface(_eglut->dpy,
+ win->config, win->native.u.window, NULL);
+ break;
+ case EGL_PIXMAP_BIT:
+ win->surface = eglCreatePixmapSurface(_eglut->dpy,
+ win->config, win->native.u.pixmap, NULL);
+ break;
+ case EGL_PBUFFER_BIT:
+ case EGL_SCREEN_BIT_MESA:
+ win->surface = win->native.u.surface;
+ break;
+ default:
+ break;
+ }
+ if (win->surface == EGL_NO_SURFACE)
+ _eglutFatal("failed to create surface");
+
+ return win;
+}
+
+void
+eglutInitAPIMask(int mask)
+{
+ _eglut->api_mask = mask;
+}
+
+void
+eglutInitWindowSize(int width, int height)
+{
+ _eglut->window_width = width;
+ _eglut->window_height = height;
+}
+
+void
+eglutInit(int argc, char **argv)
+{
+ int i;
+
+ for (i = 1; i < argc; i++) {
+ if (strcmp(argv[i], "-display") == 0)
+ _eglut->display_name = argv[++i];
+ else if (strcmp(argv[i], "-info") == 0) {
+ _eglut->verbose = 1;
+ }
+ }
+
+ _eglutNativeInitDisplay();
+ _eglut->dpy = eglGetDisplay(_eglut->native_dpy);
+
+ if (!eglInitialize(_eglut->dpy, &_eglut->major, &_eglut->minor))
+ _eglutFatal("failed to initialize EGL display");
+
+ _eglut->init_time = _eglutNow();
+
+ printf("EGL_VERSION = %s\n", eglQueryString(_eglut->dpy, EGL_VERSION));
+ if (_eglut->verbose) {
+ printf("EGL_VENDOR = %s\n", eglQueryString(_eglut->dpy, EGL_VENDOR));
+ printf("EGL_EXTENSIONS = %s\n",
+ eglQueryString(_eglut->dpy, EGL_EXTENSIONS));
+ printf("EGL_CLIENT_APIS = %s\n",
+ eglQueryString(_eglut->dpy, EGL_CLIENT_APIS));
+ }
+}
+
+int
+eglutGet(int state)
+{
+ int val;
+
+ switch (state) {
+ case EGLUT_ELAPSED_TIME:
+ val = _eglutNow() - _eglut->init_time;
+ break;
+ default:
+ val = -1;
+ break;
+ }
+
+ return val;
+}
+
+void
+eglutIdleFunc(EGLUTidleCB func)
+{
+ _eglut->idle_cb = func;
+}
+
+void
+eglutPostRedisplay(void)
+{
+ _eglut->redisplay = 1;
+}
+
+void
+eglutMainLoop(void)
+{
+ struct eglut_window *win = _eglut->current;
+
+ if (!win)
+ _eglutFatal("no window is created\n");
+
+ if (win->reshape_cb)
+ win->reshape_cb(win->native.width, win->native.height);
+
+ _eglutNativeEventLoop();
+}
+
+static void
+_eglutFini(void)
+{
+ eglTerminate(_eglut->dpy);
+ _eglutNativeFiniDisplay();
+}
+
+void
+eglutDestroyWindow(int win)
+{
+ struct eglut_window *window = _eglut->current;
+
+ if (window->index != win)
+ return;
+
+ /* XXX it causes some bug in st/egl KMS backend */
+ if ( _eglut->surface_type != EGL_SCREEN_BIT_MESA)
+ eglMakeCurrent(_eglut->dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
+
+ _eglutDestroyWindow(_eglut->current);
+}
+
+static void
+_eglutDefaultKeyboard(unsigned char key)
+{
+ if (key == 27) {
+ if (_eglut->current)
+ eglutDestroyWindow(_eglut->current->index);
+ _eglutFini();
+
+ exit(0);
+ }
+}
+
+int
+eglutCreateWindow(const char *title)
+{
+ struct eglut_window *win;
+
+ win = _eglutCreateWindow(title, 0, 0,
+ _eglut->window_width, _eglut->window_height);
+
+ win->index = _eglut->num_windows++;
+ win->reshape_cb = NULL;
+ win->display_cb = NULL;
+ win->keyboard_cb = _eglutDefaultKeyboard;
+ win->special_cb = NULL;
+
+ if (!eglMakeCurrent(_eglut->dpy, win->surface, win->surface, win->context))
+ _eglutFatal("failed to make window current");
+ _eglut->current = win;
+
+ return win->index;
+}
+
+int
+eglutGetWindowWidth(void)
+{
+ struct eglut_window *win = _eglut->current;
+ return win->native.width;
+}
+
+int
+eglutGetWindowHeight(void)
+{
+ struct eglut_window *win = _eglut->current;
+ return win->native.height;
+}
+
+void
+eglutDisplayFunc(EGLUTdisplayCB func)
+{
+ struct eglut_window *win = _eglut->current;
+ win->display_cb = func;
+
+}
+
+void
+eglutReshapeFunc(EGLUTreshapeCB func)
+{
+ struct eglut_window *win = _eglut->current;
+ win->reshape_cb = func;
+}
+
+void
+eglutKeyboardFunc(EGLUTkeyboardCB func)
+{
+ struct eglut_window *win = _eglut->current;
+ win->keyboard_cb = func;
+}
+
+void
+eglutSpecialFunc(EGLUTspecialCB func)
+{
+ struct eglut_window *win = _eglut->current;
+ win->special_cb = func;
+}
diff --git a/progs/egl/eglut/eglut.h b/progs/egl/eglut/eglut.h
new file mode 100644
index 00000000000..07df4ba9f75
--- /dev/null
+++ b/progs/egl/eglut/eglut.h
@@ -0,0 +1,68 @@
+#ifndef EGLUT_H
+#define EGLUT_H
+
+/* used by eglutInitAPIMask */
+enum {
+ EGLUT_OPENGL_BIT = 0x1,
+ EGLUT_OPENGL_ES1_BIT = 0x2,
+ EGLUT_OPENGL_ES2_BIT = 0x4,
+ EGLUT_OPENVG_BIT = 0x8
+};
+
+/* used by EGLUTspecialCB */
+enum {
+ /* function keys */
+ EGLUT_KEY_F1,
+ EGLUT_KEY_F2,
+ EGLUT_KEY_F3,
+ EGLUT_KEY_F4,
+ EGLUT_KEY_F5,
+ EGLUT_KEY_F6,
+ EGLUT_KEY_F7,
+ EGLUT_KEY_F8,
+ EGLUT_KEY_F9,
+ EGLUT_KEY_F10,
+ EGLUT_KEY_F11,
+ EGLUT_KEY_F12,
+
+ /* directional keys */
+ EGLUT_KEY_LEFT,
+ EGLUT_KEY_UP,
+ EGLUT_KEY_RIGHT,
+ EGLUT_KEY_DOWN,
+};
+
+/* used by eglutGet */
+enum {
+ EGLUT_ELAPSED_TIME
+};
+
+typedef void (*EGLUTidleCB)(void);
+typedef void (*EGLUTreshapeCB)(int, int);
+typedef void (*EGLUTdisplayCB)(void);
+typedef void (*EGLUTkeyboardCB)(unsigned char);
+typedef void (*EGLUTspecialCB)(int);
+
+void eglutInitAPIMask(int mask);
+void eglutInitWindowSize(int width, int height);
+void eglutInit(int argc, char **argv);
+
+int eglutGet(int state);
+
+void eglutIdleFunc(EGLUTidleCB func);
+void eglutPostRedisplay(void);
+
+void eglutMainLoop(void);
+
+int eglutCreateWindow(const char *title);
+void eglutDestroyWindow(int win);
+
+int eglutGetWindowWidth(void);
+int eglutGetWindowHeight(void);
+
+void eglutDisplayFunc(EGLUTdisplayCB func);
+void eglutReshapeFunc(EGLUTreshapeCB func);
+void eglutKeyboardFunc(EGLUTkeyboardCB func);
+void eglutSpecialFunc(EGLUTspecialCB func);
+
+#endif /* EGLUT_H */
diff --git a/progs/egl/eglut/eglut_screen.c b/progs/egl/eglut/eglut_screen.c
new file mode 100644
index 00000000000..50549e4bcf8
--- /dev/null
+++ b/progs/egl/eglut/eglut_screen.c
@@ -0,0 +1,154 @@
+#include
+#include
+#include
+
+#define EGL_EGLEXT_PROTOTYPES
+#include "EGL/egl.h"
+#include "EGL/eglext.h"
+
+#include "eglutint.h"
+
+#define MAX_MODES 100
+
+static EGLScreenMESA kms_screen;
+static EGLModeMESA kms_mode;
+static EGLint kms_width, kms_height;
+
+void
+_eglutNativeInitDisplay(void)
+{
+ _eglut->native_dpy = EGL_DEFAULT_DISPLAY;
+ _eglut->surface_type = EGL_SCREEN_BIT_MESA;
+}
+
+void
+_eglutNativeFiniDisplay(void)
+{
+ kms_screen = 0;
+ kms_mode = 0;
+ kms_width = 0;
+ kms_height = 0;
+}
+
+static void
+init_kms(void)
+{
+ EGLModeMESA modes[MAX_MODES];
+ EGLint num_screens, num_modes;
+ EGLint width, height, best_mode;
+ EGLint i;
+
+ if (!eglGetScreensMESA(_eglut->dpy, &kms_screen, 1, &num_screens) ||
+ !num_screens)
+ _eglutFatal("eglGetScreensMESA failed\n");
+
+ if (!eglGetModesMESA(_eglut->dpy, kms_screen,
+ modes, MAX_MODES, &num_modes) || !num_modes)
+ _eglutFatal("eglGetModesMESA failed!\n");
+
+ printf("Found %d modes:\n", num_modes);
+
+ best_mode = 0;
+ width = 0;
+ height = 0;
+ for (i = 0; i < num_modes; i++) {
+ EGLint w, h;
+ eglGetModeAttribMESA(_eglut->dpy, modes[i], EGL_WIDTH, &w);
+ eglGetModeAttribMESA(_eglut->dpy, modes[i], EGL_HEIGHT, &h);
+ printf("%3d: %d x %d\n", i, w, h);
+ if (w > width && h > height) {
+ width = w;
+ height = h;
+ best_mode = i;
+ }
+ }
+
+ printf("Will use screen size: %d x %d\n", width, height);
+
+ kms_mode = modes[best_mode];
+ kms_width = width;
+ kms_height = height;
+}
+
+void
+_eglutNativeInitWindow(struct eglut_window *win, const char *title,
+ int x, int y, int w, int h)
+{
+ EGLint surf_attribs[16];
+ EGLint i;
+ const char *exts;
+
+ exts = eglQueryString(_eglut->dpy, EGL_EXTENSIONS);
+ if (!exts || !strstr(exts, "EGL_MESA_screen_surface"))
+ _eglutFatal("EGL_MESA_screen_surface is not supported\n");
+
+ init_kms();
+
+ i = 0;
+ surf_attribs[i++] = EGL_WIDTH;
+ surf_attribs[i++] = kms_width;
+ surf_attribs[i++] = EGL_HEIGHT;
+ surf_attribs[i++] = kms_height;
+ surf_attribs[i++] = EGL_NONE;
+
+ /* create surface */
+ win->native.u.surface = eglCreateScreenSurfaceMESA(_eglut->dpy,
+ win->config, surf_attribs);
+ if (win->native.u.surface == EGL_NO_SURFACE)
+ _eglutFatal("eglCreateScreenSurfaceMESA failed\n");
+
+ if (!eglShowScreenSurfaceMESA(_eglut->dpy, kms_screen,
+ win->native.u.surface, kms_mode))
+ _eglutFatal("eglShowScreenSurfaceMESA failed\n");
+
+ win->native.width = kms_width;
+ win->native.height = kms_height;
+}
+
+void
+_eglutNativeFiniWindow(struct eglut_window *win)
+{
+ eglShowScreenSurfaceMESA(_eglut->dpy,
+ kms_screen, EGL_NO_SURFACE, 0);
+ eglDestroySurface(_eglut->dpy, win->native.u.surface);
+}
+
+void
+_eglutNativeEventLoop(void)
+{
+ int start = _eglutNow();
+ int frames = 0;
+
+ _eglut->redisplay = 1;
+
+ while (1) {
+ struct eglut_window *win = _eglut->current;
+ int now = _eglutNow();
+
+ if (now - start > 5000) {
+ double elapsed = (double) (now - start) / 1000.0;
+
+ printf("%d frames in %3.1f seconds = %6.3f FPS\n",
+ frames, elapsed, frames / elapsed);
+
+ start = now;
+ frames = 0;
+
+ /* send escape */
+ if (win->keyboard_cb)
+ win->keyboard_cb(27);
+ }
+
+ if (_eglut->idle_cb)
+ _eglut->idle_cb();
+
+ if (_eglut->redisplay) {
+ _eglut->redisplay = 0;
+
+ if (win->display_cb)
+ win->display_cb();
+ eglSwapBuffers(_eglut->dpy, win->surface);
+ frames++;
+ }
+ }
+}
diff --git a/progs/egl/eglut/eglut_x11.c b/progs/egl/eglut/eglut_x11.c
new file mode 100644
index 00000000000..f3b2280374b
--- /dev/null
+++ b/progs/egl/eglut/eglut_x11.c
@@ -0,0 +1,220 @@
+#include
+#include
+#include
+
+#include "eglutint.h"
+
+void
+_eglutNativeInitDisplay(void)
+{
+ _eglut->native_dpy = XOpenDisplay(_eglut->display_name);
+ if (!_eglut->native_dpy)
+ _eglutFatal("failed to initialize native display");
+
+ _eglut->surface_type = EGL_WINDOW_BIT;
+}
+
+void
+_eglutNativeFiniDisplay(void)
+{
+ XCloseDisplay(_eglut->native_dpy);
+}
+
+void
+_eglutNativeInitWindow(struct eglut_window *win, const char *title,
+ int x, int y, int w, int h)
+{
+ XVisualInfo *visInfo, visTemplate;
+ int num_visuals;
+ Window root, xwin;
+ XSetWindowAttributes attr;
+ unsigned long mask;
+ EGLint vid;
+
+ if (!eglGetConfigAttrib(_eglut->dpy,
+ win->config, EGL_NATIVE_VISUAL_ID, &vid))
+ _eglutFatal("failed to get visual id");
+
+ /* The X window visual must match the EGL config */
+ visTemplate.visualid = vid;
+ visInfo = XGetVisualInfo(_eglut->native_dpy,
+ VisualIDMask, &visTemplate, &num_visuals);
+ if (!visInfo)
+ _eglutFatal("failed to get an visual of id 0x%x", vid);
+
+ root = RootWindow(_eglut->native_dpy, DefaultScreen(_eglut->native_dpy));
+
+ /* window attributes */
+ attr.background_pixel = 0;
+ attr.border_pixel = 0;
+ attr.colormap = XCreateColormap(_eglut->native_dpy,
+ root, visInfo->visual, AllocNone);
+ attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
+ mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
+
+ xwin = XCreateWindow(_eglut->native_dpy, root, x, y, w, h,
+ 0, visInfo->depth, InputOutput, visInfo->visual, mask, &attr);
+ if (!xwin)
+ _eglutFatal("failed to create a window");
+
+ XFree(visInfo);
+
+ /* set hints and properties */
+ {
+ XSizeHints sizehints;
+ sizehints.x = x;
+ sizehints.y = y;
+ sizehints.width = w;
+ sizehints.height = h;
+ sizehints.flags = USSize | USPosition;
+ XSetNormalHints(_eglut->native_dpy, xwin, &sizehints);
+ XSetStandardProperties(_eglut->native_dpy, xwin,
+ title, title, None, (char **) NULL, 0, &sizehints);
+ }
+
+ XMapWindow(_eglut->native_dpy, xwin);
+
+ win->native.u.window = xwin;
+ win->native.width = w;
+ win->native.height = h;
+}
+
+void
+_eglutNativeFiniWindow(struct eglut_window *win)
+{
+ XDestroyWindow(_eglut->native_dpy, win->native.u.window);
+}
+
+static int
+lookup_keysym(KeySym sym)
+{
+ int special;
+
+ switch (sym) {
+ case XK_F1:
+ special = EGLUT_KEY_F1;
+ break;
+ case XK_F2:
+ special = EGLUT_KEY_F2;
+ break;
+ case XK_F3:
+ special = EGLUT_KEY_F3;
+ break;
+ case XK_F4:
+ special = EGLUT_KEY_F4;
+ break;
+ case XK_F5:
+ special = EGLUT_KEY_F5;
+ break;
+ case XK_F6:
+ special = EGLUT_KEY_F6;
+ break;
+ case XK_F7:
+ special = EGLUT_KEY_F7;
+ break;
+ case XK_F8:
+ special = EGLUT_KEY_F8;
+ break;
+ case XK_F9:
+ special = EGLUT_KEY_F9;
+ break;
+ case XK_F10:
+ special = EGLUT_KEY_F10;
+ break;
+ case XK_F11:
+ special = EGLUT_KEY_F11;
+ break;
+ case XK_F12:
+ special = EGLUT_KEY_F12;
+ break;
+ case XK_KP_Left:
+ case XK_Left:
+ special = EGLUT_KEY_LEFT;
+ break;
+ case XK_KP_Up:
+ case XK_Up:
+ special = EGLUT_KEY_UP;
+ break;
+ case XK_KP_Right:
+ case XK_Right:
+ special = EGLUT_KEY_RIGHT;
+ break;
+ case XK_KP_Down:
+ case XK_Down:
+ special = EGLUT_KEY_DOWN;
+ break;
+ default:
+ special = -1;
+ break;
+ }
+
+ return special;
+}
+
+static void
+next_event(struct eglut_window *win)
+{
+ int redraw = 0;
+ XEvent event;
+
+ if (!XPending(_eglut->native_dpy)) {
+ if (_eglut->idle_cb)
+ _eglut->idle_cb();
+ return;
+ }
+
+ XNextEvent(_eglut->native_dpy, &event);
+
+ switch (event.type) {
+ case Expose:
+ redraw = 1;
+ break;
+ case ConfigureNotify:
+ win->native.width = event.xconfigure.width;
+ win->native.height = event.xconfigure.height;
+ if (win->reshape_cb)
+ win->reshape_cb(win->native.width, win->native.height);
+ break;
+ case KeyPress:
+ {
+ char buffer[1];
+ KeySym sym;
+ int r;
+
+ r = XLookupString(&event.xkey,
+ buffer, sizeof(buffer), &sym, NULL);
+ if (r && win->keyboard_cb) {
+ win->keyboard_cb(buffer[0]);
+ }
+ else if (!r && win->special_cb) {
+ r = lookup_keysym(sym);
+ if (r >= 0)
+ win->special_cb(r);
+ }
+ }
+ redraw = 1;
+ break;
+ default:
+ ; /*no-op*/
+ }
+
+ _eglut->redisplay = redraw;
+}
+
+void
+_eglutNativeEventLoop(void)
+{
+ while (1) {
+ struct eglut_window *win = _eglut->current;
+
+ next_event(win);
+
+ if (_eglut->redisplay) {
+ _eglut->redisplay = 0;
+
+ if (win->display_cb)
+ win->display_cb();
+ eglSwapBuffers(_eglut->dpy, win->surface);
+ }
+ }
+}
diff --git a/progs/egl/eglut/eglutint.h b/progs/egl/eglut/eglutint.h
new file mode 100644
index 00000000000..54d329f3282
--- /dev/null
+++ b/progs/egl/eglut/eglutint.h
@@ -0,0 +1,78 @@
+#ifndef _EGLUTINT_H_
+#define _EGLUTINT_H_
+
+#include "EGL/egl.h"
+#include "eglut.h"
+
+struct eglut_window {
+ EGLConfig config;
+ EGLContext context;
+
+ /* initialized by native display */
+ struct {
+ union {
+ EGLNativeWindowType window;
+ EGLNativePixmapType pixmap;
+ EGLSurface surface; /* pbuffer or screen surface */
+ } u;
+ int width, height;
+ } native;
+
+ EGLSurface surface;
+
+ int index;
+
+ EGLUTreshapeCB reshape_cb;
+ EGLUTdisplayCB display_cb;
+ EGLUTkeyboardCB keyboard_cb;
+ EGLUTspecialCB special_cb;
+};
+
+struct eglut_state {
+ int api_mask;
+ int window_width, window_height;
+ const char *display_name;
+ int verbose;
+ int init_time;
+
+ EGLUTidleCB idle_cb;
+
+ int num_windows;
+
+ /* initialized by native display */
+ EGLNativeDisplayType native_dpy;
+ EGLint surface_type;
+
+ EGLDisplay dpy;
+ EGLint major, minor;
+
+ struct eglut_window *current;
+
+ int redisplay;
+};
+
+extern struct eglut_state *_eglut;
+
+void
+_eglutFatal(char *format, ...);
+
+int
+_eglutNow(void);
+
+void
+_eglutNativeInitDisplay(void);
+
+void
+_eglutNativeFiniDisplay(void);
+
+void
+_eglutNativeInitWindow(struct eglut_window *win, const char *title,
+ int x, int y, int w, int h);
+
+void
+_eglutNativeFiniWindow(struct eglut_window *win);
+
+void
+_eglutNativeEventLoop(void);
+
+#endif /* _EGLUTINT_H_ */
diff --git a/progs/egl/opengl/.gitignore b/progs/egl/opengl/.gitignore
new file mode 100644
index 00000000000..49c3a511f3c
--- /dev/null
+++ b/progs/egl/opengl/.gitignore
@@ -0,0 +1,13 @@
+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
new file mode 100644
index 00000000000..9a91df99064
--- /dev/null
+++ b/progs/egl/opengl/Makefile
@@ -0,0 +1,83 @@
+# progs/egl/Makefile
+
+TOP = ../../..
+include $(TOP)/configs/current
+
+
+INCLUDE_DIRS = -I$(TOP)/include
+
+HEADERS = $(TOP)/include/GLES/egl.h
+LIB_DEP = $(TOP)/$(LIB_DIR)/libEGL.so
+
+LIBS = -L$(TOP)/$(LIB_DIR) -lEGL -lGL -lm
+
+EGLUT_DIR = $(TOP)/progs/egl/eglut
+
+EGLUT_DEMOS = \
+ eglgears \
+ egltri
+
+EGLUT_X11_DEMOS := $(addsuffix _x11,$(EGLUT_DEMOS))
+EGLUT_SCREEN_DEMOS := $(addsuffix _screen,$(EGLUT_DEMOS))
+
+PROGRAMS = \
+ demo1 \
+ demo2 \
+ demo3 \
+ eglinfo \
+ eglscreen \
+ peglgears \
+ xeglgears \
+ xeglthreads
+
+
+.c.o:
+ $(CC) -c $(INCLUDE_DIRS) -I$(EGLUT_DIR) $(CFLAGS) $< -o $@
+
+
+
+default: $(PROGRAMS) $(EGLUT_X11_DEMOS) $(EGLUT_SCREEN_DEMOS)
+
+demo1: demo1.o $(HEADERS) $(LIB_DEP)
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB)
+
+demo2: demo2.o $(HEADERS) $(LIB_DEP)
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB)
+
+demo3: demo3.o $(HEADERS) $(LIB_DEP)
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB)
+
+eglinfo: eglinfo.o $(HEADERS) $(LIB_DEP)
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS)
+
+eglscreen: eglscreen.o $(HEADERS) $(LIB_DEP)
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB)
+
+peglgears: peglgears.o $(HEADERS) $(LIB_DEP)
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB) -lm
+
+xeglgears: xeglgears.o $(HEADERS) $(LIB_DEP)
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lm $(X11_LIBS)
+
+xeglthreads: xeglthreads.o $(HEADERS) $(LIB_DEP)
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lpthread -lm $(X11_LIBS)
+
+$(EGLUT_DIR)/libeglut-x11.a $(EGLUT_DIR)/libeglut-screen.a:
+ @$(MAKE) -C $(EGLUT_DIR)
+
+# define the rules for EGLUT demos
+define eglut-demo-rule
+$(1)_x11 $(1)_screen: $(1)_%: $(1).o $(EGLUT_DIR)/libeglut-%.a $(LIB_DEP)
+endef
+$(foreach demo, $(EGLUT_DEMOS), $(eval $(call eglut-demo-rule,$(demo))))
+
+# build EGLUT demos
+$(EGLUT_X11_DEMOS):
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -L$(EGLUT_DIR) -leglut-$* $(LIBS) -lX11
+$(EGLUT_SCREEN_DEMOS):
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -L$(EGLUT_DIR) -leglut-$* $(LIBS)
+
+clean:
+ -rm -f *.o *~
+ -rm -f $(PROGRAMS) $(EGLUT_X11_DEMOS) $(EGLUT_SCREEN_DEMOS)
+ @$(MAKE) -C $(EGLUT_DIR) clean
diff --git a/progs/egl/opengl/demo1.c b/progs/egl/opengl/demo1.c
new file mode 100644
index 00000000000..d892734ee55
--- /dev/null
+++ b/progs/egl/opengl/demo1.c
@@ -0,0 +1,147 @@
+/*
+ * Exercise EGL API functions
+ */
+
+#define EGL_EGLEXT_PROTOTYPES
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+
+/**
+ * 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
new file mode 100644
index 00000000000..b9e92f62ac2
--- /dev/null
+++ b/progs/egl/opengl/demo2.c
@@ -0,0 +1,216 @@
+/*
+ * Exercise EGL API functions
+ */
+
+#define EGL_EGLEXT_PROTOTYPES
+
+#include
+#include
+#include
+#include
+#include
+
+#include
+#include
+#include
+
+/*#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
new file mode 100644
index 00000000000..64b9ee652cd
--- /dev/null
+++ b/progs/egl/opengl/demo3.c
@@ -0,0 +1,647 @@
+/*
+ * Exercise EGL API functions
+ */
+
+#define EGL_EGLEXT_PROTOTYPES
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+
+
+#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=0; y--) {
+ for (x=0; x
+#include
+#include
+
+#include "eglut.h"
+
+static GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0;
+static GLint gear1, gear2, gear3;
+static GLfloat angle = 0.0;
+
+/*
+ *
+ * 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
new file mode 100644
index 00000000000..961fd9ccc76
--- /dev/null
+++ b/progs/egl/opengl/eglinfo.c
@@ -0,0 +1,223 @@
+/*
+ * 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
+#include
+#include
+#include
+#include
+#include
+
+#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
new file mode 100644
index 00000000000..520f76ea036
--- /dev/null
+++ b/progs/egl/opengl/eglscreen.c
@@ -0,0 +1,120 @@
+/*
+ * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*
+ * Stolen from eglgears
+ *
+ * Creates a surface and show that on the first screen
+ */
+
+#define EGL_EGLEXT_PROTOTYPES
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#define MAX_CONFIGS 10
+#define MAX_MODES 100
+
+int
+main(int argc, char *argv[])
+{
+ int maj, min;
+ EGLSurface screen_surf;
+ EGLConfig configs[MAX_CONFIGS];
+ EGLint numConfigs, i;
+ EGLBoolean b;
+ EGLDisplay d;
+ EGLint screenAttribs[10];
+ EGLModeMESA mode[MAX_MODES];
+ EGLScreenMESA screen;
+ EGLint count;
+ 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
new file mode 100644
index 00000000000..fb1dde3529c
--- /dev/null
+++ b/progs/egl/opengl/egltri.c
@@ -0,0 +1,141 @@
+/*
+ * Copyright (C) 2008 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*
+ * Draw a triangle with X/EGL.
+ * Brian Paul
+ * 3 June 2008
+ */
+
+
+#include
+#include
+#include
+#include
+
+#include "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
new file mode 100644
index 00000000000..212d1acf692
--- /dev/null
+++ b/progs/egl/opengl/peglgears.c
@@ -0,0 +1,451 @@
+/*
+ * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*
+ * This is a port of the infamous "glxgears" demo to straight EGL
+ * Port by Dane Rushton 10 July 2005
+ *
+ * No command line options.
+ * Program runs for 5 seconds then exits, outputing framerate to console
+ */
+
+#define EGL_EGLEXT_PROTOTYPES
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#define MAX_CONFIGS 10
+#define MAX_MODES 100
+
+#define BENCHMARK
+
+#ifdef BENCHMARK
+
+/* XXX this probably isn't very portable */
+
+#include
+#include
+
+/* return current time (in seconds) */
+static double
+current_time(void)
+{
+ struct timeval tv;
+#ifdef __VMS
+ (void) gettimeofday(&tv, NULL );
+#else
+ struct timezone tz;
+ (void) gettimeofday(&tv, &tz);
+#endif
+ return (double) tv.tv_sec + tv.tv_usec / 1000000.0;
+}
+
+#else /*BENCHMARK*/
+
+/* dummy */
+static double
+current_time(void)
+{
+ /* update this function for other platforms! */
+ static double t = 0.0;
+ static int warn = 1;
+ if (warn) {
+ fprintf(stderr, "Warning: current_time() not implemented!!\n");
+ warn = 0;
+ }
+ return t += 1.0;
+}
+
+#endif /*BENCHMARK*/
+
+
+#ifndef M_PI
+#define M_PI 3.14159265
+#endif
+
+
+static GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0;
+static GLint gear1, gear2, gear3;
+static GLfloat angle = 0.0;
+
+#if 0
+static GLfloat eyesep = 5.0; /* Eye separation. */
+static GLfloat fix_point = 40.0; /* Fixation point distance. */
+static GLfloat left, right, asp; /* Stereo frustum params. */
+#endif
+
+
+/*
+ *
+ * Draw a gear wheel. You'll probably want to call this function when
+ * building a display list since we do a lot of trig here.
+ *
+ * Input: inner_radius - radius of hole at center
+ * outer_radius - radius at center of teeth
+ * width - width of gear
+ * teeth - number of teeth
+ * tooth_depth - depth of tooth
+ */
+static void
+gear(GLfloat inner_radius, GLfloat outer_radius, GLfloat width,
+ GLint teeth, GLfloat tooth_depth)
+{
+ GLint i;
+ GLfloat r0, r1, r2;
+ GLfloat angle, da;
+ GLfloat u, v, len;
+
+ r0 = inner_radius;
+ r1 = outer_radius - tooth_depth / 2.0;
+ r2 = outer_radius + tooth_depth / 2.0;
+
+ da = 2.0 * M_PI / teeth / 4.0;
+
+ glShadeModel(GL_FLAT);
+
+ glNormal3f(0.0, 0.0, 1.0);
+
+ /* draw front face */
+ glBegin(GL_QUAD_STRIP);
+ for (i = 0; i <= teeth; i++) {
+ angle = i * 2.0 * M_PI / teeth;
+ glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
+ glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
+ if (i < teeth) {
+ glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
+ glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
+ width * 0.5);
+ }
+ }
+ glEnd();
+
+ /* draw front sides of teeth */
+ glBegin(GL_QUADS);
+ da = 2.0 * M_PI / teeth / 4.0;
+ for (i = 0; i < teeth; i++) {
+ angle = i * 2.0 * M_PI / teeth;
+
+ glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
+ glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5);
+ glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
+ width * 0.5);
+ glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
+ width * 0.5);
+ }
+ glEnd();
+
+ glNormal3f(0.0, 0.0, -1.0);
+
+ /* draw back face */
+ glBegin(GL_QUAD_STRIP);
+ for (i = 0; i <= teeth; i++) {
+ angle = i * 2.0 * M_PI / teeth;
+ glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
+ glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
+ if (i < teeth) {
+ glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
+ -width * 0.5);
+ glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
+ }
+ }
+ glEnd();
+
+ /* draw back sides of teeth */
+ glBegin(GL_QUADS);
+ da = 2.0 * M_PI / teeth / 4.0;
+ for (i = 0; i < teeth; i++) {
+ angle = i * 2.0 * M_PI / teeth;
+
+ glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
+ -width * 0.5);
+ glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
+ -width * 0.5);
+ glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5);
+ glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
+ }
+ glEnd();
+
+ /* draw outward faces of teeth */
+ glBegin(GL_QUAD_STRIP);
+ for (i = 0; i < teeth; i++) {
+ angle = i * 2.0 * M_PI / teeth;
+
+ glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
+ glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
+ u = r2 * cos(angle + da) - r1 * cos(angle);
+ v = r2 * sin(angle + da) - r1 * sin(angle);
+ len = sqrt(u * u + v * v);
+ u /= len;
+ v /= len;
+ glNormal3f(v, -u, 0.0);
+ glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5);
+ glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5);
+ glNormal3f(cos(angle), sin(angle), 0.0);
+ glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
+ width * 0.5);
+ glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
+ -width * 0.5);
+ u = r1 * cos(angle + 3 * da) - r2 * cos(angle + 2 * da);
+ v = r1 * sin(angle + 3 * da) - r2 * sin(angle + 2 * da);
+ glNormal3f(v, -u, 0.0);
+ glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
+ width * 0.5);
+ glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
+ -width * 0.5);
+ glNormal3f(cos(angle), sin(angle), 0.0);
+ }
+
+ glVertex3f(r1 * cos(0), r1 * sin(0), width * 0.5);
+ glVertex3f(r1 * cos(0), r1 * sin(0), -width * 0.5);
+
+ glEnd();
+
+ glShadeModel(GL_SMOOTH);
+
+ /* draw inside radius cylinder */
+ glBegin(GL_QUAD_STRIP);
+ for (i = 0; i <= teeth; i++) {
+ angle = i * 2.0 * M_PI / teeth;
+ glNormal3f(-cos(angle), -sin(angle), 0.0);
+ glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
+ glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
+ }
+ glEnd();
+}
+
+
+static void
+draw(void)
+{
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ glPushMatrix();
+ glRotatef(view_rotx, 1.0, 0.0, 0.0);
+ glRotatef(view_roty, 0.0, 1.0, 0.0);
+ glRotatef(view_rotz, 0.0, 0.0, 1.0);
+
+ glPushMatrix();
+ glTranslatef(-3.0, -2.0, 0.0);
+ glRotatef(angle, 0.0, 0.0, 1.0);
+ glCallList(gear1);
+ glPopMatrix();
+
+ glPushMatrix();
+ glTranslatef(3.1, -2.0, 0.0);
+ glRotatef(-2.0 * angle - 9.0, 0.0, 0.0, 1.0);
+ glCallList(gear2);
+ glPopMatrix();
+
+ glPushMatrix();
+ glTranslatef(-3.1, 4.2, 0.0);
+ glRotatef(-2.0 * angle - 25.0, 0.0, 0.0, 1.0);
+ glCallList(gear3);
+ glPopMatrix();
+
+ glPopMatrix();
+}
+
+
+/* new window size or exposure */
+static void
+reshape(int width, int height)
+{
+ 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
new file mode 100644
index 00000000000..a6a977d9fff
--- /dev/null
+++ b/progs/egl/opengl/xeglgears.c
@@ -0,0 +1,954 @@
+/*
+ * 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
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include
+
+
+#define BENCHMARK
+
+#ifdef BENCHMARK
+
+/* XXX this probably isn't very portable */
+
+#include
+#include
+
+/* return current time (in seconds) */
+static double
+current_time(void)
+{
+ struct timeval tv;
+#ifdef __VMS
+ (void) gettimeofday(&tv, NULL );
+#else
+ struct timezone tz;
+ (void) gettimeofday(&tv, &tz);
+#endif
+ return (double) tv.tv_sec + tv.tv_usec / 1000000.0;
+}
+
+#else /*BENCHMARK*/
+
+/* dummy */
+static double
+current_time(void)
+{
+ /* update this function for other platforms! */
+ static double t = 0.0;
+ static int warn = 1;
+ if (warn) {
+ fprintf(stderr, "Warning: current_time() not implemented!!\n");
+ warn = 0;
+ }
+ return t += 1.0;
+}
+
+#endif /*BENCHMARK*/
+
+
+
+#ifndef M_PI
+#define M_PI 3.14159265
+#endif
+
+
+static GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0;
+static GLint gear1, gear2, gear3;
+static GLfloat angle = 0.0;
+
+/*
+ *
+ * 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 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
new file mode 100644
index 00000000000..5787faecb90
--- /dev/null
+++ b/progs/egl/opengl/xeglthreads.c
@@ -0,0 +1,775 @@
+/*
+ * Copyright (C) 2000 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Ported to EGL by Chia-I Wu
+ */
+
+
+/*
+ * This program tests EGL thread safety.
+ * Command line options:
+ * -p Open a display connection for each thread
+ * -l Enable application-side locking
+ * -n Number of threads to create (default is 2)
+ * -display Specify X display (default is $DISPLAY)
+ * -t Use texture mapping
+ *
+ * Brian Paul 20 July 2000
+ */
+
+
+/*
+ * Notes:
+ * - Each thread gets its own EGL context.
+ *
+ * - The EGL contexts share texture objects.
+ *
+ * - When 't' is pressed to update the texture image, the window/thread which
+ * has input focus is signalled to change the texture. The other threads
+ * should see the updated texture the next time they call glBindTexture.
+ */
+
+
+#if defined(PTHREADS) /* defined by Mesa on Linux and other platforms */
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+
+/*
+ * Each window/thread/context:
+ */
+struct winthread {
+ Display *Dpy;
+ int Index;
+ pthread_t Thread;
+ Window Win;
+ EGLDisplay Display;
+ EGLContext Context;
+ EGLSurface Surface;
+ float Angle;
+ int WinWidth, WinHeight;
+ GLboolean NewSize;
+ GLboolean Initialized;
+ GLboolean MakeNewTexture;
+};
+
+
+#define MAX_WINTHREADS 100
+static struct winthread WinThreads[MAX_WINTHREADS];
+static int NumWinThreads = 0;
+static volatile GLboolean ExitFlag = GL_FALSE;
+
+static GLboolean MultiDisplays = 0;
+static GLboolean Locking = 0;
+static GLboolean Texture = GL_FALSE;
+static GLuint TexObj = 12;
+static GLboolean Animate = GL_TRUE;
+
+static pthread_mutex_t Mutex;
+static pthread_cond_t CondVar;
+static pthread_mutex_t CondMutex;
+
+
+static void
+Error(const char *msg)
+{
+ fprintf(stderr, "Error: %s\n", msg);
+ exit(1);
+}
+
+
+static void
+signal_redraw(void)
+{
+ pthread_mutex_lock(&CondMutex);
+ pthread_cond_broadcast(&CondVar);
+ pthread_mutex_unlock(&CondMutex);
+}
+
+
+static void
+MakeNewTexture(struct winthread *wt)
+{
+#define TEX_SIZE 128
+ static float step = 0.0;
+ GLfloat image[TEX_SIZE][TEX_SIZE][4];
+ GLint width;
+ int i, j;
+
+ for (j = 0; j < TEX_SIZE; j++) {
+ for (i = 0; i < TEX_SIZE; i++) {
+ float dt = 5.0 * (j - 0.5 * TEX_SIZE) / TEX_SIZE;
+ float ds = 5.0 * (i - 0.5 * TEX_SIZE) / TEX_SIZE;
+ float r = dt * dt + ds * ds + step;
+ image[j][i][0] =
+ image[j][i][1] =
+ image[j][i][2] = 0.75 + 0.25 * cos(r);
+ image[j][i][3] = 1.0;
+ }
+ }
+
+ step += 0.5;
+
+ glBindTexture(GL_TEXTURE_2D, TexObj);
+
+ glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width);
+ if (width) {
+ assert(width == TEX_SIZE);
+ /* sub-tex replace */
+ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, TEX_SIZE, TEX_SIZE,
+ GL_RGBA, GL_FLOAT, image);
+ }
+ else {
+ /* create new */
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TEX_SIZE, TEX_SIZE, 0,
+ GL_RGBA, GL_FLOAT, image);
+ }
+}
+
+
+
+/* draw a colored cube */
+static void
+draw_object(void)
+{
+ glPushMatrix();
+ glScalef(0.75, 0.75, 0.75);
+
+ glColor3f(1, 0, 0);
+
+ if (Texture) {
+ glBindTexture(GL_TEXTURE_2D, TexObj);
+ glEnable(GL_TEXTURE_2D);
+ }
+ else {
+ glDisable(GL_TEXTURE_2D);
+ }
+
+ glBegin(GL_QUADS);
+
+ /* -X */
+ glColor3f(0, 1, 1);
+ glTexCoord2f(0, 0); glVertex3f(-1, -1, -1);
+ glTexCoord2f(1, 0); glVertex3f(-1, 1, -1);
+ glTexCoord2f(1, 1); glVertex3f(-1, 1, 1);
+ glTexCoord2f(0, 1); glVertex3f(-1, -1, 1);
+
+ /* +X */
+ glColor3f(1, 0, 0);
+ glTexCoord2f(0, 0); glVertex3f(1, -1, -1);
+ glTexCoord2f(1, 0); glVertex3f(1, 1, -1);
+ glTexCoord2f(1, 1); glVertex3f(1, 1, 1);
+ glTexCoord2f(0, 1); glVertex3f(1, -1, 1);
+
+ /* -Y */
+ glColor3f(1, 0, 1);
+ glTexCoord2f(0, 0); glVertex3f(-1, -1, -1);
+ glTexCoord2f(1, 0); glVertex3f( 1, -1, -1);
+ glTexCoord2f(1, 1); glVertex3f( 1, -1, 1);
+ glTexCoord2f(0, 1); glVertex3f(-1, -1, 1);
+
+ /* +Y */
+ glColor3f(0, 1, 0);
+ glTexCoord2f(0, 0); glVertex3f(-1, 1, -1);
+ glTexCoord2f(1, 0); glVertex3f( 1, 1, -1);
+ glTexCoord2f(1, 1); glVertex3f( 1, 1, 1);
+ glTexCoord2f(0, 1); glVertex3f(-1, 1, 1);
+
+ /* -Z */
+ glColor3f(1, 1, 0);
+ glTexCoord2f(0, 0); glVertex3f(-1, -1, -1);
+ glTexCoord2f(1, 0); glVertex3f( 1, -1, -1);
+ glTexCoord2f(1, 1); glVertex3f( 1, 1, -1);
+ glTexCoord2f(0, 1); glVertex3f(-1, 1, -1);
+
+ /* +Y */
+ glColor3f(0, 0, 1);
+ glTexCoord2f(0, 0); glVertex3f(-1, -1, 1);
+ glTexCoord2f(1, 0); glVertex3f( 1, -1, 1);
+ glTexCoord2f(1, 1); glVertex3f( 1, 1, 1);
+ glTexCoord2f(0, 1); glVertex3f(-1, 1, 1);
+
+ glEnd();
+
+ glPopMatrix();
+}
+
+
+/* signal resize of given window */
+static void
+resize(struct winthread *wt, int w, int h)
+{
+ wt->NewSize = GL_TRUE;
+ wt->WinWidth = w;
+ wt->WinHeight = h;
+ if (!Animate)
+ signal_redraw();
+}
+
+
+/*
+ * We have an instance of this for each thread.
+ */
+static void
+draw_loop(struct winthread *wt)
+{
+ while (!ExitFlag) {
+
+ if (Locking)
+ pthread_mutex_lock(&Mutex);
+
+ if (!wt->Initialized) {
+ eglMakeCurrent(wt->Display, wt->Surface, wt->Surface, wt->Context);
+ printf("xeglthreads: %d: GL_RENDERER = %s\n", wt->Index,
+ (char *) glGetString(GL_RENDERER));
+ if (Texture /*&& wt->Index == 0*/) {
+ MakeNewTexture(wt);
+ }
+ wt->Initialized = GL_TRUE;
+ }
+
+ if (Locking)
+ pthread_mutex_unlock(&Mutex);
+
+ 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
+
+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
new file mode 100644
index 00000000000..135e3deb35b
--- /dev/null
+++ b/progs/egl/opengles1/.gitignore
@@ -0,0 +1,15 @@
+bindtex
+drawtex_x11
+drawtex_screen
+es1_info
+gears_x11
+gears_screen
+msaa
+pbuffer
+render_tex
+texture_from_pixmap
+torus_x11
+torus_screen
+tri_x11
+tri_screen
+two_win
diff --git a/progs/egl/opengles1/Makefile b/progs/egl/opengles1/Makefile
new file mode 100644
index 00000000000..554cff9e6b6
--- /dev/null
+++ b/progs/egl/opengles1/Makefile
@@ -0,0 +1,102 @@
+# progs/egl/opengles1/Makefile
+
+TOP = ../../..
+include $(TOP)/configs/current
+
+
+INCLUDE_DIRS = \
+ -I$(TOP)/include \
+
+HEADERS = $(TOP)/include/GLES/egl.h
+
+
+ES1_LIB_DEPS = \
+ $(TOP)/$(LIB_DIR)/libEGL.so \
+ $(TOP)/$(LIB_DIR)/libGLESv1_CM.so
+
+
+ES1_LIBS = \
+ -L$(TOP)/$(LIB_DIR) -lEGL \
+ -L$(TOP)/$(LIB_DIR) -lGLESv1_CM $(LIBDRM_LIB) -lX11
+
+EGLUT_DIR = $(TOP)/progs/egl/eglut
+
+EGLUT_DEMOS = \
+ drawtex \
+ gears \
+ torus \
+ tri
+
+EGLUT_X11_DEMOS := $(addsuffix _x11,$(EGLUT_DEMOS))
+EGLUT_SCREEN_DEMOS := $(addsuffix _screen,$(EGLUT_DEMOS))
+
+PROGRAMS = \
+ bindtex \
+ es1_info \
+ msaa \
+ pbuffer \
+ render_tex \
+ texture_from_pixmap \
+ two_win
+
+
+.c.o:
+ $(CC) -c $(INCLUDE_DIRS) -I$(EGLUT_DIR) $(CFLAGS) $< -o $@
+
+
+
+default: $(PROGRAMS) $(EGLUT_X11_DEMOS) $(EGLUT_SCREEN_DEMOS)
+
+
+
+bindtex: bindtex.o $(ES1_LIB_DEPS)
+ $(CC) $(CFLAGS) bindtex.o $(ES1_LIBS) -o $@
+
+
+es1_info: es1_info.o $(ES1_LIB_DEPS)
+ $(CC) $(CFLAGS) es1_info.o $(ES1_LIBS) -o $@
+
+
+msaa: msaa.o $(ES1_LIB_DEPS)
+ $(CC) $(CFLAGS) msaa.o $(ES1_LIBS) -o $@
+
+
+pbuffer: pbuffer.o $(ES1_LIB_DEPS)
+ $(CC) $(CFLAGS) pbuffer.o $(ES1_LIBS) -o $@
+
+
+render_tex: render_tex.o $(ES1_LIB_DEPS)
+ $(CC) $(CFLAGS) render_tex.o $(ES1_LIBS) -o $@
+
+
+texture_from_pixmap: texture_from_pixmap.o $(ES1_LIB_DEPS)
+ $(CC) $(CFLAGS) texture_from_pixmap.o $(ES1_LIBS) -o $@
+
+torus: torus.o $(ES1_LIB_DEPS)
+ $(CC) $(CFLAGS) torus.o $(ES1_LIBS) -o $@
+
+
+two_win: two_win.o $(ES1_LIB_DEPS)
+ $(CC) $(CFLAGS) two_win.o $(ES1_LIBS) -o $@
+
+
+$(EGLUT_DIR)/libeglut-x11.a $(EGLUT_DIR)/libeglut-screen.a:
+ @$(MAKE) -C $(EGLUT_DIR)
+
+# define the rules for EGLUT demos
+define eglut-demo-rule
+$(1)_x11 $(1)_screen: $(1)_%: $(1).o $(EGLUT_DIR)/libeglut-%.a $(ES1_LIB_DEPS)
+endef
+$(foreach demo, $(EGLUT_DEMOS), $(eval $(call eglut-demo-rule,$(demo))))
+
+# build EGLUT demos
+$(EGLUT_X11_DEMOS):
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -L$(EGLUT_DIR) -leglut-$* $(ES1_LIBS) -lX11
+$(EGLUT_SCREEN_DEMOS):
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -L$(EGLUT_DIR) -leglut-$* $(ES1_LIBS)
+
+
+clean:
+ -rm -f *.o *~
+ -rm -f $(PROGRAMS) $(EGLUT_X11_DEMOS) $(EGLUT_SCREEN_DEMOS)
+ @$(MAKE) -C $(EGLUT_DIR) clean
diff --git a/progs/egl/opengles1/bindtex.c b/progs/egl/opengles1/bindtex.c
new file mode 100644
index 00000000000..c243b5941b7
--- /dev/null
+++ b/progs/egl/opengles1/bindtex.c
@@ -0,0 +1,474 @@
+/*
+ * Simple demo for eglBindTexImage. Based on xegl_tri.c by
+ *
+ * Copyright (C) 2008 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*
+ * The spec says that eglBindTexImage supports only OpenGL ES context, but this
+ * demo uses OpenGL context. Keep in mind that this is non-standard.
+ */
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+static EGLDisplay dpy;
+static EGLContext ctx_win, ctx_pbuf;
+static EGLSurface surf_win, surf_pbuf;
+static GLuint tex_pbuf;
+
+static GLfloat view_rotx = 0.0, view_roty = 0.0, view_rotz = 0.0;
+static GLboolean blend = GL_TRUE;
+static GLuint color_flow;
+
+static void
+make_pbuffer(int width, int height)
+{
+ static const EGLint config_attribs[] = {
+ EGL_RED_SIZE, 8,
+ EGL_GREEN_SIZE, 8,
+ EGL_BLUE_SIZE, 8,
+ EGL_BIND_TO_TEXTURE_RGB, EGL_TRUE,
+ EGL_NONE
+ };
+ EGLint pbuf_attribs[] = {
+ EGL_WIDTH, width,
+ EGL_HEIGHT, height,
+ EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGB,
+ EGL_TEXTURE_TARGET, EGL_TEXTURE_2D,
+ EGL_NONE
+ };
+ EGLConfig config;
+ EGLint num_configs;
+
+ if (!eglChooseConfig(dpy, config_attribs, &config, 1, &num_configs) ||
+ !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
new file mode 100644
index 00000000000..e9ac0153408
--- /dev/null
+++ b/progs/egl/opengles1/drawtex.c
@@ -0,0 +1,217 @@
+/*
+ * Copyright (C) 2008 Tunsgten Graphics,Inc. All Rights Reserved.
+ */
+
+/*
+ * Test GL_OES_draw_texture
+ * Brian Paul
+ * August 2008
+ */
+
+#define GL_GLEXT_PROTOTYPES
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+#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
new file mode 100644
index 00000000000..93816b52150
--- /dev/null
+++ b/progs/egl/opengles1/es1_info.c
@@ -0,0 +1,289 @@
+/*
+ * 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
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+
+/*
+ * 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 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
new file mode 100644
index 00000000000..8462a4871a7
--- /dev/null
+++ b/progs/egl/opengles1/gears.c
@@ -0,0 +1,383 @@
+/*
+ * Copyright (C) 2009 Chia-I Wu
+ *
+ * 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
+#include
+#include
+#include
+
+#include
+#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
new file mode 100644
index 00000000000..b4c6c632177
--- /dev/null
+++ b/progs/egl/opengles1/msaa.c
@@ -0,0 +1,442 @@
+/*
+ * 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
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#if USE_FULL_GL
+#include /* use full OpenGL */
+#else
+#include /* use OpenGL ES 1.x */
+#include
+#endif
+#include
+
+
+
+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 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
new file mode 100644
index 00000000000..60f864445af
--- /dev/null
+++ b/progs/egl/opengles1/pbuffer.c
@@ -0,0 +1,608 @@
+/*
+ * Copyright (C) 2008 Tunsgten Graphics,Inc. All Rights Reserved.
+ */
+
+/*
+ * Test EGL Pbuffers
+ * Brian Paul
+ * August 2008
+ */
+
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+
+
+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 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
new file mode 100644
index 00000000000..0200fa4cb06
--- /dev/null
+++ b/progs/egl/opengles1/render_tex.c
@@ -0,0 +1,659 @@
+/*
+ * Copyright (C) 2008 Tunsgten Graphics,Inc. All Rights Reserved.
+ */
+
+/*
+ * Test EGL render to texture.
+ * Brian Paul
+ * August 2008
+ */
+
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+
+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 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
new file mode 100644
index 00000000000..79b9474a574
--- /dev/null
+++ b/progs/egl/opengles1/texture_from_pixmap.c
@@ -0,0 +1,578 @@
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.9
+ *
+ * Copyright (C) 2010 LunarG Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ * Chia-I Wu
+ */
+
+/*
+ * This demo uses EGL_KHR_image_pixmap and GL_OES_EGL_image to demonstrate
+ * texture-from-pixmap.
+ */
+
+#include
+#include
+#include
+#include
+#include /* for usleep */
+#include /* for gettimeofday */
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+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
new file mode 100644
index 00000000000..8f262b53d6c
--- /dev/null
+++ b/progs/egl/opengles1/torus.c
@@ -0,0 +1,448 @@
+/*
+ * 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
+#include
+#include
+#include
+#include
+
+#include "eglut.h"
+
+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
new file mode 100644
index 00000000000..01ad9bd37e4
--- /dev/null
+++ b/progs/egl/opengles1/tri.c
@@ -0,0 +1,211 @@
+/*
+ * Copyright (C) 2008 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*
+ * Draw a triangle with X/EGL and OpenGL ES 1.x
+ * Brian Paul
+ * 5 June 2008
+ */
+
+#define USE_FIXED_POINT 0
+
+
+#include
+#include
+#include