summaryrefslogtreecommitdiff
path: root/progs
diff options
context:
space:
mode:
Diffstat (limited to 'progs')
-rw-r--r--progs/SConscript38
-rw-r--r--progs/SConstruct65
-rw-r--r--progs/demos/SConscript124
-rw-r--r--progs/demos/arbfplight.c3
-rw-r--r--progs/demos/arbfslight.c3
-rw-r--r--progs/demos/arbocclude.c3
-rw-r--r--progs/demos/bounce.c4
-rw-r--r--progs/demos/clearspd.c3
-rw-r--r--progs/demos/copypix.c7
-rw-r--r--progs/demos/cubemap.c3
-rw-r--r--progs/demos/drawpix.c7
-rw-r--r--progs/demos/engine.c2
-rw-r--r--progs/demos/fbo_firecube.c2
-rw-r--r--progs/demos/fire.c1
-rw-r--r--progs/demos/fogcoord.c2
-rw-r--r--progs/demos/fplight.c3
-rw-r--r--progs/demos/fslight.c3
-rw-r--r--progs/demos/gamma.c5
-rw-r--r--progs/demos/gearbox.c2
-rw-r--r--progs/demos/gears.c4
-rw-r--r--progs/demos/geartrain.c13
-rw-r--r--progs/demos/gloss.c2
-rw-r--r--progs/demos/gltestperf.c3
-rw-r--r--progs/demos/ipers.c1
-rw-r--r--progs/demos/isosurf.c3
-rw-r--r--progs/demos/lodbias.c3
-rw-r--r--progs/demos/morph3d.c3
-rw-r--r--progs/demos/multiarb.c3
-rw-r--r--progs/demos/paltex.c5
-rw-r--r--progs/demos/pointblast.c4
-rw-r--r--progs/demos/projtex.c9
-rw-r--r--progs/demos/ray.c1
-rw-r--r--progs/demos/readpix.c5
-rw-r--r--progs/demos/renormal.c5
-rw-r--r--progs/demos/shadowtex.c3
-rw-r--r--progs/demos/spectex.c6
-rw-r--r--progs/demos/spriteblast.c4
-rw-r--r--progs/demos/teapot.c1
-rw-r--r--progs/demos/terrain.c1
-rw-r--r--progs/demos/tessdemo.c3
-rw-r--r--progs/demos/texcyl.c4
-rw-r--r--progs/demos/texenv.c3
-rw-r--r--progs/demos/textures.c3
-rw-r--r--progs/demos/trispd.c7
-rw-r--r--progs/demos/tunnel.c1
-rw-r--r--progs/demos/tunnel2.c1
-rw-r--r--progs/demos/vao_demo.c3
-rw-r--r--progs/demos/winpos.c3
-rw-r--r--progs/egl/demo1.c1
-rw-r--r--progs/egl/demo2.c14
-rw-r--r--progs/egl/demo3.c15
-rw-r--r--progs/egl/eglgears.c1
-rw-r--r--progs/egl/egltri.c1
-rw-r--r--progs/egl/xegl_tri.c4
-rw-r--r--progs/egl/xeglbindtex.c12
-rw-r--r--progs/egl/xeglgears.c2
-rw-r--r--progs/egl/xeglthreads.c4
-rw-r--r--progs/es1/.gitignore10
-rw-r--r--progs/es1/screen/Makefile32
-rw-r--r--progs/es1/screen/gears.c374
-rw-r--r--progs/es1/screen/tri.c129
-rw-r--r--progs/es1/screen/winsys.c272
-rw-r--r--progs/es1/screen/winsys.h36
-rw-r--r--progs/es1/xegl/Makefile77
-rw-r--r--progs/es1/xegl/drawtex.c427
-rw-r--r--progs/es1/xegl/es1_info.c289
-rw-r--r--progs/es1/xegl/msaa.c442
-rw-r--r--progs/es1/xegl/pbuffer.c607
-rw-r--r--progs/es1/xegl/render_tex.c659
-rw-r--r--progs/es1/xegl/torus.c656
-rw-r--r--progs/es1/xegl/tri.c470
-rw-r--r--progs/es1/xegl/two_win.c433
-rw-r--r--progs/es2/.gitignore3
-rw-r--r--progs/es2/xegl/Makefile51
-rw-r--r--progs/es2/xegl/tri.c515
-rw-r--r--progs/fp/SConscript15
-rw-r--r--progs/fp/fp-tri.c13
-rw-r--r--progs/fp/mov-imm.txt3
-rw-r--r--progs/fp/mov-param.txt4
-rw-r--r--progs/fp/position-frc-integer.txt7
-rw-r--r--progs/fp/position-frc.txt6
-rw-r--r--progs/fp/position-upper-left.txt7
-rw-r--r--progs/fp/position.txt2
-rw-r--r--progs/glsl/CH11-bumpmaptex.frag47
-rw-r--r--progs/glsl/SConscript20
-rw-r--r--progs/glsl/bump.c55
-rw-r--r--progs/glsl/deriv.c15
-rw-r--r--progs/objviewer/.gitignore8
-rw-r--r--progs/openvg/demos/eglcommon.c5
-rw-r--r--progs/openvg/demos/lion.c5
-rw-r--r--progs/openvg/trivial/eglcommon.c5
-rw-r--r--progs/osdemos/Makefile13
-rw-r--r--progs/perf/SConscript11
-rw-r--r--progs/rbug/bin_to_bmp.c16
-rw-r--r--progs/rbug/tex_dump.c3
-rw-r--r--progs/redbook/SConscript20
-rw-r--r--progs/samples/.gitignore1
-rw-r--r--progs/samples/SConscript20
-rw-r--r--progs/tests/Makefile3
-rw-r--r--progs/tests/SConscript22
-rw-r--r--progs/tests/condrender.c242
-rw-r--r--progs/tests/drawbuffers2.c364
-rw-r--r--progs/tests/texleak.c140
-rw-r--r--progs/trivial/.gitignore1
-rw-r--r--progs/trivial/Makefile2
-rw-r--r--progs/trivial/SConscript12
-rw-r--r--progs/trivial/tri-orig.c10
-rw-r--r--progs/trivial/tri-point-line-clipped.c116
-rw-r--r--progs/trivial/vbo-tri.c131
-rw-r--r--progs/vp/SConscript11
-rw-r--r--progs/vp/add-param-imm.txt7
-rw-r--r--progs/vpglsl/SConscript11
-rw-r--r--progs/wgl/SConscript14
-rw-r--r--progs/xdemos/.gitignore1
-rw-r--r--progs/xdemos/Makefile1
-rw-r--r--progs/xdemos/glsync.c111
-rw-r--r--progs/xdemos/msctest.c202
-rw-r--r--progs/xdemos/offset.c10
118 files changed, 7160 insertions, 475 deletions
diff --git a/progs/SConscript b/progs/SConscript
index 66eaf9e541..3b180d00bc 100644
--- a/progs/SConscript
+++ b/progs/SConscript
@@ -1,5 +1,43 @@
SConscript([
'util/SConscript',
+])
+
+Import('*')
+
+progs_env = env.Clone()
+
+if progs_env['platform'] == 'windows':
+ progs_env.Append(CPPDEFINES = ['NOMINMAX'])
+ progs_env.Prepend(LIBS = [
+ 'winmm',
+ 'kernel32',
+ 'user32',
+ 'gdi32',
+ ])
+
+# OpenGL
+if progs_env['platform'] == 'windows':
+ progs_env.Prepend(LIBS = ['glu32', 'opengl32'])
+else:
+ progs_env.Prepend(LIBS = ['GLU', 'GL'])
+
+# Glut
+progs_env.Prepend(LIBS = [glut])
+
+# GLEW
+progs_env.Prepend(LIBS = [glew])
+
+progs_env.Prepend(CPPPATH = [
+ '#progs/util',
+])
+
+progs_env.Prepend(LIBS = [
+ util,
+])
+
+Export('progs_env')
+
+SConscript([
'demos/SConscript',
'glsl/SConscript',
'redbook/SConscript',
diff --git a/progs/SConstruct b/progs/SConstruct
deleted file mode 100644
index 4d268cc6d7..0000000000
--- a/progs/SConstruct
+++ /dev/null
@@ -1,65 +0,0 @@
-import os
-import os.path
-import sys
-
-env = Environment(
- tools = ['generic'],
- toolpath = ['../scons'],
- ENV = os.environ,
-)
-
-
-# Use Mesa's headers and libs
-if 1:
- build_topdir = 'build'
- build_subdir = env['platform']
- if env['machine'] != 'generic':
- build_subdir += '-' + env['machine']
- if env['debug']:
- build_subdir += "-debug"
- if env['profile']:
- build_subdir += "-profile"
- build_dir = os.path.join(build_topdir, build_subdir)
-
- env.Append(CPPDEFINES = ['GLEW_STATIC'])
- env.Append(CPPPATH = ['#../include'])
- env.Append(LIBPATH = [
- '#../' + build_dir + '/glew/',
- '#../' + build_dir + '/glut/glx',
- ])
-
-
-conf = Configure(env)
-
-# OpenGL
-if env['platform'] == 'windows':
- env.Prepend(LIBS = ['glu32', 'opengl32'])
-else:
- env.Prepend(LIBS = ['GLU', 'GL'])
-
-# Glut
-env['GLUT'] = False
-if conf.CheckCHeader('GL/glut.h'):
- if env['platform'] == 'windows':
- env['GLUT_LIB'] = 'glut32'
- else:
- env['GLUT_LIB'] = 'glut'
- env['GLUT'] = True
-
-# GLEW
-env['GLEW'] = False
-if conf.CheckCHeader('GL/glew.h'):
- env['GLEW_LIB'] = 'glew'
- env['GLEW'] = True
- env.Prepend(LIBS = ['glew'])
-
-conf.Finish()
-
-
-Export('env')
-
-SConscript(
- 'SConscript',
- build_dir = env['build'],
- duplicate = 0 # http://www.scons.org/doc/0.97/HTML/scons-user/x2261.html
-)
diff --git a/progs/demos/SConscript b/progs/demos/SConscript
index f851870bcf..742dd66f36 100644
--- a/progs/demos/SConscript
+++ b/progs/demos/SConscript
@@ -1,84 +1,66 @@
Import('*')
-if not env['GLUT']:
- Return()
-
-env = env.Clone()
-
-env.Prepend(CPPPATH = [
- '../util',
-])
-
-env.Prepend(LIBS = [
- util,
- '$GLUT_LIB'
-])
-
-if env['platform'] == 'windows':
- env.Append(CPPDEFINES = ['NOMINMAX'])
- env.Prepend(LIBS = ['winmm'])
-
progs = [
- 'arbfplight',
- 'arbfslight',
- 'arbocclude',
- 'bounce',
- 'clearspd',
- 'copypix',
- 'cubemap',
- 'drawpix',
- 'engine',
- 'fbo_firecube',
- 'fire',
- 'fogcoord',
- 'fplight',
- 'fslight',
- 'gamma',
- 'gearbox',
- 'gears',
- 'geartrain',
- 'glinfo',
- 'gloss',
- 'gltestperf',
- 'ipers',
- 'isosurf',
- 'lodbias',
- 'morph3d',
- 'multiarb',
- 'paltex',
- 'pointblast',
- 'ray',
- 'readpix',
- 'reflect',
- 'renormal',
- 'shadowtex',
- 'singlebuffer',
- 'spectex',
- 'spriteblast',
- 'stex3d',
- 'teapot',
- 'terrain',
- 'tessdemo',
- 'texcyl',
- 'texenv',
- 'textures',
- 'trispd',
- 'tunnel',
- 'tunnel2',
- 'vao_demo',
- 'winpos',
- 'dinoshade',
- 'fbotexture',
- 'projtex',
+ 'arbfplight',
+ 'arbfslight',
+ 'arbocclude',
+ 'bounce',
+ 'clearspd',
+ 'copypix',
+ 'cubemap',
+ 'drawpix',
+ 'engine',
+ 'fbo_firecube',
+ 'fire',
+ 'fogcoord',
+ 'fplight',
+ 'fslight',
+ 'gamma',
+ 'gearbox',
+ 'gears',
+ 'geartrain',
+ 'glinfo',
+ 'gloss',
+ 'gltestperf',
+ 'ipers',
+ 'isosurf',
+ 'lodbias',
+ 'morph3d',
+ 'multiarb',
+ 'paltex',
+ 'pointblast',
+ 'ray',
+ 'readpix',
+ 'reflect',
+ 'renormal',
+ 'shadowtex',
+ 'singlebuffer',
+ 'spectex',
+ 'spriteblast',
+ 'stex3d',
+ 'teapot',
+ 'terrain',
+ 'tessdemo',
+ 'texcyl',
+ 'texenv',
+ 'textures',
+ 'trispd',
+ 'tunnel',
+ 'tunnel2',
+ 'vao_demo',
+ 'winpos',
+ 'dinoshade',
+ 'fbotexture',
+ 'projtex',
]
for prog in progs:
- env.Program(
+ progs_env.Program(
target = prog,
source = prog + '.c',
)
-env.Program(
+progs_env.Program(
target = 'rain',
source = [
'rain.cxx',
diff --git a/progs/demos/arbfplight.c b/progs/demos/arbfplight.c
index 7b7a12bf88..861b3b7252 100644
--- a/progs/demos/arbfplight.c
+++ b/progs/demos/arbfplight.c
@@ -388,9 +388,8 @@ static void Init( void )
int main( int argc, char *argv[] )
{
- glutInit( &argc, argv );
- glutInitWindowPosition( 0, 0 );
glutInitWindowSize( 200, 200 );
+ glutInit( &argc, argv );
glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
Win = glutCreateWindow(argv[0]);
glutReshapeFunc( Reshape );
diff --git a/progs/demos/arbfslight.c b/progs/demos/arbfslight.c
index 275c85105e..a0ce7f3f5b 100644
--- a/progs/demos/arbfslight.c
+++ b/progs/demos/arbfslight.c
@@ -311,9 +311,8 @@ static void Init (void)
int main (int argc, char *argv[])
{
- glutInit (&argc, argv);
- glutInitWindowPosition ( 0, 0);
glutInitWindowSize (200, 200);
+ glutInit (&argc, argv);
glutInitDisplayMode (GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow (argv[0]);
glutReshapeFunc (Reshape);
diff --git a/progs/demos/arbocclude.c b/progs/demos/arbocclude.c
index 9188ad5a56..f669a1f26b 100644
--- a/progs/demos/arbocclude.c
+++ b/progs/demos/arbocclude.c
@@ -268,9 +268,8 @@ static void Init( void )
int main( int argc, char *argv[] )
{
- glutInit( &argc, argv );
- glutInitWindowPosition( 0, 0 );
glutInitWindowSize( 400, 400 );
+ glutInit( &argc, argv );
glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
Win = glutCreateWindow(argv[0]);
glewInit();
diff --git a/progs/demos/bounce.c b/progs/demos/bounce.c
index 436bc7d1fb..a9a291e0a6 100644
--- a/progs/demos/bounce.c
+++ b/progs/demos/bounce.c
@@ -192,10 +192,8 @@ visible(int vis)
int main(int argc, char *argv[])
{
- glutInit(&argc, argv);
- glutInitWindowPosition(0, 0);
glutInitWindowSize(600, 450);
-
+ glutInit(&argc, argv);
IndexMode = argc > 1 && strcmp(argv[1], "-ci") == 0;
if (IndexMode)
diff --git a/progs/demos/clearspd.c b/progs/demos/clearspd.c
index 42953f6675..c40f118a64 100644
--- a/progs/demos/clearspd.c
+++ b/progs/demos/clearspd.c
@@ -187,9 +187,8 @@ int main( int argc, char *argv[] )
Init( argc, argv );
- glutInit( &argc, argv );
glutInitWindowSize( (int) Width, (int) Height );
- glutInitWindowPosition( 0, 0 );
+ glutInit( &argc, argv );
mode = ColorMode | GLUT_DOUBLE;
if (BufferMask & GL_STENCIL_BUFFER_BIT)
diff --git a/progs/demos/copypix.c b/progs/demos/copypix.c
index a13339ea62..98c835f44f 100644
--- a/progs/demos/copypix.c
+++ b/progs/demos/copypix.c
@@ -237,6 +237,9 @@ int main( int argc, char *argv[] )
const char *filename = IMAGE_FILE;
int i = 1;
+ glutInitWindowSize( WinWidth, WinHeight );
+ glutInit( &argc, argv );
+
if (argc > i && strcmp(argv[i], "-ci")==0) {
ciMode = GL_TRUE;
i++;
@@ -245,10 +248,6 @@ int main( int argc, char *argv[] )
filename = argv[i];
}
- glutInit( &argc, argv );
- glutInitWindowPosition( 0, 0 );
- glutInitWindowSize( WinWidth, WinHeight );
-
if (ciMode)
glutInitDisplayMode( GLUT_INDEX | GLUT_DOUBLE );
else
diff --git a/progs/demos/cubemap.c b/progs/demos/cubemap.c
index 20332b1d96..3e79d6a558 100644
--- a/progs/demos/cubemap.c
+++ b/progs/demos/cubemap.c
@@ -613,9 +613,8 @@ static void parse_args(int argc, char *argv[])
int main( int argc, char *argv[] )
{
- glutInit(&argc, argv);
- glutInitWindowPosition(0, 0);
glutInitWindowSize(600, 500);
+ glutInit(&argc, argv);
glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE );
glutCreateWindow("Texture Cube Mapping");
glewInit();
diff --git a/progs/demos/drawpix.c b/progs/demos/drawpix.c
index 5490bcc635..9bc7086e04 100644
--- a/progs/demos/drawpix.c
+++ b/progs/demos/drawpix.c
@@ -328,6 +328,9 @@ int main( int argc, char *argv[] )
const char *filename = IMAGE_FILE;
int i = 1;
+ glutInitWindowSize( 500, 400 );
+ glutInit( &argc, argv );
+
if (argc > i && strcmp(argv[i], "-ci")==0) {
ciMode = GL_TRUE;
i++;
@@ -336,10 +339,6 @@ int main( int argc, char *argv[] )
filename = argv[i];
}
- glutInit( &argc, argv );
- glutInitWindowPosition( 0, 0 );
- glutInitWindowSize( 500, 400 );
-
if (ciMode)
glutInitDisplayMode( GLUT_INDEX | GLUT_DOUBLE );
else
diff --git a/progs/demos/engine.c b/progs/demos/engine.c
index 838d28c363..7e485111da 100644
--- a/progs/demos/engine.c
+++ b/progs/demos/engine.c
@@ -1320,8 +1320,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);
glutCreateWindow("OpenGL Engine Demo");
glewInit();
diff --git a/progs/demos/fbo_firecube.c b/progs/demos/fbo_firecube.c
index b3f7e00e5a..17767a148f 100644
--- a/progs/demos/fbo_firecube.c
+++ b/progs/demos/fbo_firecube.c
@@ -1051,11 +1051,11 @@ visible(int vis)
int
main(int argc, char *argv[])
{
+ glutInitWindowSize(WinWidth, WinHeight);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
- glutInitWindowSize(WinWidth, WinHeight);
Win = glutCreateWindow("fbo_firecube");
glewInit();
init(argc, argv);
diff --git a/progs/demos/fire.c b/progs/demos/fire.c
index 475582c81b..bb912fb447 100644
--- a/progs/demos/fire.c
+++ b/progs/demos/fire.c
@@ -739,7 +739,6 @@ main(int ac, char **av)
HEIGHT = atoi(av[3]);
}
- glutInitWindowPosition(0, 0);
glutInitWindowSize(WIDTH, HEIGHT);
glutInit(&ac, av);
diff --git a/progs/demos/fogcoord.c b/progs/demos/fogcoord.c
index 7d5c11aabf..336aa58075 100644
--- a/progs/demos/fogcoord.c
+++ b/progs/demos/fogcoord.c
@@ -404,8 +404,8 @@ Init(void)
int
main( int argc, char *argv[] )
{
- glutInit( &argc, argv );
glutInitWindowSize( 600, 600 );
+ glutInit( &argc, argv );
glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
glutCreateWindow(argv[0]);
glewInit();
diff --git a/progs/demos/fplight.c b/progs/demos/fplight.c
index c297354103..f52a4f7868 100644
--- a/progs/demos/fplight.c
+++ b/progs/demos/fplight.c
@@ -268,9 +268,8 @@ static void Init( void )
int main( int argc, char *argv[] )
{
- glutInit( &argc, argv );
- glutInitWindowPosition( 0, 0 );
glutInitWindowSize( 200, 200 );
+ glutInit( &argc, argv );
glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
Win = glutCreateWindow(argv[0]);
glewInit();
diff --git a/progs/demos/fslight.c b/progs/demos/fslight.c
index acba3e9583..395b7caa2c 100644
--- a/progs/demos/fslight.c
+++ b/progs/demos/fslight.c
@@ -600,9 +600,8 @@ ParseOptions(int argc, char *argv[])
int
main(int argc, char *argv[])
{
- glutInit(&argc, argv);
- glutInitWindowPosition( 0, 0);
glutInitWindowSize(200, 200);
+ glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
win = glutCreateWindow(argv[0]);
glutReshapeFunc(Reshape);
diff --git a/progs/demos/gamma.c b/progs/demos/gamma.c
index 9b2c3e1052..61c6d125fb 100644
--- a/progs/demos/gamma.c
+++ b/progs/demos/gamma.c
@@ -146,12 +146,9 @@ display(void)
int
main(int argc, char **argv)
{
+ glutInitWindowSize(500, 400);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
-
- glutInitWindowPosition(50, 50);
- glutInitWindowSize(500, 400);
-
glutCreateWindow("gamma test patterns");
glutReshapeFunc(Reshape);
glutDisplayFunc(display);
diff --git a/progs/demos/gearbox.c b/progs/demos/gearbox.c
index 2dcf32f92f..71d0281904 100644
--- a/progs/demos/gearbox.c
+++ b/progs/demos/gearbox.c
@@ -474,10 +474,10 @@ visible(int vis)
int
main(int argc, char *argv[])
{
+ glutInitWindowSize(WinWidth, WinHeight);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
- glutInitWindowSize(WinWidth, WinHeight);
Win = glutCreateWindow("gearbox");
init(argc, argv);
diff --git a/progs/demos/gears.c b/progs/demos/gears.c
index 6016162d6f..31a5b79eab 100644
--- a/progs/demos/gears.c
+++ b/progs/demos/gears.c
@@ -385,11 +385,9 @@ visible(int vis)
int main(int argc, char *argv[])
{
+ glutInitWindowSize(300, 300);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
-
- glutInitWindowPosition(0, 0);
- glutInitWindowSize(300, 300);
win = glutCreateWindow("Gears");
init(argc, argv);
diff --git a/progs/demos/geartrain.c b/progs/demos/geartrain.c
index e6567dd647..00b6e78b72 100644
--- a/progs/demos/geartrain.c
+++ b/progs/demos/geartrain.c
@@ -1060,19 +1060,18 @@ main (int argc, char *argv[])
{
char *file;
- if (argc < 2)
- file = "geartrain.dat";
- else
- file = argv[1];
-
- glutInit(&argc, argv);
- glutInitWindowPosition (0, 0);
glutInitWindowSize(640,480);
+ glutInit(&argc, argv);
glutInitDisplayMode (GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE );
if (glutCreateWindow ("Gear Train Simulation") == GL_FALSE)
exit (1);
+ if (argc < 2)
+ file = "geartrain.dat";
+ else
+ file = argv[1];
+
getdata (file);
process ();
init ();
diff --git a/progs/demos/gloss.c b/progs/demos/gloss.c
index 69694b23a0..578736b4e2 100644
--- a/progs/demos/gloss.c
+++ b/progs/demos/gloss.c
@@ -436,8 +436,8 @@ static void Init( int argc, char *argv[] )
int main( int argc, char *argv[] )
{
- glutInit( &argc, argv );
glutInitWindowSize(WinWidth, WinHeight);
+ glutInit( &argc, argv );
glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
glutCreateWindow(argv[0] );
glewInit();
diff --git a/progs/demos/gltestperf.c b/progs/demos/gltestperf.c
index 2188b02419..3658a39598 100644
--- a/progs/demos/gltestperf.c
+++ b/progs/demos/gltestperf.c
@@ -569,10 +569,9 @@ main(int ac, char **av)
if (ac == 2)
frontbuffer = 0;
+ glutInitWindowSize(640, 480);
glutInit(&ac, av);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
- glutInitWindowPosition(0, 0);
- glutInitWindowSize(640, 480);
glutCreateWindow("OpenGL/Mesa Performances");
glutDisplayFunc(display);
glutMainLoop();
diff --git a/progs/demos/ipers.c b/progs/demos/ipers.c
index ed03673cb6..265378b90a 100644
--- a/progs/demos/ipers.c
+++ b/progs/demos/ipers.c
@@ -682,7 +682,6 @@ main(int ac, char **av)
fprintf(stderr,
"IperS V1.0\nWritten by David Bucciarelli (tech.hmw@plus.it)\n");
- glutInitWindowPosition(0, 0);
glutInitWindowSize(WIDTH, HEIGHT);
glutInit(&ac, av);
diff --git a/progs/demos/isosurf.c b/progs/demos/isosurf.c
index d9e50a3c19..a5b21ffb5c 100644
--- a/progs/demos/isosurf.c
+++ b/progs/demos/isosurf.c
@@ -1062,9 +1062,8 @@ int main(int argc, char **argv)
read_surface( "isosurf.dat" );
- glutInit( &argc, argv);
- glutInitWindowPosition(0, 0);
glutInitWindowSize(400, 400);
+ glutInit( &argc, argv);
type = GLUT_DEPTH;
type |= GLUT_RGB;
diff --git a/progs/demos/lodbias.c b/progs/demos/lodbias.c
index 8d39bd605a..23488b1616 100644
--- a/progs/demos/lodbias.c
+++ b/progs/demos/lodbias.c
@@ -282,9 +282,8 @@ static void Init( void )
int main( int argc, char *argv[] )
{
- glutInit( &argc, argv );
- glutInitWindowPosition( 0, 0 );
glutInitWindowSize( 350, 350 );
+ glutInit( &argc, argv );
glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
win = glutCreateWindow(argv[0]);
glutReshapeFunc( Reshape );
diff --git a/progs/demos/morph3d.c b/progs/demos/morph3d.c
index eab520a989..07458eb156 100644
--- a/progs/demos/morph3d.c
+++ b/progs/demos/morph3d.c
@@ -840,9 +840,8 @@ int main(int argc, char **argv)
object=1;
- glutInit(&argc, argv);
- glutInitWindowPosition(0,0);
glutInitWindowSize(640,480);
+ glutInit(&argc, argv);
glutInitDisplayMode( GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGB );
diff --git a/progs/demos/multiarb.c b/progs/demos/multiarb.c
index 3d89d3a13e..82796a0c3f 100644
--- a/progs/demos/multiarb.c
+++ b/progs/demos/multiarb.c
@@ -338,9 +338,8 @@ int main( int argc, char *argv[] )
{
GLint i;
- glutInit( &argc, argv );
glutInitWindowSize( 300, 300 );
- glutInitWindowPosition( 0, 0 );
+ glutInit( &argc, argv );
glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
glutCreateWindow(argv[0] );
glewInit();
diff --git a/progs/demos/paltex.c b/progs/demos/paltex.c
index d0cbcfb5e9..5d4b8662b5 100644
--- a/progs/demos/paltex.c
+++ b/progs/demos/paltex.c
@@ -248,12 +248,9 @@ static void Init2( void )
int main( int argc, char *argv[] )
{
- glutInit( &argc, argv );
- glutInitWindowPosition( 0, 0 );
glutInitWindowSize( 400, 300 );
-
+ glutInit( &argc, argv );
glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
-
glutCreateWindow(argv[0]);
glewInit();
diff --git a/progs/demos/pointblast.c b/progs/demos/pointblast.c
index 2d70b72589..b4d0a67f99 100644
--- a/progs/demos/pointblast.c
+++ b/progs/demos/pointblast.c
@@ -427,10 +427,10 @@ int
main(int argc, char **argv)
{
int i;
+
+ glutInitWindowSize(300, 300);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE);
- glutInitWindowPosition(0, 0);
- glutInitWindowSize(300, 300);
for (i=1; i<argc; i++) {
if(!strcmp("-noms", argv[i])) {
diff --git a/progs/demos/projtex.c b/progs/demos/projtex.c
index 503cf5de08..d162568b9f 100644
--- a/progs/demos/projtex.c
+++ b/progs/demos/projtex.c
@@ -998,18 +998,17 @@ menu(int selection)
int
main(int argc, char **argv)
{
+ glutInitWindowSize(500,500);
glutInit(&argc, argv);
+ glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);
+ (void) glutCreateWindow("projtex");
+ glewInit();
if (argc > 1) {
NumTextures = atoi(argv[1]);
}
assert(NumTextures <= MAX_TEX);
- glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);
- glutInitWindowSize(500,500);
- (void) glutCreateWindow("projtex");
- glewInit();
-
loadTexture = loadImageTextures;
drawObject = drawCube;
initialize();
diff --git a/progs/demos/ray.c b/progs/demos/ray.c
index e9211aa339..9cc464d239 100644
--- a/progs/demos/ray.c
+++ b/progs/demos/ray.c
@@ -856,7 +856,6 @@ main(int ac, char **av)
}
*/
- glutInitWindowPosition(0, 0);
glutInitWindowSize(WIDTH, HEIGHT);
glutInit(&ac, av);
diff --git a/progs/demos/readpix.c b/progs/demos/readpix.c
index 182b01d7ff..cc4e490269 100644
--- a/progs/demos/readpix.c
+++ b/progs/demos/readpix.c
@@ -383,12 +383,11 @@ int
main( int argc, char *argv[] )
{
GLboolean ciMode = GL_FALSE;
+ glutInitWindowSize( 750, 250 );
+ glutInit( &argc, argv );
if (argc > 1 && strcmp(argv[1], "-ci")==0) {
ciMode = GL_TRUE;
}
- glutInit( &argc, argv );
- glutInitWindowPosition( 0, 0 );
- glutInitWindowSize( 750, 250 );
if (ciMode)
glutInitDisplayMode( GLUT_INDEX | GLUT_DOUBLE );
else
diff --git a/progs/demos/renormal.c b/progs/demos/renormal.c
index 9e5da95484..61dd860ddb 100644
--- a/progs/demos/renormal.c
+++ b/progs/demos/renormal.c
@@ -112,12 +112,9 @@ key(unsigned char k, int x, int y)
int main( int argc, char *argv[] )
{
- glutInit( &argc, argv );
- glutInitWindowPosition(0, 0);
glutInitWindowSize( 400, 400 );
-
+ glutInit( &argc, argv );
glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
-
glutCreateWindow(argv[0]);
Init();
diff --git a/progs/demos/shadowtex.c b/progs/demos/shadowtex.c
index dc5a4bbc48..036f73d40b 100644
--- a/progs/demos/shadowtex.c
+++ b/progs/demos/shadowtex.c
@@ -1022,9 +1022,8 @@ PrintHelp(void)
int
main(int argc, char *argv[])
{
- glutInit(&argc, argv);
- glutInitWindowPosition(0, 0);
glutInitWindowSize(WindowWidth, WindowHeight);
+ glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_STENCIL);
glutCreateWindow(argv[0]);
glewInit();
diff --git a/progs/demos/spectex.c b/progs/demos/spectex.c
index 6ab1191579..c1dada9d63 100644
--- a/progs/demos/spectex.c
+++ b/progs/demos/spectex.c
@@ -239,13 +239,9 @@ static void ModeMenu(int entry)
int main( int argc, char *argv[] )
{
-
- glutInit( &argc, argv );
- glutInitWindowPosition( 0, 0 );
glutInitWindowSize( 300, 300 );
-
+ glutInit( &argc, argv );
glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
-
glutCreateWindow( "spectex" );
Init();
diff --git a/progs/demos/spriteblast.c b/progs/demos/spriteblast.c
index d73b680b79..36e226e1d0 100644
--- a/progs/demos/spriteblast.c
+++ b/progs/demos/spriteblast.c
@@ -493,6 +493,8 @@ int
main(int argc, char **argv)
{
int i;
+
+ glutInitWindowSize(600,300);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE);
@@ -506,8 +508,6 @@ main(int argc, char **argv)
linearFiltering = 0;
}
}
- glutInitWindowPosition(0, 0);
- glutInitWindowSize(600,300);
glutCreateWindow("sprite blast");
glewInit();
glutReshapeFunc(reshape);
diff --git a/progs/demos/teapot.c b/progs/demos/teapot.c
index 6bf6e06409..04a675f36e 100644
--- a/progs/demos/teapot.c
+++ b/progs/demos/teapot.c
@@ -638,7 +638,6 @@ int main(int ac, char **av)
}
*/
- glutInitWindowPosition(0,0);
glutInitWindowSize(WIDTH,HEIGHT);
glutInit(&ac,av);
diff --git a/progs/demos/terrain.c b/progs/demos/terrain.c
index 9ba7b61a63..a72c8d3cae 100644
--- a/progs/demos/terrain.c
+++ b/progs/demos/terrain.c
@@ -626,7 +626,6 @@ init(void)
int
main(int ac, char **av)
{
- glutInitWindowPosition(0, 0);
glutInitWindowSize(WIDTH, HEIGHT);
glutInit(&ac, av);
diff --git a/progs/demos/tessdemo.c b/progs/demos/tessdemo.c
index f71cea1274..8b988e36c1 100644
--- a/progs/demos/tessdemo.c
+++ b/progs/demos/tessdemo.c
@@ -503,10 +503,9 @@ int main( int argc, char **argv )
usage();
+ glutInitWindowSize( 400, 400 );
glutInit( &argc, argv );
glutInitDisplayMode( GLUT_SINGLE | GLUT_RGB );
- glutInitWindowPosition(0, 0);
- glutInitWindowSize( 400, 400 );
glutCreateWindow( argv[0] );
/* GH: Bit of a hack...
diff --git a/progs/demos/texcyl.c b/progs/demos/texcyl.c
index 0e6089bced..4df97ec4f5 100644
--- a/progs/demos/texcyl.c
+++ b/progs/demos/texcyl.c
@@ -261,10 +261,8 @@ static void Init( int argc, char *argv[] )
int main( int argc, char *argv[] )
{
- glutInit( &argc, argv );
glutInitWindowSize( 400, 400 );
- glutInitWindowPosition( 0, 0 );
-
+ glutInit( &argc, argv );
glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
Win = glutCreateWindow(argv[0] );
diff --git a/progs/demos/texenv.c b/progs/demos/texenv.c
index c5a8b13f35..260ca8718f 100644
--- a/progs/demos/texenv.c
+++ b/progs/demos/texenv.c
@@ -765,6 +765,7 @@ int main( int argc, char *argv[] )
GLboolean info = GL_FALSE;
int i;
+ glutInitWindowSize( winWidth, winHeight );
glutInit( &argc, argv );
for ( i = 1 ; i < argc ; i++ ) {
@@ -786,8 +787,6 @@ int main( int argc, char *argv[] )
glutInitDisplayMode( GLUT_RGB | GLUT_SINGLE );
}
- glutInitWindowSize( winWidth, winHeight );
- glutInitWindowPosition( 0, 0 );
Win = glutCreateWindow( "Texture Environment Test" );
initialize();
diff --git a/progs/demos/textures.c b/progs/demos/textures.c
index 31e1bbb3db..1415ef1c43 100644
--- a/progs/demos/textures.c
+++ b/progs/demos/textures.c
@@ -356,9 +356,8 @@ Usage(void)
int
main(int argc, char *argv[])
{
- glutInit(&argc, argv);
- glutInitWindowPosition(0, 0);
glutInitWindowSize(700, 700);
+ glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
Win = glutCreateWindow(argv[0]);
glutReshapeFunc(Reshape);
diff --git a/progs/demos/trispd.c b/progs/demos/trispd.c
index 165d088e3d..c07c340947 100644
--- a/progs/demos/trispd.c
+++ b/progs/demos/trispd.c
@@ -227,15 +227,12 @@ static void Help( const char *program )
int main( int argc, char *argv[] )
{
- printf("For options: %s -help\n", argv[0]);
- glutInit( &argc, argv );
glutInitWindowSize( (int) Width, (int) Height );
- glutInitWindowPosition( 0, 0 );
-
+ glutInit( &argc, argv );
glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
-
glutCreateWindow( argv[0] );
+ printf("For options: %s -help\n", argv[0]);
if (argc==2 && strcmp(argv[1],"-help")==0) {
Help(argv[0]);
return 0;
diff --git a/progs/demos/tunnel.c b/progs/demos/tunnel.c
index 6981da3298..efc007c79a 100644
--- a/progs/demos/tunnel.c
+++ b/progs/demos/tunnel.c
@@ -491,7 +491,6 @@ main(int ac, char **av)
fprintf(stderr,
"Tunnel V1.5\nWritten by David Bucciarelli (tech.hmw@plus.it)\n");
- glutInitWindowPosition(0, 0);
glutInitWindowSize(WIDTH, HEIGHT);
glutInit(&ac, av);
diff --git a/progs/demos/tunnel2.c b/progs/demos/tunnel2.c
index 0288ea0f8c..f15da95b18 100644
--- a/progs/demos/tunnel2.c
+++ b/progs/demos/tunnel2.c
@@ -559,7 +559,6 @@ main(int ac, char **av)
fprintf(stderr,
"Tunnel2 V1.0\nWritten by David Bucciarelli (tech.hmw@plus.it)\n");
- glutInitWindowPosition(0, 0);
glutInitWindowSize(WIDTHC0, HEIGHTC0);
glutInit(&ac, av);
diff --git a/progs/demos/vao_demo.c b/progs/demos/vao_demo.c
index 206e06fc6c..5ce07ecc63 100644
--- a/progs/demos/vao_demo.c
+++ b/progs/demos/vao_demo.c
@@ -317,9 +317,8 @@ static void Init( void )
int main( int argc, char *argv[] )
{
- glutInit( &argc, argv );
- glutInitWindowPosition( 0, 0 );
glutInitWindowSize( Width, Height );
+ glutInit( &argc, argv );
glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
Win = glutCreateWindow( "GL_APPLE_vertex_array_object demo" );
glutReshapeFunc( Reshape );
diff --git a/progs/demos/winpos.c b/progs/demos/winpos.c
index 13a9c7e9a8..f935f9bee0 100644
--- a/progs/demos/winpos.c
+++ b/progs/demos/winpos.c
@@ -96,9 +96,8 @@ static void init( void )
int main( int argc, char *argv[] )
{
- glutInit(&argc, argv);
- glutInitWindowPosition(0, 0);
glutInitWindowSize(500, 500);
+ glutInit(&argc, argv);
glutInitDisplayMode( GLUT_RGB );
if (glutCreateWindow("winpos") <= 0) {
diff --git a/progs/egl/demo1.c b/progs/egl/demo1.c
index 34a516e72f..d892734ee5 100644
--- a/progs/egl/demo1.c
+++ b/progs/egl/demo1.c
@@ -114,6 +114,7 @@ main(int argc, char *argv[])
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");
diff --git a/progs/egl/demo2.c b/progs/egl/demo2.c
index 3994656721..b9e92f62ac 100644
--- a/progs/egl/demo2.c
+++ b/progs/egl/demo2.c
@@ -111,11 +111,7 @@ main(int argc, char *argv[])
EGL_HEIGHT, 500,
EGL_NONE
};
- const EGLint screenAttribs[] = {
- EGL_WIDTH, 1024,
- EGL_HEIGHT, 768,
- EGL_NONE
- };
+ EGLint screenAttribs[32];
EGLModeMESA mode;
EGLScreenMESA screen;
EGLint count;
@@ -149,6 +145,7 @@ main(int argc, char *argv[])
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");
@@ -169,6 +166,13 @@ main(int argc, char *argv[])
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");
diff --git a/progs/egl/demo3.c b/progs/egl/demo3.c
index 0665fd0516..64b9ee652c 100644
--- a/progs/egl/demo3.c
+++ b/progs/egl/demo3.c
@@ -564,11 +564,8 @@ main(int argc, char *argv[])
EGLint numConfigs, count;
EGLBoolean b;
const GLubyte *bitmap;
- const EGLint screenAttribs[] = {
- EGL_WIDTH, 1024,
- EGL_HEIGHT, 768,
- EGL_NONE
- };
+ EGLint screenAttribs[32];
+ EGLint i;
EGLDisplay d = eglGetDisplay(EGL_DEFAULT_DISPLAY);
assert(d);
@@ -590,12 +587,20 @@ main(int argc, char *argv[])
eglGetScreensMESA(d, &screen, 1, &count);
eglGetModesMESA(d, screen, &mode, 1, &count);
+ eglBindAPI(EGL_OPENGL_API);
ctx = eglCreateContext(d, configs[0], EGL_NO_CONTEXT, NULL);
if (ctx == EGL_NO_CONTEXT) {
printf("failed to create context\n");
return 0;
}
+ i = 0;
+ screenAttribs[i++] = EGL_WIDTH;
+ eglGetModeAttribMESA(d, mode, EGL_WIDTH, &screenAttribs[i++]);
+ screenAttribs[i++] = EGL_HEIGHT;
+ eglGetModeAttribMESA(d, mode, EGL_HEIGHT, &screenAttribs[i++]);
+ screenAttribs[i] = EGL_NONE;
+
screen_surf = eglCreateScreenSurfaceMESA(d, configs[0], screenAttribs);
if (screen_surf == EGL_NO_SURFACE) {
printf("failed to create screen surface\n");
diff --git a/progs/egl/eglgears.c b/progs/egl/eglgears.c
index 2d9b8cac7f..63490953ae 100644
--- a/progs/egl/eglgears.c
+++ b/progs/egl/eglgears.c
@@ -426,6 +426,7 @@ main(int argc, char *argv[])
}
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");
diff --git a/progs/egl/egltri.c b/progs/egl/egltri.c
index 9bbc3cddaf..006e06eb03 100644
--- a/progs/egl/egltri.c
+++ b/progs/egl/egltri.c
@@ -208,6 +208,7 @@ int main(int argc, char *argv[])
}
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");
diff --git a/progs/egl/xegl_tri.c b/progs/egl/xegl_tri.c
index 65f352ddfa..1f1a005a21 100644
--- a/progs/egl/xegl_tri.c
+++ b/progs/egl/xegl_tri.c
@@ -120,6 +120,7 @@ make_x_window(Display *x_dpy, EGLDisplay egl_dpy,
EGL_GREEN_SIZE, 1,
EGL_BLUE_SIZE, 1,
EGL_DEPTH_SIZE, 1,
+ EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
EGL_NONE
};
@@ -138,7 +139,8 @@ make_x_window(Display *x_dpy, EGLDisplay egl_dpy,
scrnum = DefaultScreen( x_dpy );
root = RootWindow( x_dpy, scrnum );
- if (!eglChooseConfig( egl_dpy, attribs, &config, 1, &num_configs)) {
+ if (!eglChooseConfig( egl_dpy, attribs, &config, 1, &num_configs) ||
+ !num_configs) {
printf("Error: couldn't get an EGL visual config\n");
exit(1);
}
diff --git a/progs/egl/xeglbindtex.c b/progs/egl/xeglbindtex.c
index fdd9fe2b87..de0ede92ca 100644
--- a/progs/egl/xeglbindtex.c
+++ b/progs/egl/xeglbindtex.c
@@ -53,6 +53,7 @@ make_pbuffer(int width, int height)
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_BIND_TO_TEXTURE_RGB, EGL_TRUE,
+ EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
EGL_NONE
};
EGLint pbuf_attribs[] = {
@@ -65,7 +66,8 @@ make_pbuffer(int width, int height)
EGLConfig config;
EGLint num_configs;
- if (!eglChooseConfig(dpy, config_attribs, &config, 1, &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);
}
@@ -77,8 +79,6 @@ make_pbuffer(int width, int height)
printf("failed to allocate pbuffer\n");
exit(1);
}
-
- glGenTextures(1, &tex_pbuf);
}
static void
@@ -112,6 +112,8 @@ use_pbuffer(void)
glTranslatef(0.0, 0.0, -5.0);
glClearColor(0.2, 0.2, 0.2, 0.0);
+
+ glGenTextures(1, &tex_pbuf);
}
}
@@ -126,6 +128,7 @@ make_window(Display *x_dpy, const char *name,
EGL_BLUE_SIZE, 8,
EGL_ALPHA_SIZE, 8,
EGL_DEPTH_SIZE, 8,
+ EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
EGL_NONE
};
@@ -142,7 +145,8 @@ make_window(Display *x_dpy, const char *name,
scrnum = DefaultScreen( x_dpy );
root = RootWindow( x_dpy, scrnum );
- if (!eglChooseConfig(dpy, attribs, &config, 1, &num_configs)) {
+ if (!eglChooseConfig(dpy, attribs, &config, 1, &num_configs) ||
+ !num_configs) {
printf("Error: couldn't get an EGL visual config\n");
exit(1);
}
diff --git a/progs/egl/xeglgears.c b/progs/egl/xeglgears.c
index 614a625603..9fdf474244 100644
--- a/progs/egl/xeglgears.c
+++ b/progs/egl/xeglgears.c
@@ -604,7 +604,7 @@ event_loop(struct egl_manager *eman, EGLint surface_type, EGLint w, EGLint h)
break;
case EGL_PBUFFER_BIT:
eglWaitClient();
- if (!eglCopyBuffers(eman->xdpy, eman->pbuf, eman->xpix))
+ if (!eglCopyBuffers(eman->dpy, eman->pbuf, eman->xpix))
break;
/* fall through */
case EGL_PIXMAP_BIT:
diff --git a/progs/egl/xeglthreads.c b/progs/egl/xeglthreads.c
index 508dbc0943..5787faecb9 100644
--- a/progs/egl/xeglthreads.c
+++ b/progs/egl/xeglthreads.c
@@ -467,6 +467,7 @@ create_window(struct winthread *wt, EGLContext shareCtx)
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;
@@ -484,7 +485,8 @@ create_window(struct winthread *wt, EGLContext shareCtx)
scrnum = DefaultScreen(wt->Dpy);
root = RootWindow(wt->Dpy, scrnum);
- if (!eglChooseConfig(wt->Display, attribs, &config, 1, &num_configs)) {
+ if (!eglChooseConfig(wt->Display, attribs, &config, 1, &num_configs) ||
+ !num_configs) {
Error("Unable to choose an EGL config");
}
diff --git a/progs/es1/.gitignore b/progs/es1/.gitignore
new file mode 100644
index 0000000000..4f1427531a
--- /dev/null
+++ b/progs/es1/.gitignore
@@ -0,0 +1,10 @@
+screen/gears
+screen/tri
+xegl/drawtex
+xegl/es1_info
+xegl/msaa
+xegl/pbuffer
+xegl/render_tex
+xegl/torus
+xegl/tri
+xegl/two_win
diff --git a/progs/es1/screen/Makefile b/progs/es1/screen/Makefile
new file mode 100644
index 0000000000..4ba2f9a7dc
--- /dev/null
+++ b/progs/es1/screen/Makefile
@@ -0,0 +1,32 @@
+# progs/es1/screen/Makefile
+
+TOP = ../../..
+include $(TOP)/configs/current
+
+ES1_CFLAGS = -I$(TOP)/include
+ES1_LIBS = -L$(TOP)/$(LIB_DIR) -lEGL -lGLESv1_CM
+
+ES1_LIB_DEPS = \
+ $(TOP)/$(LIB_DIR)/libEGL.so \
+ $(TOP)/$(LIB_DIR)/libGLESv1_CM.so
+
+WINSYS_OBJS = winsys.o
+
+PROGRAMS = \
+ gears \
+ tri
+
+.c.o:
+ $(CC) -c $(ES1_CFLAGS) $(CFLAGS) $< -o $@
+
+default: $(PROGRAMS)
+
+gears: gears.o $(WINSYS_OBJS) $(ES1_LIB_DEPS)
+ $(CC) $(CFLAGS) -o $@ $@.o $(WINSYS_OBJS) $(ES1_LIBS)
+
+tri: tri.o $(WINSYS_OBJS) $(ES1_LIB_DEPS)
+ $(CC) $(CFLAGS) -o $@ $@.o $(WINSYS_OBJS) $(ES1_LIBS)
+
+clean:
+ -rm -f *.o *~
+ -rm -f $(PROGRAMS)
diff --git a/progs/es1/screen/gears.c b/progs/es1/screen/gears.c
new file mode 100644
index 0000000000..c7625826b9
--- /dev/null
+++ b/progs/es1/screen/gears.c
@@ -0,0 +1,374 @@
+/*
+ * Copyright (C) 2009 Chia-I Wu <olv@0xlab.org>
+ *
+ * Based on eglgears by
+ * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <math.h>
+#include <assert.h>
+
+#include <GLES/gl.h>
+#include "winsys.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 *data)
+{
+ 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();
+
+ /* advance rotation for next frame */
+ angle += 0.5; /* 0.5 degree per frame */
+ if (angle > 3600.0)
+ angle -= 3600.0;
+}
+
+
+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_run(void)
+{
+ winsysRun(5.0, gears_draw, NULL);
+}
+
+
+int
+main(int argc, char *argv[])
+{
+ EGLint width, height;
+
+ if (!winsysInitScreen())
+ exit(1);
+ winsysQueryScreenSize(&width, &height);
+
+ gears_init();
+ gears_reshape(width, height);
+ gears_run();
+ gears_fini();
+
+ winsysFiniScreen();
+
+ return 0;
+}
diff --git a/progs/es1/screen/tri.c b/progs/es1/screen/tri.c
new file mode 100644
index 0000000000..bab9499944
--- /dev/null
+++ b/progs/es1/screen/tri.c
@@ -0,0 +1,129 @@
+/*
+ * Copyright (C) 2009 Chia-I Wu <olv@0xlab.org>
+ *
+ * Based on egltri by
+ * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
+ * Copyright (C) 2008 Brian Paul All Rights Reserved.
+ * Copyright (C) 2008 Jakob Bornecrantz All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <GLES/gl.h>
+#include "winsys.h"
+
+static GLfloat view_rotx = 0.0, view_roty = 0.0, view_rotz = 0.0;
+
+static void tri_init()
+{
+ glClearColor(0.4, 0.4, 0.4, 0.0);
+}
+
+static void tri_reshape(int width, int height)
+{
+ GLfloat ar = (GLfloat) width / (GLfloat) height;
+
+ 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, -10.0);
+}
+
+static void tri_draw(void *data)
+{
+ static const GLfloat verts[3][2] = {
+ { -1, -1 },
+ { 1, -1 },
+ { 0, 1 }
+ };
+ static const GLfloat colors[3][4] = {
+ { 1, 0, 0, 1 },
+ { 0, 1, 0, 1 },
+ { 0, 0, 1, 1 }
+ };
+
+ 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);
+
+ glDrawArrays(GL_TRIANGLES, 0, 3);
+
+ glDisableClientState(GL_VERTEX_ARRAY);
+ glDisableClientState(GL_COLOR_ARRAY);
+ }
+
+ glPopMatrix();
+}
+
+static void tri_run(void)
+{
+ winsysRun(3.0, tri_draw, NULL);
+}
+
+int main(int argc, char *argv[])
+{
+ EGLint width, height;
+ GLboolean printInfo = GL_FALSE;
+ int i;
+
+ /* parse cmd line args */
+ for (i = 1; i < argc; i++) {
+ if (strcmp(argv[i], "-info") == 0) {
+ printInfo = GL_TRUE;
+ }
+ else {
+ printf("Warning: unknown parameter: %s\n", argv[i]);
+ }
+ }
+
+ if (!winsysInitScreen())
+ exit(1);
+ winsysQueryScreenSize(&width, &height);
+
+ 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));
+ }
+
+ tri_init();
+ tri_reshape(width, height);
+ tri_run();
+
+ winsysFiniScreen();
+
+ return 0;
+}
diff --git a/progs/es1/screen/winsys.c b/progs/es1/screen/winsys.c
new file mode 100644
index 0000000000..84d00471eb
--- /dev/null
+++ b/progs/es1/screen/winsys.c
@@ -0,0 +1,272 @@
+/*
+ * Copyright (C) 2009 Chia-I Wu <olv@0xlab.org>
+ *
+ * Based on eglgears by
+ * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <sys/time.h>
+
+#define EGL_EGLEXT_PROTOTYPES
+
+#include <EGL/egl.h>
+#include <EGL/eglext.h>
+
+#include "winsys.h"
+
+#define MAX_MODES 100
+
+static struct {
+ EGLBoolean verbose;
+
+ EGLDisplay dpy;
+ EGLConfig conf;
+
+ EGLScreenMESA screen;
+ EGLModeMESA mode;
+ EGLint width, height;
+
+ EGLContext ctx;
+ EGLSurface surf;
+} screen;
+
+
+static EGLBoolean
+init_screen(void)
+{
+ EGLModeMESA modes[MAX_MODES];
+ EGLint num_screens, num_modes;
+ EGLint width, height, best_mode;
+ EGLint i;
+
+ if (!eglGetScreensMESA(screen.dpy, &screen.screen, 1, &num_screens) ||
+ !num_screens) {
+ printf("eglGetScreensMESA failed\n");
+ return EGL_FALSE;
+ }
+
+ if (!eglGetModesMESA(screen.dpy, screen.screen, modes, MAX_MODES,
+ &num_modes) ||
+ !num_modes) {
+ printf("eglGetModesMESA failed!\n");
+ return EGL_FALSE;
+ }
+
+ printf("Found %d modes:\n", num_modes);
+
+ best_mode = 0;
+ width = 0;
+ height = 0;
+ for (i = 0; i < num_modes; i++) {
+ EGLint w, h;
+ eglGetModeAttribMESA(screen.dpy, modes[i], EGL_WIDTH, &w);
+ eglGetModeAttribMESA(screen.dpy, modes[i], EGL_HEIGHT, &h);
+ printf("%3d: %d x %d\n", i, w, h);
+ if (w > width && h > height) {
+ width = w;
+ height = h;
+ best_mode = i;
+ }
+ }
+
+ screen.mode = modes[best_mode];
+ screen.width = width;
+ screen.height = height;
+
+ return EGL_TRUE;
+}
+
+
+static EGLBoolean
+init_display(void)
+{
+ EGLint maj, min;
+ const char *exts;
+ const EGLint attribs[] = {
+ EGL_SURFACE_TYPE, 0x0, /* should be EGL_SCREEN_BIT_MESA */
+ EGL_RENDERABLE_TYPE, 0x0, /* should be EGL_OPENGL_ES_BIT */
+ EGL_NONE
+ };
+ EGLint num_configs;
+
+ screen.dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
+ if (!screen.dpy) {
+ printf("eglGetDisplay failed\n");
+ return EGL_FALSE;
+ }
+
+ if (!eglInitialize(screen.dpy, &maj, &min)) {
+ printf("eglInitialize failed\n");
+ return EGL_FALSE;
+ }
+
+ printf("EGL_VERSION = %s\n", eglQueryString(screen.dpy, EGL_VERSION));
+ printf("EGL_VENDOR = %s\n", eglQueryString(screen.dpy, EGL_VENDOR));
+
+ exts = eglQueryString(screen.dpy, EGL_EXTENSIONS);
+ assert(exts);
+
+ if (!strstr(exts, "EGL_MESA_screen_surface")) {
+ printf("EGL_MESA_screen_surface is not supported\n");
+ return EGL_FALSE;
+ }
+
+ if (!eglChooseConfig(screen.dpy, attribs, &screen.conf, 1,
+ &num_configs) ||
+ !num_configs) {
+ printf("eglChooseConfig failed\n");
+ return EGL_FALSE;
+ }
+
+ return EGL_TRUE;
+}
+
+
+EGLBoolean
+winsysInitScreen(void)
+{
+ EGLint surf_attribs[20];
+ EGLint i;
+ EGLBoolean ok;
+
+ if (!init_display())
+ goto fail;
+ if (!init_screen())
+ goto fail;
+
+ /* create context */
+ screen.ctx = eglCreateContext(screen.dpy, screen.conf,
+ EGL_NO_CONTEXT, NULL);
+ if (screen.ctx == EGL_NO_CONTEXT) {
+ printf("eglCreateContext failed\n");
+ goto fail;
+ }
+
+ i = 0;
+ surf_attribs[i++] = EGL_WIDTH;
+ surf_attribs[i++] = screen.width;
+ surf_attribs[i++] = EGL_HEIGHT;
+ surf_attribs[i++] = screen.height;
+ surf_attribs[i++] = EGL_NONE;
+
+ /* create surface */
+ printf("Using screen size: %d x %d\n", screen.width, screen.height);
+ screen.surf = eglCreateScreenSurfaceMESA(screen.dpy, screen.conf,
+ surf_attribs);
+ if (screen.surf == EGL_NO_SURFACE) {
+ printf("eglCreateScreenSurfaceMESA failed\n");
+ goto fail;
+ }
+
+ ok = eglMakeCurrent(screen.dpy, screen.surf, screen.surf, screen.ctx);
+ if (!ok) {
+ printf("eglMakeCurrent failed\n");
+ goto fail;
+ }
+
+ ok = eglShowScreenSurfaceMESA(screen.dpy, screen.screen,
+ screen.surf, screen.mode);
+ if (!ok) {
+ printf("eglShowScreenSurfaceMESA failed\n");
+ goto fail;
+ }
+
+ return EGL_TRUE;
+
+fail:
+ winsysFiniScreen();
+ return EGL_FALSE;
+}
+
+
+EGLBoolean
+winsysQueryScreenSize(EGLint *width, EGLint *height)
+{
+ if (!screen.dpy)
+ return EGL_FALSE;
+
+ if (width)
+ *width = screen.width;
+ if (height)
+ *height = screen.height;
+
+ return EGL_TRUE;
+}
+
+
+void
+winsysFiniScreen(void)
+{
+ if (screen.dpy) {
+ eglMakeCurrent(screen.dpy, EGL_NO_SURFACE, EGL_NO_SURFACE,
+ EGL_NO_CONTEXT);
+ if (screen.surf != EGL_NO_SURFACE)
+ eglDestroySurface(screen.dpy, screen.surf);
+ if (screen.ctx != EGL_NO_CONTEXT)
+ eglDestroyContext(screen.dpy, screen.ctx);
+ eglTerminate(screen.dpy);
+
+ memset(&screen, 0, sizeof(screen));
+ }
+}
+
+
+void
+winsysSwapBuffers(void)
+{
+ eglSwapBuffers(screen.dpy, screen.surf);
+}
+
+
+/* return current time (in seconds) */
+double
+winsysNow(void)
+{
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ return (double) tv.tv_sec + tv.tv_usec / 1000000.0;
+}
+
+
+void
+winsysRun(double seconds, void (*draw_frame)(void *data), void *data)
+{
+ double begin, end, last_frame, duration;
+ EGLint num_frames = 0;
+
+ begin = winsysNow();
+ end = begin + seconds;
+
+ last_frame = begin;
+ while (last_frame < end) {
+ draw_frame(data);
+ winsysSwapBuffers();
+ last_frame = winsysNow();
+ num_frames++;
+ }
+
+ duration = last_frame - begin;
+ printf("%d frames in %3.1f seconds = %6.3f FPS\n",
+ num_frames, duration, (double) num_frames / duration);
+}
diff --git a/progs/es1/screen/winsys.h b/progs/es1/screen/winsys.h
new file mode 100644
index 0000000000..679c7e0bd6
--- /dev/null
+++ b/progs/es1/screen/winsys.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2009 Chia-I Wu <olv@0xlab.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _WINSYS_H_
+#define _WINSYS_H_
+
+#include <EGL/egl.h>
+
+EGLBoolean winsysInitScreen(void);
+EGLBoolean winsysQueryScreenSize(EGLint *width, EGLint *height);
+void winsysFiniScreen(void);
+
+void winsysSwapBuffers(void);
+double winsysNow(void);
+
+void winsysRun(double seconds, void (*draw_frame)(void *data), void *data);
+
+#endif /* _WINSYS_H_ */
diff --git a/progs/es1/xegl/Makefile b/progs/es1/xegl/Makefile
new file mode 100644
index 0000000000..7f684d68e3
--- /dev/null
+++ b/progs/es1/xegl/Makefile
@@ -0,0 +1,77 @@
+# progs/es1/xegl/Makefile
+
+TOP = ../../..
+include $(TOP)/configs/current
+
+
+INCLUDE_DIRS = \
+ -I$(TOP)/include \
+
+HEADERS = $(TOP)/include/GLES/egl.h
+
+
+ES1_LIB_DEPS = \
+ $(TOP)/$(LIB_DIR)/libEGL.so \
+ $(TOP)/$(LIB_DIR)/libGLESv1_CM.so
+
+
+ES1_LIBS = \
+ -L$(TOP)/$(LIB_DIR) -lEGL \
+ -L$(TOP)/$(LIB_DIR) -lGLESv1_CM $(LIBDRM_LIB) -lX11
+
+PROGRAMS = \
+ drawtex \
+ es1_info \
+ msaa \
+ pbuffer \
+ render_tex \
+ torus \
+ tri \
+ two_win
+
+
+.c.o:
+ $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $< -o $@
+
+
+
+default: $(PROGRAMS)
+
+
+
+drawtex: drawtex.o $(ES1_LIB_DEPS)
+ $(CC) $(CFLAGS) drawtex.o $(ES1_LIBS) -o $@
+
+
+es1_info: es1_info.o $(ES1_LIB_DEPS)
+ $(CC) $(CFLAGS) es1_info.o $(ES1_LIBS) -o $@
+
+
+msaa: msaa.o $(ES1_LIB_DEPS)
+ $(CC) $(CFLAGS) msaa.o $(ES1_LIBS) -o $@
+
+
+pbuffer: pbuffer.o $(ES1_LIB_DEPS)
+ $(CC) $(CFLAGS) pbuffer.o $(ES1_LIBS) -o $@
+
+
+render_tex: render_tex.o $(ES1_LIB_DEPS)
+ $(CC) $(CFLAGS) render_tex.o $(ES1_LIBS) -o $@
+
+
+torus: torus.o $(ES1_LIB_DEPS)
+ $(CC) $(CFLAGS) torus.o $(ES1_LIBS) -o $@
+
+
+two_win: two_win.o $(ES1_LIB_DEPS)
+ $(CC) $(CFLAGS) two_win.o $(ES1_LIBS) -o $@
+
+
+tri: tri.o $(ES1_LIB_DEPS)
+ $(CC) $(CFLAGS) tri.o $(ES1_LIBS) -o $@
+
+
+clean:
+ rm -f *.o *~
+ rm -f $(PROGRAMS)
+
diff --git a/progs/es1/xegl/drawtex.c b/progs/es1/xegl/drawtex.c
new file mode 100644
index 0000000000..ca0615e267
--- /dev/null
+++ b/progs/es1/xegl/drawtex.c
@@ -0,0 +1,427 @@
+/*
+ * Copyright (C) 2008 Tunsgten Graphics,Inc. All Rights Reserved.
+ */
+
+/*
+ * Test GL_OES_draw_texture
+ * Brian Paul
+ * August 2008
+ */
+
+#define GL_GLEXT_PROTOTYPES
+
+#include <assert.h>
+#include <math.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/keysym.h>
+#include <GLES/gl.h>
+#include <GLES/glext.h>
+#include <EGL/egl.h>
+
+
+
+static GLfloat view_posx = 10.0, view_posy = 20.0;
+static GLfloat width = 200, height = 200;
+
+
+static void
+draw(void)
+{
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ glDrawTexfOES(view_posx, view_posy, 0.0, width, height);
+}
+
+
+/* new window size or exposure */
+static void
+reshape(int width, int height)
+{
+ GLfloat ar = (GLfloat) width / (GLfloat) height;
+
+ glViewport(0, 0, (GLint) width, (GLint) height);
+
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+
+#ifdef GL_VERSION_ES_CM_1_0
+ glFrustumf(-ar, ar, -1, 1, 5.0, 60.0);
+#else
+ glFrustum(-ar, ar, -1, 1, 5.0, 60.0);
+#endif
+
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ glTranslatef(0.0, 0.0, -15.0);
+}
+
+
+static float
+dist(GLuint i, GLuint j, float x, float y)
+{
+ return sqrt((i-x) * (i-x) + (j-y) * (j-y));
+}
+
+static void
+make_smile_texture(void)
+{
+#define SZ 128
+ GLenum Filter = GL_LINEAR;
+ GLubyte image[SZ][SZ][4];
+ GLuint i, j;
+ GLint cropRect[4];
+
+ for (i = 0; i < SZ; i++) {
+ for (j = 0; j < SZ; j++) {
+ GLfloat d_mouth = dist(i, j, SZ/2, SZ/2);
+ GLfloat d_rt_eye = dist(i, j, SZ*3/4, SZ*3/4);
+ GLfloat d_lt_eye = dist(i, j, SZ*3/4, SZ*1/4);
+ if (d_rt_eye < SZ / 8 || d_lt_eye < SZ / 8) {
+ image[i][j][0] = 20;
+ image[i][j][1] = 50;
+ image[i][j][2] = 255;
+ image[i][j][3] = 255;
+ }
+ else if (i < SZ/2 && d_mouth < SZ/3) {
+ image[i][j][0] = 255;
+ image[i][j][1] = 20;
+ image[i][j][2] = 20;
+ image[i][j][3] = 255;
+ }
+ else {
+ image[i][j][0] = 200;
+ image[i][j][1] = 200;
+ image[i][j][2] = 200;
+ image[i][j][3] = 255;
+ }
+ }
+ }
+
+ glActiveTexture(GL_TEXTURE0); /* unit 0 */
+ glBindTexture(GL_TEXTURE_2D, 42);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, SZ, SZ, 0,
+ GL_RGBA, GL_UNSIGNED_BYTE, image);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, Filter);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, Filter);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+
+ cropRect[0] = 0;
+ cropRect[1] = 0;
+ cropRect[2] = SZ;
+ cropRect[3] = SZ;
+ glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, cropRect);
+#undef SZ
+}
+
+
+
+static void
+init(void)
+{
+ const char *ext = (char *) glGetString(GL_EXTENSIONS);
+
+ if (!strstr(ext, "GL_OES_draw_texture")) {
+ fprintf(stderr, "Sorry, this program requires GL_OES_draw_texture");
+ exit(1);
+ }
+
+ glClearColor(0.4, 0.4, 0.4, 0.0);
+
+ make_smile_texture();
+ glEnable(GL_TEXTURE_2D);
+}
+
+
+/*
+ * Create an RGB, double-buffered X window.
+ * Return the window and context handles.
+ */
+static void
+make_x_window(Display *x_dpy, EGLDisplay egl_dpy,
+ const char *name,
+ int x, int y, int width, int height,
+ Window *winRet,
+ EGLContext *ctxRet,
+ EGLSurface *surfRet)
+{
+ static const EGLint attribs[] = {
+ EGL_RED_SIZE, 1,
+ EGL_GREEN_SIZE, 1,
+ EGL_BLUE_SIZE, 1,
+ EGL_NONE
+ };
+
+ int scrnum;
+ XSetWindowAttributes attr;
+ unsigned long mask;
+ Window root;
+ Window win;
+ XVisualInfo *visInfo, visTemplate;
+ int num_visuals;
+ EGLContext ctx;
+ EGLConfig config;
+ EGLint num_configs;
+ EGLint vid;
+
+ scrnum = DefaultScreen( x_dpy );
+ root = RootWindow( x_dpy, scrnum );
+
+ if (!eglChooseConfig( egl_dpy, attribs, &config, 1, &num_configs)) {
+ printf("Error: couldn't get an EGL visual config\n");
+ exit(1);
+ }
+
+ assert(config);
+ assert(num_configs > 0);
+
+ if (!eglGetConfigAttrib(egl_dpy, config, EGL_NATIVE_VISUAL_ID, &vid)) {
+ printf("Error: eglGetConfigAttrib() failed\n");
+ exit(1);
+ }
+
+ /* The X window visual must match the EGL config */
+ visTemplate.visualid = vid;
+ visInfo = XGetVisualInfo(x_dpy, VisualIDMask, &visTemplate, &num_visuals);
+ if (!visInfo) {
+ printf("Error: couldn't get X visual\n");
+ exit(1);
+ }
+
+ /* window attributes */
+ attr.background_pixel = 0;
+ attr.border_pixel = 0;
+ attr.colormap = XCreateColormap( x_dpy, root, visInfo->visual, AllocNone);
+ attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
+ mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
+
+ win = XCreateWindow( x_dpy, root, 0, 0, width, height,
+ 0, visInfo->depth, InputOutput,
+ visInfo->visual, mask, &attr );
+
+ /* set hints and properties */
+ {
+ XSizeHints sizehints;
+ sizehints.x = x;
+ sizehints.y = y;
+ sizehints.width = width;
+ sizehints.height = height;
+ sizehints.flags = USSize | USPosition;
+ XSetNormalHints(x_dpy, win, &sizehints);
+ XSetStandardProperties(x_dpy, win, name, name,
+ None, (char **)NULL, 0, &sizehints);
+ }
+
+ eglBindAPI(EGL_OPENGL_ES_API);
+
+ ctx = eglCreateContext(egl_dpy, config, EGL_NO_CONTEXT, NULL );
+ if (!ctx) {
+ printf("Error: eglCreateContext failed\n");
+ exit(1);
+ }
+
+ *surfRet = eglCreateWindowSurface(egl_dpy, config, win, NULL);
+
+ if (!*surfRet) {
+ printf("Error: eglCreateWindowSurface failed\n");
+ exit(1);
+ }
+
+ XFree(visInfo);
+
+ *winRet = win;
+ *ctxRet = ctx;
+}
+
+
+static void
+event_loop(Display *dpy, Window win,
+ EGLDisplay egl_dpy, EGLSurface egl_surf)
+{
+ int anim = 0;
+
+ while (1) {
+ int redraw = 0;
+
+ if (!anim || XPending(dpy)) {
+ XEvent event;
+ XNextEvent(dpy, &event);
+
+ switch (event.type) {
+ case Expose:
+ redraw = 1;
+ break;
+ case ConfigureNotify:
+ reshape(event.xconfigure.width, event.xconfigure.height);
+ break;
+ case KeyPress:
+ {
+ char buffer[10];
+ int r, code;
+ code = XLookupKeysym(&event.xkey, 0);
+ if (code == XK_Left) {
+ view_posx -= 1.0;
+ }
+ else if (code == XK_Right) {
+ view_posx += 1.0;
+ }
+ else if (code == XK_Up) {
+ view_posy += 1.0;
+ }
+ else if (code == XK_Down) {
+ view_posy -= 1.0;
+ }
+ else {
+ r = XLookupString(&event.xkey, buffer, sizeof(buffer),
+ NULL, NULL);
+ if (buffer[0] == ' ') {
+ anim = !anim;
+ }
+ else if (buffer[0] == 'w') {
+ width -= 1.0f;
+ }
+ else if (buffer[0] == 'W') {
+ width += 1.0f;
+ }
+ else if (buffer[0] == 'h') {
+ height -= 1.0f;
+ }
+ else if (buffer[0] == 'H') {
+ height += 1.0f;
+ }
+ else if (buffer[0] == 27) {
+ /* escape */
+ return;
+ }
+ }
+ }
+ redraw = 1;
+ break;
+ default:
+ ; /*no-op*/
+ }
+ }
+
+ if (anim) {
+ view_posx += 1.0;
+ view_posy += 2.0;
+ redraw = 1;
+ }
+
+ if (redraw) {
+ draw();
+ eglSwapBuffers(egl_dpy, egl_surf);
+ }
+ }
+}
+
+
+static void
+usage(void)
+{
+ printf("Usage:\n");
+ printf(" -display <displayname> set the display to run on\n");
+ printf(" -info display OpenGL renderer info\n");
+}
+
+
+int
+main(int argc, char *argv[])
+{
+ const int winWidth = 400, winHeight = 300;
+ Display *x_dpy;
+ Window win;
+ EGLSurface egl_surf;
+ EGLContext egl_ctx;
+ EGLDisplay egl_dpy;
+ char *dpyName = NULL;
+ GLboolean printInfo = GL_FALSE;
+ EGLint egl_major, egl_minor;
+ int i;
+ const char *s;
+
+ for (i = 1; i < argc; i++) {
+ if (strcmp(argv[i], "-display") == 0) {
+ dpyName = argv[i+1];
+ i++;
+ }
+ else if (strcmp(argv[i], "-info") == 0) {
+ printInfo = GL_TRUE;
+ }
+ else {
+ usage();
+ return -1;
+ }
+ }
+
+ x_dpy = XOpenDisplay(dpyName);
+ if (!x_dpy) {
+ printf("Error: couldn't open display %s\n",
+ dpyName ? dpyName : getenv("DISPLAY"));
+ return -1;
+ }
+
+ egl_dpy = eglGetDisplay(x_dpy);
+ if (!egl_dpy) {
+ printf("Error: eglGetDisplay() failed\n");
+ return -1;
+ }
+
+ if (!eglInitialize(egl_dpy, &egl_major, &egl_minor)) {
+ printf("Error: eglInitialize() failed\n");
+ return -1;
+ }
+
+ s = eglQueryString(egl_dpy, EGL_VERSION);
+ printf("EGL_VERSION = %s\n", s);
+
+ s = eglQueryString(egl_dpy, EGL_VENDOR);
+ printf("EGL_VENDOR = %s\n", s);
+
+ s = eglQueryString(egl_dpy, EGL_EXTENSIONS);
+ printf("EGL_EXTENSIONS = %s\n", s);
+
+ s = eglQueryString(egl_dpy, EGL_CLIENT_APIS);
+ printf("EGL_CLIENT_APIS = %s\n", s);
+
+ make_x_window(x_dpy, egl_dpy,
+ "drawtex", 0, 0, winWidth, winHeight,
+ &win, &egl_ctx, &egl_surf);
+
+ XMapWindow(x_dpy, win);
+ if (!eglMakeCurrent(egl_dpy, egl_surf, egl_surf, egl_ctx)) {
+ printf("Error: eglMakeCurrent() failed\n");
+ return -1;
+ }
+
+ if (printInfo) {
+ printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
+ printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
+ printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR));
+ printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS));
+ }
+
+ init();
+
+ /* Set initial projection/viewing transformation.
+ * We can't be sure we'll get a ConfigureNotify event when the window
+ * first appears.
+ */
+ reshape(winWidth, winHeight);
+
+ event_loop(x_dpy, win, egl_dpy, egl_surf);
+
+ eglDestroyContext(egl_dpy, egl_ctx);
+ eglDestroySurface(egl_dpy, egl_surf);
+ eglTerminate(egl_dpy);
+
+
+ XDestroyWindow(x_dpy, win);
+ XCloseDisplay(x_dpy);
+
+ return 0;
+}
diff --git a/progs/es1/xegl/es1_info.c b/progs/es1/xegl/es1_info.c
new file mode 100644
index 0000000000..93816b5215
--- /dev/null
+++ b/progs/es1/xegl/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 <assert.h>
+#include <math.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/keysym.h>
+#include <GLES/gl.h>
+#include <GLES/glext.h>
+#include <EGL/egl.h>
+
+
+/*
+ * Print a list of extensions, with word-wrapping.
+ */
+static void
+print_extension_list(const char *ext)
+{
+ const char *indentString = " ";
+ const int indent = 4;
+ const int max = 79;
+ int width, i, j;
+
+ if (!ext || !ext[0])
+ return;
+
+ width = indent;
+ printf(indentString);
+ i = j = 0;
+ while (1) {
+ if (ext[j] == ' ' || ext[j] == 0) {
+ /* found end of an extension name */
+ const int len = j - i;
+ if (width + len > max) {
+ /* start a new line */
+ printf("\n");
+ width = indent;
+ printf(indentString);
+ }
+ /* print the extension name between ext[i] and ext[j] */
+ while (i < j) {
+ printf("%c", ext[i]);
+ i++;
+ }
+ /* either we're all done, or we'll continue with next extension */
+ width += len + 1;
+ if (ext[j] == 0) {
+ break;
+ }
+ else {
+ i++;
+ j++;
+ if (ext[j] == 0)
+ break;
+ printf(", ");
+ width += 2;
+ }
+ }
+ j++;
+ }
+ printf("\n");
+}
+
+
+static void
+info(EGLDisplay egl_dpy)
+{
+ const char *s;
+
+ s = eglQueryString(egl_dpy, EGL_VERSION);
+ printf("EGL_VERSION = %s\n", s);
+
+ s = eglQueryString(egl_dpy, EGL_VENDOR);
+ printf("EGL_VENDOR = %s\n", s);
+
+ s = eglQueryString(egl_dpy, EGL_EXTENSIONS);
+ printf("EGL_EXTENSIONS = %s\n", s);
+
+ s = eglQueryString(egl_dpy, EGL_CLIENT_APIS);
+ printf("EGL_CLIENT_APIS = %s\n", s);
+
+ printf("GL_VERSION: %s\n", (char *) glGetString(GL_VERSION));
+ printf("GL_RENDERER: %s\n", (char *) glGetString(GL_RENDERER));
+ printf("GL_EXTENSIONS:\n");
+ print_extension_list((char *) glGetString(GL_EXTENSIONS));
+}
+
+
+/*
+ * Create an RGB, double-buffered X window.
+ * Return the window and context handles.
+ */
+static void
+make_x_window(Display *x_dpy, EGLDisplay egl_dpy,
+ const char *name,
+ int x, int y, int width, int height, int es_ver,
+ Window *winRet,
+ EGLContext *ctxRet,
+ EGLSurface *surfRet)
+{
+ EGLint attribs[] = {
+ EGL_RENDERABLE_TYPE, 0x0,
+ EGL_RED_SIZE, 1,
+ EGL_GREEN_SIZE, 1,
+ EGL_BLUE_SIZE, 1,
+ EGL_NONE
+ };
+ EGLint ctx_attribs[] = {
+ EGL_CONTEXT_CLIENT_VERSION, 0,
+ EGL_NONE
+ };
+
+ int scrnum;
+ XSetWindowAttributes attr;
+ unsigned long mask;
+ Window root;
+ Window win;
+ XVisualInfo *visInfo, visTemplate;
+ int num_visuals;
+ EGLContext ctx;
+ EGLConfig config;
+ EGLint num_configs;
+ EGLint vid;
+
+ scrnum = DefaultScreen( x_dpy );
+ root = RootWindow( x_dpy, scrnum );
+
+ if (es_ver == 1)
+ attribs[1] = EGL_OPENGL_ES_BIT;
+ else
+ attribs[1] = EGL_OPENGL_ES2_BIT;
+ ctx_attribs[1] = es_ver;
+
+ if (!eglChooseConfig( egl_dpy, attribs, &config, 1, &num_configs)) {
+ printf("Error: couldn't get an EGL visual config\n");
+ exit(1);
+ }
+
+ assert(config);
+ assert(num_configs > 0);
+
+ if (!eglGetConfigAttrib(egl_dpy, config, EGL_NATIVE_VISUAL_ID, &vid)) {
+ printf("Error: eglGetConfigAttrib() failed\n");
+ exit(1);
+ }
+
+ /* The X window visual must match the EGL config */
+ visTemplate.visualid = vid;
+ visInfo = XGetVisualInfo(x_dpy, VisualIDMask, &visTemplate, &num_visuals);
+ if (!visInfo) {
+ printf("Error: couldn't get X visual\n");
+ exit(1);
+ }
+
+ /* window attributes */
+ attr.background_pixel = 0;
+ attr.border_pixel = 0;
+ attr.colormap = XCreateColormap( x_dpy, root, visInfo->visual, AllocNone);
+ attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
+ mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
+
+ win = XCreateWindow( x_dpy, root, 0, 0, width, height,
+ 0, visInfo->depth, InputOutput,
+ visInfo->visual, mask, &attr );
+
+ /* set hints and properties */
+ {
+ XSizeHints sizehints;
+ sizehints.x = x;
+ sizehints.y = y;
+ sizehints.width = width;
+ sizehints.height = height;
+ sizehints.flags = USSize | USPosition;
+ XSetNormalHints(x_dpy, win, &sizehints);
+ XSetStandardProperties(x_dpy, win, name, name,
+ None, (char **)NULL, 0, &sizehints);
+ }
+
+ eglBindAPI(EGL_OPENGL_ES_API);
+
+ ctx = eglCreateContext(egl_dpy, config, EGL_NO_CONTEXT, ctx_attribs );
+ if (!ctx) {
+ printf("Error: eglCreateContext failed\n");
+ exit(1);
+ }
+
+ *surfRet = eglCreateWindowSurface(egl_dpy, config, win, NULL);
+
+ if (!*surfRet) {
+ printf("Error: eglCreateWindowSurface failed\n");
+ exit(1);
+ }
+
+ XFree(visInfo);
+
+ *winRet = win;
+ *ctxRet = ctx;
+}
+
+
+static void
+usage(void)
+{
+ printf("Usage:\n");
+ printf(" -display <displayname> set the display to run on\n");
+}
+
+
+int
+main(int argc, char *argv[])
+{
+ const int winWidth = 400, winHeight = 300;
+ Display *x_dpy;
+ Window win;
+ EGLSurface egl_surf;
+ EGLContext egl_ctx;
+ EGLDisplay egl_dpy;
+ char *dpyName = NULL;
+ EGLint egl_major, egl_minor, es_ver;
+ int i;
+
+ for (i = 1; i < argc; i++) {
+ if (strcmp(argv[i], "-display") == 0) {
+ dpyName = argv[i+1];
+ i++;
+ }
+ else {
+ usage();
+ return -1;
+ }
+ }
+
+ x_dpy = XOpenDisplay(dpyName);
+ if (!x_dpy) {
+ printf("Error: couldn't open display %s\n",
+ dpyName ? dpyName : getenv("DISPLAY"));
+ return -1;
+ }
+
+ egl_dpy = eglGetDisplay(x_dpy);
+ if (!egl_dpy) {
+ printf("Error: eglGetDisplay() failed\n");
+ return -1;
+ }
+
+ if (!eglInitialize(egl_dpy, &egl_major, &egl_minor)) {
+ printf("Error: eglInitialize() failed\n");
+ return -1;
+ }
+
+ es_ver = 1;
+ /* decide the version from the executable's name */
+ if (argc > 0 && argv[0] && strstr(argv[0], "es2"))
+ es_ver = 2;
+ make_x_window(x_dpy, egl_dpy,
+ "ES info", 0, 0, winWidth, winHeight, es_ver,
+ &win, &egl_ctx, &egl_surf);
+
+ /*XMapWindow(x_dpy, win);*/
+ if (!eglMakeCurrent(egl_dpy, egl_surf, egl_surf, egl_ctx)) {
+ printf("Error: eglMakeCurrent() failed\n");
+ return -1;
+ }
+
+ info(egl_dpy);
+
+ eglDestroyContext(egl_dpy, egl_ctx);
+ eglDestroySurface(egl_dpy, egl_surf);
+ eglTerminate(egl_dpy);
+
+
+ XDestroyWindow(x_dpy, win);
+ XCloseDisplay(x_dpy);
+
+ return 0;
+}
diff --git a/progs/es1/xegl/msaa.c b/progs/es1/xegl/msaa.c
new file mode 100644
index 0000000000..b4c6c63217
--- /dev/null
+++ b/progs/es1/xegl/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 <assert.h>
+#include <math.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/keysym.h>
+#if USE_FULL_GL
+#include <GL/gl.h> /* use full OpenGL */
+#else
+#include <GLES/gl.h> /* use OpenGL ES 1.x */
+#include <GLES/glext.h>
+#endif
+#include <EGL/egl.h>
+
+
+
+static GLfloat view_rotx = 0.0, view_roty = 0.0, view_rotz = 0.0;
+static GLboolean AA = 0*GL_TRUE;
+
+
+static void
+draw(void)
+{
+ float a;
+
+ static const GLfloat verts[4][2] = {
+ { -1, -.1 },
+ { 1, -.1 },
+ { -1, .1 },
+ { 1, .1 }
+ };
+ static const GLfloat colors[4][4] = {
+ { 1, 0, 0, 1 },
+ { 0, 1, 0, 1 },
+ { 0, 0, 1, 1 },
+ { 1, 0, 1, 1 }
+ };
+
+ if (AA) {
+ printf("MSAA enabled\n");
+ glEnable(GL_MULTISAMPLE);
+ }
+ else {
+ printf("MSAA disabled\n");
+ glDisable(GL_MULTISAMPLE);
+ }
+
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ glPushMatrix();
+ glRotatef(view_rotx, 1, 0, 0);
+ glRotatef(view_roty, 0, 1, 0);
+ glRotatef(view_rotz, 0, 0, 1);
+
+ {
+ glVertexPointer(2, GL_FLOAT, 0, verts);
+ glColorPointer(4, GL_FLOAT, 0, colors);
+
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glEnableClientState(GL_COLOR_ARRAY);
+
+ for (a = 0; a < 360; a += 20.0) {
+ glPushMatrix();
+
+ glRotatef(a, 0, 0, 1);
+ glTranslatef(1.5, 0, 0);
+
+ /* draw triangle */
+ glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+
+ glPopMatrix();
+ }
+
+ glDisableClientState(GL_VERTEX_ARRAY);
+ glDisableClientState(GL_COLOR_ARRAY);
+ }
+
+ glPopMatrix();
+}
+
+
+/* new window size or exposure */
+static void
+reshape(int width, int height)
+{
+ GLfloat ary = 3.0;
+ GLfloat arx = ary * (GLfloat) width / (GLfloat) height;
+
+ glViewport(0, 0, (GLint) width, (GLint) height);
+
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+#ifdef GL_VERSION_ES_CM_1_0
+ glOrthof(-arx, arx, -ary, ary, -1.0, 1.0);
+#else
+ glOrtho(-arx, arx, -ary, ary, -1.0, 1.0);
+#endif
+
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+}
+
+
+
+static void
+init(void)
+{
+ printf("Press 'a' to toggle multisample antialiasing\n");
+ printf("Press 'Esc' to exit\n");
+}
+
+
+/*
+ * Create an RGB, double-buffered X window.
+ * Return the window and context handles.
+ */
+static void
+make_x_window(Display *x_dpy, EGLDisplay egl_dpy,
+ const char *name,
+ int x, int y, int width, int height,
+ Window *winRet,
+ EGLContext *ctxRet,
+ EGLSurface *surfRet)
+{
+ static const EGLint attribs[] = {
+ EGL_RED_SIZE, 1,
+ EGL_GREEN_SIZE, 1,
+ EGL_BLUE_SIZE, 1,
+ EGL_DEPTH_SIZE, 1,
+ EGL_SAMPLES, 1,
+ EGL_SAMPLE_BUFFERS, 1,
+ EGL_NONE
+ };
+
+ int scrnum;
+ XSetWindowAttributes attr;
+ unsigned long mask;
+ Window root;
+ Window win;
+ XVisualInfo *visInfo, visTemplate;
+ int num_visuals;
+ EGLContext ctx;
+ EGLConfig config;
+ EGLint num_configs;
+ EGLint vid;
+
+ scrnum = DefaultScreen( x_dpy );
+ root = RootWindow( x_dpy, scrnum );
+
+ if (!eglChooseConfig( egl_dpy, attribs, &config, 1, &num_configs)) {
+ printf("Error: couldn't get an EGL visual config\n");
+ exit(1);
+ }
+
+ if (num_configs < 1) {
+ printf("Error: Unable to find multisample pixel format.\n");
+ printf("Try running glxinfo to see if your server supports MSAA.\n");
+ exit(1);
+ }
+
+ if (!eglGetConfigAttrib(egl_dpy, config, EGL_NATIVE_VISUAL_ID, &vid)) {
+ printf("Error: eglGetConfigAttrib() failed\n");
+ exit(1);
+ }
+
+ /* The X window visual must match the EGL config */
+ visTemplate.visualid = vid;
+ visInfo = XGetVisualInfo(x_dpy, VisualIDMask, &visTemplate, &num_visuals);
+ if (!visInfo) {
+ printf("Error: couldn't get X visual\n");
+ exit(1);
+ }
+
+ /* window attributes */
+ attr.background_pixel = 0;
+ attr.border_pixel = 0;
+ attr.colormap = XCreateColormap( x_dpy, root, visInfo->visual, AllocNone);
+ attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
+ mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
+
+ win = XCreateWindow( x_dpy, root, 0, 0, width, height,
+ 0, visInfo->depth, InputOutput,
+ visInfo->visual, mask, &attr );
+
+ /* set hints and properties */
+ {
+ XSizeHints sizehints;
+ sizehints.x = x;
+ sizehints.y = y;
+ sizehints.width = width;
+ sizehints.height = height;
+ sizehints.flags = USSize | USPosition;
+ XSetNormalHints(x_dpy, win, &sizehints);
+ XSetStandardProperties(x_dpy, win, name, name,
+ None, (char **)NULL, 0, &sizehints);
+ }
+
+#if USE_FULL_GL
+ eglBindAPI(EGL_OPENGL_API);
+#else
+ eglBindAPI(EGL_OPENGL_ES_API);
+#endif
+
+ ctx = eglCreateContext(egl_dpy, config, EGL_NO_CONTEXT, NULL );
+ if (!ctx) {
+ printf("Error: eglCreateContext failed\n");
+ exit(1);
+ }
+
+ *surfRet = eglCreateWindowSurface(egl_dpy, config, win, NULL);
+
+ if (!*surfRet) {
+ printf("Error: eglCreateWindowSurface failed\n");
+ exit(1);
+ }
+
+ XFree(visInfo);
+
+ *winRet = win;
+ *ctxRet = ctx;
+}
+
+
+static void
+event_loop(Display *dpy, Window win,
+ EGLDisplay egl_dpy, EGLSurface egl_surf)
+{
+ while (1) {
+ int redraw = 0;
+ XEvent event;
+
+ XNextEvent(dpy, &event);
+
+ switch (event.type) {
+ case Expose:
+ redraw = 1;
+ break;
+ case ConfigureNotify:
+ reshape(event.xconfigure.width, event.xconfigure.height);
+ break;
+ case KeyPress:
+ {
+ char buffer[10];
+ int r, code;
+ code = XLookupKeysym(&event.xkey, 0);
+ if (code == XK_Left) {
+ view_roty += 5.0;
+ }
+ else if (code == XK_Right) {
+ view_roty -= 5.0;
+ }
+ else if (code == XK_Up) {
+ view_rotx += 5.0;
+ }
+ else if (code == XK_Down) {
+ view_rotx -= 5.0;
+ }
+ else {
+ r = XLookupString(&event.xkey, buffer, sizeof(buffer),
+ NULL, NULL);
+ if (buffer[0] == 'a') {
+ AA = !AA;
+ redraw = 1;
+ }
+ else if (buffer[0] == 27) {
+ /* escape */
+ return;
+ }
+ }
+ }
+ redraw = 1;
+ break;
+ default:
+ ; /*no-op*/
+ }
+
+ if (redraw) {
+ draw();
+ eglSwapBuffers(egl_dpy, egl_surf);
+ }
+ }
+}
+
+
+static void
+usage(void)
+{
+ printf("Usage:\n");
+ printf(" -display <displayname> set the display to run on\n");
+ printf(" -info display OpenGL renderer info\n");
+}
+
+
+int
+main(int argc, char *argv[])
+{
+ const int winWidth = 600, winHeight = 600;
+ Display *x_dpy;
+ Window win;
+ EGLSurface egl_surf;
+ EGLContext egl_ctx;
+ EGLDisplay egl_dpy;
+ char *dpyName = NULL;
+ GLboolean printInfo = GL_FALSE;
+ EGLint egl_major, egl_minor;
+ int i;
+ const char *s;
+
+ static struct {
+ char *name;
+ GLenum value;
+ enum {GetString, GetInteger} type;
+ } info_items[] = {
+ {"GL_RENDERER", GL_RENDERER, GetString},
+ {"GL_VERSION", GL_VERSION, GetString},
+ {"GL_VENDOR", GL_VENDOR, GetString},
+ {"GL_EXTENSIONS", GL_EXTENSIONS, GetString},
+ {"GL_MAX_PALETTE_MATRICES_OES", GL_MAX_PALETTE_MATRICES_OES, GetInteger},
+ {"GL_MAX_VERTEX_UNITS_OES", GL_MAX_VERTEX_UNITS_OES, GetInteger},
+ };
+
+ for (i = 1; i < argc; i++) {
+ if (strcmp(argv[i], "-display") == 0) {
+ dpyName = argv[i+1];
+ i++;
+ }
+ else if (strcmp(argv[i], "-info") == 0) {
+ printInfo = GL_TRUE;
+ }
+ else {
+ usage();
+ return -1;
+ }
+ }
+
+ x_dpy = XOpenDisplay(dpyName);
+ if (!x_dpy) {
+ printf("Error: couldn't open display %s\n",
+ dpyName ? dpyName : getenv("DISPLAY"));
+ return -1;
+ }
+
+ egl_dpy = eglGetDisplay(x_dpy);
+ if (!egl_dpy) {
+ printf("Error: eglGetDisplay() failed\n");
+ return -1;
+ }
+
+ if (!eglInitialize(egl_dpy, &egl_major, &egl_minor)) {
+ printf("Error: eglInitialize() failed\n");
+ return -1;
+ }
+
+ s = eglQueryString(egl_dpy, EGL_VERSION);
+ printf("EGL_VERSION = %s\n", s);
+
+ s = eglQueryString(egl_dpy, EGL_VENDOR);
+ printf("EGL_VENDOR = %s\n", s);
+
+ s = eglQueryString(egl_dpy, EGL_EXTENSIONS);
+ printf("EGL_EXTENSIONS = %s\n", s);
+
+ s = eglQueryString(egl_dpy, EGL_CLIENT_APIS);
+ printf("EGL_CLIENT_APIS = %s\n", s);
+
+ make_x_window(x_dpy, egl_dpy,
+ "msaa", 0, 0, winWidth, winHeight,
+ &win, &egl_ctx, &egl_surf);
+
+ XMapWindow(x_dpy, win);
+ if (!eglMakeCurrent(egl_dpy, egl_surf, egl_surf, egl_ctx)) {
+ printf("Error: eglMakeCurrent() failed\n");
+ return -1;
+ }
+
+ if (printInfo) {
+ for (i = 0; i < sizeof(info_items)/sizeof(info_items[0]); i++) {
+ switch (info_items[i].type) {
+ case GetString:
+ printf("%s = %s\n", info_items[i].name, (char *)glGetString(info_items[i].value));
+ break;
+ case GetInteger: {
+ GLint rv = -1;
+ glGetIntegerv(info_items[i].value, &rv);
+ printf("%s = %d\n", info_items[i].name, rv);
+ break;
+ }
+ }
+ }
+ };
+ init();
+
+ /* Set initial projection/viewing transformation.
+ * We can't be sure we'll get a ConfigureNotify event when the window
+ * first appears.
+ */
+ reshape(winWidth, winHeight);
+
+ event_loop(x_dpy, win, egl_dpy, egl_surf);
+
+ eglDestroyContext(egl_dpy, egl_ctx);
+ eglDestroySurface(egl_dpy, egl_surf);
+ eglTerminate(egl_dpy);
+
+
+ XDestroyWindow(x_dpy, win);
+ XCloseDisplay(x_dpy);
+
+ return 0;
+}
diff --git a/progs/es1/xegl/pbuffer.c b/progs/es1/xegl/pbuffer.c
new file mode 100644
index 0000000000..011c2af58f
--- /dev/null
+++ b/progs/es1/xegl/pbuffer.c
@@ -0,0 +1,607 @@
+/*
+ * Copyright (C) 2008 Tunsgten Graphics,Inc. All Rights Reserved.
+ */
+
+/*
+ * Test EGL Pbuffers
+ * Brian Paul
+ * August 2008
+ */
+
+
+#include <assert.h>
+#include <math.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/keysym.h>
+#include <GLES/gl.h>
+#include <GLES/glext.h>
+#include <EGL/egl.h>
+
+
+
+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]);
+
+ /* 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]);
+
+ eglSwapBuffers(egl_dpy, egl_surf);
+
+ /* compare renderings */
+ for (dif = i = 0; i < WinWidth * WinHeight; i++) {
+ if (wbuf[i] != pbuf[i]) {
+ dif = 1;
+ break;
+ }
+ }
+
+ if (dif)
+ printf("Difference at %d: 0x%08x vs. 0x%08x\n", i, wbuf[i], pbuf[i]);
+ else
+ printf("Window rendering matches Pbuffer rendering!\n");
+
+ free(wbuf);
+ free(pbuf);
+}
+
+
+/* new window size or exposure */
+static void
+reshape(int width, int height)
+{
+ GLfloat ar = (GLfloat) width / (GLfloat) height;
+
+ WinWidth = width;
+ WinHeight = height;
+
+ glViewport(0, 0, (GLint) width, (GLint) height);
+
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+
+#ifdef GL_VERSION_ES_CM_1_0
+ glFrustumf(-ar, ar, -1, 1, 5.0, 60.0);
+#else
+ glFrustum(-ar, ar, -1, 1, 5.0, 60.0);
+#endif
+
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ glTranslatef(0.0, 0.0, -15.0);
+}
+
+
+static void
+make_texture(void)
+{
+#define SZ 64
+ GLenum Filter = GL_LINEAR;
+ GLubyte image[SZ][SZ][4];
+ GLuint i, j;
+
+ for (i = 0; i < SZ; i++) {
+ for (j = 0; j < SZ; j++) {
+ GLfloat d = (i - SZ/2) * (i - SZ/2) + (j - SZ/2) * (j - SZ/2);
+ d = sqrt(d);
+ if (d < SZ/3) {
+ image[i][j][0] = 255;
+ image[i][j][1] = 255;
+ image[i][j][2] = 255;
+ image[i][j][3] = 255;
+ }
+ else {
+ image[i][j][0] = 127;
+ image[i][j][1] = 127;
+ image[i][j][2] = 127;
+ image[i][j][3] = 255;
+ }
+ }
+ }
+
+ glActiveTexture(GL_TEXTURE0); /* unit 0 */
+ glBindTexture(GL_TEXTURE_2D, 42);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, SZ, SZ, 0,
+ GL_RGBA, GL_UNSIGNED_BYTE, image);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, Filter);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, Filter);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+#undef SZ
+}
+
+
+
+static void
+init(void)
+{
+ static const GLfloat red[4] = {1, 0, 0, 0};
+ static const GLfloat white[4] = {1.0, 1.0, 1.0, 1.0};
+ static const GLfloat diffuse[4] = {0.7, 0.7, 0.7, 1.0};
+ static const GLfloat specular[4] = {0.001, 0.001, 0.001, 1.0};
+ static const GLfloat pos[4] = {20, 20, 50, 1};
+
+ glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, red);
+ glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, white);
+ glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 9.0);
+
+ glEnable(GL_LIGHTING);
+ glEnable(GL_LIGHT0);
+ glLightfv(GL_LIGHT0, GL_POSITION, pos);
+ glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
+ glLightfv(GL_LIGHT0, GL_SPECULAR, specular);
+
+ glClearColor(0.4, 0.4, 0.4, 0.0);
+ glEnable(GL_DEPTH_TEST);
+
+ make_texture();
+ glEnable(GL_TEXTURE_2D);
+}
+
+
+/*
+ * Create an RGB, double-buffered X window.
+ * Return the window and context handles.
+ */
+static void
+make_x_window(Display *x_dpy, EGLDisplay egl_dpy,
+ const char *name,
+ int x, int y, int width, int height,
+ Window *winRet,
+ EGLContext *ctxRet,
+ EGLSurface *surfRet)
+{
+ static const EGLint attribs[] = {
+ EGL_RED_SIZE, 1,
+ EGL_GREEN_SIZE, 1,
+ EGL_BLUE_SIZE, 1,
+ EGL_DEPTH_SIZE, 1,
+ EGL_NONE
+ };
+
+ int scrnum;
+ XSetWindowAttributes attr;
+ unsigned long mask;
+ Window root;
+ Window win;
+ XVisualInfo *visInfo, visTemplate;
+ int num_visuals;
+ EGLContext ctx;
+ EGLConfig config;
+ EGLint num_configs;
+ EGLint vid;
+
+ scrnum = DefaultScreen( x_dpy );
+ root = RootWindow( x_dpy, scrnum );
+
+ if (!eglChooseConfig( egl_dpy, attribs, &config, 1, &num_configs)) {
+ printf("Error: couldn't get an EGL visual config\n");
+ exit(1);
+ }
+
+ assert(config);
+ assert(num_configs > 0);
+
+ if (!eglGetConfigAttrib(egl_dpy, config, EGL_NATIVE_VISUAL_ID, &vid)) {
+ printf("Error: eglGetConfigAttrib() failed\n");
+ exit(1);
+ }
+
+ /* The X window visual must match the EGL config */
+ visTemplate.visualid = vid;
+ visInfo = XGetVisualInfo(x_dpy, VisualIDMask, &visTemplate, &num_visuals);
+ if (!visInfo) {
+ printf("Error: couldn't get X visual\n");
+ exit(1);
+ }
+
+ /* window attributes */
+ attr.background_pixel = 0;
+ attr.border_pixel = 0;
+ attr.colormap = XCreateColormap( x_dpy, root, visInfo->visual, AllocNone);
+ attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
+ mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
+
+ win = XCreateWindow( x_dpy, root, 0, 0, width, height,
+ 0, visInfo->depth, InputOutput,
+ visInfo->visual, mask, &attr );
+
+ /* set hints and properties */
+ {
+ XSizeHints sizehints;
+ sizehints.x = x;
+ sizehints.y = y;
+ sizehints.width = width;
+ sizehints.height = height;
+ sizehints.flags = USSize | USPosition;
+ XSetNormalHints(x_dpy, win, &sizehints);
+ XSetStandardProperties(x_dpy, win, name, name,
+ None, (char **)NULL, 0, &sizehints);
+ }
+
+ eglBindAPI(EGL_OPENGL_ES_API);
+
+ ctx = eglCreateContext(egl_dpy, config, EGL_NO_CONTEXT, NULL );
+ if (!ctx) {
+ printf("Error: eglCreateContext failed\n");
+ exit(1);
+ }
+
+ *surfRet = eglCreateWindowSurface(egl_dpy, config, win, NULL);
+
+ if (!*surfRet) {
+ printf("Error: eglCreateWindowSurface failed\n");
+ exit(1);
+ }
+
+ XFree(visInfo);
+
+ *winRet = win;
+ *ctxRet = ctx;
+}
+
+
+static EGLSurface
+make_pbuffer(Display *x_dpy, EGLDisplay egl_dpy, int width, int height)
+{
+ static const EGLint config_attribs[] = {
+ EGL_RED_SIZE, 1,
+ EGL_GREEN_SIZE, 1,
+ EGL_BLUE_SIZE, 1,
+ EGL_DEPTH_SIZE, 1,
+ EGL_NONE
+ };
+ EGLConfig config;
+ EGLSurface pbuf;
+ EGLint num_configs;
+ EGLint pbuf_attribs[5];
+
+ pbuf_attribs[0] = EGL_WIDTH;
+ pbuf_attribs[1] = width;
+ pbuf_attribs[2] = EGL_HEIGHT;
+ pbuf_attribs[3] = height;
+ pbuf_attribs[4] = EGL_NONE;
+
+ if (!eglChooseConfig( egl_dpy, config_attribs, &config, 1, &num_configs)) {
+ printf("Error: couldn't get an EGL config for pbuffer\n");
+ exit(1);
+ }
+
+ pbuf = eglCreatePbufferSurface(egl_dpy, config, pbuf_attribs);
+
+ return pbuf;
+}
+
+
+static void
+event_loop(Display *dpy, Window win,
+ EGLDisplay egl_dpy, EGLSurface egl_surf, EGLSurface egl_pbuf,
+ EGLContext egl_ctx)
+{
+ int anim = 0;
+
+ while (1) {
+ int redraw = 0;
+
+ if (!anim || XPending(dpy)) {
+ XEvent event;
+ XNextEvent(dpy, &event);
+
+ switch (event.type) {
+ case Expose:
+ redraw = 1;
+ break;
+ case ConfigureNotify:
+ if (event.xconfigure.window == win)
+ reshape(event.xconfigure.width, event.xconfigure.height);
+ break;
+ case KeyPress:
+ {
+ char buffer[10];
+ int r, code;
+ code = XLookupKeysym(&event.xkey, 0);
+ if (code == XK_Left) {
+ view_roty += 5.0;
+ }
+ else if (code == XK_Right) {
+ view_roty -= 5.0;
+ }
+ else if (code == XK_Up) {
+ view_rotx += 5.0;
+ }
+ else if (code == XK_Down) {
+ view_rotx -= 5.0;
+ }
+ else {
+ r = XLookupString(&event.xkey, buffer, sizeof(buffer),
+ NULL, NULL);
+ if (buffer[0] == ' ') {
+ anim = !anim;
+ }
+ else if (buffer[0] == 27) {
+ /* escape */
+ return;
+ }
+ }
+ }
+ redraw = 1;
+ break;
+ default:
+ ; /*no-op*/
+ }
+ }
+
+ if (anim) {
+ view_rotx += 1.0;
+ view_roty += 2.0;
+ redraw = 1;
+ }
+
+ if (redraw) {
+ draw_both(egl_dpy, egl_surf, egl_pbuf, egl_ctx);
+ }
+ }
+}
+
+
+static void
+usage(void)
+{
+ printf("Usage:\n");
+ printf(" -display <displayname> set the display to run on\n");
+ printf(" -info display OpenGL renderer info\n");
+}
+
+
+int
+main(int argc, char *argv[])
+{
+ Display *x_dpy;
+ Window win;
+ EGLSurface egl_surf, egl_pbuf;
+ EGLContext egl_ctx;
+ EGLDisplay egl_dpy;
+ char *dpyName = NULL;
+ GLboolean printInfo = GL_FALSE;
+ EGLint egl_major, egl_minor;
+ int i;
+ const char *s;
+
+ for (i = 1; i < argc; i++) {
+ if (strcmp(argv[i], "-display") == 0) {
+ dpyName = argv[i+1];
+ i++;
+ }
+ else if (strcmp(argv[i], "-info") == 0) {
+ printInfo = GL_TRUE;
+ }
+ else {
+ usage();
+ return -1;
+ }
+ }
+
+ x_dpy = XOpenDisplay(dpyName);
+ if (!x_dpy) {
+ printf("Error: couldn't open display %s\n",
+ dpyName ? dpyName : getenv("DISPLAY"));
+ return -1;
+ }
+
+ egl_dpy = eglGetDisplay(x_dpy);
+ if (!egl_dpy) {
+ printf("Error: eglGetDisplay() failed\n");
+ return -1;
+ }
+
+ if (!eglInitialize(egl_dpy, &egl_major, &egl_minor)) {
+ printf("Error: eglInitialize() failed\n");
+ return -1;
+ }
+
+ s = eglQueryString(egl_dpy, EGL_VERSION);
+ printf("EGL_VERSION = %s\n", s);
+
+ s = eglQueryString(egl_dpy, EGL_VENDOR);
+ printf("EGL_VENDOR = %s\n", s);
+
+ s = eglQueryString(egl_dpy, EGL_EXTENSIONS);
+ printf("EGL_EXTENSIONS = %s\n", s);
+
+ s = eglQueryString(egl_dpy, EGL_CLIENT_APIS);
+ printf("EGL_CLIENT_APIS = %s\n", s);
+
+ make_x_window(x_dpy, egl_dpy,
+ "pbuffer", 0, 0, WinWidth, WinHeight,
+ &win, &egl_ctx, &egl_surf);
+
+ egl_pbuf = make_pbuffer(x_dpy, egl_dpy, WinWidth, WinHeight);
+ if (!egl_pbuf) {
+ printf("Error: eglCreatePBufferSurface() failed\n");
+ return -1;
+ }
+
+ XMapWindow(x_dpy, win);
+ if (!eglMakeCurrent(egl_dpy, egl_surf, egl_surf, egl_ctx)) {
+ printf("Error: eglMakeCurrent() failed\n");
+ return -1;
+ }
+
+ if (printInfo) {
+ printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
+ printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
+ printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR));
+ printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS));
+ }
+
+ init();
+
+ /* Set initial projection/viewing transformation.
+ * We can't be sure we'll get a ConfigureNotify event when the window
+ * first appears.
+ */
+ reshape(WinWidth, WinHeight);
+
+ event_loop(x_dpy, win, egl_dpy, egl_surf, egl_pbuf, egl_ctx);
+
+ eglDestroyContext(egl_dpy, egl_ctx);
+ eglDestroySurface(egl_dpy, egl_surf);
+ eglTerminate(egl_dpy);
+
+
+ XDestroyWindow(x_dpy, win);
+ XCloseDisplay(x_dpy);
+
+ return 0;
+}
diff --git a/progs/es1/xegl/render_tex.c b/progs/es1/xegl/render_tex.c
new file mode 100644
index 0000000000..0200fa4cb0
--- /dev/null
+++ b/progs/es1/xegl/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 <assert.h>
+#include <math.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/keysym.h>
+#include <GLES/gl.h>
+#include <GLES/glext.h>
+#include <EGL/egl.h>
+
+
+static int TexWidth = 256, TexHeight = 256;
+
+static int WinWidth = 300, WinHeight = 300;
+
+static GLfloat view_rotx = 0.0, view_roty = 0.0, view_rotz = 0.0;
+
+static GLuint DotTexture, RenderTexture;
+
+
+static void
+Normal(GLfloat *n, GLfloat nx, GLfloat ny, GLfloat nz)
+{
+ n[0] = nx;
+ n[1] = ny;
+ n[2] = nz;
+}
+
+static void
+Vertex(GLfloat *v, GLfloat vx, GLfloat vy, GLfloat vz)
+{
+ v[0] = vx;
+ v[1] = vy;
+ v[2] = vz;
+}
+
+static void
+Texcoord(GLfloat *v, GLfloat s, GLfloat t)
+{
+ v[0] = s;
+ v[1] = t;
+}
+
+
+/* Borrowed from glut, adapted */
+static void
+draw_torus(GLfloat r, GLfloat R, GLint nsides, GLint rings)
+{
+ int i, j;
+ GLfloat theta, phi, theta1;
+ GLfloat cosTheta, sinTheta;
+ GLfloat cosTheta1, sinTheta1;
+ GLfloat ringDelta, sideDelta;
+ GLfloat varray[100][3], narray[100][3], tarray[100][2];
+ int vcount;
+
+ glVertexPointer(3, GL_FLOAT, 0, varray);
+ glNormalPointer(GL_FLOAT, 0, narray);
+ glTexCoordPointer(2, GL_FLOAT, 0, tarray);
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glEnableClientState(GL_NORMAL_ARRAY);
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+
+ ringDelta = 2.0 * M_PI / rings;
+ sideDelta = 2.0 * M_PI / nsides;
+
+ theta = 0.0;
+ cosTheta = 1.0;
+ sinTheta = 0.0;
+ for (i = rings - 1; i >= 0; i--) {
+ theta1 = theta + ringDelta;
+ cosTheta1 = cos(theta1);
+ sinTheta1 = sin(theta1);
+
+ vcount = 0; /* glBegin(GL_QUAD_STRIP); */
+
+ phi = 0.0;
+ for (j = nsides; j >= 0; j--) {
+ GLfloat s0, s1, t;
+ GLfloat cosPhi, sinPhi, dist;
+
+ phi += sideDelta;
+ cosPhi = cos(phi);
+ sinPhi = sin(phi);
+ dist = R + r * cosPhi;
+
+ s0 = 20.0 * theta / (2.0 * M_PI);
+ s1 = 20.0 * theta1 / (2.0 * M_PI);
+ t = 8.0 * phi / (2.0 * M_PI);
+
+ Normal(narray[vcount], cosTheta1 * cosPhi, -sinTheta1 * cosPhi, sinPhi);
+ Texcoord(tarray[vcount], s1, t);
+ Vertex(varray[vcount], cosTheta1 * dist, -sinTheta1 * dist, r * sinPhi);
+ vcount++;
+
+ Normal(narray[vcount], cosTheta * cosPhi, -sinTheta * cosPhi, sinPhi);
+ Texcoord(tarray[vcount], s0, t);
+ Vertex(varray[vcount], cosTheta * dist, -sinTheta * dist, r * sinPhi);
+ vcount++;
+ }
+
+ /*glEnd();*/
+ assert(vcount <= 100);
+ glDrawArrays(GL_TRIANGLE_STRIP, 0, vcount);
+
+ theta = theta1;
+ cosTheta = cosTheta1;
+ sinTheta = sinTheta1;
+ }
+
+ glDisableClientState(GL_VERTEX_ARRAY);
+ glDisableClientState(GL_NORMAL_ARRAY);
+ glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+}
+
+
+static void
+draw_torus_to_texture(void)
+{
+ glViewport(0, 0, TexWidth, TexHeight);
+
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glFrustumf(-1, 1, -1, 1, 5.0, 60.0);
+
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ glTranslatef(0.0, 0.0, -15.0);
+
+ glClearColor(0.4, 0.4, 0.4, 0.0);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ glBindTexture(GL_TEXTURE_2D, DotTexture);
+
+ glEnable(GL_LIGHTING);
+
+ glPushMatrix();
+ glRotatef(view_roty, 0, 1, 0);
+ glScalef(0.5, 0.5, 0.5);
+
+ draw_torus(1.0, 3.0, 30, 60);
+
+ glPopMatrix();
+
+ glDisable(GL_LIGHTING);
+
+#if 0
+ glBindTexture(GL_TEXTURE_2D, RenderTexture);
+ glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, TexWidth, TexHeight);
+#endif
+
+ glFinish();
+}
+
+
+static void
+draw_textured_quad(void)
+{
+ GLfloat ar = (GLfloat) WinWidth / (GLfloat) WinHeight;
+
+ glViewport(0, 0, WinWidth, WinHeight);
+
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glFrustumf(-ar, ar, -1, 1, 5.0, 60.0);
+
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ glTranslatef(0.0, 0.0, -8.0);
+
+ glClearColor(0.4, 0.4, 1.0, 0.0);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ glBindTexture(GL_TEXTURE_2D, RenderTexture);
+
+ glPushMatrix();
+ glRotatef(view_rotx, 1, 0, 0);
+ glRotatef(view_rotz, 0, 0, 1);
+
+ {
+ static const GLfloat texcoord[4][2] = {
+ { 0, 0 }, { 1, 0 }, { 0, 1 }, { 1, 1 }
+ };
+ static const GLfloat vertex[4][2] = {
+ { -1, -1 }, { 1, -1 }, { -1, 1 }, { 1, 1 }
+ };
+
+ glVertexPointer(2, GL_FLOAT, 0, vertex);
+ glTexCoordPointer(2, GL_FLOAT, 0, texcoord);
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+
+ glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+
+ glDisableClientState(GL_VERTEX_ARRAY);
+ glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+ }
+
+ glPopMatrix();
+}
+
+
+
+static void
+draw(EGLDisplay egl_dpy, EGLSurface egl_surf, EGLSurface egl_pbuf,
+ EGLContext egl_ctx)
+{
+ /*printf("Begin draw\n");*/
+
+ /* first draw torus to pbuffer /texture */
+#if 01
+ if (!eglMakeCurrent(egl_dpy, egl_pbuf, egl_pbuf, egl_ctx)) {
+#else
+ if (!eglMakeCurrent(egl_dpy, egl_surf, egl_surf, egl_ctx)) {
+#endif
+ printf("Error: eglMakeCurrent(pbuf) failed\n");
+ return;
+ }
+ draw_torus_to_texture();
+
+ /* draw textured quad to window */
+ if (!eglMakeCurrent(egl_dpy, egl_surf, egl_surf, egl_ctx)) {
+ printf("Error: eglMakeCurrent(pbuffer) failed\n");
+ return;
+ }
+
+ glBindTexture(GL_TEXTURE_2D, RenderTexture);
+ eglBindTexImage(egl_dpy, egl_pbuf, EGL_BACK_BUFFER);
+ draw_textured_quad();
+ eglReleaseTexImage(egl_dpy, egl_pbuf, EGL_BACK_BUFFER);
+
+ eglSwapBuffers(egl_dpy, egl_surf);
+
+ /*printf("End draw\n");*/
+}
+
+
+
+static void
+make_dot_texture(void)
+{
+#define SZ 64
+ GLenum Filter = GL_LINEAR;
+ GLubyte image[SZ][SZ][4];
+ GLuint i, j;
+
+ for (i = 0; i < SZ; i++) {
+ for (j = 0; j < SZ; j++) {
+ GLfloat d = (i - SZ/2) * (i - SZ/2) + (j - SZ/2) * (j - SZ/2);
+ d = sqrt(d);
+ if (d < SZ/3) {
+ image[i][j][0] = 255;
+ image[i][j][1] = 255;
+ image[i][j][2] = 255;
+ image[i][j][3] = 255;
+ }
+ else {
+ image[i][j][0] = 127;
+ image[i][j][1] = 127;
+ image[i][j][2] = 127;
+ image[i][j][3] = 255;
+ }
+ }
+ }
+
+ glGenTextures(1, &DotTexture);
+ glBindTexture(GL_TEXTURE_2D, DotTexture);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, SZ, SZ, 0,
+ GL_RGBA, GL_UNSIGNED_BYTE, image);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, Filter);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, Filter);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+#undef SZ
+}
+
+
+static void
+make_render_texture(void)
+{
+ GLenum Filter = GL_LINEAR;
+ glGenTextures(1, &RenderTexture);
+ glBindTexture(GL_TEXTURE_2D, RenderTexture);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TexWidth, TexHeight, 0,
+ GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, Filter);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, Filter);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+}
+
+
+static void
+init(void)
+{
+ static const GLfloat red[4] = {1, 0, 0, 0};
+ static const GLfloat white[4] = {1.0, 1.0, 1.0, 1.0};
+ static const GLfloat diffuse[4] = {0.7, 0.7, 0.7, 1.0};
+ static const GLfloat specular[4] = {0.001, 0.001, 0.001, 1.0};
+ static const GLfloat pos[4] = {20, 20, 50, 1};
+
+ glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, red);
+ glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, white);
+ glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 9.0);
+
+ glEnable(GL_LIGHT0);
+ glLightfv(GL_LIGHT0, GL_POSITION, pos);
+ glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
+ glLightfv(GL_LIGHT0, GL_SPECULAR, specular);
+
+ glEnable(GL_DEPTH_TEST);
+
+ make_dot_texture();
+ make_render_texture();
+
+ printf("DotTexture=%u RenderTexture=%u\n", DotTexture, RenderTexture);
+
+ glEnable(GL_TEXTURE_2D);
+}
+
+
+/*
+ * Create an RGB, double-buffered X window.
+ * Return the window and context handles.
+ */
+static void
+make_x_window(Display *x_dpy, EGLDisplay egl_dpy,
+ const char *name,
+ int x, int y, int width, int height,
+ Window *winRet,
+ EGLContext *ctxRet,
+ EGLSurface *surfRet)
+{
+ static const EGLint attribs[] = {
+ EGL_RED_SIZE, 1,
+ EGL_GREEN_SIZE, 1,
+ EGL_BLUE_SIZE, 1,
+ EGL_DEPTH_SIZE, 1,
+ EGL_NONE
+ };
+
+ int scrnum;
+ XSetWindowAttributes attr;
+ unsigned long mask;
+ Window root;
+ Window win;
+ XVisualInfo *visInfo, visTemplate;
+ int num_visuals;
+ EGLContext ctx;
+ EGLConfig config;
+ EGLint num_configs;
+ EGLint vid;
+
+ scrnum = DefaultScreen( x_dpy );
+ root = RootWindow( x_dpy, scrnum );
+
+ if (!eglChooseConfig( egl_dpy, attribs, &config, 1, &num_configs)) {
+ printf("Error: couldn't get an EGL visual config\n");
+ exit(1);
+ }
+
+ assert(config);
+ assert(num_configs > 0);
+
+ if (!eglGetConfigAttrib(egl_dpy, config, EGL_NATIVE_VISUAL_ID, &vid)) {
+ printf("Error: eglGetConfigAttrib() failed\n");
+ exit(1);
+ }
+
+ /* The X window visual must match the EGL config */
+ visTemplate.visualid = vid;
+ visInfo = XGetVisualInfo(x_dpy, VisualIDMask, &visTemplate, &num_visuals);
+ if (!visInfo) {
+ printf("Error: couldn't get X visual\n");
+ exit(1);
+ }
+
+ /* window attributes */
+ attr.background_pixel = 0;
+ attr.border_pixel = 0;
+ attr.colormap = XCreateColormap( x_dpy, root, visInfo->visual, AllocNone);
+ attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
+ mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
+
+ win = XCreateWindow( x_dpy, root, 0, 0, width, height,
+ 0, visInfo->depth, InputOutput,
+ visInfo->visual, mask, &attr );
+
+ /* set hints and properties */
+ {
+ XSizeHints sizehints;
+ sizehints.x = x;
+ sizehints.y = y;
+ sizehints.width = width;
+ sizehints.height = height;
+ sizehints.flags = USSize | USPosition;
+ XSetNormalHints(x_dpy, win, &sizehints);
+ XSetStandardProperties(x_dpy, win, name, name,
+ None, (char **)NULL, 0, &sizehints);
+ }
+
+ eglBindAPI(EGL_OPENGL_ES_API);
+
+ ctx = eglCreateContext(egl_dpy, config, EGL_NO_CONTEXT, NULL );
+ if (!ctx) {
+ printf("Error: eglCreateContext failed\n");
+ exit(1);
+ }
+
+ *surfRet = eglCreateWindowSurface(egl_dpy, config, win, NULL);
+
+ if (!*surfRet) {
+ printf("Error: eglCreateWindowSurface failed\n");
+ exit(1);
+ }
+
+ XFree(visInfo);
+
+ *winRet = win;
+ *ctxRet = ctx;
+}
+
+
+static EGLSurface
+make_pbuffer(Display *x_dpy, EGLDisplay egl_dpy, int width, int height)
+{
+ static const EGLint config_attribs[] = {
+ EGL_RED_SIZE, 1,
+ EGL_GREEN_SIZE, 1,
+ EGL_BLUE_SIZE, 1,
+ EGL_DEPTH_SIZE, 1,
+ EGL_NONE
+ };
+ EGLConfig config;
+ EGLSurface pbuf;
+ EGLint num_configs;
+ EGLint pbuf_attribs[15];
+ int i = 0;
+
+ pbuf_attribs[i++] = EGL_WIDTH;
+ pbuf_attribs[i++] = width;
+ pbuf_attribs[i++] = EGL_HEIGHT;
+ pbuf_attribs[i++] = height;
+ pbuf_attribs[i++] = EGL_TEXTURE_FORMAT;
+ pbuf_attribs[i++] = EGL_TEXTURE_RGBA;
+ pbuf_attribs[i++] = EGL_TEXTURE_TARGET;
+ pbuf_attribs[i++] = EGL_TEXTURE_2D;
+ pbuf_attribs[i++] = EGL_MIPMAP_TEXTURE;
+ pbuf_attribs[i++] = EGL_FALSE;
+ pbuf_attribs[i++] = EGL_NONE;
+ assert(i <= 15);
+
+ if (!eglChooseConfig( egl_dpy, config_attribs, &config, 1, &num_configs)) {
+ printf("Error: couldn't get an EGL config for pbuffer\n");
+ exit(1);
+ }
+
+ pbuf = eglCreatePbufferSurface(egl_dpy, config, pbuf_attribs);
+
+ return pbuf;
+}
+
+
+static void
+event_loop(Display *dpy, Window win,
+ EGLDisplay egl_dpy, EGLSurface egl_surf, EGLSurface egl_pbuf,
+ EGLContext egl_ctx)
+{
+ int anim = 0;
+
+ while (1) {
+ int redraw = 0;
+
+ if (!anim || XPending(dpy)) {
+ XEvent event;
+ XNextEvent(dpy, &event);
+
+ switch (event.type) {
+ case Expose:
+ redraw = 1;
+ break;
+ case ConfigureNotify:
+ if (event.xconfigure.window == win) {
+ WinWidth = event.xconfigure.width;
+ WinHeight = event.xconfigure.height;
+ }
+ break;
+ case KeyPress:
+ {
+ char buffer[10];
+ int r, code;
+ code = XLookupKeysym(&event.xkey, 0);
+ if (code == XK_Left) {
+ view_roty += 5.0;
+ }
+ else if (code == XK_Right) {
+ view_roty -= 5.0;
+ }
+ else if (code == XK_Up) {
+ view_rotx += 5.0;
+ }
+ else if (code == XK_Down) {
+ view_rotx -= 5.0;
+ }
+ else {
+ r = XLookupString(&event.xkey, buffer, sizeof(buffer),
+ NULL, NULL);
+ if (buffer[0] == ' ') {
+ anim = !anim;
+ }
+ else if (buffer[0] == 'z') {
+ view_rotz += 5.0;
+ }
+ else if (buffer[0] == 'Z') {
+ view_rotz -= 5.0;
+ }
+ else if (buffer[0] == 27) {
+ /* escape */
+ return;
+ }
+ }
+ }
+ redraw = 1;
+ break;
+ default:
+ ; /*no-op*/
+ }
+ }
+
+ if (anim) {
+ view_rotx += 1.0;
+ view_roty += 2.0;
+ redraw = 1;
+ }
+
+ if (redraw) {
+ draw(egl_dpy, egl_surf, egl_pbuf, egl_ctx);
+ }
+ }
+}
+
+
+static void
+usage(void)
+{
+ printf("Usage:\n");
+ printf(" -display <displayname> set the display to run on\n");
+ printf(" -info display OpenGL renderer info\n");
+}
+
+
+int
+main(int argc, char *argv[])
+{
+ Display *x_dpy;
+ Window win;
+ EGLSurface egl_surf, egl_pbuf;
+ EGLContext egl_ctx;
+ EGLDisplay egl_dpy;
+ char *dpyName = NULL;
+ GLboolean printInfo = GL_FALSE;
+ EGLint egl_major, egl_minor;
+ int i;
+ const char *s;
+
+ for (i = 1; i < argc; i++) {
+ if (strcmp(argv[i], "-display") == 0) {
+ dpyName = argv[i+1];
+ i++;
+ }
+ else if (strcmp(argv[i], "-info") == 0) {
+ printInfo = GL_TRUE;
+ }
+ else {
+ usage();
+ return -1;
+ }
+ }
+
+ x_dpy = XOpenDisplay(dpyName);
+ if (!x_dpy) {
+ printf("Error: couldn't open display %s\n",
+ dpyName ? dpyName : getenv("DISPLAY"));
+ return -1;
+ }
+
+ egl_dpy = eglGetDisplay(x_dpy);
+ if (!egl_dpy) {
+ printf("Error: eglGetDisplay() failed\n");
+ return -1;
+ }
+
+ if (!eglInitialize(egl_dpy, &egl_major, &egl_minor)) {
+ printf("Error: eglInitialize() failed\n");
+ return -1;
+ }
+
+ s = eglQueryString(egl_dpy, EGL_VERSION);
+ printf("EGL_VERSION = %s\n", s);
+
+ s = eglQueryString(egl_dpy, EGL_VENDOR);
+ printf("EGL_VENDOR = %s\n", s);
+
+ s = eglQueryString(egl_dpy, EGL_EXTENSIONS);
+ printf("EGL_EXTENSIONS = %s\n", s);
+
+ s = eglQueryString(egl_dpy, EGL_CLIENT_APIS);
+ printf("EGL_CLIENT_APIS = %s\n", s);
+
+ make_x_window(x_dpy, egl_dpy,
+ "render_tex", 0, 0, WinWidth, WinHeight,
+ &win, &egl_ctx, &egl_surf);
+
+ egl_pbuf = make_pbuffer(x_dpy, egl_dpy, TexWidth, TexHeight);
+ if (!egl_pbuf) {
+ printf("Error: eglCreatePBufferSurface() failed\n");
+ return -1;
+ }
+
+ XMapWindow(x_dpy, win);
+ if (!eglMakeCurrent(egl_dpy, egl_surf, egl_surf, egl_ctx)) {
+ printf("Error: eglMakeCurrent() failed\n");
+ return -1;
+ }
+
+ if (printInfo) {
+ printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
+ printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
+ printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR));
+ printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS));
+ }
+
+ init();
+
+ event_loop(x_dpy, win, egl_dpy, egl_surf, egl_pbuf, egl_ctx);
+
+ eglDestroyContext(egl_dpy, egl_ctx);
+ eglDestroySurface(egl_dpy, egl_surf);
+ eglTerminate(egl_dpy);
+
+
+ XDestroyWindow(x_dpy, win);
+ XCloseDisplay(x_dpy);
+
+ return 0;
+}
diff --git a/progs/es1/xegl/torus.c b/progs/es1/xegl/torus.c
new file mode 100644
index 0000000000..9438a4fe59
--- /dev/null
+++ b/progs/es1/xegl/torus.c
@@ -0,0 +1,656 @@
+/*
+ * Copyright (C) 2008 Tunsgten Graphics,Inc. All Rights Reserved.
+ */
+
+/*
+ * Draw a lit, textured torus with X/EGL and OpenGL ES 1.x
+ * Brian Paul
+ * July 2008
+ */
+
+
+#include <assert.h>
+#include <math.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/keysym.h>
+#include <GLES/gl.h>
+#include <GLES/glext.h>
+#include <EGL/egl.h>
+
+
+static 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 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);
+}
+
+
+/*
+ * 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 void
+event_loop(Display *dpy, Window win,
+ EGLDisplay egl_dpy, EGLSurface egl_surf)
+{
+ int anim = 1;
+
+ while (1) {
+ int redraw = 0;
+
+ if (!anim || XPending(dpy)) {
+ XEvent event;
+ XNextEvent(dpy, &event);
+
+ switch (event.type) {
+ case Expose:
+ redraw = 1;
+ break;
+ case ConfigureNotify:
+ reshape(event.xconfigure.width, event.xconfigure.height);
+ break;
+ case KeyPress:
+ {
+ char buffer[10];
+ int r, code;
+ code = XLookupKeysym(&event.xkey, 0);
+ if (code == XK_Left) {
+ view_roty += 5.0;
+ }
+ else if (code == XK_Right) {
+ view_roty -= 5.0;
+ }
+ else if (code == XK_Up) {
+ view_rotx += 5.0;
+ }
+ else if (code == XK_Down) {
+ view_rotx -= 5.0;
+ }
+ else if (code == XK_t) {
+ GLint size;
+ tex_format = (tex_format + 1) % (NUM_CPAL_FORMATS + 1);
+ if (tex_format < NUM_CPAL_FORMATS) {
+ size = make_cpal_texture(tex_format);
+ printf("Using %s (%d bytes)\n",
+ cpal_formats[tex_format].name, size);
+ }
+ else {
+ size = make_texture();
+ printf("Using uncompressed texture (%d bytes)\n", size);
+ }
+ }
+ else {
+ r = XLookupString(&event.xkey, buffer, sizeof(buffer),
+ NULL, NULL);
+ if (buffer[0] == ' ') {
+ anim = !anim;
+ }
+ else if (buffer[0] == 27) {
+ /* escape */
+ return;
+ }
+ }
+ }
+ redraw = 1;
+ break;
+ default:
+ ; /*no-op*/
+ }
+ }
+
+ if (anim) {
+ view_rotx += 1.0;
+ view_roty += 2.0;
+ redraw = 1;
+ }
+
+ if (redraw) {
+ draw();
+ eglSwapBuffers(egl_dpy, egl_surf);
+ }
+ }
+}
+
+
+static void
+usage(void)
+{
+ printf("Usage:\n");
+ printf(" -display <displayname> set the display to run on\n");
+ printf(" -info display OpenGL renderer info\n");
+}
+
+
+int
+main(int argc, char *argv[])
+{
+ const int winWidth = 300, winHeight = 300;
+ Display *x_dpy;
+ Window win;
+ EGLSurface egl_surf;
+ EGLContext egl_ctx;
+ EGLDisplay egl_dpy;
+ char *dpyName = NULL;
+ GLboolean printInfo = GL_FALSE;
+ EGLint egl_major, egl_minor;
+ int i;
+ const char *s;
+
+ for (i = 1; i < argc; i++) {
+ if (strcmp(argv[i], "-display") == 0) {
+ dpyName = argv[i+1];
+ i++;
+ }
+ else if (strcmp(argv[i], "-info") == 0) {
+ printInfo = GL_TRUE;
+ }
+ else {
+ usage();
+ return -1;
+ }
+ }
+
+ x_dpy = XOpenDisplay(dpyName);
+ if (!x_dpy) {
+ printf("Error: couldn't open display %s\n",
+ dpyName ? dpyName : getenv("DISPLAY"));
+ return -1;
+ }
+
+ egl_dpy = eglGetDisplay(x_dpy);
+ if (!egl_dpy) {
+ printf("Error: eglGetDisplay() failed\n");
+ return -1;
+ }
+
+ if (!eglInitialize(egl_dpy, &egl_major, &egl_minor)) {
+ printf("Error: eglInitialize() failed\n");
+ return -1;
+ }
+
+ s = eglQueryString(egl_dpy, EGL_VERSION);
+ printf("EGL_VERSION = %s\n", s);
+
+ s = eglQueryString(egl_dpy, EGL_VENDOR);
+ printf("EGL_VENDOR = %s\n", s);
+
+ s = eglQueryString(egl_dpy, EGL_EXTENSIONS);
+ printf("EGL_EXTENSIONS = %s\n", s);
+
+ s = eglQueryString(egl_dpy, EGL_CLIENT_APIS);
+ printf("EGL_CLIENT_APIS = %s\n", s);
+
+ make_x_window(x_dpy, egl_dpy,
+ "torus", 0, 0, winWidth, winHeight,
+ &win, &egl_ctx, &egl_surf);
+
+ XMapWindow(x_dpy, win);
+ if (!eglMakeCurrent(egl_dpy, egl_surf, egl_surf, egl_ctx)) {
+ printf("Error: eglMakeCurrent() failed\n");
+ return -1;
+ }
+
+ if (printInfo) {
+ printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
+ printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
+ printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR));
+ printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS));
+ }
+
+ init();
+
+ /* Set initial projection/viewing transformation.
+ * We can't be sure we'll get a ConfigureNotify event when the window
+ * first appears.
+ */
+ reshape(winWidth, winHeight);
+
+ event_loop(x_dpy, win, egl_dpy, egl_surf);
+
+ eglDestroyContext(egl_dpy, egl_ctx);
+ eglDestroySurface(egl_dpy, egl_surf);
+ eglTerminate(egl_dpy);
+
+
+ XDestroyWindow(x_dpy, win);
+ XCloseDisplay(x_dpy);
+
+ return 0;
+}
diff --git a/progs/es1/xegl/tri.c b/progs/es1/xegl/tri.c
new file mode 100644
index 0000000000..42a978207c
--- /dev/null
+++ b/progs/es1/xegl/tri.c
@@ -0,0 +1,470 @@
+/*
+ * Copyright (C) 2008 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*
+ * Draw a triangle with X/EGL and OpenGL ES 1.x
+ * Brian Paul
+ * 5 June 2008
+ */
+
+#define USE_FULL_GL 0
+
+#define USE_FIXED_POINT 0
+
+
+#include <assert.h>
+#include <math.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/keysym.h>
+#if USE_FULL_GL
+#include <GL/gl.h> /* use full OpenGL */
+#else
+#include <GLES/gl.h> /* use OpenGL ES 1.x */
+#include <GLES/glext.h>
+#endif
+#include <EGL/egl.h>
+
+
+#define FLOAT_TO_FIXED(X) ((X) * 65535.0)
+
+
+
+static GLfloat view_rotx = 0.0, view_roty = 0.0, view_rotz = 0.0;
+
+
+static void
+draw(void)
+{
+#if USE_FIXED_POINT
+ static const GLfixed verts[3][2] = {
+ { -65536, -65536 },
+ { 65536, -65536 },
+ { 0, 65536 }
+ };
+ static const GLfixed colors[3][4] = {
+ { 65536, 0, 0, 65536 },
+ { 0, 65536, 0 , 65536},
+ { 0, 0, 65536 , 65536}
+ };
+#else
+ static const GLfloat verts[3][2] = {
+ { -1, -1 },
+ { 1, -1 },
+ { 0, 1 }
+ };
+ static const GLfloat colors[3][4] = {
+ { 1, 0, 0, 1 },
+ { 0, 1, 0, 1 },
+ { 0, 0, 1, 1 }
+ };
+#endif
+
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ glPushMatrix();
+ glRotatef(view_rotx, 1, 0, 0);
+ glRotatef(view_roty, 0, 1, 0);
+ glRotatef(view_rotz, 0, 0, 1);
+
+ {
+#if USE_FIXED_POINT
+ glVertexPointer(2, GL_FIXED, 0, verts);
+ glColorPointer(4, GL_FIXED, 0, colors);
+#else
+ glVertexPointer(2, GL_FLOAT, 0, verts);
+ glColorPointer(4, GL_FLOAT, 0, colors);
+#endif
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glEnableClientState(GL_COLOR_ARRAY);
+
+ /* draw triangle */
+ glDrawArrays(GL_TRIANGLES, 0, 3);
+
+ /* draw some points */
+ glPointSizex(FLOAT_TO_FIXED(15.5));
+ glDrawArrays(GL_POINTS, 0, 3);
+
+ glDisableClientState(GL_VERTEX_ARRAY);
+ glDisableClientState(GL_COLOR_ARRAY);
+ }
+
+ if (0) {
+ /* test code */
+ GLfixed size;
+ glGetFixedv(GL_POINT_SIZE, &size);
+ printf("GL_POINT_SIZE = 0x%x %f\n", size, size / 65536.0);
+ }
+
+ glPopMatrix();
+}
+
+
+/* new window size or exposure */
+static void
+reshape(int width, int height)
+{
+ GLfloat ar = (GLfloat) width / (GLfloat) height;
+
+ glViewport(0, 0, (GLint) width, (GLint) height);
+
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+#ifdef GL_VERSION_ES_CM_1_0
+ glFrustumf(-ar, ar, -1, 1, 5.0, 60.0);
+#else
+ glFrustum(-ar, ar, -1, 1, 5.0, 60.0);
+#endif
+
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ glTranslatef(0.0, 0.0, -10.0);
+}
+
+
+static void
+test_query_matrix(void)
+{
+ PFNGLQUERYMATRIXXOESPROC procQueryMatrixx;
+ typedef void (*voidproc)();
+ GLfixed mantissa[16];
+ GLint exponent[16];
+ GLbitfield rv;
+ int i;
+
+ procQueryMatrixx = (PFNGLQUERYMATRIXXOESPROC) eglGetProcAddress("glQueryMatrixxOES");
+ assert(procQueryMatrixx);
+ /* Actually try out this one */
+ rv = (*procQueryMatrixx)(mantissa, exponent);
+ for (i = 0; i < 16; i++) {
+ if (rv & (1<<i)) {
+ printf("matrix[%d] invalid\n", i);
+ }
+ else {
+ printf("matrix[%d] = %f * 2^(%d)\n", i, mantissa[i]/65536.0, exponent[i]);
+ }
+ }
+ assert(!eglGetProcAddress("glFoo"));
+}
+
+
+static void
+init(void)
+{
+ glClearColor(0.4, 0.4, 0.4, 0.0);
+
+ if (0)
+ test_query_matrix();
+}
+
+
+/*
+ * Create an RGB, double-buffered X window.
+ * Return the window and context handles.
+ */
+static void
+make_x_window(Display *x_dpy, EGLDisplay egl_dpy,
+ const char *name,
+ int x, int y, int width, int height,
+ Window *winRet,
+ EGLContext *ctxRet,
+ EGLSurface *surfRet)
+{
+ static const EGLint attribs[] = {
+ EGL_RED_SIZE, 1,
+ EGL_GREEN_SIZE, 1,
+ EGL_BLUE_SIZE, 1,
+ EGL_DEPTH_SIZE, 1,
+ EGL_NONE
+ };
+
+ int scrnum;
+ XSetWindowAttributes attr;
+ unsigned long mask;
+ Window root;
+ Window win;
+ XVisualInfo *visInfo, visTemplate;
+ int num_visuals;
+ EGLContext ctx;
+ EGLConfig config;
+ EGLint num_configs;
+ EGLint vid;
+
+ scrnum = DefaultScreen( x_dpy );
+ root = RootWindow( x_dpy, scrnum );
+
+ if (!eglChooseConfig( egl_dpy, attribs, &config, 1, &num_configs)) {
+ printf("Error: couldn't get an EGL visual config\n");
+ exit(1);
+ }
+
+ assert(config);
+ assert(num_configs > 0);
+
+ if (!eglGetConfigAttrib(egl_dpy, config, EGL_NATIVE_VISUAL_ID, &vid)) {
+ printf("Error: eglGetConfigAttrib() failed\n");
+ exit(1);
+ }
+
+ /* The X window visual must match the EGL config */
+ visTemplate.visualid = vid;
+ visInfo = XGetVisualInfo(x_dpy, VisualIDMask, &visTemplate, &num_visuals);
+ if (!visInfo) {
+ printf("Error: couldn't get X visual\n");
+ exit(1);
+ }
+
+ /* window attributes */
+ attr.background_pixel = 0;
+ attr.border_pixel = 0;
+ attr.colormap = XCreateColormap( x_dpy, root, visInfo->visual, AllocNone);
+ attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
+ mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
+
+ win = XCreateWindow( x_dpy, root, 0, 0, width, height,
+ 0, visInfo->depth, InputOutput,
+ visInfo->visual, mask, &attr );
+
+ /* set hints and properties */
+ {
+ XSizeHints sizehints;
+ sizehints.x = x;
+ sizehints.y = y;
+ sizehints.width = width;
+ sizehints.height = height;
+ sizehints.flags = USSize | USPosition;
+ XSetNormalHints(x_dpy, win, &sizehints);
+ XSetStandardProperties(x_dpy, win, name, name,
+ None, (char **)NULL, 0, &sizehints);
+ }
+
+#if USE_FULL_GL
+ eglBindAPI(EGL_OPENGL_API);
+#else
+ eglBindAPI(EGL_OPENGL_ES_API);
+#endif
+
+ ctx = eglCreateContext(egl_dpy, config, EGL_NO_CONTEXT, NULL );
+ if (!ctx) {
+ printf("Error: eglCreateContext failed\n");
+ exit(1);
+ }
+
+ *surfRet = eglCreateWindowSurface(egl_dpy, config, win, NULL);
+
+ if (!*surfRet) {
+ printf("Error: eglCreateWindowSurface failed\n");
+ exit(1);
+ }
+
+ XFree(visInfo);
+
+ *winRet = win;
+ *ctxRet = ctx;
+}
+
+
+static void
+event_loop(Display *dpy, Window win,
+ EGLDisplay egl_dpy, EGLSurface egl_surf)
+{
+ while (1) {
+ int redraw = 0;
+ XEvent event;
+
+ XNextEvent(dpy, &event);
+
+ switch (event.type) {
+ case Expose:
+ redraw = 1;
+ break;
+ case ConfigureNotify:
+ reshape(event.xconfigure.width, event.xconfigure.height);
+ break;
+ case KeyPress:
+ {
+ char buffer[10];
+ int r, code;
+ code = XLookupKeysym(&event.xkey, 0);
+ if (code == XK_Left) {
+ view_roty += 5.0;
+ }
+ else if (code == XK_Right) {
+ view_roty -= 5.0;
+ }
+ else if (code == XK_Up) {
+ view_rotx += 5.0;
+ }
+ else if (code == XK_Down) {
+ view_rotx -= 5.0;
+ }
+ else {
+ r = XLookupString(&event.xkey, buffer, sizeof(buffer),
+ NULL, NULL);
+ if (buffer[0] == 27) {
+ /* escape */
+ return;
+ }
+ }
+ }
+ redraw = 1;
+ break;
+ default:
+ ; /*no-op*/
+ }
+
+ if (redraw) {
+ draw();
+ eglSwapBuffers(egl_dpy, egl_surf);
+ }
+ }
+}
+
+
+static void
+usage(void)
+{
+ printf("Usage:\n");
+ printf(" -display <displayname> set the display to run on\n");
+ printf(" -info display OpenGL renderer info\n");
+}
+
+
+int
+main(int argc, char *argv[])
+{
+ const int winWidth = 300, winHeight = 300;
+ Display *x_dpy;
+ Window win;
+ EGLSurface egl_surf;
+ EGLContext egl_ctx;
+ EGLDisplay egl_dpy;
+ char *dpyName = NULL;
+ GLboolean printInfo = GL_FALSE;
+ EGLint egl_major, egl_minor;
+ int i;
+ const char *s;
+
+ static struct {
+ char *name;
+ GLenum value;
+ enum {GetString, GetInteger} type;
+ } info_items[] = {
+ {"GL_RENDERER", GL_RENDERER, GetString},
+ {"GL_VERSION", GL_VERSION, GetString},
+ {"GL_VENDOR", GL_VENDOR, GetString},
+ {"GL_EXTENSIONS", GL_EXTENSIONS, GetString},
+ {"GL_MAX_PALETTE_MATRICES_OES", GL_MAX_PALETTE_MATRICES_OES, GetInteger},
+ {"GL_MAX_VERTEX_UNITS_OES", GL_MAX_VERTEX_UNITS_OES, GetInteger},
+ };
+
+ for (i = 1; i < argc; i++) {
+ if (strcmp(argv[i], "-display") == 0) {
+ dpyName = argv[i+1];
+ i++;
+ }
+ else if (strcmp(argv[i], "-info") == 0) {
+ printInfo = GL_TRUE;
+ }
+ else {
+ usage();
+ return -1;
+ }
+ }
+
+ x_dpy = XOpenDisplay(dpyName);
+ if (!x_dpy) {
+ printf("Error: couldn't open display %s\n",
+ dpyName ? dpyName : getenv("DISPLAY"));
+ return -1;
+ }
+
+ egl_dpy = eglGetDisplay(x_dpy);
+ if (!egl_dpy) {
+ printf("Error: eglGetDisplay() failed\n");
+ return -1;
+ }
+
+ if (!eglInitialize(egl_dpy, &egl_major, &egl_minor)) {
+ printf("Error: eglInitialize() failed\n");
+ return -1;
+ }
+
+ s = eglQueryString(egl_dpy, EGL_VERSION);
+ printf("EGL_VERSION = %s\n", s);
+
+ s = eglQueryString(egl_dpy, EGL_VENDOR);
+ printf("EGL_VENDOR = %s\n", s);
+
+ s = eglQueryString(egl_dpy, EGL_EXTENSIONS);
+ printf("EGL_EXTENSIONS = %s\n", s);
+
+ s = eglQueryString(egl_dpy, EGL_CLIENT_APIS);
+ printf("EGL_CLIENT_APIS = %s\n", s);
+
+ make_x_window(x_dpy, egl_dpy,
+ "OpenGL ES 1.x tri", 0, 0, winWidth, winHeight,
+ &win, &egl_ctx, &egl_surf);
+
+ XMapWindow(x_dpy, win);
+ if (!eglMakeCurrent(egl_dpy, egl_surf, egl_surf, egl_ctx)) {
+ printf("Error: eglMakeCurrent() failed\n");
+ return -1;
+ }
+
+ if (printInfo) {
+ for (i = 0; i < sizeof(info_items)/sizeof(info_items[0]); i++) {
+ switch (info_items[i].type) {
+ case GetString:
+ printf("%s = %s\n", info_items[i].name, (char *)glGetString(info_items[i].value));
+ break;
+ case GetInteger: {
+ GLint rv = -1;
+ glGetIntegerv(info_items[i].value, &rv);
+ printf("%s = %d\n", info_items[i].name, rv);
+ break;
+ }
+ }
+ }
+ };
+ init();
+
+ /* Set initial projection/viewing transformation.
+ * We can't be sure we'll get a ConfigureNotify event when the window
+ * first appears.
+ */
+ reshape(winWidth, winHeight);
+
+ event_loop(x_dpy, win, egl_dpy, egl_surf);
+
+ eglDestroyContext(egl_dpy, egl_ctx);
+ eglDestroySurface(egl_dpy, egl_surf);
+ eglTerminate(egl_dpy);
+
+
+ XDestroyWindow(x_dpy, win);
+ XCloseDisplay(x_dpy);
+
+ return 0;
+}
diff --git a/progs/es1/xegl/two_win.c b/progs/es1/xegl/two_win.c
new file mode 100644
index 0000000000..4785e5304d
--- /dev/null
+++ b/progs/es1/xegl/two_win.c
@@ -0,0 +1,433 @@
+/*
+ * Copyright (C) 2008 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*
+ * Test drawing to two windows.
+ * Brian Paul
+ * August 2008
+ */
+
+
+#include <assert.h>
+#include <math.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/keysym.h>
+#include <GLES/gl.h>
+#include <GLES/glext.h>
+#include <EGL/egl.h>
+
+
+static int WinWidth[2] = {150, 300}, WinHeight[2] = {150, 300};
+
+
+static GLfloat view_rotx = 0.0, view_roty = 0.0, view_rotz = 0.0;
+
+
+/* new window size or exposure */
+static void
+reshape(int width, int height)
+{
+ GLfloat ar = (GLfloat) width / (GLfloat) height;
+
+ glViewport(0, 0, (GLint) width, (GLint) height);
+
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+#ifdef GL_VERSION_ES_CM_1_0
+ glFrustumf(-ar, ar, -1, 1, 5.0, 60.0);
+#else
+ glFrustum(-ar, ar, -1, 1, 5.0, 60.0);
+#endif
+
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ glTranslatef(0.0, 0.0, -10.0);
+}
+
+
+static void
+draw(int win)
+{
+ static const GLfloat verts[3][2] = {
+ { -1, -1 },
+ { 1, -1 },
+ { 0, 1 }
+ };
+ static const GLfloat colors[3][4] = {
+ { 1, 0, 0, 1 },
+ { 0, 1, 0, 1 },
+ { 0, 0, 1, 1 }
+ };
+
+ assert(win == 0 || win == 1);
+
+ reshape(WinWidth[win], WinHeight[win]);
+
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ glPushMatrix();
+ glRotatef(view_rotx, 1, 0, 0);
+ glRotatef(view_roty, 0, 1, 0);
+ glRotatef(view_rotz, 0, 0, 1);
+
+ /* draw triangle */
+ {
+ glVertexPointer(2, GL_FLOAT, 0, verts);
+ glColorPointer(4, GL_FLOAT, 0, colors);
+
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glEnableClientState(GL_COLOR_ARRAY);
+
+ glDrawArrays(GL_TRIANGLES, 0, 3);
+
+ glDisableClientState(GL_VERTEX_ARRAY);
+ glDisableClientState(GL_COLOR_ARRAY);
+ }
+
+ glPopMatrix();
+}
+
+
+static void
+init(void)
+{
+ glClearColor(0.4, 0.4, 0.4, 0.0);
+}
+
+
+/*
+ * Create an RGB, double-buffered X window.
+ * Return the window and context handles.
+ */
+static void
+make_x_window(Display *x_dpy, EGLDisplay egl_dpy,
+ const char *name,
+ int x, int y, int width, int height,
+ Window *winRet,
+ EGLContext *ctxRet,
+ EGLSurface *surfRet)
+{
+ static const EGLint attribs[] = {
+ EGL_RED_SIZE, 1,
+ EGL_GREEN_SIZE, 1,
+ EGL_BLUE_SIZE, 1,
+ EGL_DEPTH_SIZE, 1,
+ EGL_NONE
+ };
+
+ int scrnum;
+ XSetWindowAttributes attr;
+ unsigned long mask;
+ Window root;
+ Window win;
+ XVisualInfo *visInfo, visTemplate;
+ int num_visuals;
+ EGLContext ctx;
+ EGLConfig config;
+ EGLint num_configs;
+ EGLint vid;
+
+ scrnum = DefaultScreen( x_dpy );
+ root = RootWindow( x_dpy, scrnum );
+
+ if (!eglChooseConfig( egl_dpy, attribs, &config, 1, &num_configs)) {
+ printf("Error: couldn't get an EGL visual config\n");
+ exit(1);
+ }
+
+ assert(config);
+ assert(num_configs > 0);
+
+ if (!eglGetConfigAttrib(egl_dpy, config, EGL_NATIVE_VISUAL_ID, &vid)) {
+ printf("Error: eglGetConfigAttrib() failed\n");
+ exit(1);
+ }
+
+ /* The X window visual must match the EGL config */
+ visTemplate.visualid = vid;
+ visInfo = XGetVisualInfo(x_dpy, VisualIDMask, &visTemplate, &num_visuals);
+ if (!visInfo) {
+ printf("Error: couldn't get X visual\n");
+ exit(1);
+ }
+
+ /* window attributes */
+ attr.background_pixel = 0;
+ attr.border_pixel = 0;
+ attr.colormap = XCreateColormap( x_dpy, root, visInfo->visual, AllocNone);
+ attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
+ mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
+
+ win = XCreateWindow( x_dpy, root, x, y, width, height,
+ 0, visInfo->depth, InputOutput,
+ visInfo->visual, mask, &attr );
+
+ /* set hints and properties */
+ {
+ XSizeHints sizehints;
+ sizehints.x = x;
+ sizehints.y = y;
+ sizehints.width = width;
+ sizehints.height = height;
+ sizehints.flags = USSize | USPosition;
+ XSetNormalHints(x_dpy, win, &sizehints);
+ XSetStandardProperties(x_dpy, win, name, name,
+ None, (char **)NULL, 0, &sizehints);
+ }
+
+#if USE_FULL_GL
+ eglBindAPI(EGL_OPENGL_API);
+#else
+ eglBindAPI(EGL_OPENGL_ES_API);
+#endif
+
+ if (ctxRet) {
+ ctx = eglCreateContext(egl_dpy, config, EGL_NO_CONTEXT, NULL );
+ if (!ctx) {
+ printf("Error: eglCreateContext failed\n");
+ exit(1);
+ }
+ *ctxRet = ctx;
+ }
+
+ *surfRet = eglCreateWindowSurface(egl_dpy, config, win, NULL);
+
+ if (!*surfRet) {
+ printf("Error: eglCreateWindowSurface failed\n");
+ exit(1);
+ }
+
+ XFree(visInfo);
+
+ *winRet = win;
+}
+
+
+static void
+event_loop(Display *dpy, Window win1, Window win2,
+ EGLDisplay egl_dpy, EGLSurface egl_surf1, EGLSurface egl_surf2,
+ EGLContext egl_ctx)
+{
+ while (1) {
+ int redraw = 0;
+ int win;
+ XEvent event;
+
+ XNextEvent(dpy, &event);
+
+ switch (event.type) {
+ case Expose:
+ redraw = 1;
+ break;
+ case ConfigureNotify:
+ if (event.xconfigure.window == win1)
+ win = 0;
+ else
+ win = 1;
+ WinWidth[win] = event.xconfigure.width;
+ WinHeight[win] = event.xconfigure.height;
+ break;
+ case KeyPress:
+ {
+ char buffer[10];
+ int r, code;
+ code = XLookupKeysym(&event.xkey, 0);
+ if (code == XK_Left) {
+ view_roty += 5.0;
+ }
+ else if (code == XK_Right) {
+ view_roty -= 5.0;
+ }
+ else if (code == XK_Up) {
+ view_rotx += 5.0;
+ }
+ else if (code == XK_Down) {
+ view_rotx -= 5.0;
+ }
+ else {
+ r = XLookupString(&event.xkey, buffer, sizeof(buffer),
+ NULL, NULL);
+ if (buffer[0] == 27) {
+ /* escape */
+ return;
+ }
+ }
+ }
+ redraw = 1;
+ break;
+ default:
+ ; /*no-op*/
+ }
+
+ if (redraw) {
+ /* win 1 */
+ if (!eglMakeCurrent(egl_dpy, egl_surf1, egl_surf1, egl_ctx)) {
+ printf("Error: eglMakeCurrent(1) failed\n");
+ return;
+ }
+ draw(0);
+ eglSwapBuffers(egl_dpy, egl_surf1);
+
+ /* win 2 */
+ if (!eglMakeCurrent(egl_dpy, egl_surf2, egl_surf2, egl_ctx)) {
+ printf("Error: eglMakeCurrent(2) failed\n");
+ return;
+ }
+ draw(1);
+ eglSwapBuffers(egl_dpy, egl_surf2);
+ }
+ }
+}
+
+
+static void
+usage(void)
+{
+ printf("Usage:\n");
+ printf(" -display <displayname> set the display to run on\n");
+ printf(" -info display OpenGL renderer info\n");
+}
+
+
+int
+main(int argc, char *argv[])
+{
+ Display *x_dpy;
+ Window win1, win2;
+ EGLSurface egl_surf1, egl_surf2;
+ EGLContext egl_ctx;
+ EGLDisplay egl_dpy;
+ char *dpyName = NULL;
+ GLboolean printInfo = GL_FALSE;
+ EGLint egl_major, egl_minor;
+ int i;
+ const char *s;
+
+ static struct {
+ char *name;
+ GLenum value;
+ enum {GetString, GetInteger} type;
+ } info_items[] = {
+ {"GL_RENDERER", GL_RENDERER, GetString},
+ {"GL_VERSION", GL_VERSION, GetString},
+ {"GL_VENDOR", GL_VENDOR, GetString},
+ {"GL_EXTENSIONS", GL_EXTENSIONS, GetString},
+ {"GL_MAX_PALETTE_MATRICES_OES", GL_MAX_PALETTE_MATRICES_OES, GetInteger},
+ {"GL_MAX_VERTEX_UNITS_OES", GL_MAX_VERTEX_UNITS_OES, GetInteger},
+ };
+
+ for (i = 1; i < argc; i++) {
+ if (strcmp(argv[i], "-display") == 0) {
+ dpyName = argv[i+1];
+ i++;
+ }
+ else if (strcmp(argv[i], "-info") == 0) {
+ printInfo = GL_TRUE;
+ }
+ else {
+ usage();
+ return -1;
+ }
+ }
+
+ x_dpy = XOpenDisplay(dpyName);
+ if (!x_dpy) {
+ printf("Error: couldn't open display %s\n",
+ dpyName ? dpyName : getenv("DISPLAY"));
+ return -1;
+ }
+
+ egl_dpy = eglGetDisplay(x_dpy);
+ if (!egl_dpy) {
+ printf("Error: eglGetDisplay() failed\n");
+ return -1;
+ }
+
+ if (!eglInitialize(egl_dpy, &egl_major, &egl_minor)) {
+ printf("Error: eglInitialize() failed\n");
+ return -1;
+ }
+
+ s = eglQueryString(egl_dpy, EGL_VERSION);
+ printf("EGL_VERSION = %s\n", s);
+
+ s = eglQueryString(egl_dpy, EGL_VENDOR);
+ printf("EGL_VENDOR = %s\n", s);
+
+ s = eglQueryString(egl_dpy, EGL_EXTENSIONS);
+ printf("EGL_EXTENSIONS = %s\n", s);
+
+ s = eglQueryString(egl_dpy, EGL_CLIENT_APIS);
+ printf("EGL_CLIENT_APIS = %s\n", s);
+
+ make_x_window(x_dpy, egl_dpy,
+ "xegl_two_win #1", 0, 0, WinWidth[0], WinHeight[0],
+ &win1, &egl_ctx, &egl_surf1);
+
+ make_x_window(x_dpy, egl_dpy,
+ "xegl_two_win #2", WinWidth[0] + 50, 0,
+ WinWidth[1], WinHeight[1],
+ &win2, NULL, &egl_surf2);
+
+ XMapWindow(x_dpy, win1);
+
+ XMapWindow(x_dpy, win2);
+
+ if (!eglMakeCurrent(egl_dpy, egl_surf1, egl_surf1, egl_ctx)) {
+ printf("Error: eglMakeCurrent() failed\n");
+ return -1;
+ }
+
+ if (printInfo) {
+ for (i = 0; i < sizeof(info_items)/sizeof(info_items[0]); i++) {
+ switch (info_items[i].type) {
+ case GetString:
+ printf("%s = %s\n", info_items[i].name, (char *)glGetString(info_items[i].value));
+ break;
+ case GetInteger: {
+ GLint rv = -1;
+ glGetIntegerv(info_items[i].value, &rv);
+ printf("%s = %d\n", info_items[i].name, rv);
+ break;
+ }
+ }
+ }
+ };
+
+ init();
+
+ event_loop(x_dpy, win1, win2, egl_dpy, egl_surf1, egl_surf2, egl_ctx);
+
+ eglDestroyContext(egl_dpy, egl_ctx);
+ eglDestroySurface(egl_dpy, egl_surf1);
+ eglDestroySurface(egl_dpy, egl_surf2);
+ eglTerminate(egl_dpy);
+
+ XDestroyWindow(x_dpy, win1);
+ XDestroyWindow(x_dpy, win2);
+ XCloseDisplay(x_dpy);
+
+ return 0;
+}
diff --git a/progs/es2/.gitignore b/progs/es2/.gitignore
new file mode 100644
index 0000000000..7d5c16936c
--- /dev/null
+++ b/progs/es2/.gitignore
@@ -0,0 +1,3 @@
+xegl/es2_info.c
+xegl/es2_info
+xegl/tri
diff --git a/progs/es2/xegl/Makefile b/progs/es2/xegl/Makefile
new file mode 100644
index 0000000000..5bb167c1c6
--- /dev/null
+++ b/progs/es2/xegl/Makefile
@@ -0,0 +1,51 @@
+# progs/es2/xegl/Makefile
+
+TOP = ../../..
+include $(TOP)/configs/current
+
+
+INCLUDE_DIRS = \
+ -I$(TOP)/include \
+
+HEADERS = $(TOP)/include/GLES/egl.h
+
+
+ES2_LIB_DEPS = \
+ $(TOP)/$(LIB_DIR)/libEGL.so \
+ $(TOP)/$(LIB_DIR)/libGLESv2.so
+
+
+ES2_LIBS = \
+ -L$(TOP)/$(LIB_DIR) -lEGL \
+ -L$(TOP)/$(LIB_DIR) -lGLESv2 $(LIBDRM_LIB) -lX11
+
+PROGRAMS = \
+ es2_info \
+ tri
+
+
+.c.o:
+ $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $< -o $@
+
+
+
+default: $(PROGRAMS)
+
+
+
+es2_info.c: ../../es1/xegl/es1_info.c
+ cp -f $^ $@
+
+es2_info: es2_info.o $(ES2_LIB_DEPS)
+ $(CC) $(CFLAGS) es2_info.o $(ES2_LIBS) -o $@
+
+tri: tri.o $(ES2_LIB_DEPS)
+ $(CC) $(CFLAGS) tri.o $(ES2_LIBS) -o $@
+
+
+
+clean:
+ rm -f *.o *~
+ rm -f $(PROGRAMS)
+ rm -f es2_info.c
+
diff --git a/progs/es2/xegl/tri.c b/progs/es2/xegl/tri.c
new file mode 100644
index 0000000000..7729a09957
--- /dev/null
+++ b/progs/es2/xegl/tri.c
@@ -0,0 +1,515 @@
+/**************************************************************************
+ *
+ * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ **************************************************************************/
+
+/*
+ * Draw a triangle with X/EGL and OpenGL ES 2.x
+ */
+
+#define USE_FULL_GL 0
+
+
+
+#include <assert.h>
+#include <math.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/keysym.h>
+#if USE_FULL_GL
+#include <GL/gl.h> /* use full OpenGL */
+#else
+#include <GLES2/gl2.h> /* use OpenGL ES 2.x */
+#endif
+#include <EGL/egl.h>
+
+
+#define FLOAT_TO_FIXED(X) ((X) * 65535.0)
+
+
+
+static GLfloat view_rotx = 0.0, view_roty = 0.0;
+
+static GLint u_matrix = -1;
+static GLint attr_pos = 0, attr_color = 1;
+
+
+static void
+make_z_rot_matrix(GLfloat angle, GLfloat *m)
+{
+ float c = cos(angle * M_PI / 180.0);
+ float s = sin(angle * M_PI / 180.0);
+ int i;
+ for (i = 0; i < 16; i++)
+ m[i] = 0.0;
+ m[0] = m[5] = m[10] = m[15] = 1.0;
+
+ m[0] = c;
+ m[1] = s;
+ m[4] = -s;
+ m[5] = c;
+}
+
+static void
+make_scale_matrix(GLfloat xs, GLfloat ys, GLfloat zs, GLfloat *m)
+{
+ int i;
+ for (i = 0; i < 16; i++)
+ m[i] = 0.0;
+ m[0] = xs;
+ m[5] = ys;
+ m[10] = zs;
+ m[15] = 1.0;
+}
+
+
+static void
+mul_matrix(GLfloat *prod, const GLfloat *a, const GLfloat *b)
+{
+#define A(row,col) a[(col<<2)+row]
+#define B(row,col) b[(col<<2)+row]
+#define P(row,col) p[(col<<2)+row]
+ GLfloat p[16];
+ GLint i;
+ for (i = 0; i < 4; i++) {
+ const GLfloat ai0=A(i,0), ai1=A(i,1), ai2=A(i,2), ai3=A(i,3);
+ P(i,0) = ai0 * B(0,0) + ai1 * B(1,0) + ai2 * B(2,0) + ai3 * B(3,0);
+ P(i,1) = ai0 * B(0,1) + ai1 * B(1,1) + ai2 * B(2,1) + ai3 * B(3,1);
+ P(i,2) = ai0 * B(0,2) + ai1 * B(1,2) + ai2 * B(2,2) + ai3 * B(3,2);
+ P(i,3) = ai0 * B(0,3) + ai1 * B(1,3) + ai2 * B(2,3) + ai3 * B(3,3);
+ }
+ memcpy(prod, p, sizeof(p));
+#undef A
+#undef B
+#undef PROD
+}
+
+
+static void
+draw(void)
+{
+ static const GLfloat verts[3][2] = {
+ { -1, -1 },
+ { 1, -1 },
+ { 0, 1 }
+ };
+ static const GLfloat colors[3][3] = {
+ { 1, 0, 0 },
+ { 0, 1, 0 },
+ { 0, 0, 1 }
+ };
+ GLfloat mat[16], rot[16], scale[16];
+
+ /* Set modelview/projection matrix */
+ make_z_rot_matrix(view_rotx, rot);
+ make_scale_matrix(0.5, 0.5, 0.5, scale);
+ mul_matrix(mat, rot, scale);
+ glUniformMatrix4fv(u_matrix, 1, GL_FALSE, mat);
+
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ {
+ glVertexAttribPointer(attr_pos, 2, GL_FLOAT, GL_FALSE, 0, verts);
+ glVertexAttribPointer(attr_color, 3, GL_FLOAT, GL_FALSE, 0, colors);
+ glEnableVertexAttribArray(attr_pos);
+ glEnableVertexAttribArray(attr_color);
+
+ glDrawArrays(GL_TRIANGLES, 0, 3);
+
+ glDisableVertexAttribArray(attr_pos);
+ glDisableVertexAttribArray(attr_color);
+ }
+}
+
+
+/* new window size or exposure */
+static void
+reshape(int width, int height)
+{
+ glViewport(0, 0, (GLint) width, (GLint) height);
+}
+
+
+static void
+create_shaders(void)
+{
+ static const char *fragShaderText =
+ "varying vec4 v_color;\n"
+ "void main() {\n"
+ " gl_FragColor = v_color;\n"
+ "}\n";
+ static const char *vertShaderText =
+ "uniform mat4 modelviewProjection;\n"
+ "attribute vec4 pos;\n"
+ "attribute vec4 color;\n"
+ "varying vec4 v_color;\n"
+ "void main() {\n"
+ " gl_Position = modelviewProjection * pos;\n"
+ " v_color = color;\n"
+ "}\n";
+
+ GLuint fragShader, vertShader, program;
+ GLint stat;
+
+ fragShader = glCreateShader(GL_FRAGMENT_SHADER);
+ glShaderSource(fragShader, 1, (const char **) &fragShaderText, NULL);
+ glCompileShader(fragShader);
+ glGetShaderiv(fragShader, GL_COMPILE_STATUS, &stat);
+ if (!stat) {
+ printf("Error: fragment shader did not compile!\n");
+ exit(1);
+ }
+
+ vertShader = glCreateShader(GL_VERTEX_SHADER);
+ glShaderSource(vertShader, 1, (const char **) &vertShaderText, NULL);
+ glCompileShader(vertShader);
+ glGetShaderiv(vertShader, GL_COMPILE_STATUS, &stat);
+ if (!stat) {
+ printf("Error: vertex shader did not compile!\n");
+ exit(1);
+ }
+
+ program = glCreateProgram();
+ glAttachShader(program, fragShader);
+ glAttachShader(program, vertShader);
+ glLinkProgram(program);
+
+ glGetProgramiv(program, GL_LINK_STATUS, &stat);
+ if (!stat) {
+ char log[1000];
+ GLsizei len;
+ glGetProgramInfoLog(program, 1000, &len, log);
+ printf("Error: linking:\n%s\n", log);
+ exit(1);
+ }
+
+ glUseProgram(program);
+
+ if (1) {
+ /* test setting attrib locations */
+ glBindAttribLocation(program, attr_pos, "pos");
+ glBindAttribLocation(program, attr_color, "color");
+ glLinkProgram(program); /* needed to put attribs into effect */
+ }
+ else {
+ /* test automatic attrib locations */
+ attr_pos = glGetAttribLocation(program, "pos");
+ attr_color = glGetAttribLocation(program, "color");
+ }
+
+ u_matrix = glGetUniformLocation(program, "modelviewProjection");
+ printf("Uniform modelviewProjection at %d\n", u_matrix);
+ printf("Attrib pos at %d\n", attr_pos);
+ printf("Attrib color at %d\n", attr_color);
+}
+
+
+static void
+init(void)
+{
+ typedef void (*proc)();
+
+#if 1 /* test code */
+ proc p = eglGetProcAddress("glMapBufferOES");
+ assert(p);
+#endif
+
+ glClearColor(0.4, 0.4, 0.4, 0.0);
+
+ create_shaders();
+}
+
+
+/*
+ * Create an RGB, double-buffered X window.
+ * Return the window and context handles.
+ */
+static void
+make_x_window(Display *x_dpy, EGLDisplay egl_dpy,
+ const char *name,
+ int x, int y, int width, int height,
+ Window *winRet,
+ EGLContext *ctxRet,
+ EGLSurface *surfRet)
+{
+ static const EGLint attribs[] = {
+ EGL_RED_SIZE, 1,
+ EGL_GREEN_SIZE, 1,
+ EGL_BLUE_SIZE, 1,
+ EGL_DEPTH_SIZE, 1,
+ EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
+ EGL_NONE
+ };
+ static const EGLint ctx_attribs[] = {
+ EGL_CONTEXT_CLIENT_VERSION, 2,
+ EGL_NONE
+ };
+ int scrnum;
+ XSetWindowAttributes attr;
+ unsigned long mask;
+ Window root;
+ Window win;
+ XVisualInfo *visInfo, visTemplate;
+ int num_visuals;
+ EGLContext ctx;
+ EGLConfig config;
+ EGLint num_configs;
+ EGLint vid;
+
+ scrnum = DefaultScreen( x_dpy );
+ root = RootWindow( x_dpy, scrnum );
+
+ if (!eglChooseConfig( egl_dpy, attribs, &config, 1, &num_configs)) {
+ printf("Error: couldn't get an EGL visual config\n");
+ exit(1);
+ }
+
+ assert(config);
+ assert(num_configs > 0);
+
+ if (!eglGetConfigAttrib(egl_dpy, config, EGL_NATIVE_VISUAL_ID, &vid)) {
+ printf("Error: eglGetConfigAttrib() failed\n");
+ exit(1);
+ }
+
+ /* The X window visual must match the EGL config */
+ visTemplate.visualid = vid;
+ visInfo = XGetVisualInfo(x_dpy, VisualIDMask, &visTemplate, &num_visuals);
+ if (!visInfo) {
+ printf("Error: couldn't get X visual\n");
+ exit(1);
+ }
+
+ /* window attributes */
+ attr.background_pixel = 0;
+ attr.border_pixel = 0;
+ attr.colormap = XCreateColormap( x_dpy, root, visInfo->visual, AllocNone);
+ attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
+ mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
+
+ win = XCreateWindow( x_dpy, root, 0, 0, width, height,
+ 0, visInfo->depth, InputOutput,
+ visInfo->visual, mask, &attr );
+
+ /* set hints and properties */
+ {
+ XSizeHints sizehints;
+ sizehints.x = x;
+ sizehints.y = y;
+ sizehints.width = width;
+ sizehints.height = height;
+ sizehints.flags = USSize | USPosition;
+ XSetNormalHints(x_dpy, win, &sizehints);
+ XSetStandardProperties(x_dpy, win, name, name,
+ None, (char **)NULL, 0, &sizehints);
+ }
+
+#if USE_FULL_GL /* XXX fix this when eglBindAPI() works */
+ eglBindAPI(EGL_OPENGL_API);
+#else
+ eglBindAPI(EGL_OPENGL_ES_API);
+#endif
+
+ ctx = eglCreateContext(egl_dpy, config, EGL_NO_CONTEXT, ctx_attribs );
+ if (!ctx) {
+ printf("Error: eglCreateContext failed\n");
+ exit(1);
+ }
+
+ /* test eglQueryContext() */
+ {
+ EGLint val;
+ eglQueryContext(egl_dpy, ctx, EGL_CONTEXT_CLIENT_VERSION, &val);
+ assert(val == 2);
+ }
+
+ *surfRet = eglCreateWindowSurface(egl_dpy, config, win, NULL);
+ if (!*surfRet) {
+ printf("Error: eglCreateWindowSurface failed\n");
+ exit(1);
+ }
+
+ {
+ EGLint val;
+ eglQuerySurface(egl_dpy, *surfRet, EGL_WIDTH, &val);
+ assert(val == width);
+ eglQuerySurface(egl_dpy, *surfRet, EGL_HEIGHT, &val);
+ assert(val == height);
+ eglQuerySurface(egl_dpy, *surfRet, EGL_SURFACE_TYPE, &val);
+ assert(val == EGL_WINDOW_BIT);
+ }
+
+ XFree(visInfo);
+
+ *winRet = win;
+ *ctxRet = ctx;
+}
+
+
+static void
+event_loop(Display *dpy, Window win,
+ EGLDisplay egl_dpy, EGLSurface egl_surf)
+{
+ while (1) {
+ int redraw = 0;
+ XEvent event;
+
+ XNextEvent(dpy, &event);
+
+ switch (event.type) {
+ case Expose:
+ redraw = 1;
+ break;
+ case ConfigureNotify:
+ reshape(event.xconfigure.width, event.xconfigure.height);
+ break;
+ case KeyPress:
+ {
+ char buffer[10];
+ int r, code;
+ code = XLookupKeysym(&event.xkey, 0);
+ if (code == XK_Left) {
+ view_roty += 5.0;
+ }
+ else if (code == XK_Right) {
+ view_roty -= 5.0;
+ }
+ else if (code == XK_Up) {
+ view_rotx += 5.0;
+ }
+ else if (code == XK_Down) {
+ view_rotx -= 5.0;
+ }
+ else {
+ r = XLookupString(&event.xkey, buffer, sizeof(buffer),
+ NULL, NULL);
+ if (buffer[0] == 27) {
+ /* escape */
+ return;
+ }
+ }
+ }
+ redraw = 1;
+ break;
+ default:
+ ; /*no-op*/
+ }
+
+ if (redraw) {
+ draw();
+ eglSwapBuffers(egl_dpy, egl_surf);
+ }
+ }
+}
+
+
+static void
+usage(void)
+{
+ printf("Usage:\n");
+ printf(" -display <displayname> set the display to run on\n");
+ printf(" -info display OpenGL renderer info\n");
+}
+
+
+int
+main(int argc, char *argv[])
+{
+ const int winWidth = 300, winHeight = 300;
+ Display *x_dpy;
+ Window win;
+ EGLSurface egl_surf;
+ EGLContext egl_ctx;
+ EGLDisplay egl_dpy;
+ char *dpyName = NULL;
+ GLboolean printInfo = GL_FALSE;
+ EGLint egl_major, egl_minor;
+ int i;
+ const char *s;
+
+ for (i = 1; i < argc; i++) {
+ if (strcmp(argv[i], "-display") == 0) {
+ dpyName = argv[i+1];
+ i++;
+ }
+ else if (strcmp(argv[i], "-info") == 0) {
+ printInfo = GL_TRUE;
+ }
+ else {
+ usage();
+ return -1;
+ }
+ }
+
+ x_dpy = XOpenDisplay(dpyName);
+ if (!x_dpy) {
+ printf("Error: couldn't open display %s\n",
+ dpyName ? dpyName : getenv("DISPLAY"));
+ return -1;
+ }
+
+ egl_dpy = eglGetDisplay(x_dpy);
+ if (!egl_dpy) {
+ printf("Error: eglGetDisplay() failed\n");
+ return -1;
+ }
+
+ if (!eglInitialize(egl_dpy, &egl_major, &egl_minor)) {
+ printf("Error: eglInitialize() failed\n");
+ return -1;
+ }
+
+ s = eglQueryString(egl_dpy, EGL_VERSION);
+ printf("EGL_VERSION = %s\n", s);
+
+ s = eglQueryString(egl_dpy, EGL_VENDOR);
+ printf("EGL_VENDOR = %s\n", s);
+
+ s = eglQueryString(egl_dpy, EGL_EXTENSIONS);
+ printf("EGL_EXTENSIONS = %s\n", s);
+
+ s = eglQueryString(egl_dpy, EGL_CLIENT_APIS);
+ printf("EGL_CLIENT_APIS = %s\n", s);
+
+ make_x_window(x_dpy, egl_dpy,
+ "OpenGL ES 2.x tri", 0, 0, winWidth, winHeight,
+ &win, &egl_ctx, &egl_surf);
+
+ XMapWindow(x_dpy, win);
+ if (!eglMakeCurrent(egl_dpy, egl_surf, egl_surf, egl_ctx)) {
+ printf("Error: eglMakeCurrent() failed\n");
+ return -1;
+ }
+
+ if (printInfo) {
+ printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
+ printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
+ printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR));
+ printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS));
+ }
+
+ init();
+
+ /* Set initial projection/viewing transformation.
+ * We can't be sure we'll get a ConfigureNotify event when the window
+ * first appears.
+ */
+ reshape(winWidth, winHeight);
+
+ event_loop(x_dpy, win, egl_dpy, egl_surf);
+
+ eglDestroyContext(egl_dpy, egl_ctx);
+ eglDestroySurface(egl_dpy, egl_surf);
+ eglTerminate(egl_dpy);
+
+
+ XDestroyWindow(x_dpy, win);
+ XCloseDisplay(x_dpy);
+
+ return 0;
+}
diff --git a/progs/fp/SConscript b/progs/fp/SConscript
index 69614e1a9e..e209161f32 100644
--- a/progs/fp/SConscript
+++ b/progs/fp/SConscript
@@ -1,15 +1,4 @@
-Import('env')
-
-if not env['GLUT']:
- Return()
-
-env = env.Clone()
-
-env.Prepend(CPPPATH = [
- '../util',
-])
-
-env.Prepend(LIBS = ['$GLUT_LIB'])
+Import('*')
progs = [
'fp-tri',
@@ -23,7 +12,7 @@ progs = [
]
for prog in progs:
- env.Program(
+ progs_env.Program(
target = prog,
source = [prog + '.c'],
)
diff --git a/progs/fp/fp-tri.c b/progs/fp/fp-tri.c
index 26af66ad84..70676d4c40 100644
--- a/progs/fp/fp-tri.c
+++ b/progs/fp/fp-tri.c
@@ -73,7 +73,7 @@ static void Init( void )
GLuint Texture;
GLint errno;
GLuint prognum;
- char buf[4096];
+ char buf[50000];
GLuint sz;
FILE *f;
@@ -176,6 +176,17 @@ static void Init( void )
}
+ {
+ const float Ambient[4] = { 0.0, 1.0, 0.0, 0.0 };
+ const float Diffuse[4] = { 1.0, 0.0, 0.0, 0.0 };
+ const float Specular[4] = { 0.0, 0.0, 1.0, 0.0 };
+ const float Emission[4] = { 0.0, 0.0, 0.0, 1.0 };
+ glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, Ambient);
+ glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, Diffuse);
+ glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, Specular);
+ glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, Emission);
+ }
+
glClearColor(.1, .3, .5, 0);
}
diff --git a/progs/fp/mov-imm.txt b/progs/fp/mov-imm.txt
new file mode 100644
index 0000000000..38e48079d0
--- /dev/null
+++ b/progs/fp/mov-imm.txt
@@ -0,0 +1,3 @@
+!!ARBfp1.0
+MOV result.color, {0.5, 0.8, 0.3, 1.0};
+END
diff --git a/progs/fp/mov-param.txt b/progs/fp/mov-param.txt
new file mode 100644
index 0000000000..13d82fe00b
--- /dev/null
+++ b/progs/fp/mov-param.txt
@@ -0,0 +1,4 @@
+!!ARBfp1.0
+PARAM Diffuse = state.material.diffuse;
+MOV result.color, Diffuse;
+END
diff --git a/progs/fp/position-frc-integer.txt b/progs/fp/position-frc-integer.txt
new file mode 100644
index 0000000000..3a634c9b3b
--- /dev/null
+++ b/progs/fp/position-frc-integer.txt
@@ -0,0 +1,7 @@
+!!ARBfp1.0
+# expected: black triangle
+# brown means the wrong pixel center convention is being used
+OPTION ARB_fragment_coord_pixel_center_integer;
+MOV result.color, {0}.x;
+FRC result.color.xy, fragment.position;
+END
diff --git a/progs/fp/position-frc.txt b/progs/fp/position-frc.txt
new file mode 100644
index 0000000000..35ae3efa10
--- /dev/null
+++ b/progs/fp/position-frc.txt
@@ -0,0 +1,6 @@
+!!ARBfp1.0
+# expected: brown triangle
+# black means the wrong pixel center convention is being used
+MOV result.color, {0}.x;
+FRC result.color.xy, fragment.position;
+END
diff --git a/progs/fp/position-upper-left.txt b/progs/fp/position-upper-left.txt
new file mode 100644
index 0000000000..ac632dbfb7
--- /dev/null
+++ b/progs/fp/position-upper-left.txt
@@ -0,0 +1,7 @@
+!!ARBfp1.0
+# expected: the yellow vertex is the bottom one
+# if it is the top one, the wrong origin convention is being used
+OPTION ARB_fragment_coord_origin_upper_left;
+MOV result.color, {0}.x;
+MUL result.color.xy, fragment.position, {.005}.x;
+END
diff --git a/progs/fp/position.txt b/progs/fp/position.txt
index 1875897d78..f59d0259c7 100644
--- a/progs/fp/position.txt
+++ b/progs/fp/position.txt
@@ -1,4 +1,6 @@
!!ARBfp1.0
+# expected: the yellow vertex is the top one
+# if it is the bottom one, the wrong origin convention is being used
MOV result.color, {0}.x;
MUL result.color.xy, fragment.position, {.005}.x;
END
diff --git a/progs/glsl/CH11-bumpmaptex.frag b/progs/glsl/CH11-bumpmaptex.frag
new file mode 100644
index 0000000000..b1f93b784d
--- /dev/null
+++ b/progs/glsl/CH11-bumpmaptex.frag
@@ -0,0 +1,47 @@
+//
+// Fragment shader for procedural bumps
+//
+// Authors: John Kessenich, Randi Rost
+//
+// Copyright (c) 2002-2006 3Dlabs Inc. Ltd.
+//
+// See 3Dlabs-License.txt for license information
+//
+// Texture mapping/modulation added by Brian Paul
+//
+
+varying vec3 LightDir;
+varying vec3 EyeDir;
+
+uniform float BumpDensity; // = 16.0
+uniform float BumpSize; // = 0.15
+uniform float SpecularFactor; // = 0.5
+
+sampler2D Tex;
+
+void main()
+{
+ vec3 ambient = vec3(0.25);
+ vec3 litColor;
+ vec2 c = BumpDensity * gl_TexCoord[0].st;
+ vec2 p = fract(c) - vec2(0.5);
+
+ float d, f;
+ d = p.x * p.x + p.y * p.y;
+ f = inversesqrt(d + 1.0);
+
+ if (d >= BumpSize)
+ { p = vec2(0.0); f = 1.0; }
+
+ vec3 SurfaceColor = texture2D(Tex, gl_TexCoord[0].st).xyz;
+
+ vec3 normDelta = vec3(p.x, p.y, 1.0) * f;
+ litColor = SurfaceColor * (ambient + max(dot(normDelta, LightDir), 0.0));
+ vec3 reflectDir = reflect(LightDir, normDelta);
+
+ float spec = max(dot(EyeDir, reflectDir), 0.0);
+ spec *= SpecularFactor;
+ litColor = min(litColor + spec, vec3(1.0));
+
+ gl_FragColor = vec4(litColor, 1.0);
+}
diff --git a/progs/glsl/SConscript b/progs/glsl/SConscript
index 7a4549cd70..8f2ebcf69c 100644
--- a/progs/glsl/SConscript
+++ b/progs/glsl/SConscript
@@ -1,23 +1,5 @@
Import('*')
-if not env['GLUT']:
- Return()
-
-env = env.Clone()
-
-env.Prepend(CPPPATH = [
- '../util',
-])
-
-env.Prepend(LIBS = [
- util,
- '$GLUT_LIB'
-])
-
-if env['platform'] == 'windows':
- env.Append(CPPDEFINES = ['NOMINMAX'])
- env.Prepend(LIBS = ['winmm'])
-
progs = [
'array',
'bitmap',
@@ -48,7 +30,7 @@ progs = [
]
for prog in progs:
- env.Program(
+ progs_env.Program(
target = prog,
source = prog + '.c',
)
diff --git a/progs/glsl/bump.c b/progs/glsl/bump.c
index 50a0900f1c..e31afab939 100644
--- a/progs/glsl/bump.c
+++ b/progs/glsl/bump.c
@@ -12,15 +12,20 @@
#include <GL/glew.h>
#include <GL/glut.h>
#include "shaderutil.h"
+#include "readtex.h"
static char *FragProgFile = "CH11-bumpmap.frag";
+static char *FragTexProgFile = "CH11-bumpmaptex.frag";
static char *VertProgFile = "CH11-bumpmap.vert";
+static char *TextureFile = "../images/tile.rgb";
/* program/shader objects */
static GLuint fragShader;
+static GLuint fragTexShader;
static GLuint vertShader;
static GLuint program;
+static GLuint texProgram;
static struct uniform_info Uniforms[] = {
@@ -32,13 +37,26 @@ static struct uniform_info Uniforms[] = {
END_OF_UNIFORMS
};
+static struct uniform_info TexUniforms[] = {
+ { "LightPosition", 1, GL_FLOAT_VEC3, { 0.57737, 0.57735, 0.57735, 0.0 }, -1 },
+ { "Tex", 1, GL_INT, { 0, 0, 0, 0 }, -1 },
+ { "BumpDensity", 1, GL_FLOAT, { 10.0, 0, 0, 0 }, -1 },
+ { "BumpSize", 1, GL_FLOAT, { 0.125, 0, 0, 0 }, -1 },
+ { "SpecularFactor", 1, GL_FLOAT, { 0.5, 0, 0, 0 }, -1 },
+ END_OF_UNIFORMS
+};
+
static GLint win = 0;
static GLfloat xRot = 20.0f, yRot = 0.0f, zRot = 0.0f;
static GLint tangentAttrib;
+static GLint tangentAttribTex;
+
+static GLuint Texture;
static GLboolean Anim = GL_FALSE;
+static GLboolean Textured = GL_FALSE;
static void
@@ -135,6 +153,11 @@ Redisplay(void)
glRotatef(yRot, 0.0f, 1.0f, 0.0f);
glRotatef(zRot, 0.0f, 0.0f, 1.0f);
+ if (Textured)
+ glUseProgram(texProgram);
+ else
+ glUseProgram(program);
+
Cube(1.5);
glPopMatrix();
@@ -163,8 +186,10 @@ static void
CleanUp(void)
{
glDeleteShader(fragShader);
+ glDeleteShader(fragTexShader);
glDeleteShader(vertShader);
glDeleteProgram(program);
+ glDeleteProgram(texProgram);
glutDestroyWindow(win);
}
@@ -181,6 +206,9 @@ Key(unsigned char key, int x, int y)
Anim = !Anim;
glutIdleFunc(Anim ? Idle : NULL);
break;
+ case 't':
+ Textured = !Textured;
+ break;
case 'z':
zRot += step;
break;
@@ -254,6 +282,26 @@ Init(void)
CheckError(__LINE__);
+
+ /*
+ * As above, but fragment shader also uses a texture map.
+ */
+ fragTexShader = CompileShaderFile(GL_FRAGMENT_SHADER, FragTexProgFile);
+ texProgram = LinkShaders(vertShader, fragTexShader);
+ glUseProgram(texProgram);
+ assert(glIsProgram(texProgram));
+ assert(glIsShader(fragTexShader));
+ SetUniformValues(texProgram, TexUniforms);
+ PrintUniforms(TexUniforms);
+
+ /*
+ * Load tex image.
+ */
+ glGenTextures(1, &Texture);
+ glBindTexture(GL_TEXTURE_2D, Texture);
+ LoadRGBMipmaps(TextureFile, GL_RGB);
+
+
glClearColor(0.4f, 0.4f, 0.8f, 0.0f);
glEnable(GL_DEPTH_TEST);
@@ -268,10 +316,13 @@ ParseOptions(int argc, char *argv[])
int i;
for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "-fs") == 0) {
- FragProgFile = argv[i+1];
+ FragProgFile = argv[++i];
}
else if (strcmp(argv[i], "-vs") == 0) {
- VertProgFile = argv[i+1];
+ VertProgFile = argv[++i];
+ }
+ else if (strcmp(argv[i], "-t") == 0) {
+ TextureFile = argv[++i];
}
}
}
diff --git a/progs/glsl/deriv.c b/progs/glsl/deriv.c
index 30f2b75fef..588246b71a 100644
--- a/progs/glsl/deriv.c
+++ b/progs/glsl/deriv.c
@@ -27,11 +27,15 @@ static GLuint SphereList, RectList, CurList;
static GLint win = 0;
static GLboolean anim = GL_TRUE;
static GLfloat xRot = 0.0f, yRot = 0.0f;
+static GLint WinSize[2];
+static GLint WinSizeUniform = -1;
static void
Redisplay(void)
{
+ glUniform2iv(WinSizeUniform, 1, WinSize);
+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
@@ -55,6 +59,8 @@ Idle(void)
static void
Reshape(int width, int height)
{
+ WinSize[0] = width;
+ WinSize[1] = height;
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
@@ -163,8 +169,10 @@ static void
Init(void)
{
static const char *fragShaderText =
+ "uniform ivec2 WinSize; \n"
"void main() {\n"
- " gl_FragColor = abs(dFdy(gl_TexCoord[0])) * 50.0;\n"
+ " vec2 d = dFdy(gl_TexCoord[0].xy) * vec2(WinSize); \n"
+ " gl_FragColor = vec4(d.x, d.y, 0.0, 1.0);\n"
" // gl_FragColor = gl_TexCoord[0];\n"
"}\n";
static const char *vertShaderText =
@@ -181,6 +189,7 @@ Init(void)
program = LinkShaders(vertShader, fragShader);
glUseProgram(program);
+ WinSizeUniform = glGetUniformLocation(program, "WinSize");
/*assert(glGetError() == 0);*/
@@ -220,8 +229,10 @@ ParseOptions(int argc, char *argv[])
int
main(int argc, char *argv[])
{
+ WinSize[0] = WinSize[1] = 200;
+
glutInit(&argc, argv);
- glutInitWindowSize(200, 200);
+ glutInitWindowSize(WinSize[0], WinSize[1]);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
win = glutCreateWindow(argv[0]);
glewInit();
diff --git a/progs/objviewer/.gitignore b/progs/objviewer/.gitignore
new file mode 100644
index 0000000000..ff094f833e
--- /dev/null
+++ b/progs/objviewer/.gitignore
@@ -0,0 +1,8 @@
+extfuncs.h
+objview
+readtex.c
+readtex.h
+shaderutil.c
+shaderutil.h
+trackball.c
+trackball.h
diff --git a/progs/openvg/demos/eglcommon.c b/progs/openvg/demos/eglcommon.c
index bacd5685d7..0316e596c6 100644
--- a/progs/openvg/demos/eglcommon.c
+++ b/progs/openvg/demos/eglcommon.c
@@ -42,6 +42,7 @@ make_x_window(Display *x_dpy, EGLDisplay egl_dpy,
EGL_RED_SIZE, 1,
EGL_GREEN_SIZE, 1,
EGL_BLUE_SIZE, 1,
+ EGL_RENDERABLE_TYPE, EGL_OPENVG_BIT,
EGL_NONE
};
@@ -60,13 +61,13 @@ make_x_window(Display *x_dpy, EGLDisplay egl_dpy,
scrnum = DefaultScreen( x_dpy );
root = RootWindow( x_dpy, scrnum );
- if (!eglChooseConfig( egl_dpy, attribs, &config, 1, &num_configs)) {
+ if (!eglChooseConfig( egl_dpy, attribs, &config, 1, &num_configs) ||
+ !num_configs) {
printf("Error: couldn't get an EGL visual config\n");
exit(1);
}
assert(config);
- assert(num_configs > 0);
if (!eglGetConfigAttrib(egl_dpy, config, EGL_NATIVE_VISUAL_ID, &vid)) {
printf("Error: eglGetConfigAttrib() failed\n");
diff --git a/progs/openvg/demos/lion.c b/progs/openvg/demos/lion.c
index 7224fed399..adb269bfd8 100644
--- a/progs/openvg/demos/lion.c
+++ b/progs/openvg/demos/lion.c
@@ -67,6 +67,7 @@ make_x_window(Display *x_dpy, EGLDisplay egl_dpy,
EGL_RED_SIZE, 1,
EGL_GREEN_SIZE, 1,
EGL_BLUE_SIZE, 1,
+ EGL_RENDERABLE_TYPE, EGL_OPENVG_BIT,
EGL_NONE
};
@@ -85,13 +86,13 @@ make_x_window(Display *x_dpy, EGLDisplay egl_dpy,
scrnum = DefaultScreen( x_dpy );
root = RootWindow( x_dpy, scrnum );
- if (!eglChooseConfig( egl_dpy, attribs, &config, 1, &num_configs)) {
+ if (!eglChooseConfig( egl_dpy, attribs, &config, 1, &num_configs) ||
+ !num_configs) {
printf("Error: couldn't get an EGL visual config\n");
exit(1);
}
assert(config);
- assert(num_configs > 0);
if (!eglGetConfigAttrib(egl_dpy, config, EGL_NATIVE_VISUAL_ID, &vid)) {
printf("Error: eglGetConfigAttrib() failed\n");
diff --git a/progs/openvg/trivial/eglcommon.c b/progs/openvg/trivial/eglcommon.c
index bacd5685d7..0316e596c6 100644
--- a/progs/openvg/trivial/eglcommon.c
+++ b/progs/openvg/trivial/eglcommon.c
@@ -42,6 +42,7 @@ make_x_window(Display *x_dpy, EGLDisplay egl_dpy,
EGL_RED_SIZE, 1,
EGL_GREEN_SIZE, 1,
EGL_BLUE_SIZE, 1,
+ EGL_RENDERABLE_TYPE, EGL_OPENVG_BIT,
EGL_NONE
};
@@ -60,13 +61,13 @@ make_x_window(Display *x_dpy, EGLDisplay egl_dpy,
scrnum = DefaultScreen( x_dpy );
root = RootWindow( x_dpy, scrnum );
- if (!eglChooseConfig( egl_dpy, attribs, &config, 1, &num_configs)) {
+ if (!eglChooseConfig( egl_dpy, attribs, &config, 1, &num_configs) ||
+ !num_configs) {
printf("Error: couldn't get an EGL visual config\n");
exit(1);
}
assert(config);
- assert(num_configs > 0);
if (!eglGetConfigAttrib(egl_dpy, config, EGL_NATIVE_VISUAL_ID, &vid)) {
printf("Error: eglGetConfigAttrib() failed\n");
diff --git a/progs/osdemos/Makefile b/progs/osdemos/Makefile
index 023ea02ae2..f53515cb0a 100644
--- a/progs/osdemos/Makefile
+++ b/progs/osdemos/Makefile
@@ -5,7 +5,7 @@ include $(TOP)/configs/current
INCDIR = $(TOP)/include
-OSMESA_LIBS = -L$(TOP)/$(LIB_DIR) -l$(GLU_LIB) -l$(OSMESA_LIB) $(APP_LIB_DEPS)
+OSMESA_LIBS = -L$(TOP)/$(LIB_DIR) -l$(GLU_LIB) -l$(GL_LIB) -l$(OSMESA_LIB) $(APP_LIB_DEPS)
OSMESA16_LIBS = -L$(TOP)/$(LIB_DIR) -l$(GLUT_LIB) -lOSMesa16 -l$(GLU_LIB) \
-l$(GL_LIB) $(APP_LIB_DEPS)
@@ -13,12 +13,6 @@ OSMESA16_LIBS = -L$(TOP)/$(LIB_DIR) -l$(GLUT_LIB) -lOSMesa16 -l$(GLU_LIB) \
OSMESA32_LIBS = -L$(TOP)/$(LIB_DIR) -l$(GLUT_LIB) -lOSMesa32 -l$(GLU_LIB) \
-l$(GL_LIB) $(APP_LIB_DEPS)
-LIB_DEP = $(TOP)/$(LIB_DIR)/$(GL_LIB_NAME) $(TOP)/$(LIB_DIR)/$(GLU_LIB_NAME) \
- $(TOP)/$(LIB_DIR)/$(GLUT_LIB_NAME)
-
-LIBS = -L$(TOP)/$(LIB_DIR) -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) \
- $(APP_LIB_DEPS)
-
PROGS = \
osdemo \
ostest1
@@ -30,11 +24,6 @@ PROGS = \
.SUFFIXES: .c
-# make executable from .c file:
-.c: $(LIB_DEP) readtex.o
- $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) $< readtex.o $(LIBS) -o $@
-
-
##### TARGETS #####
default: readtex.o $(PROGS)
diff --git a/progs/perf/SConscript b/progs/perf/SConscript
index a5ec9a7c2a..691478ab64 100644
--- a/progs/perf/SConscript
+++ b/progs/perf/SConscript
@@ -1,11 +1,4 @@
-Import('env')
-
-if not env['GLUT']:
- Return()
-
-env = env.Clone()
-
-env.Prepend(LIBS = ['$GLUT_LIB'])
+Import('*')
progs = [
'copytex',
@@ -21,7 +14,7 @@ progs = [
]
for prog in progs:
- env.Program(
+ progs_env.Program(
target = prog,
source = [
prog + '.c',
diff --git a/progs/rbug/bin_to_bmp.c b/progs/rbug/bin_to_bmp.c
index cdae3486ce..49a5416787 100644
--- a/progs/rbug/bin_to_bmp.c
+++ b/progs/rbug/bin_to_bmp.c
@@ -25,8 +25,10 @@
#include "pipe/p_compiler.h"
#include "pipe/p_format.h"
#include "pipe/p_state.h"
+#include "util/u_format.h"
#include "util/u_memory.h"
#include "util/u_debug.h"
+#include "util/u_format.h"
#include "util/u_network.h"
#include "util/u_tile.h"
@@ -54,10 +56,7 @@ static void dump(unsigned width, unsigned height,
unsigned src_stride, enum pipe_format src_format,
uint8_t *data, unsigned src_size)
{
- struct pipe_format_block src_block;
-
enum pipe_format dst_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
- struct pipe_format_block dst_block;
unsigned dst_stride;
unsigned dst_size;
float *rgba;
@@ -65,20 +64,17 @@ static void dump(unsigned width, unsigned height,
char filename[512];
{
- pf_get_block(src_format, &src_block);
- assert(src_stride >= pf_get_stride(&src_block, width));
- assert(src_size >= pf_get_2d_size(&src_block, src_stride, width));
+ assert(src_stride >= util_format_get_stride(src_format, width));
}
{
- pf_get_block(dst_format, &dst_block);
- dst_stride = pf_get_stride(&dst_block, width);
- dst_size = pf_get_2d_size(&dst_block, dst_stride, width);
+ dst_stride = util_format_get_stride(dst_format, width);
+ dst_size = util_format_get_2d_size(dst_format, dst_stride, width);
rgba = MALLOC(dst_size);
}
util_snprintf(filename, 512, "%s.bmp", pf_name(src_format));
- if (pf_is_compressed(src_format)) {
+ if (util_format_is_compressed(src_format)) {
debug_printf("skipping: %s\n", filename);
return;
}
diff --git a/progs/rbug/tex_dump.c b/progs/rbug/tex_dump.c
index f9e06ee994..963f8eeede 100644
--- a/progs/rbug/tex_dump.c
+++ b/progs/rbug/tex_dump.c
@@ -27,6 +27,7 @@
#include "pipe/p_state.h"
#include "util/u_memory.h"
#include "util/u_debug.h"
+#include "util/u_format.h"
#include "util/u_network.h"
#include "util/u_tile.h"
#include "rbug/rbug.h"
@@ -49,7 +50,7 @@ static void dump(rbug_texture_t tex,
util_snprintf(filename, 512, "%llu_%s_%u.bmp",
(unsigned long long)tex, pf_name(info->format), mip);
- if (pf_is_compressed(info->format)) {
+ if (util_format_is_compressed(info->format)) {
debug_printf("skipping: %s\n", filename);
return;
}
diff --git a/progs/redbook/SConscript b/progs/redbook/SConscript
index 242cb6647f..24d7cff1b6 100644
--- a/progs/redbook/SConscript
+++ b/progs/redbook/SConscript
@@ -1,23 +1,5 @@
Import('*')
-if not env['GLUT']:
- Return()
-
-env = env.Clone()
-
-env.Prepend(CPPPATH = [
- '../util',
-])
-
-env.Prepend(LIBS = [
- util,
- '$GLUT_LIB'
-])
-
-if env['platform'] == 'windows':
- env.Append(CPPDEFINES = ['NOMINMAX'])
- env.Prepend(LIBS = ['winmm'])
-
progs = [
'aaindex',
'aapoly',
@@ -85,7 +67,7 @@ progs = [
]
for prog in progs:
- env.Program(
+ progs_env.Program(
target = prog,
source = prog + '.c',
)
diff --git a/progs/samples/.gitignore b/progs/samples/.gitignore
index f60d6e94ea..c15b886b88 100644
--- a/progs/samples/.gitignore
+++ b/progs/samples/.gitignore
@@ -36,6 +36,7 @@ prim
quad
readtex.c
readtex.h
+rgbtoppm
select
shape
sphere
diff --git a/progs/samples/SConscript b/progs/samples/SConscript
index 7a8a0d62d8..134dfa9980 100644
--- a/progs/samples/SConscript
+++ b/progs/samples/SConscript
@@ -1,23 +1,5 @@
Import('*')
-if not env['GLUT']:
- Return()
-
-env = env.Clone()
-
-env.Prepend(CPPPATH = [
- '../util',
-])
-
-env.Prepend(LIBS = [
- util,
- '$GLUT_LIB'
-])
-
-if env['platform'] == 'windows':
- env.Append(CPPDEFINES = ['NOMINMAX'])
- env.Prepend(LIBS = ['winmm'])
-
progs = [
'accum',
'bitmap1',
@@ -52,7 +34,7 @@ progs = [
]
for prog in progs:
- env.Program(
+ progs_env.Program(
target = prog,
source = prog + '.c',
)
diff --git a/progs/tests/Makefile b/progs/tests/Makefile
index 197e14d5b0..836396b249 100644
--- a/progs/tests/Makefile
+++ b/progs/tests/Makefile
@@ -37,10 +37,12 @@ SOURCES = \
bug_3195.c \
bug_texstore_i8.c \
calibrate_rast.c \
+ condrender.c \
copypixrate.c \
crossbar.c \
cva.c \
drawbuffers.c \
+ drawbuffers2.c \
exactrast.c \
ext422square.c \
floattex.c \
@@ -98,6 +100,7 @@ SOURCES = \
texdown \
texfilt.c \
texgenmix.c \
+ texleak.c \
texline.c \
texobj.c \
texobjshare.c \
diff --git a/progs/tests/SConscript b/progs/tests/SConscript
index 3a0da62717..e2c6538288 100644
--- a/progs/tests/SConscript
+++ b/progs/tests/SConscript
@@ -1,23 +1,5 @@
Import('*')
-if not env['GLUT']:
- Return()
-
-env = env.Clone()
-
-env.Prepend(CPPPATH = [
- '../util',
-])
-
-env.Prepend(LIBS = [
- util,
- '$GLUT_LIB'
-])
-
-if env['platform'] == 'windows':
- env.Append(CPPDEFINES = ['NOMINMAX'])
- env.Prepend(LIBS = ['winmm'])
-
linux_progs = [
'api_speed',
]
@@ -59,10 +41,12 @@ progs = [
'bug_3195',
'bug_texstore_i8',
'calibrate_rast',
+ 'condrender',
'copypixrate',
'crossbar',
'cva',
'drawbuffers',
+ 'drawbuffers2',
'exactrast',
'ext422square',
'fbotest1',
@@ -138,7 +122,7 @@ progs = [
]
for prog in progs:
- env.Program(
+ progs_env.Program(
target = prog,
source = prog + '.c',
)
diff --git a/progs/tests/condrender.c b/progs/tests/condrender.c
new file mode 100644
index 0000000000..1db8a7c15a
--- /dev/null
+++ b/progs/tests/condrender.c
@@ -0,0 +1,242 @@
+/*
+ * Test GL_NV_conditional_render
+ *
+ * Brian Paul
+ * 30 Dec 2009
+ *
+ * Copyright (C) 2009 VMware, Inc. 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
+ * THE AUTHORS 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 <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+#include <GL/glew.h>
+#include <GL/glut.h>
+
+#define TEST_DISPLAY_LISTS 0
+
+static GLboolean Anim = GL_TRUE;
+static GLfloat Xpos = 0;
+static GLuint OccQuery;
+static GLint Win = 0;
+
+
+static void Idle(void)
+{
+ static int lastTime = 0;
+ static int sign = +1;
+ int time = glutGet(GLUT_ELAPSED_TIME);
+ float step;
+
+ if (lastTime == 0)
+ lastTime = time;
+ else if (time - lastTime < 20) /* 50Hz update */
+ return;
+
+ step = (time - lastTime) / 1000.0 * sign;
+ lastTime = time;
+
+ Xpos += step;
+
+ if (Xpos > 2.5) {
+ Xpos = 2.5;
+ sign = -1;
+ }
+ else if (Xpos < -2.5) {
+ Xpos = -2.5;
+ sign = +1;
+ }
+ glutPostRedisplay();
+}
+
+
+static void Display( void )
+{
+ glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
+
+ glEnable(GL_DEPTH_TEST);
+
+ glMatrixMode( GL_PROJECTION );
+ glLoadIdentity();
+ glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 );
+ glMatrixMode( GL_MODELVIEW );
+ glLoadIdentity();
+ glTranslatef( 0.0, 0.0, -15.0 );
+
+ /* draw the occluding polygons */
+ glColor3f(0, 0.6, 0.8);
+ glBegin(GL_QUADS);
+ glVertex2f(-1.6, -1.5);
+ glVertex2f(-0.4, -1.5);
+ glVertex2f(-0.4, 1.5);
+ glVertex2f(-1.6, 1.5);
+
+ glVertex2f( 0.4, -1.5);
+ glVertex2f( 1.6, -1.5);
+ glVertex2f( 1.6, 1.5);
+ glVertex2f( 0.4, 1.5);
+ glEnd();
+
+ /* draw the test polygon with occlusion testing */
+ glPushMatrix();
+ glTranslatef(Xpos, 0, -0.5);
+ glScalef(0.3, 0.3, 1.0);
+ glRotatef(-90.0 * Xpos, 0, 0, 1);
+
+#if TEST_DISPLAY_LISTS
+ glNewList(10, GL_COMPILE);
+ glBeginQueryARB(GL_SAMPLES_PASSED_ARB, OccQuery);
+ glEndList();
+ glCallList(10);
+#else
+ glBeginQueryARB(GL_SAMPLES_PASSED_ARB, OccQuery);
+#endif
+
+ glColorMask(0, 0, 0, 0);
+ glDepthMask(GL_FALSE);
+
+ glBegin(GL_POLYGON);
+ glVertex3f(-1, -1, 0);
+ glVertex3f( 1, -1, 0);
+ glVertex3f( 1, 1, 0);
+ glVertex3f(-1, 1, 0);
+ glEnd();
+
+#if TEST_DISPLAY_LISTS
+ glNewList(11, GL_COMPILE);
+ glEndQueryARB(GL_SAMPLES_PASSED_ARB);
+ glEndList();
+ glCallList(11);
+#else
+ glEndQueryARB(GL_SAMPLES_PASSED_ARB);
+#endif
+
+ glColorMask(1, 1, 1, 1);
+ glDepthMask(GL_TRUE);
+
+ /* Note: disable depth test here so that we'll always see the orange
+ * box, except when it's totally culled.
+ */
+ glDisable(GL_DEPTH_TEST);
+
+ glBeginConditionalRenderNV(OccQuery, GL_QUERY_WAIT_NV);
+ /* draw the orange rect, so we can see what's going on */
+ glColor3f(0.8, 0.5, 0);
+ glBegin(GL_POLYGON);
+ glVertex3f(-1, -1, 0);
+ glVertex3f( 1, -1, 0);
+ glVertex3f( 1, 1, 0);
+ glVertex3f(-1, 1, 0);
+ glEnd();
+ glEndConditionalRenderNV();
+
+ /* always draw white outline around orange box */
+ glColor3f(1.0, 1.0, 1.0);
+ glBegin(GL_LINE_LOOP);
+ glVertex3f(-1, -1, 0);
+ glVertex3f( 1, -1, 0);
+ glVertex3f( 1, 1, 0);
+ glVertex3f(-1, 1, 0);
+ glEnd();
+
+ glPopMatrix();
+
+ glutSwapBuffers();
+}
+
+
+static void Reshape( int width, int height )
+{
+ glViewport( 0, 0, width, height );
+}
+
+
+static void Key( unsigned char key, int x, int y )
+{
+ (void) x;
+ (void) y;
+ switch (key) {
+ case 27:
+ glDeleteQueriesARB(1, &OccQuery);
+ glutDestroyWindow(Win);
+ exit(0);
+ break;
+ case ' ':
+ Anim = !Anim;
+ if (Anim)
+ glutIdleFunc(Idle);
+ else
+ glutIdleFunc(NULL);
+ break;
+ }
+ glutPostRedisplay();
+}
+
+
+static void SpecialKey( int key, int x, int y )
+{
+ const GLfloat step = 0.1;
+ (void) x;
+ (void) y;
+ switch (key) {
+ case GLUT_KEY_LEFT:
+ Xpos -= step;
+ break;
+ case GLUT_KEY_RIGHT:
+ Xpos += step;
+ break;
+ }
+ glutPostRedisplay();
+}
+
+
+static void Init( void )
+{
+ if (!glutExtensionSupported("GL_ARB_occlusion_query") ||
+ !glutExtensionSupported("GL_NV_conditional_render")) {
+ printf("Sorry, this demo requires the extensions:\n");
+ printf(" GL_ARB_occlusion_query\n");
+ printf(" GL_NV_conditional_render\n");
+ exit(-1);
+ }
+
+ glGenQueriesARB(1, &OccQuery);
+ assert(OccQuery > 0);
+}
+
+
+int main( int argc, char *argv[] )
+{
+ glutInitWindowSize( 400, 400 );
+ glutInit( &argc, argv );
+ glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
+ Win = glutCreateWindow(argv[0]);
+ glewInit();
+ glutReshapeFunc( Reshape );
+ glutKeyboardFunc( Key );
+ glutSpecialFunc( SpecialKey );
+ glutIdleFunc( Idle );
+ glutDisplayFunc( Display );
+ Init();
+ glutMainLoop();
+ return 0;
+}
diff --git a/progs/tests/drawbuffers2.c b/progs/tests/drawbuffers2.c
new file mode 100644
index 0000000000..7b8cc5ca6a
--- /dev/null
+++ b/progs/tests/drawbuffers2.c
@@ -0,0 +1,364 @@
+/*
+ * Test GL_ARB_draw_buffers2, GL_ARB_draw_buffers, GL_EXT_framebuffer_object
+ * and GLSL's gl_FragData[].
+ *
+ * We draw to two color buffers and show the left half of the first
+ * color buffer on the left side of the window, and show the right
+ * half of the second color buffer on the right side of the window.
+ *
+ * Different color masks are used for the two color buffers.
+ * Blending is enabled for the second buffer only.
+ *
+ * Brian Paul
+ * 31 Dec 2009
+ */
+
+
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include <GL/glew.h>
+#include <GL/glut.h>
+#include "extfuncs.h"
+
+static int Win;
+static int Width = 400, Height = 400;
+static GLuint FBobject, RBobjects[3];
+static GLfloat Xrot = 0.0, Yrot = 0.0;
+static GLuint Program;
+static GLboolean Anim = GL_TRUE;
+
+
+static void
+CheckError(int line)
+{
+ GLenum err = glGetError();
+ if (err) {
+ printf("GL Error 0x%x at line %d\n", (int) err, line);
+ }
+}
+
+
+static void
+Display(void)
+{
+ GLubyte *buffer = malloc(Width * Height * 4);
+ static const GLenum buffers[2] = {
+ GL_COLOR_ATTACHMENT0_EXT,
+ GL_COLOR_ATTACHMENT1_EXT
+ };
+
+ glUseProgram_func(Program);
+
+ glEnable(GL_DEPTH_TEST);
+
+ /* draw to user framebuffer */
+ glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, FBobject);
+
+ /* Clear color buffer 0 (blue) */
+ glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ /* Clear color buffer 1 (1 - blue) */
+ glDrawBuffer(GL_COLOR_ATTACHMENT1_EXT);
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ glClear(GL_DEPTH_BUFFER_BIT);
+
+ /* draw to two buffers w/ fragment shader */
+ glDrawBuffersARB(2, buffers);
+
+ /* different color masks for each buffer */
+ if (1) {
+ glColorMaskIndexedEXT(0, GL_TRUE, GL_FALSE, GL_FALSE, GL_FALSE);
+ glColorMaskIndexedEXT(1, GL_FALSE, GL_TRUE, GL_FALSE, GL_FALSE);
+ }
+
+ glPushMatrix();
+ glRotatef(Xrot, 1, 0, 0);
+ glRotatef(Yrot, 0, 1, 0);
+ glPushMatrix();
+ glTranslatef(1, 0, 0);
+ glutSolidTorus(1.0, 2.0, 10, 20);
+ glPopMatrix();
+ glPushMatrix();
+ glTranslatef(-1, 0, 0);
+ glRotatef(90, 1, 0, 0);
+ glutSolidTorus(1.0, 2.0, 10, 20);
+ glPopMatrix();
+ glPopMatrix();
+
+ /* restore default color masks */
+ glColorMaskIndexedEXT(0, GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
+ glColorMaskIndexedEXT(1, GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
+
+ /* read from user framebuffer */
+ /* left half = colorbuffer 0 */
+ glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
+ glPixelStorei(GL_PACK_ROW_LENGTH, Width);
+ glPixelStorei(GL_PACK_SKIP_PIXELS, 0);
+ glReadPixels(0, 0, Width / 2, Height, GL_RGBA, GL_UNSIGNED_BYTE,
+ buffer);
+
+ /* right half = colorbuffer 1 */
+ glReadBuffer(GL_COLOR_ATTACHMENT1_EXT);
+ glPixelStorei(GL_PACK_SKIP_PIXELS, Width / 2);
+ glReadPixels(Width / 2, 0, Width - Width / 2, Height,
+ GL_RGBA, GL_UNSIGNED_BYTE,
+ buffer);
+
+ /* draw to window */
+ glUseProgram_func(0);
+ glDisable(GL_DEPTH_TEST);
+ glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
+ glWindowPos2iARB(0, 0);
+ glDrawPixels(Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
+
+ free(buffer);
+ glutSwapBuffers();
+ CheckError(__LINE__);
+}
+
+
+static void
+Idle(void)
+{
+ Xrot = glutGet(GLUT_ELAPSED_TIME) * 0.05;
+ glutPostRedisplay();
+}
+
+
+static void
+Reshape(int width, int height)
+{
+ float ar = (float) width / (float) height;
+
+ glViewport(0, 0, width, height);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glFrustum(-ar, ar, -1.0, 1.0, 5.0, 35.0);
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ glTranslatef(0.0, 0.0, -20.0);
+
+ Width = width;
+ Height = height;
+
+ glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, RBobjects[0]);
+ glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGB, Width, Height);
+ glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, RBobjects[1]);
+ glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGB, Width, Height);
+ glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, RBobjects[2]);
+ glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT,
+ Width, Height);
+}
+
+
+static void
+CleanUp(void)
+{
+ glDeleteFramebuffersEXT(1, &FBobject);
+ glDeleteRenderbuffersEXT(3, RBobjects);
+ glutDestroyWindow(Win);
+ exit(0);
+}
+
+
+static void
+Key(unsigned char key, int x, int y)
+{
+ (void) x;
+ (void) y;
+ switch (key) {
+ case ' ':
+ Anim = !Anim;
+ glutIdleFunc(Anim ? Idle : NULL);
+ break;
+ case 'x':
+ Xrot += 5.0;
+ break;
+ case 'X':
+ Xrot -= 5.0;
+ break;
+ case 'y':
+ Yrot += 5.0;
+ break;
+ case 'Y':
+ Yrot -= 5.0;
+ break;
+ case 27:
+ CleanUp();
+ break;
+ }
+ glutPostRedisplay();
+}
+
+
+static void
+CheckExtensions(void)
+{
+ const char *req[] = {
+ "GL_EXT_framebuffer_object",
+ "GL_ARB_draw_buffers",
+ "GL_EXT_draw_buffers2"
+ };
+
+ const char *version = (const char *) glGetString(GL_VERSION);
+ GLint numBuf;
+ GLint i;
+
+ for (i = 0; i < 3; i++) {
+ if (!glutExtensionSupported(req[i])) {
+ printf("Sorry, %s extension is required!\n", req[i]);
+ exit(1);
+ }
+ }
+ if (version[0] != '2') {
+ printf("Sorry, OpenGL 2.0 is required!\n");
+ exit(1);
+ }
+
+ glGetIntegerv(GL_MAX_DRAW_BUFFERS_ARB, &numBuf);
+ printf("GL_MAX_DRAW_BUFFERS_ARB = %d\n", numBuf);
+ if (numBuf < 2) {
+ printf("Sorry, GL_MAX_DRAW_BUFFERS_ARB needs to be >= 2\n");
+ exit(1);
+ }
+
+ printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
+}
+
+
+static void
+SetupRenderbuffers(void)
+{
+ glGenFramebuffersEXT(1, &FBobject);
+ glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, FBobject);
+
+ glGenRenderbuffersEXT(3, RBobjects);
+
+ glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, RBobjects[0]);
+ glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGB, Width, Height);
+
+ glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, RBobjects[1]);
+ glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGB, Width, Height);
+
+ glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, RBobjects[2]);
+ glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT,
+ Width, Height);
+
+ glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
+ GL_RENDERBUFFER_EXT, RBobjects[0]);
+ glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT,
+ GL_RENDERBUFFER_EXT, RBobjects[1]);
+ glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
+ GL_RENDERBUFFER_EXT, RBobjects[2]);
+
+ CheckError(__LINE__);
+}
+
+
+static GLuint
+LoadAndCompileShader(GLenum target, const char *text)
+{
+ GLint stat;
+ GLuint shader = glCreateShader_func(target);
+ glShaderSource_func(shader, 1, (const GLchar **) &text, NULL);
+ glCompileShader_func(shader);
+ glGetShaderiv_func(shader, GL_COMPILE_STATUS, &stat);
+ if (!stat) {
+ GLchar log[1000];
+ GLsizei len;
+ glGetShaderInfoLog_func(shader, 1000, &len, log);
+ fprintf(stderr, "drawbuffers: problem compiling shader:\n%s\n", log);
+ exit(1);
+ }
+ return shader;
+}
+
+
+static void
+CheckLink(GLuint prog)
+{
+ GLint stat;
+ glGetProgramiv_func(prog, GL_LINK_STATUS, &stat);
+ if (!stat) {
+ GLchar log[1000];
+ GLsizei len;
+ glGetProgramInfoLog_func(prog, 1000, &len, log);
+ fprintf(stderr, "drawbuffers: shader link error:\n%s\n", log);
+ }
+}
+
+
+static void
+SetupShaders(void)
+{
+ /* emit same color to both draw buffers */
+ static const char *fragShaderText =
+ "void main() {\n"
+ " gl_FragData[0] = gl_Color; \n"
+ " gl_FragData[1] = gl_Color; \n"
+ "}\n";
+
+ GLuint fragShader;
+
+ fragShader = LoadAndCompileShader(GL_FRAGMENT_SHADER, fragShaderText);
+ Program = glCreateProgram_func();
+
+ glAttachShader_func(Program, fragShader);
+ glLinkProgram_func(Program);
+ CheckLink(Program);
+ glUseProgram_func(Program);
+}
+
+
+static void
+SetupLighting(void)
+{
+ static const GLfloat ambient[4] = { 0.0, 0.0, 0.0, 0.0 };
+ static const GLfloat diffuse[4] = { 1.0, 1.0, 1.0, 0.75 };
+
+ glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient);
+ glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambient);
+ glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse);
+
+ glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 0);
+ glEnable(GL_LIGHT0);
+ glEnable(GL_LIGHTING);
+}
+
+
+static void
+Init(void)
+{
+ CheckExtensions();
+ GetExtensionFuncs();
+ SetupRenderbuffers();
+ SetupShaders();
+ SetupLighting();
+ glEnable(GL_DEPTH_TEST);
+
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glEnableIndexedEXT(GL_BLEND, 1);
+}
+
+
+int
+main(int argc, char *argv[])
+{
+ glutInit(&argc, argv);
+ glutInitWindowPosition(0, 0);
+ glutInitWindowSize(Width, Height);
+ glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
+ Win = glutCreateWindow(argv[0]);
+ glewInit();
+ glutIdleFunc(Anim ? Idle : NULL);
+ glutReshapeFunc(Reshape);
+ glutKeyboardFunc(Key);
+ glutDisplayFunc(Display);
+ Init();
+ glutMainLoop();
+ return 0;
+}
diff --git a/progs/tests/texleak.c b/progs/tests/texleak.c
new file mode 100644
index 0000000000..5cf4ff3239
--- /dev/null
+++ b/progs/tests/texleak.c
@@ -0,0 +1,140 @@
+/*
+ * 'Texture leak' test
+ *
+ * Allocates and uses an additional texture of the maximum supported size for
+ * each frame. This tests the system's ability to cope with using increasing
+ * amounts of texture memory.
+ *
+ * Michel Dänzer July 2009 This program is in the public domain.
+ */
+
+
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <GL/glew.h>
+#include <GL/glut.h>
+
+
+GLint size;
+GLvoid *image;
+static GLuint numTexObj;
+static GLuint *texObj;
+
+
+static void Idle( void )
+{
+ glutPostRedisplay();
+}
+
+
+static void DrawObject(void)
+{
+ static const GLfloat tex_coords[] = { 0.0, 0.0, 1.0, 1.0, 0.0 };
+ static const GLfloat vtx_coords[] = { -1.0, -1.0, 1.0, 1.0, -1.0 };
+ GLint i, j;
+
+ glEnable(GL_TEXTURE_2D);
+
+ for (i = 0; i < numTexObj; i++) {
+ glBindTexture(GL_TEXTURE_2D, texObj[i]);
+ glBegin(GL_QUADS);
+ for (j = 0; j < 4; j++ ) {
+ glTexCoord2f(tex_coords[j], tex_coords[j+1]);
+ glVertex2f( vtx_coords[j], vtx_coords[j+1] );
+ }
+ glEnd();
+ }
+}
+
+
+static void Display( void )
+{
+ struct timeval start, end;
+
+ texObj = realloc(texObj, ++numTexObj * sizeof(*texObj));
+
+ /* allocate a texture object */
+ glGenTextures(1, texObj + (numTexObj - 1));
+
+ glBindTexture(GL_TEXTURE_2D, texObj[numTexObj - 1]);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ memset(image, (16 * numTexObj) & 0xff, 4 * size * size);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size, size, 0,
+ GL_RGBA, GL_UNSIGNED_BYTE, image);
+
+ gettimeofday(&start, NULL);
+
+ glClear( GL_COLOR_BUFFER_BIT );
+
+ glPushMatrix();
+ glScalef(5.0, 5.0, 5.0);
+ DrawObject();
+ glPopMatrix();
+
+ glutSwapBuffers();
+
+ glFinish();
+ gettimeofday(&end, NULL);
+ printf("Rendering frame took %lu ms using %u MB of textures\n",
+ end.tv_sec * 1000 + end.tv_usec / 1000 - start.tv_sec * 1000 -
+ start.tv_usec / 1000, numTexObj * 4 * size / 1024 * size / 1024);
+
+ sleep(1);
+}
+
+
+static void Reshape( int width, int height )
+{
+ glViewport( 0, 0, width, height );
+ glMatrixMode( GL_PROJECTION );
+ glLoadIdentity();
+ glOrtho( -6.0, 6.0, -6.0, 6.0, 10.0, 100.0 );
+ glMatrixMode( GL_MODELVIEW );
+ glLoadIdentity();
+ glTranslatef( 0.0, 0.0, -70.0 );
+}
+
+
+static void Init( int argc, char *argv[] )
+{
+ glGetIntegerv(GL_MAX_TEXTURE_SIZE, &size);
+ printf("%d x %d max texture size\n", size, size);
+
+ image = malloc(4 * size * size);
+ if (!image) {
+ fprintf(stderr, "Failed to allocate %u bytes of memory\n", 4 * size * size);
+ exit(1);
+ }
+
+ glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+
+ glShadeModel(GL_FLAT);
+ glClearColor(0.3, 0.3, 0.4, 1.0);
+
+ Idle();
+}
+
+
+int main( int argc, char *argv[] )
+{
+ glutInit( &argc, argv );
+ glutInitWindowSize( 300, 300 );
+ glutInitWindowPosition( 0, 0 );
+ glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
+ glutCreateWindow(argv[0] );
+ glewInit();
+
+ Init( argc, argv );
+
+ glutReshapeFunc( Reshape );
+ glutDisplayFunc( Display );
+ glutIdleFunc(Idle);
+
+ glutMainLoop();
+ return 0;
+}
diff --git a/progs/trivial/.gitignore b/progs/trivial/.gitignore
index 4d6e405c50..4317eb607f 100644
--- a/progs/trivial/.gitignore
+++ b/progs/trivial/.gitignore
@@ -147,6 +147,7 @@ vbo-drawarrays
vbo-drawelements
vbo-drawrange
vbo-noninterleaved
+vbo-tri
vp-array
vp-array-int
vp-clip
diff --git a/progs/trivial/Makefile b/progs/trivial/Makefile
index 70728616d2..5e08d60389 100644
--- a/progs/trivial/Makefile
+++ b/progs/trivial/Makefile
@@ -119,6 +119,7 @@ SOURCES = \
tri-lit-material.c \
tri-mask-tri.c \
tri-orig.c \
+ tri-point-line-clipped.c \
tri-query.c \
tri-repeat.c \
tri-scissor-tri.c \
@@ -153,6 +154,7 @@ SOURCES = \
tristrip-clip.c \
tristrip-flat.c \
tristrip.c \
+ vbo-tri.c \
vbo-drawarrays.c \
vbo-noninterleaved.c \
vbo-drawelements.c \
diff --git a/progs/trivial/SConscript b/progs/trivial/SConscript
index 9a1f3575bd..e9ed1cb71e 100644
--- a/progs/trivial/SConscript
+++ b/progs/trivial/SConscript
@@ -1,11 +1,4 @@
-Import('env')
-
-if not env['GLUT']:
- Return()
-
-env = env.Clone()
-
-env.Prepend(LIBS = ['$GLUT_LIB'])
+Import('*')
progs = [
'clear-fbo-tex',
@@ -103,6 +96,7 @@ progs = [
'tri-logicop-xor',
'tri-mask-tri',
'tri-orig',
+ 'tri-point-line-clipped',
'tri-query',
'tri-repeat',
'tri-scissor-tri',
@@ -154,7 +148,7 @@ progs = [
]
for prog in progs:
- prog = env.Program(
+ prog = progs_env.Program(
target = prog,
source = prog + '.c',
)
diff --git a/progs/trivial/tri-orig.c b/progs/trivial/tri-orig.c
index d86d34c39d..f86ac52a02 100644
--- a/progs/trivial/tri-orig.c
+++ b/progs/trivial/tri-orig.c
@@ -51,7 +51,7 @@ static void Reshape(int width, int height)
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
-/* glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0); */
+ glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
glMatrixMode(GL_MODELVIEW);
}
@@ -74,11 +74,11 @@ static void Draw(void)
glBegin(GL_TRIANGLES);
glColor3f(0,0,.7);
- glVertex3f( 0.9, -0.9, -0.0);
+ glVertex3f( 0.9, -0.9, -30.0);
glColor3f(.8,0,0);
- glVertex3f( 0.9, 0.9, -0.0);
+ glVertex3f( 0.9, 0.9, -30.0);
glColor3f(0,.9,0);
- glVertex3f(-0.9, 0.0, -0.0);
+ glVertex3f(-0.9, 0.0, -30.0);
glEnd();
glFlush();
@@ -119,7 +119,7 @@ int main(int argc, char **argv)
glutInitWindowPosition(0, 0); glutInitWindowSize( 250, 250);
- type = GLUT_RGB | GLUT_ALPHA;
+ type = GLUT_RGB;
type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
glutInitDisplayMode(type);
diff --git a/progs/trivial/tri-point-line-clipped.c b/progs/trivial/tri-point-line-clipped.c
new file mode 100644
index 0000000000..f8c1015f5f
--- /dev/null
+++ b/progs/trivial/tri-point-line-clipped.c
@@ -0,0 +1,116 @@
+/**
+ * Test frustum/user clipping w/ glPolygonMode LINE/POINT.
+ *
+ * The bottom/left and bottom/right verts are outside the frustum and clipped.
+ * The top vertex is clipped by a user clipping plane.
+ *
+ * A filled gray reference triangle is shown underneath the points/lines.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <GL/glut.h>
+
+
+static int win;
+
+
+static void
+ColorTri(void)
+{
+ glBegin(GL_TRIANGLES);
+ glColor3f(1, 0, 0); glVertex3f(-1.5, -0.8, 0.0);
+ glColor3f(0, 1, 0); glVertex3f( 1.5, -0.8, 0.0);
+ glColor3f(0, 0, 1); glVertex3f( 0.0, 0.9, 0.0);
+ glEnd();
+}
+
+
+static void
+GrayTri(void)
+{
+ glColor3f(0.3, 0.3, 0.3);
+ glBegin(GL_TRIANGLES);
+ glVertex3f(-1.5, -0.8, 0.0);
+ glVertex3f( 1.5, -0.8, 0.0);
+ glVertex3f( 0.0, 0.9, 0.0);
+ glEnd();
+}
+
+
+static void
+Draw(void)
+{
+ static const GLdouble plane[4] = { 0, -1.0, 0, 0.5 };
+
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ glPointSize(13.0);
+ glLineWidth(5.0);
+
+ glClipPlane(GL_CLIP_PLANE0, plane);
+ glEnable(GL_CLIP_PLANE0);
+
+ glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+ GrayTri();
+
+ glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
+ ColorTri();
+
+ glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
+ ColorTri();
+
+ glutSwapBuffers();
+}
+
+
+static void Reshape(int width, int height)
+{
+ glViewport(0, 0, (GLint)width, (GLint)height);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
+ glMatrixMode(GL_MODELVIEW);
+}
+
+
+static void
+Key(unsigned char key, int x, int y)
+{
+ if (key == 27) {
+ glutDestroyWindow(win);
+ exit(0);
+ }
+ else {
+ glutPostRedisplay();
+ }
+}
+
+
+static void
+Init(void)
+{
+ fprintf(stderr, "GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
+ fprintf(stderr, "GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
+ fprintf(stderr, "GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR));
+ fflush(stderr);
+}
+
+
+int
+main(int argc, char **argv)
+{
+ glutInitWindowSize(300, 300);
+ glutInit(&argc, argv);
+ glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
+ win = glutCreateWindow(*argv);
+ if (!win) {
+ return 1;
+ }
+ Init();
+ glutReshapeFunc(Reshape);
+ glutKeyboardFunc(Key);
+ glutDisplayFunc(Draw);
+ glutMainLoop();
+ return 0;
+}
diff --git a/progs/trivial/vbo-tri.c b/progs/trivial/vbo-tri.c
new file mode 100644
index 0000000000..d4cba14414
--- /dev/null
+++ b/progs/trivial/vbo-tri.c
@@ -0,0 +1,131 @@
+/* Even simpler for many drivers than trivial/tri -- pass-through
+ * vertex shader and vertex data in a VBO.
+ */
+
+#include <assert.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include <GL/glew.h>
+#include <GL/glut.h>
+
+
+struct {
+ GLfloat pos[4];
+ GLfloat color[4];
+} verts[] =
+{
+ { { -0.9, -0.9, 0.0, 1.0 },
+ {.8,0,0, 1},
+ },
+
+ { { 0.9, -0.9, 0.0, 1.0 },
+ { 0, .9, 0, 1 },
+ },
+
+ { { 0, 0.9, 0.0, 1.0 },
+ {0,0,.7, 1},
+ },
+};
+
+GLuint arrayObj;
+
+static void Init( void )
+{
+ GLint errno;
+ GLuint prognum;
+
+ static const char *prog1 =
+ "!!ARBvp1.0\n"
+ "MOV result.color, vertex.color;\n"
+ "MOV result.position, vertex.position;\n"
+ "END\n";
+
+
+ glGenProgramsARB(1, &prognum);
+
+ glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prognum);
+ glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
+ strlen(prog1), (const GLubyte *) prog1);
+
+ assert(glIsProgramARB(prognum));
+ errno = glGetError();
+ printf("glGetError = %d\n", errno);
+ if (errno != GL_NO_ERROR)
+ {
+ GLint errorpos;
+
+ glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorpos);
+ printf("errorpos: %d\n", errorpos);
+ printf("%s\n", (char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB));
+ }
+
+
+ glEnableClientState( GL_VERTEX_ARRAY );
+ glEnableClientState( GL_COLOR_ARRAY );
+
+ glGenBuffersARB(1, &arrayObj);
+ glBindBufferARB(GL_ARRAY_BUFFER_ARB, arrayObj);
+ glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(verts), verts, GL_STATIC_DRAW_ARB);
+
+ glVertexPointer( 4, GL_FLOAT, sizeof(verts[0]), 0 );
+ glColorPointer( 4, GL_FLOAT, sizeof(verts[0]), (void *)(4*sizeof(float)) );
+}
+
+
+
+static void Display( void )
+{
+ glClearColor(0.3, 0.3, 0.3, 1);
+ glClear( GL_COLOR_BUFFER_BIT );
+
+ glEnable(GL_VERTEX_PROGRAM_NV);
+ glDrawArrays( GL_TRIANGLES, 0, 3 );
+
+ glutSwapBuffers();
+}
+
+
+static void Reshape( int width, int height )
+{
+ glViewport( 0, 0, width, height );
+ glMatrixMode( GL_PROJECTION );
+ glLoadIdentity();
+ glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
+ glMatrixMode( GL_MODELVIEW );
+ glLoadIdentity();
+ /*glTranslatef( 0.0, 0.0, -15.0 );*/
+}
+
+
+static void Key( unsigned char key, int x, int y )
+{
+ (void) x;
+ (void) y;
+ switch (key) {
+ case 27:
+ exit(0);
+ break;
+ }
+ glutPostRedisplay();
+}
+
+
+
+
+int main( int argc, char *argv[] )
+{
+ glutInit( &argc, argv );
+ glutInitWindowPosition( 0, 0 );
+ glutInitWindowSize( 250, 250 );
+ glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
+ glutCreateWindow(argv[0]);
+ glewInit();
+ glutReshapeFunc( Reshape );
+ glutKeyboardFunc( Key );
+ glutDisplayFunc( Display );
+ Init();
+ glutMainLoop();
+ return 0;
+}
diff --git a/progs/vp/SConscript b/progs/vp/SConscript
index 640c5dd847..787cb793af 100644
--- a/progs/vp/SConscript
+++ b/progs/vp/SConscript
@@ -1,13 +1,6 @@
-Import('env')
+Import('*')
-if not env['GLUT']:
- Return()
-
-env = env.Clone()
-
-env.Prepend(LIBS = ['$GLUT_LIB'])
-
-env.Program(
+progs_env.Program(
target = 'vp-tris',
source = ['vp-tris.c'],
)
diff --git a/progs/vp/add-param-imm.txt b/progs/vp/add-param-imm.txt
new file mode 100644
index 0000000000..90bcf96528
--- /dev/null
+++ b/progs/vp/add-param-imm.txt
@@ -0,0 +1,7 @@
+!!ARBvp1.0
+TEMP R0;
+PARAM Emission = state.material.emission;
+ADD R0, vertex.color, {-0.5}.x;
+ADD result.color, R0, Emission.w;
+MOV result.position, vertex.position;
+END
diff --git a/progs/vpglsl/SConscript b/progs/vpglsl/SConscript
index 640c5dd847..787cb793af 100644
--- a/progs/vpglsl/SConscript
+++ b/progs/vpglsl/SConscript
@@ -1,13 +1,6 @@
-Import('env')
+Import('*')
-if not env['GLUT']:
- Return()
-
-env = env.Clone()
-
-env.Prepend(LIBS = ['$GLUT_LIB'])
-
-env.Program(
+progs_env.Program(
target = 'vp-tris',
source = ['vp-tris.c'],
)
diff --git a/progs/wgl/SConscript b/progs/wgl/SConscript
index 31f61676de..248cc53a8d 100644
--- a/progs/wgl/SConscript
+++ b/progs/wgl/SConscript
@@ -1,25 +1,17 @@
Import('*')
-if env['platform'] != 'windows':
+if progs_env['platform'] != 'windows':
Return()
-env = env.Clone()
-
-env.Append(LIBS = [
- 'kernel32',
- 'user32',
- 'gdi32',
-])
-
progs = [
'sharedtex_mt',
'wglthreads',
]
for prog in progs:
- env.Program(
+ progs_env.Program(
target = prog,
source = prog + '/' + prog + '.c',
)
-env.Program('wglinfo', ['wglinfo.c'])
+progs_env.Program('wglinfo', ['wglinfo.c'])
diff --git a/progs/xdemos/.gitignore b/progs/xdemos/.gitignore
index 1b9b3a87c0..5ae0f5a062 100644
--- a/progs/xdemos/.gitignore
+++ b/progs/xdemos/.gitignore
@@ -26,3 +26,4 @@ xdemo
xfont
xrotfontdemo
yuvrect_client
+msctest
diff --git a/progs/xdemos/Makefile b/progs/xdemos/Makefile
index 77f667978c..f866a32865 100644
--- a/progs/xdemos/Makefile
+++ b/progs/xdemos/Makefile
@@ -29,6 +29,7 @@ PROGS = \
glxsnoop \
glxswapcontrol \
manywin \
+ msctest \
multictx \
offset \
overlay \
diff --git a/progs/xdemos/glsync.c b/progs/xdemos/glsync.c
index 9d4b0f1ce2..c00ba9e468 100644
--- a/progs/xdemos/glsync.c
+++ b/progs/xdemos/glsync.c
@@ -59,6 +59,7 @@
void (*video_sync_get)();
void (*video_sync)();
+void (*swap_interval)();
static int GLXExtensionSupported(Display *dpy, const char *extension)
{
@@ -84,7 +85,7 @@ static int GLXExtensionSupported(Display *dpy, const char *extension)
extern char *optarg;
extern int optind, opterr, optopt;
-static char optstr[] = "w:h:s:v";
+static char optstr[] = "w:h:s:vi:";
enum sync_type {
none = 0,
@@ -100,6 +101,7 @@ static void usage(char *name)
printf("\t\tn: none\n");
printf("\t\ts: SGI video sync extension\n");
printf("\t\tb: buffer swap\n");
+ printf("\t-i<swap interval>\n");
printf("\t-v: verbose (print count)\n");
exit(-1);
}
@@ -109,16 +111,28 @@ int main(int argc, char *argv[])
Display *disp;
XVisualInfo *pvi;
XSetWindowAttributes swa;
- int attrib[14];
GLint last_val = -1, count = 0;
Window winGL;
GLXContext context;
int dummy;
Atom wmDelete;
enum sync_type waitforsync = none;
- int width = 500, height = 500, verbose = 0,
- countonly = 0;
+ int width = 500, height = 500, verbose = 0, interval = 1;
int c, i = 1;
+ int ret;
+ int attribs[] = { GLX_RGBA,
+ GLX_RED_SIZE, 1,
+ GLX_GREEN_SIZE, 1,
+ GLX_BLUE_SIZE, 1,
+ None };
+ int db_attribs[] = { GLX_RGBA,
+ GLX_RED_SIZE, 1,
+ GLX_GREEN_SIZE, 1,
+ GLX_BLUE_SIZE, 1,
+ GLX_DOUBLEBUFFER,
+ GLX_DEPTH_SIZE, 1,
+ None };
+ XSizeHints sizehints;
opterr = 0;
while ((c = getopt(argc, argv, optstr)) != -1) {
@@ -148,6 +162,9 @@ int main(int argc, char *argv[])
case 'v':
verbose = 1;
break;
+ case 'i':
+ interval = atoi(optarg);
+ break;
default:
usage(argv[0]);
break;
@@ -170,34 +187,17 @@ int main(int argc, char *argv[])
return -1;
}
- attrib[0] = GLX_RGBA;
- attrib[1] = 1;
- attrib[2] = GLX_RED_SIZE;
- attrib[3] = 1;
- attrib[4] = GLX_GREEN_SIZE;
- attrib[5] = 1;
- attrib[6] = GLX_BLUE_SIZE;
- attrib[7] = 1;
- if (waitforsync != buffer_swap)
- attrib[8] = None;
- else {
- attrib[8] = GLX_DOUBLEBUFFER;
- attrib[9] = 1;
- attrib[10] = None;
+ if (waitforsync != buffer_swap) {
+ pvi = glXChooseVisual(disp, DefaultScreen(disp), attribs);
+ } else {
+ pvi = glXChooseVisual(disp, DefaultScreen(disp), db_attribs);
}
- pvi = glXChooseVisual(disp, DefaultScreen(disp), attrib);
if (!pvi) {
fprintf(stderr, "failed to choose visual, exiting\n");
return -1;
}
- context = glXCreateContext(disp, pvi, None, GL_TRUE);
- if (!context) {
- fprintf(stderr, "failed to create glx context\n");
- return -1;
- }
-
pvi->screen = DefaultScreen(disp);
swa.colormap = XCreateColormap(disp, RootWindow(disp, pvi->screen),
@@ -217,24 +217,58 @@ int main(int argc, char *argv[])
wmDelete = XInternAtom(disp, "WM_DELETE_WINDOW", True);
XSetWMProtocols(disp, winGL, &wmDelete, 1);
+ sizehints.x = 0;
+ sizehints.y = 0;
+ sizehints.width = width;
+ sizehints.height = height;
+ sizehints.flags = USSize | USPosition;
+
+ XSetNormalHints(disp, winGL, &sizehints);
XSetStandardProperties(disp, winGL, "glsync test", "glsync text",
- None, NULL, 0, NULL);
+ None, NULL, 0, &sizehints);
- XMapRaised(disp, winGL);
+ context = glXCreateContext(disp, pvi, NULL, GL_TRUE);
+ if (!context) {
+ fprintf(stderr, "failed to create glx context\n");
+ return -1;
+ }
- glXMakeCurrent(disp, winGL, context);
+ XMapWindow(disp, winGL);
+ ret = glXMakeCurrent(disp, winGL, context);
+ if (ret) {
+ fprintf(stderr, "failed to make context current: %d\n", ret);
+ }
video_sync_get = glXGetProcAddress((unsigned char *)"glXGetVideoSyncSGI");
video_sync = glXGetProcAddress((unsigned char *)"glXWaitVideoSyncSGI");
- if (!video_sync_get || !video_sync) {
+ swap_interval = glXGetProcAddress((unsigned char *)"glXSwapIntervalSGI");
+
+ if (!video_sync_get || !video_sync || !swap_interval) {
fprintf(stderr, "failed to get sync functions\n");
return -1;
}
+ if (waitforsync == buffer_swap) {
+ swap_interval(interval);
+ fprintf(stderr, "set swap interval to %d\n", interval);
+ }
video_sync_get(&count);
count++;
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
while (i++) {
+ /* Alternate colors to make tearing obvious */
+ if (i & 1) {
+ glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
+ glColor3f(1.0f, 1.0f, 1.0f);
+ } else {
+ glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
+ glColor3f(1.0f, 0.0f, 0.0f);
+ }
+
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ glRectf(0, 0, width, height);
+
/* Wait for vsync */
if (waitforsync == sgi_video_sync) {
if (verbose)
@@ -245,24 +279,19 @@ int main(int argc, char *argv[])
if (count == last_val)
fprintf(stderr, "error: count didn't change: %d\n", count);
last_val = count;
+ glFlush();
} else if (waitforsync == buffer_swap) {
glXSwapBuffers(disp, winGL);
+ } else {
+ video_sync_get(&count);
+ sleep(1);
+ glFinish();
}
- if (countonly) {
- video_sync(2, 1, &count);
+ if (verbose) {
+ video_sync_get(&count);
fprintf(stderr, "current count: %d\n", count);
- sleep(1);
- continue;
}
-
- /* Alternate colors to make tearing obvious */
- if (i & 1)
- glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
- else
- glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
- glClear(GL_COLOR_BUFFER_BIT);
- glFlush();
}
XDestroyWindow(disp, winGL);
diff --git a/progs/xdemos/msctest.c b/progs/xdemos/msctest.c
new file mode 100644
index 0000000000..001ecf04d6
--- /dev/null
+++ b/progs/xdemos/msctest.c
@@ -0,0 +1,202 @@
+/*
+ * Copyright © 2009 Intel Corporation
+ *
+ * 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 (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Authors:
+ * Jesse Barnes <jesse.barnes@intel.com>
+ *
+ */
+
+/** @file msctest.c
+ * Simple test for MSC functionality.
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <GL/gl.h>
+#include <GL/glu.h>
+#include <GL/glx.h>
+#include <GL/glxext.h>
+#include <X11/X.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+
+void (*get_sync_values)(Display *dpy, Window winGL, int64_t *ust, int64_t *msc, int64_t *sbc);
+void (*wait_sync)(Display *dpy, Window winGL, int64_t target_msc, int64_t divisor, int64_t remainder, int64_t *ust, int64_t *msc, int64_t *sbc);
+
+static int GLXExtensionSupported(Display *dpy, const char *extension)
+{
+ const char *extensionsString, *client_extensions, *pos;
+
+ extensionsString = glXQueryExtensionsString(dpy, DefaultScreen(dpy));
+ client_extensions = glXGetClientString(dpy, GLX_EXTENSIONS);
+
+ pos = strstr(extensionsString, extension);
+
+ if (pos != NULL && (pos == extensionsString || pos[-1] == ' ') &&
+ (pos[strlen(extension)] == ' ' || pos[strlen(extension)] == '\0'))
+ return 1;
+
+ pos = strstr(client_extensions, extension);
+
+ if (pos != NULL && (pos == extensionsString || pos[-1] == ' ') &&
+ (pos[strlen(extension)] == ' ' || pos[strlen(extension)] == '\0'))
+ return 1;
+
+ return 0;
+}
+
+extern char *optarg;
+extern int optind, opterr, optopt;
+static char optstr[] = "v";
+
+static void usage(char *name)
+{
+ printf("usage: %s\n", name);
+ exit(-1);
+}
+
+int main(int argc, char *argv[])
+{
+ Display *disp;
+ XVisualInfo *pvi;
+ XSetWindowAttributes swa;
+ int attrib[14];
+ Window winGL;
+ GLXContext context;
+ int dummy;
+ Atom wmDelete;
+ int verbose = 0, width = 200, height = 200;
+ int c, i = 1;
+ int64_t ust, msc, sbc;
+
+ opterr = 0;
+ while ((c = getopt(argc, argv, optstr)) != -1) {
+ switch (c) {
+ case 'v':
+ verbose = 1;
+ break;
+ default:
+ usage(argv[0]);
+ break;
+ }
+ }
+
+ disp = XOpenDisplay(NULL);
+ if (!disp) {
+ fprintf(stderr, "failed to open display\n");
+ return -1;
+ }
+
+ if (!glXQueryExtension(disp, &dummy, &dummy)) {
+ fprintf(stderr, "glXQueryExtension failed\n");
+ return -1;
+ }
+
+ if (!GLXExtensionSupported(disp, "GLX_OML_sync_control")) {
+ fprintf(stderr, "GLX_OML_sync_control not supported, exiting\n");
+ return -1;
+ }
+
+ attrib[0] = GLX_RGBA;
+ attrib[1] = 1;
+ attrib[2] = GLX_RED_SIZE;
+ attrib[3] = 1;
+ attrib[4] = GLX_GREEN_SIZE;
+ attrib[5] = 1;
+ attrib[6] = GLX_BLUE_SIZE;
+ attrib[7] = 1;
+ attrib[8] = GLX_DOUBLEBUFFER;
+ attrib[9] = 1;
+ attrib[10] = None;
+
+ pvi = glXChooseVisual(disp, DefaultScreen(disp), attrib);
+ if (!pvi) {
+ fprintf(stderr, "failed to choose visual, exiting\n");
+ return -1;
+ }
+
+ context = glXCreateContext(disp, pvi, None, GL_TRUE);
+ if (!context) {
+ fprintf(stderr, "failed to create glx context\n");
+ return -1;
+ }
+
+ pvi->screen = DefaultScreen(disp);
+
+ swa.colormap = XCreateColormap(disp, RootWindow(disp, pvi->screen),
+ pvi->visual, AllocNone);
+ swa.border_pixel = 0;
+ swa.event_mask = ExposureMask | KeyPressMask | ButtonPressMask |
+ StructureNotifyMask;
+ winGL = XCreateWindow(disp, RootWindow(disp, pvi->screen),
+ 0, 0,
+ width, height,
+ 0, pvi->depth, InputOutput, pvi->visual,
+ CWBorderPixel | CWColormap | CWEventMask, &swa);
+ if (!winGL) {
+ fprintf(stderr, "window creation failed\n");
+ return -1;
+ }
+ wmDelete = XInternAtom(disp, "WM_DELETE_WINDOW", True);
+ XSetWMProtocols(disp, winGL, &wmDelete, 1);
+
+ XSetStandardProperties(disp, winGL, "msc test", "msc text",
+ None, NULL, 0, NULL);
+
+ XMapRaised(disp, winGL);
+
+ glXMakeCurrent(disp, winGL, context);
+
+ get_sync_values = glXGetProcAddress((unsigned char *)"glXGetSyncValuesOML");
+ wait_sync = glXGetProcAddress((unsigned char *)"glXWaitForMscOML");
+
+ if (!get_sync_values || !wait_sync) {
+ fprintf(stderr, "failed to get sync values function\n");
+ return -1;
+ }
+
+ while (i++) {
+ get_sync_values(disp, winGL, &ust, &msc, &sbc);
+ fprintf(stderr, "ust: %llu, msc: %llu, sbc: %llu\n", ust, msc,
+ sbc);
+
+ /* Alternate colors to make tearing obvious */
+ if (i & 1)
+ glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
+ else
+ glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
+ glClear(GL_COLOR_BUFFER_BIT);
+ glXSwapBuffers(disp, winGL);
+ wait_sync(disp, winGL, 0, 60, 0, &ust, &msc, &sbc);
+ fprintf(stderr,
+ "wait returned ust: %llu, msc: %llu, sbc: %llu\n",
+ ust, msc, sbc);
+ sleep(1);
+ }
+
+ XDestroyWindow(disp, winGL);
+ glXDestroyContext(disp, context);
+ XCloseDisplay(disp);
+
+ return 0;
+}
diff --git a/progs/xdemos/offset.c b/progs/xdemos/offset.c
index 314a4fcdd1..3858a5b802 100644
--- a/progs/xdemos/offset.c
+++ b/progs/xdemos/offset.c
@@ -94,6 +94,9 @@ static int attributeList[] = { GLX_RGBA, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1,
static int dimension = 3;
+static float Scale = 1.0;
+
+
int main(int argc, char** argv) {
Display *dpy;
XVisualInfo *vi;
@@ -182,6 +185,7 @@ draw_scene(int mx, int my) {
#else
glEnable(GL_POLYGON_OFFSET_FILL);
#endif
+ glScalef(Scale, Scale, Scale);
cubes(mx, my, HIDDEN_LINE);
#ifdef GL_EXT_polygon_offset
glDisable(GL_POLYGON_OFFSET_EXT);
@@ -289,6 +293,12 @@ process_input(Display *dpy, Window win) {
case KeyPress:
(void) XLookupString(&event.xkey, buf, sizeof(buf), &keysym, NULL);
switch (keysym) {
+ case 'Z':
+ Scale *= 1.1;
+ break;
+ case 'z':
+ Scale *= 0.9;
+ break;
case XK_Escape:
exit(EXIT_SUCCESS);
default: