summaryrefslogtreecommitdiff
path: root/progs
diff options
context:
space:
mode:
Diffstat (limited to 'progs')
-rw-r--r--progs/SConscript2
-rw-r--r--progs/demos/dissolve.c137
-rw-r--r--progs/demos/stex3d.c15
-rw-r--r--progs/egl/Makefile70
-rw-r--r--progs/egl/egltri.c264
-rw-r--r--progs/egl/eglut/Makefile35
-rw-r--r--progs/egl/eglut/eglut.c346
-rw-r--r--progs/egl/eglut/eglut.h68
-rw-r--r--progs/egl/eglut/eglut_screen.c154
-rw-r--r--progs/egl/eglut/eglut_x11.c220
-rw-r--r--progs/egl/eglut/eglutint.h78
-rw-r--r--progs/egl/opengl/.gitignore (renamed from progs/egl/.gitignore)7
-rw-r--r--progs/egl/opengl/Makefile83
-rw-r--r--progs/egl/opengl/demo1.c (renamed from progs/egl/demo1.c)0
-rw-r--r--progs/egl/opengl/demo2.c (renamed from progs/egl/demo2.c)0
-rw-r--r--progs/egl/opengl/demo3.c (renamed from progs/egl/demo3.c)0
-rw-r--r--progs/egl/opengl/eglgears.c (renamed from progs/egl/eglgears.c)241
-rw-r--r--progs/egl/opengl/eglinfo.c (renamed from progs/egl/eglinfo.c)0
-rw-r--r--progs/egl/opengl/eglscreen.c (renamed from progs/egl/eglscreen.c)0
-rw-r--r--progs/egl/opengl/egltri.c (renamed from progs/es1/screen/tri.c)138
-rw-r--r--progs/egl/opengl/peglgears.c (renamed from progs/egl/peglgears.c)0
-rw-r--r--progs/egl/opengl/xeglgears.c (renamed from progs/egl/xeglgears.c)0
-rw-r--r--progs/egl/opengl/xeglthreads.c (renamed from progs/egl/xeglthreads.c)0
-rw-r--r--progs/egl/opengles1/.gitignore15
-rw-r--r--progs/egl/opengles1/Makefile102
-rw-r--r--progs/egl/opengles1/bindtex.c (renamed from progs/es1/xegl/bindtex.c)0
-rw-r--r--progs/egl/opengles1/drawtex.c217
-rw-r--r--progs/egl/opengles1/es1_info.c (renamed from progs/es1/xegl/es1_info.c)0
-rw-r--r--progs/egl/opengles1/gears.c (renamed from progs/es1/screen/gears.c)43
-rw-r--r--progs/egl/opengles1/msaa.c (renamed from progs/es1/xegl/msaa.c)0
-rw-r--r--progs/egl/opengles1/pbuffer.c (renamed from progs/es1/xegl/pbuffer.c)3
-rw-r--r--progs/egl/opengles1/render_tex.c (renamed from progs/es1/xegl/render_tex.c)0
-rw-r--r--progs/egl/opengles1/texture_from_pixmap.c578
-rw-r--r--progs/egl/opengles1/torus.c (renamed from progs/es1/xegl/torus.c)328
-rw-r--r--progs/egl/opengles1/tri.c211
-rw-r--r--progs/egl/opengles1/two_win.c (renamed from progs/es1/xegl/two_win.c)0
-rw-r--r--progs/egl/opengles2/.gitignore3
-rw-r--r--progs/egl/opengles2/Makefile (renamed from progs/es2/xegl/Makefile)4
-rw-r--r--progs/egl/opengles2/tri.c (renamed from progs/es2/xegl/tri.c)0
-rw-r--r--progs/egl/openvg/.gitignore (renamed from progs/openvg/.gitignore)6
-rw-r--r--progs/egl/openvg/Makefile55
-rw-r--r--progs/egl/openvg/lion-render.c (renamed from progs/openvg/demos/lion-render.c)0
-rw-r--r--progs/egl/openvg/lion-render.h (renamed from progs/openvg/demos/lion-render.h)0
-rw-r--r--progs/egl/openvg/lion.c65
-rw-r--r--progs/egl/openvg/sp.c (renamed from progs/openvg/demos/sp.c)47
-rw-r--r--progs/egl/openvg/trivial/Makefile (renamed from progs/openvg/trivial/Makefile)3
-rw-r--r--progs/egl/openvg/trivial/arc.c (renamed from progs/openvg/trivial/arc.c)0
-rw-r--r--progs/egl/openvg/trivial/cap.c (renamed from progs/openvg/trivial/cap.c)0
-rw-r--r--progs/egl/openvg/trivial/clear.c (renamed from progs/openvg/trivial/clear.c)0
-rw-r--r--progs/egl/openvg/trivial/coord.c (renamed from progs/openvg/trivial/coord.c)0
-rw-r--r--progs/egl/openvg/trivial/dash.c (renamed from progs/openvg/trivial/dash.c)0
-rw-r--r--progs/egl/openvg/trivial/eglcommon.c (renamed from progs/openvg/demos/eglcommon.c)0
-rw-r--r--progs/egl/openvg/trivial/eglcommon.h (renamed from progs/openvg/demos/eglcommon.h)0
-rw-r--r--progs/egl/openvg/trivial/ellipse.c (renamed from progs/openvg/trivial/ellipse.c)0
-rw-r--r--progs/egl/openvg/trivial/filter.c (renamed from progs/openvg/trivial/filter.c)0
-rw-r--r--progs/egl/openvg/trivial/gradorigin.c (renamed from progs/openvg/trivial/gradorigin.c)0
-rw-r--r--progs/egl/openvg/trivial/lineto.c (renamed from progs/openvg/trivial/lineto.c)0
-rw-r--r--progs/egl/openvg/trivial/lingrad.c (renamed from progs/openvg/trivial/lingrad.c)0
-rw-r--r--progs/egl/openvg/trivial/lookup.c (renamed from progs/openvg/trivial/lookup.c)0
-rw-r--r--progs/egl/openvg/trivial/mask.c (renamed from progs/openvg/trivial/mask.c)0
-rw-r--r--progs/egl/openvg/trivial/mask4.c (renamed from progs/openvg/trivial/mask4.c)0
-rw-r--r--progs/egl/openvg/trivial/path3.c (renamed from progs/openvg/trivial/path3.c)0
-rw-r--r--progs/egl/openvg/trivial/radialgrad.c (renamed from progs/openvg/trivial/radialgrad.c)0
-rw-r--r--progs/egl/openvg/trivial/readpixels.c (renamed from progs/openvg/trivial/readpixels.c)0
-rw-r--r--progs/egl/openvg/trivial/roundedrect.c (renamed from progs/openvg/trivial/roundedrect.c)0
-rw-r--r--progs/egl/openvg/trivial/star-nonzero.c (renamed from progs/openvg/trivial/star-nonzero.c)0
-rw-r--r--progs/egl/openvg/trivial/star-oddeven.c (renamed from progs/openvg/trivial/star-oddeven.c)0
-rw-r--r--progs/egl/openvg/trivial/stroke.c (renamed from progs/openvg/trivial/stroke.c)0
-rw-r--r--progs/egl/openvg/trivial/stroke2.c (renamed from progs/openvg/trivial/stroke2.c)0
-rw-r--r--progs/egl/openvg/trivial/vguarc.c (renamed from progs/openvg/trivial/vguarc.c)0
-rw-r--r--progs/egl/xegl_tri.c361
-rw-r--r--progs/es1/.gitignore11
-rw-r--r--progs/es1/screen/Makefile32
-rw-r--r--progs/es1/screen/winsys.c272
-rw-r--r--progs/es1/screen/winsys.h36
-rw-r--r--progs/es1/xegl/Makefile82
-rw-r--r--progs/es1/xegl/drawtex.c427
-rw-r--r--progs/es1/xegl/tri.c470
-rw-r--r--progs/es2/.gitignore3
-rw-r--r--progs/fpglsl/dowhile.glsl8
-rw-r--r--progs/fpglsl/dowhile2.glsl10
-rw-r--r--progs/fpglsl/for.glsl11
-rw-r--r--progs/fpglsl/forbreak.glsl13
-rw-r--r--progs/fpglsl/fp-tri.c5
-rw-r--r--progs/fpglsl/simpleif.glsl6
-rw-r--r--progs/fpglsl/while.glsl7
-rw-r--r--progs/fpglsl/while2.glsl9
-rwxr-xr-xprogs/gallium/python/retrace/interpreter.py1
-rw-r--r--progs/gallium/python/samples/tri.py21
-rwxr-xr-xprogs/gallium/python/tests/base.py91
-rwxr-xr-xprogs/gallium/python/tests/surface_copy.py130
-rwxr-xr-xprogs/gallium/python/tests/texture_blit.py (renamed from progs/gallium/python/tests/texture_sample.py)203
-rwxr-xr-xprogs/gallium/python/tests/texture_render.py4
-rwxr-xr-xprogs/gallium/python/tests/texture_transfer.py115
-rw-r--r--progs/gallium/raw/SConscript17
-rw-r--r--progs/gallium/raw/clear.c95
-rw-r--r--progs/gallium/trivial/.gitignore3
-rw-r--r--progs/gallium/trivial/Makefile44
-rw-r--r--progs/gallium/trivial/quad-tex.c346
-rw-r--r--progs/gallium/trivial/tri.c278
-rw-r--r--progs/gallium/unit/Makefile44
-rw-r--r--progs/gallium/unit/SConscript5
-rw-r--r--progs/gallium/unit/u_format_test.c1144
-rw-r--r--progs/gallium/unit/u_half_test.c32
-rw-r--r--progs/glsl/Makefile4
-rw-r--r--progs/glsl/SConscript2
-rw-r--r--progs/glsl/fsraytrace.c412
-rw-r--r--progs/glsl/vsraytrace.c401
-rw-r--r--progs/objviewer/skybox.c4
-rw-r--r--progs/openvg/demos/Makefile39
-rw-r--r--progs/openvg/demos/lion.c289
-rw-r--r--progs/openvg/trivial/eglcommon.c289
-rw-r--r--progs/openvg/trivial/eglcommon.h20
-rw-r--r--progs/samples/copy.c27
-rw-r--r--progs/samples/loadppm.c6
-rw-r--r--progs/tests/fbotest1.c6
-rw-r--r--progs/tests/fbotest2.c52
-rw-r--r--progs/tests/fbotest3.c6
-rw-r--r--progs/tests/stencil_twoside.c85
-rw-r--r--progs/trivial/Makefile1
-rw-r--r--progs/trivial/SConscript3
-rw-r--r--progs/trivial/clear-fbo-scissor.c234
-rw-r--r--progs/trivial/tri-stencil.c3
-rw-r--r--progs/xdemos/Makefile4
-rw-r--r--progs/xdemos/omlsync.c10
125 files changed, 5607 insertions, 4164 deletions
diff --git a/progs/SConscript b/progs/SConscript
index aa6640cf7a..4cd35fec64 100644
--- a/progs/SConscript
+++ b/progs/SConscript
@@ -24,6 +24,7 @@ if progs_env['platform'] == 'windows':
if progs_env['platform'] == 'windows':
progs_env.Prepend(LIBS = ['glu32', 'opengl32'])
else:
+ progs_env.Tool('x11')
progs_env.Prepend(LIBS = ['GLU', 'GL'])
# Glut
@@ -56,4 +57,5 @@ SConscript([
'wgl/SConscript',
'perf/SConscript',
'gallium/unit/SConscript',
+# 'gallium/raw/SConscript',
])
diff --git a/progs/demos/dissolve.c b/progs/demos/dissolve.c
index 0b8df1bb66..8ab5242d91 100644
--- a/progs/demos/dissolve.c
+++ b/progs/demos/dissolve.c
@@ -1,5 +1,5 @@
/**
- * Dissolve between two images using randomized stencil buffer
+ * Dissolve between two images using randomized/patterned stencil buffer
* and varying stencil ref.
*
* Brian Paul
@@ -9,6 +9,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <math.h>
#include <GL/glut.h>
#include "readtex.h"
@@ -28,6 +29,8 @@ static GLfloat ScaleX[2], ScaleY[2];
static GLubyte StencilRef = 0;
+static int Mode = 0;
+
static void
Idle(void)
@@ -38,13 +41,114 @@ Idle(void)
static void
-RandomizeStencilBuffer(void)
+FillRandomPixels(GLubyte *b)
{
- GLubyte *b = malloc(WinWidth * WinHeight);
int i;
for (i = 0; i < WinWidth * WinHeight; i++) {
b[i] = rand() & 0xff;
}
+}
+
+
+static void
+FillRandomRects(GLubyte *b)
+{
+ int i;
+
+ memset(b, 0, WinWidth * WinHeight);
+
+ for (i = 0; i < 256; i++) {
+ int x = rand() % WinWidth;
+ int y = rand() % WinHeight;
+ int w = rand() % 60;
+ int h = rand() % 60;
+ int ix, iy;
+
+ if (x + w > WinWidth)
+ w = WinWidth - x;
+ if (y + h > WinHeight)
+ h = WinHeight - y;
+
+ for (iy = 0; iy < h; iy++) {
+ for (ix = 0; ix < w; ix++) {
+ int p = (y + iy) * WinWidth + x + ix;
+ b[p] = i;
+ }
+ }
+ }
+}
+
+
+static void
+FillWipe(GLubyte *b)
+{
+ int iy, ix;
+
+ memset(b, 0, WinWidth * WinHeight);
+
+ for (iy = 0; iy < WinHeight; iy++) {
+ for (ix = 0; ix < WinWidth; ix++) {
+ int p = iy * WinWidth + ix;
+ b[p] = 2 * ix + iy / 2;
+ }
+ }
+}
+
+
+static void
+FillMoire(GLubyte *b)
+{
+ int iy, ix;
+
+ memset(b, 0, WinWidth * WinHeight);
+
+ for (iy = 0; iy < WinHeight; iy++) {
+ for (ix = 0; ix < WinWidth; ix++) {
+ int p = iy * WinWidth + ix;
+ b[p] = (ix / 2) * (ix / 2) - (iy / 2) * (iy / 2);
+ }
+ }
+}
+
+
+static void
+FillWaves(GLubyte *b)
+{
+ int iy, ix;
+
+ memset(b, 0, WinWidth * WinHeight);
+
+ for (iy = 0; iy < WinHeight; iy++) {
+ for (ix = 0; ix < WinWidth; ix++) {
+ int p = iy * WinWidth + ix;
+ float x = 8.0 * 3.1415 * ix / (float) WinWidth;
+ b[p] = (int) (25.0 * sin(x) ) - iy*2;
+ }
+ }
+}
+
+
+typedef void (*FillFunc)(GLubyte *b);
+
+
+static FillFunc Funcs[] = {
+ FillRandomPixels,
+ FillRandomRects,
+ FillWipe,
+ FillMoire,
+ FillWaves
+};
+
+#define NUM_MODES (sizeof(Funcs) / sizeof(Funcs[0]))
+
+
+
+static void
+InitStencilBuffer(void)
+{
+ GLubyte *b = malloc(WinWidth * WinHeight);
+
+ Funcs[Mode](b);
glStencilFunc(GL_ALWAYS, 0, ~0);
glPixelZoom(1.0, 1.0);
@@ -54,7 +158,6 @@ RandomizeStencilBuffer(void)
}
-
static void
Draw(void)
{
@@ -85,7 +188,7 @@ Reshape(int width, int height)
glLoadIdentity();
glTranslatef(0.0, 0.0, -15.0);
- RandomizeStencilBuffer();
+ InitStencilBuffer();
ScaleX[0] = (float) width / ImgWidth[0];
ScaleY[0] = (float) height / ImgHeight[0];
@@ -102,12 +205,26 @@ Key(unsigned char key, int x, int y)
(void) y;
switch (key) {
case 'a':
+ case ' ':
Anim = !Anim;
if (Anim)
glutIdleFunc(Idle);
else
glutIdleFunc(NULL);
break;
+ case 'i':
+ InitStencilBuffer();
+ break;
+ case '-':
+ StencilRef--;
+ break;
+ case '+':
+ StencilRef++;
+ break;
+ case 'm':
+ Mode = (Mode + 1) % NUM_MODES;
+ InitStencilBuffer();
+ break;
case 27:
glutDestroyWindow(Win);
exit(0);
@@ -143,8 +260,8 @@ Init(void)
int
main(int argc, char *argv[])
{
- glutInit(&argc, argv);
glutInitWindowSize(WinWidth, WinHeight);
+ glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_STENCIL);
Win = glutCreateWindow(argv[0]);
glutReshapeFunc(Reshape);
@@ -153,6 +270,14 @@ main(int argc, char *argv[])
if (Anim)
glutIdleFunc(Idle);
Init();
+
+ printf("Keys:\n");
+ printf(" a/SPACE toggle animation\n");
+ printf(" +/- single step\n");
+ printf(" i re-init pattern\n");
+ printf(" m change pattern/dissolve mode\n");
+ printf(" ESC exit\n");
+
glutMainLoop();
return 0;
}
diff --git a/progs/demos/stex3d.c b/progs/demos/stex3d.c
index c0bbea0960..de18480c25 100644
--- a/progs/demos/stex3d.c
+++ b/progs/demos/stex3d.c
@@ -36,6 +36,7 @@ static int tex_width=64, tex_height=64, tex_depth=64;
static float angx=0, angy=0, angz=0;
static int texgen = 2, animate = 1, smooth = 1, wireframe = 0;
static int CurTexture = NOISE_TEXTURE, CurObject = TORUS;
+static GLenum Filter = GL_LINEAR;
static void
@@ -298,8 +299,6 @@ create3Dtexture(void)
printf("setting up 3d texture...\n");
glBindTexture(GL_TEXTURE_3D, NOISE_TEXTURE);
- glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_REPEAT);
@@ -406,6 +405,9 @@ drawScene(void)
glDisable(GL_TEXTURE_GEN_R);
}
+ glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, Filter);
+ glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, Filter);
+
glCallList(CurObject);
glPopMatrix();
@@ -505,6 +507,12 @@ KeyHandler(unsigned char key, int x, int y)
else
CurObject = TORUS;
break;
+ case 'f':
+ if (Filter == GL_LINEAR)
+ Filter = GL_NEAREST;
+ else
+ Filter = GL_LINEAR;
+ break;
case 'i':
if (CurTexture == NOISE_TEXTURE)
CurTexture = GRADIENT_TEXTURE;
@@ -513,6 +521,7 @@ KeyHandler(unsigned char key, int x, int y)
glBindTexture(GL_TEXTURE_3D, CurTexture);
break;
case 'a':
+ case ' ':
animate = !animate;
if (animate)
glutIdleFunc(Idle);
@@ -559,8 +568,6 @@ create3Dgradient(void)
glBindTexture(GL_TEXTURE_3D, GRADIENT_TEXTURE);
- glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_REPEAT);
diff --git a/progs/egl/Makefile b/progs/egl/Makefile
deleted file mode 100644
index 25de6e1f70..0000000000
--- a/progs/egl/Makefile
+++ /dev/null
@@ -1,70 +0,0 @@
-# progs/egl/Makefile
-
-TOP = ../..
-include $(TOP)/configs/current
-
-
-INCLUDE_DIRS = -I$(TOP)/include
-
-HEADERS = $(TOP)/include/GLES/egl.h
-LIB_DEP = $(TOP)/$(LIB_DIR)/libEGL.so
-
-LIBS = -L$(TOP)/$(LIB_DIR) -lEGL -lGL
-
-PROGRAMS = \
- demo1 \
- demo2 \
- demo3 \
- egltri \
- eglinfo \
- eglgears \
- eglscreen \
- peglgears \
- xeglgears \
- xeglthreads \
- xegl_tri
-
-
-.c.o:
- $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $< -o $@
-
-
-
-default: $(PROGRAMS)
-
-demo1: demo1.o $(HEADERS) $(LIB_DEP)
- $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB)
-
-demo2: demo2.o $(HEADERS) $(LIB_DEP)
- $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB)
-
-demo3: demo3.o $(HEADERS) $(LIB_DEP)
- $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB)
-
-egltri: egltri.o $(HEADERS) $(LIB_DEP)
- $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB)
-
-eglinfo: eglinfo.o $(HEADERS) $(LIB_DEP)
- $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS)
-
-eglgears: eglgears.o $(HEADERS) $(LIB_DEP)
- $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB) -lm
-
-eglscreen: eglscreen.o $(HEADERS) $(LIB_DEP)
- $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB)
-
-peglgears: peglgears.o $(HEADERS) $(LIB_DEP)
- $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB) -lm
-
-xeglgears: xeglgears.o $(HEADERS) $(LIB_DEP)
- $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lm -L$(libdir) -lX11
-
-xeglthreads: xeglthreads.o $(HEADERS) $(LIB_DEP)
- $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lm -L$(libdir) -lX11
-
-xegl_tri: xegl_tri.o $(HEADERS) $(LIB_DEP)
- $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lm -L$(libdir) -lX11
-
-clean:
- -rm -f *.o *~
- -rm -f $(PROGRAMS)
diff --git a/progs/egl/egltri.c b/progs/egl/egltri.c
deleted file mode 100644
index 006e06eb03..0000000000
--- a/progs/egl/egltri.c
+++ /dev/null
@@ -1,264 +0,0 @@
-/*
- * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
- * Copyright (C) 2008 Brian Paul All Rights Reserved.
- * Copyright (C) 2008 Jakob Bornecrantz All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-/*
- * This program is based on eglgears and xegl_tri.
- * Remixed by Jakob Bornecrantz
- *
- * No command line options.
- * Program runs for 5 seconds then exits, outputing framerate to console
- */
-
-#define EGL_EGLEXT_PROTOTYPES
-
-#include <assert.h>
-#include <math.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <GL/gl.h>
-#include <EGL/egl.h>
-#include <EGL/eglext.h>
-
-#define MAX_CONFIGS 10
-#define MAX_MODES 100
-
-
-/* XXX this probably isn't very portable */
-
-#include <sys/time.h>
-#include <unistd.h>
-
-/* return current time (in seconds) */
-static double
-current_time(void)
-{
- struct timeval tv;
-#ifdef __VMS
- (void) gettimeofday(&tv, NULL );
-#else
- struct timezone tz;
- (void) gettimeofday(&tv, &tz);
-#endif
- return (double) tv.tv_sec + tv.tv_usec / 1000000.0;
-}
-
-
-static GLfloat view_rotx = 0.0, view_roty = 0.0, view_rotz = 0.0;
-
-static void draw()
-{
- static const GLfloat verts[3][2] = {
- { -1, -1 },
- { 1, -1 },
- { 0, 1 }
- };
- static const GLfloat colors[3][3] = {
- { 1, 0, 0 },
- { 0, 1, 0 },
- { 0, 0, 1 }
- };
-
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- glPushMatrix();
- glRotatef(view_rotx, 1, 0, 0);
- glRotatef(view_roty, 0, 1, 0);
- glRotatef(view_rotz, 0, 0, 1);
-
- {
- glVertexPointer(2, GL_FLOAT, 0, verts);
- glColorPointer(3, GL_FLOAT, 0, colors);
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_COLOR_ARRAY);
-
- glDrawArrays(GL_TRIANGLES, 0, 3);
-
- glDisableClientState(GL_VERTEX_ARRAY);
- glDisableClientState(GL_COLOR_ARRAY);
- }
-
- glPopMatrix();
-}
-
-static void init()
-{
- glClearColor(0.4, 0.4, 0.4, 0.0);
-}
-
-/* new window size or exposure */
-static void reshape(int width, int height)
-{
- GLfloat ar = (GLfloat) width / (GLfloat) height;
-
- glViewport(0, 0, (GLint) width, (GLint) height);
-
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glFrustum(-ar, ar, -1, 1, 5.0, 60.0);
-
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTranslatef(0.0, 0.0, -10.0);
-}
-
-static void run(EGLDisplay dpy, EGLSurface surf, int ttr)
-{
- double st = current_time();
- double ct = st;
- int frames = 0;
- GLfloat seconds, fps;
-
- while (ct - st < ttr)
- {
- ct = current_time();
-
- draw();
-
- eglSwapBuffers(dpy, surf);
-
- frames++;
- }
-
- seconds = ct - st;
- fps = frames / seconds;
- printf("%d frames in %3.1f seconds = %6.3f FPS\n", frames, seconds, fps);
-}
-
-int main(int argc, char *argv[])
-{
- int maj, min;
- EGLContext ctx;
- EGLSurface screen_surf;
- EGLConfig configs[MAX_CONFIGS];
- EGLint numConfigs, i;
- EGLBoolean b;
- EGLDisplay d;
- EGLint screenAttribs[10];
- EGLModeMESA mode[MAX_MODES];
- EGLScreenMESA screen;
- EGLint count, chosenMode = 0;
- GLboolean printInfo = GL_FALSE;
- EGLint width = 0, height = 0;
-
- /* parse cmd line args */
- for (i = 1; i < argc; i++)
- {
- if (strcmp(argv[i], "-info") == 0)
- {
- printInfo = GL_TRUE;
- }
- else
- printf("Warning: unknown parameter: %s\n", argv[i]);
- }
-
- /* DBR : Create EGL context/surface etc */
- d = eglGetDisplay(EGL_DEFAULT_DISPLAY);
- assert(d);
-
- if (!eglInitialize(d, &maj, &min)) {
- printf("egltri: eglInitialize failed\n");
- exit(1);
- }
-
- printf("egltri: EGL version = %d.%d\n", maj, min);
- printf("egltri: EGL_VENDOR = %s\n", eglQueryString(d, EGL_VENDOR));
-
- /* XXX use ChooseConfig */
- eglGetConfigs(d, configs, MAX_CONFIGS, &numConfigs);
- eglGetScreensMESA(d, &screen, 1, &count);
-
- if (!eglGetModesMESA(d, screen, mode, MAX_MODES, &count) || count == 0) {
- printf("egltri: eglGetModesMESA failed!\n");
- return 0;
- }
-
- /* Print list of modes, and find the one to use */
- printf("egltri: Found %d modes:\n", count);
- for (i = 0; i < count; i++) {
- EGLint w, h;
- eglGetModeAttribMESA(d, mode[i], EGL_WIDTH, &w);
- eglGetModeAttribMESA(d, mode[i], EGL_HEIGHT, &h);
- printf("%3d: %d x %d\n", i, w, h);
- if (w > width && h > height) {
- width = w;
- height = h;
- chosenMode = i;
- }
- }
- printf("egltri: Using screen mode/size %d: %d x %d\n", chosenMode, width, height);
-
- eglBindAPI(EGL_OPENGL_API);
- ctx = eglCreateContext(d, configs[0], EGL_NO_CONTEXT, NULL);
- if (ctx == EGL_NO_CONTEXT) {
- printf("egltri: failed to create context\n");
- return 0;
- }
-
- /* build up screenAttribs array */
- i = 0;
- screenAttribs[i++] = EGL_WIDTH;
- screenAttribs[i++] = width;
- screenAttribs[i++] = EGL_HEIGHT;
- screenAttribs[i++] = height;
- screenAttribs[i++] = EGL_NONE;
-
- screen_surf = eglCreateScreenSurfaceMESA(d, configs[0], screenAttribs);
- if (screen_surf == EGL_NO_SURFACE) {
- printf("egltri: failed to create screen surface\n");
- return 0;
- }
-
- b = eglShowScreenSurfaceMESA(d, screen, screen_surf, mode[chosenMode]);
- if (!b) {
- printf("egltri: show surface failed\n");
- return 0;
- }
-
- b = eglMakeCurrent(d, screen_surf, screen_surf, ctx);
- if (!b) {
- printf("egltri: make current failed\n");
- return 0;
- }
-
- if (printInfo)
- {
- printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
- printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
- printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR));
- printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS));
- }
-
- init();
- reshape(width, height);
-
- glDrawBuffer( GL_BACK );
-
- run(d, screen_surf, 5.0);
-
- eglDestroySurface(d, screen_surf);
- eglDestroyContext(d, ctx);
- eglTerminate(d);
-
- return 0;
-}
diff --git a/progs/egl/eglut/Makefile b/progs/egl/eglut/Makefile
new file mode 100644
index 0000000000..f5cafa7010
--- /dev/null
+++ b/progs/egl/eglut/Makefile
@@ -0,0 +1,35 @@
+# progs/egl/eglut
+
+TOP = ../../..
+include $(TOP)/configs/current
+
+INCLUDES = \
+ -I$(TOP)/include
+
+SOURCES = $(wildcard *.c)
+
+EGLUT_X11_OBJECTS = eglut.o eglut_x11.o
+EGLUT_SCREEN_OBJECTS = eglut.o eglut_screen.o
+
+default: depend libeglut-x11.a libeglut-screen.a
+
+libeglut-x11.a: $(EGLUT_X11_OBJECTS)
+ $(MKLIB) -o eglut-x11 -static $(EGLUT_X11_OBJECTS)
+
+libeglut-screen.a: $(EGLUT_SCREEN_OBJECTS)
+ $(MKLIB) -o eglut-screen -static $(EGLUT_SCREEN_OBJECTS)
+
+.c.o:
+ $(CC) -c -o $@ $< $(INCLUDES) $(DEFINES) $(CFLAGS)
+
+depend: $(SOURCES)
+ @rm -f depend
+ @touch depend
+ @$(MKDEP) $(MKDEP_OPTIONS) $(INCLUDES) $(SOURCES) \
+ > /dev/null 2>/dev/null
+
+clean:
+ rm -f *.o *.a
+ rm -f depend depend.bak
+
+sinclude depend
diff --git a/progs/egl/eglut/eglut.c b/progs/egl/eglut/eglut.c
new file mode 100644
index 0000000000..b9b5e6e5a8
--- /dev/null
+++ b/progs/egl/eglut/eglut.c
@@ -0,0 +1,346 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+#include <sys/time.h>
+
+#include "EGL/egl.h"
+#include "EGL/eglext.h"
+
+#include "eglutint.h"
+
+static struct eglut_state _eglut_state = {
+ .api_mask = EGLUT_OPENGL_ES1_BIT,
+ .window_width = 300,
+ .window_height = 300,
+ .verbose = 0,
+ .num_windows = 0,
+};
+
+struct eglut_state *_eglut = &_eglut_state;
+
+void
+_eglutFatal(char *format, ...)
+{
+ va_list args;
+
+ va_start(args, format);
+
+ fprintf(stderr, "EGLUT: ");
+ vfprintf(stderr, format, args);
+ va_end(args);
+ putc('\n', stderr);
+
+ exit(1);
+}
+
+/* return current time (in milliseconds) */
+int
+_eglutNow(void)
+{
+ struct timeval tv;
+#ifdef __VMS
+ (void) gettimeofday(&tv, NULL );
+#else
+ struct timezone tz;
+ (void) gettimeofday(&tv, &tz);
+#endif
+ return tv.tv_sec * 1000 + tv.tv_usec / 1000;
+}
+
+static void
+_eglutDestroyWindow(struct eglut_window *win)
+{
+ if (_eglut->surface_type != EGL_PBUFFER_BIT &&
+ _eglut->surface_type != EGL_SCREEN_BIT_MESA)
+ eglDestroySurface(_eglut->dpy, win->surface);
+
+ _eglutNativeFiniWindow(win);
+
+ eglDestroyContext(_eglut->dpy, win->context);
+}
+
+static EGLConfig
+_eglutChooseConfig(void)
+{
+ EGLConfig config;
+ EGLint config_attribs[32];
+ EGLint renderable_type, num_configs, i;
+
+ i = 0;
+ config_attribs[i++] = EGL_RED_SIZE;
+ config_attribs[i++] = 1;
+ config_attribs[i++] = EGL_GREEN_SIZE;
+ config_attribs[i++] = 1;
+ config_attribs[i++] = EGL_BLUE_SIZE;
+ config_attribs[i++] = 1;
+ config_attribs[i++] = EGL_DEPTH_SIZE;
+ config_attribs[i++] = 1;
+
+ config_attribs[i++] = EGL_SURFACE_TYPE;
+ config_attribs[i++] = _eglut->surface_type;
+
+ config_attribs[i++] = EGL_RENDERABLE_TYPE;
+ renderable_type = 0x0;
+ if (_eglut->api_mask & EGLUT_OPENGL_BIT)
+ renderable_type |= EGL_OPENGL_BIT;
+ if (_eglut->api_mask & (EGLUT_OPENGL_ES1_BIT | EGLUT_OPENGL_ES2_BIT))
+ renderable_type |= EGL_OPENGL_ES_BIT;
+ if (_eglut->api_mask & EGLUT_OPENVG_BIT)
+ renderable_type |= EGL_OPENVG_BIT;
+ config_attribs[i++] = renderable_type;
+
+ config_attribs[i] = EGL_NONE;
+
+ if (!eglChooseConfig(_eglut->dpy,
+ config_attribs, &config, 1, &num_configs) || !num_configs)
+ _eglutFatal("failed to choose a config");
+
+ return config;
+}
+
+static struct eglut_window *
+_eglutCreateWindow(const char *title, int x, int y, int w, int h)
+{
+ struct eglut_window *win;
+ EGLint context_attribs[4];
+ EGLint api, i;
+
+ win = calloc(1, sizeof(*win));
+ if (!win)
+ _eglutFatal("failed to allocate window");
+
+ win->config = _eglutChooseConfig();
+
+ i = 0;
+ context_attribs[i] = EGL_NONE;
+
+ /* multiple APIs? */
+
+ api = EGL_OPENGL_ES_API;
+ if (_eglut->api_mask & EGLUT_OPENGL_BIT) {
+ api = EGL_OPENGL_API;
+ }
+ else if (_eglut->api_mask & EGLUT_OPENVG_BIT) {
+ api = EGL_OPENVG_API;
+ }
+ else if (_eglut->api_mask & EGLUT_OPENGL_ES2_BIT) {
+ context_attribs[i++] = EGL_CONTEXT_CLIENT_VERSION;
+ context_attribs[i++] = 2;
+ }
+
+ context_attribs[i] = EGL_NONE;
+
+ eglBindAPI(api);
+ win->context = eglCreateContext(_eglut->dpy,
+ win->config, EGL_NO_CONTEXT, context_attribs);
+ if (!win->context)
+ _eglutFatal("failed to create context");
+
+ _eglutNativeInitWindow(win, title, x, y, w, h);
+ switch (_eglut->surface_type) {
+ case EGL_WINDOW_BIT:
+ win->surface = eglCreateWindowSurface(_eglut->dpy,
+ win->config, win->native.u.window, NULL);
+ break;
+ case EGL_PIXMAP_BIT:
+ win->surface = eglCreatePixmapSurface(_eglut->dpy,
+ win->config, win->native.u.pixmap, NULL);
+ break;
+ case EGL_PBUFFER_BIT:
+ case EGL_SCREEN_BIT_MESA:
+ win->surface = win->native.u.surface;
+ break;
+ default:
+ break;
+ }
+ if (win->surface == EGL_NO_SURFACE)
+ _eglutFatal("failed to create surface");
+
+ return win;
+}
+
+void
+eglutInitAPIMask(int mask)
+{
+ _eglut->api_mask = mask;
+}
+
+void
+eglutInitWindowSize(int width, int height)
+{
+ _eglut->window_width = width;
+ _eglut->window_height = height;
+}
+
+void
+eglutInit(int argc, char **argv)
+{
+ int i;
+
+ for (i = 1; i < argc; i++) {
+ if (strcmp(argv[i], "-display") == 0)
+ _eglut->display_name = argv[++i];
+ else if (strcmp(argv[i], "-info") == 0) {
+ _eglut->verbose = 1;
+ }
+ }
+
+ _eglutNativeInitDisplay();
+ _eglut->dpy = eglGetDisplay(_eglut->native_dpy);
+
+ if (!eglInitialize(_eglut->dpy, &_eglut->major, &_eglut->minor))
+ _eglutFatal("failed to initialize EGL display");
+
+ _eglut->init_time = _eglutNow();
+
+ printf("EGL_VERSION = %s\n", eglQueryString(_eglut->dpy, EGL_VERSION));
+ if (_eglut->verbose) {
+ printf("EGL_VENDOR = %s\n", eglQueryString(_eglut->dpy, EGL_VENDOR));
+ printf("EGL_EXTENSIONS = %s\n",
+ eglQueryString(_eglut->dpy, EGL_EXTENSIONS));
+ printf("EGL_CLIENT_APIS = %s\n",
+ eglQueryString(_eglut->dpy, EGL_CLIENT_APIS));
+ }
+}
+
+int
+eglutGet(int state)
+{
+ int val;
+
+ switch (state) {
+ case EGLUT_ELAPSED_TIME:
+ val = _eglutNow() - _eglut->init_time;
+ break;
+ default:
+ val = -1;
+ break;
+ }
+
+ return val;
+}
+
+void
+eglutIdleFunc(EGLUTidleCB func)
+{
+ _eglut->idle_cb = func;
+}
+
+void
+eglutPostRedisplay(void)
+{
+ _eglut->redisplay = 1;
+}
+
+void
+eglutMainLoop(void)
+{
+ struct eglut_window *win = _eglut->current;
+
+ if (!win)
+ _eglutFatal("no window is created\n");
+
+ if (win->reshape_cb)
+ win->reshape_cb(win->native.width, win->native.height);
+
+ _eglutNativeEventLoop();
+}
+
+static void
+_eglutFini(void)
+{
+ eglTerminate(_eglut->dpy);
+ _eglutNativeFiniDisplay();
+}
+
+void
+eglutDestroyWindow(int win)
+{
+ struct eglut_window *window = _eglut->current;
+
+ if (window->index != win)
+ return;
+
+ /* XXX it causes some bug in st/egl KMS backend */
+ if ( _eglut->surface_type != EGL_SCREEN_BIT_MESA)
+ eglMakeCurrent(_eglut->dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
+
+ _eglutDestroyWindow(_eglut->current);
+}
+
+static void
+_eglutDefaultKeyboard(unsigned char key)
+{
+ if (key == 27) {
+ if (_eglut->current)
+ eglutDestroyWindow(_eglut->current->index);
+ _eglutFini();
+
+ exit(0);
+ }
+}
+
+int
+eglutCreateWindow(const char *title)
+{
+ struct eglut_window *win;
+
+ win = _eglutCreateWindow(title, 0, 0,
+ _eglut->window_width, _eglut->window_height);
+
+ win->index = _eglut->num_windows++;
+ win->reshape_cb = NULL;
+ win->display_cb = NULL;
+ win->keyboard_cb = _eglutDefaultKeyboard;
+ win->special_cb = NULL;
+
+ if (!eglMakeCurrent(_eglut->dpy, win->surface, win->surface, win->context))
+ _eglutFatal("failed to make window current");
+ _eglut->current = win;
+
+ return win->index;
+}
+
+int
+eglutGetWindowWidth(void)
+{
+ struct eglut_window *win = _eglut->current;
+ return win->native.width;
+}
+
+int
+eglutGetWindowHeight(void)
+{
+ struct eglut_window *win = _eglut->current;
+ return win->native.height;
+}
+
+void
+eglutDisplayFunc(EGLUTdisplayCB func)
+{
+ struct eglut_window *win = _eglut->current;
+ win->display_cb = func;
+
+}
+
+void
+eglutReshapeFunc(EGLUTreshapeCB func)
+{
+ struct eglut_window *win = _eglut->current;
+ win->reshape_cb = func;
+}
+
+void
+eglutKeyboardFunc(EGLUTkeyboardCB func)
+{
+ struct eglut_window *win = _eglut->current;
+ win->keyboard_cb = func;
+}
+
+void
+eglutSpecialFunc(EGLUTspecialCB func)
+{
+ struct eglut_window *win = _eglut->current;
+ win->special_cb = func;
+}
diff --git a/progs/egl/eglut/eglut.h b/progs/egl/eglut/eglut.h
new file mode 100644
index 0000000000..07df4ba9f7
--- /dev/null
+++ b/progs/egl/eglut/eglut.h
@@ -0,0 +1,68 @@
+#ifndef EGLUT_H
+#define EGLUT_H
+
+/* used by eglutInitAPIMask */
+enum {
+ EGLUT_OPENGL_BIT = 0x1,
+ EGLUT_OPENGL_ES1_BIT = 0x2,
+ EGLUT_OPENGL_ES2_BIT = 0x4,
+ EGLUT_OPENVG_BIT = 0x8
+};
+
+/* used by EGLUTspecialCB */
+enum {
+ /* function keys */
+ EGLUT_KEY_F1,
+ EGLUT_KEY_F2,
+ EGLUT_KEY_F3,
+ EGLUT_KEY_F4,
+ EGLUT_KEY_F5,
+ EGLUT_KEY_F6,
+ EGLUT_KEY_F7,
+ EGLUT_KEY_F8,
+ EGLUT_KEY_F9,
+ EGLUT_KEY_F10,
+ EGLUT_KEY_F11,
+ EGLUT_KEY_F12,
+
+ /* directional keys */
+ EGLUT_KEY_LEFT,
+ EGLUT_KEY_UP,
+ EGLUT_KEY_RIGHT,
+ EGLUT_KEY_DOWN,
+};
+
+/* used by eglutGet */
+enum {
+ EGLUT_ELAPSED_TIME
+};
+
+typedef void (*EGLUTidleCB)(void);
+typedef void (*EGLUTreshapeCB)(int, int);
+typedef void (*EGLUTdisplayCB)(void);
+typedef void (*EGLUTkeyboardCB)(unsigned char);
+typedef void (*EGLUTspecialCB)(int);
+
+void eglutInitAPIMask(int mask);
+void eglutInitWindowSize(int width, int height);
+void eglutInit(int argc, char **argv);
+
+int eglutGet(int state);
+
+void eglutIdleFunc(EGLUTidleCB func);
+void eglutPostRedisplay(void);
+
+void eglutMainLoop(void);
+
+int eglutCreateWindow(const char *title);
+void eglutDestroyWindow(int win);
+
+int eglutGetWindowWidth(void);
+int eglutGetWindowHeight(void);
+
+void eglutDisplayFunc(EGLUTdisplayCB func);
+void eglutReshapeFunc(EGLUTreshapeCB func);
+void eglutKeyboardFunc(EGLUTkeyboardCB func);
+void eglutSpecialFunc(EGLUTspecialCB func);
+
+#endif /* EGLUT_H */
diff --git a/progs/egl/eglut/eglut_screen.c b/progs/egl/eglut/eglut_screen.c
new file mode 100644
index 0000000000..50549e4bcf
--- /dev/null
+++ b/progs/egl/eglut/eglut_screen.c
@@ -0,0 +1,154 @@
+#include <stdio.h>
+#include <string.h>
+#include <sys/time.h>
+
+#define EGL_EGLEXT_PROTOTYPES
+#include "EGL/egl.h"
+#include "EGL/eglext.h"
+
+#include "eglutint.h"
+
+#define MAX_MODES 100
+
+static EGLScreenMESA kms_screen;
+static EGLModeMESA kms_mode;
+static EGLint kms_width, kms_height;
+
+void
+_eglutNativeInitDisplay(void)
+{
+ _eglut->native_dpy = EGL_DEFAULT_DISPLAY;
+ _eglut->surface_type = EGL_SCREEN_BIT_MESA;
+}
+
+void
+_eglutNativeFiniDisplay(void)
+{
+ kms_screen = 0;
+ kms_mode = 0;
+ kms_width = 0;
+ kms_height = 0;
+}
+
+static void
+init_kms(void)
+{
+ EGLModeMESA modes[MAX_MODES];
+ EGLint num_screens, num_modes;
+ EGLint width, height, best_mode;
+ EGLint i;
+
+ if (!eglGetScreensMESA(_eglut->dpy, &kms_screen, 1, &num_screens) ||
+ !num_screens)
+ _eglutFatal("eglGetScreensMESA failed\n");
+
+ if (!eglGetModesMESA(_eglut->dpy, kms_screen,
+ modes, MAX_MODES, &num_modes) || !num_modes)
+ _eglutFatal("eglGetModesMESA failed!\n");
+
+ printf("Found %d modes:\n", num_modes);
+
+ best_mode = 0;
+ width = 0;
+ height = 0;
+ for (i = 0; i < num_modes; i++) {
+ EGLint w, h;
+ eglGetModeAttribMESA(_eglut->dpy, modes[i], EGL_WIDTH, &w);
+ eglGetModeAttribMESA(_eglut->dpy, modes[i], EGL_HEIGHT, &h);
+ printf("%3d: %d x %d\n", i, w, h);
+ if (w > width && h > height) {
+ width = w;
+ height = h;
+ best_mode = i;
+ }
+ }
+
+ printf("Will use screen size: %d x %d\n", width, height);
+
+ kms_mode = modes[best_mode];
+ kms_width = width;
+ kms_height = height;
+}
+
+void
+_eglutNativeInitWindow(struct eglut_window *win, const char *title,
+ int x, int y, int w, int h)
+{
+ EGLint surf_attribs[16];
+ EGLint i;
+ const char *exts;
+
+ exts = eglQueryString(_eglut->dpy, EGL_EXTENSIONS);
+ if (!exts || !strstr(exts, "EGL_MESA_screen_surface"))
+ _eglutFatal("EGL_MESA_screen_surface is not supported\n");
+
+ init_kms();
+
+ i = 0;
+ surf_attribs[i++] = EGL_WIDTH;
+ surf_attribs[i++] = kms_width;
+ surf_attribs[i++] = EGL_HEIGHT;
+ surf_attribs[i++] = kms_height;
+ surf_attribs[i++] = EGL_NONE;
+
+ /* create surface */
+ win->native.u.surface = eglCreateScreenSurfaceMESA(_eglut->dpy,
+ win->config, surf_attribs);
+ if (win->native.u.surface == EGL_NO_SURFACE)
+ _eglutFatal("eglCreateScreenSurfaceMESA failed\n");
+
+ if (!eglShowScreenSurfaceMESA(_eglut->dpy, kms_screen,
+ win->native.u.surface, kms_mode))
+ _eglutFatal("eglShowScreenSurfaceMESA failed\n");
+
+ win->native.width = kms_width;
+ win->native.height = kms_height;
+}
+
+void
+_eglutNativeFiniWindow(struct eglut_window *win)
+{
+ eglShowScreenSurfaceMESA(_eglut->dpy,
+ kms_screen, EGL_NO_SURFACE, 0);
+ eglDestroySurface(_eglut->dpy, win->native.u.surface);
+}
+
+void
+_eglutNativeEventLoop(void)
+{
+ int start = _eglutNow();
+ int frames = 0;
+
+ _eglut->redisplay = 1;
+
+ while (1) {
+ struct eglut_window *win = _eglut->current;
+ int now = _eglutNow();
+
+ if (now - start > 5000) {
+ double elapsed = (double) (now - start) / 1000.0;
+
+ printf("%d frames in %3.1f seconds = %6.3f FPS\n",
+ frames, elapsed, frames / elapsed);
+
+ start = now;
+ frames = 0;
+
+ /* send escape */
+ if (win->keyboard_cb)
+ win->keyboard_cb(27);
+ }
+
+ if (_eglut->idle_cb)
+ _eglut->idle_cb();
+
+ if (_eglut->redisplay) {
+ _eglut->redisplay = 0;
+
+ if (win->display_cb)
+ win->display_cb();
+ eglSwapBuffers(_eglut->dpy, win->surface);
+ frames++;
+ }
+ }
+}
diff --git a/progs/egl/eglut/eglut_x11.c b/progs/egl/eglut/eglut_x11.c
new file mode 100644
index 0000000000..f3b2280374
--- /dev/null
+++ b/progs/egl/eglut/eglut_x11.c
@@ -0,0 +1,220 @@
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/keysym.h>
+
+#include "eglutint.h"
+
+void
+_eglutNativeInitDisplay(void)
+{
+ _eglut->native_dpy = XOpenDisplay(_eglut->display_name);
+ if (!_eglut->native_dpy)
+ _eglutFatal("failed to initialize native display");
+
+ _eglut->surface_type = EGL_WINDOW_BIT;
+}
+
+void
+_eglutNativeFiniDisplay(void)
+{
+ XCloseDisplay(_eglut->native_dpy);
+}
+
+void
+_eglutNativeInitWindow(struct eglut_window *win, const char *title,
+ int x, int y, int w, int h)
+{
+ XVisualInfo *visInfo, visTemplate;
+ int num_visuals;
+ Window root, xwin;
+ XSetWindowAttributes attr;
+ unsigned long mask;
+ EGLint vid;
+
+ if (!eglGetConfigAttrib(_eglut->dpy,
+ win->config, EGL_NATIVE_VISUAL_ID, &vid))
+ _eglutFatal("failed to get visual id");
+
+ /* The X window visual must match the EGL config */
+ visTemplate.visualid = vid;
+ visInfo = XGetVisualInfo(_eglut->native_dpy,
+ VisualIDMask, &visTemplate, &num_visuals);
+ if (!visInfo)
+ _eglutFatal("failed to get an visual of id 0x%x", vid);
+
+ root = RootWindow(_eglut->native_dpy, DefaultScreen(_eglut->native_dpy));
+
+ /* window attributes */
+ attr.background_pixel = 0;
+ attr.border_pixel = 0;
+ attr.colormap = XCreateColormap(_eglut->native_dpy,
+ root, visInfo->visual, AllocNone);
+ attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
+ mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
+
+ xwin = XCreateWindow(_eglut->native_dpy, root, x, y, w, h,
+ 0, visInfo->depth, InputOutput, visInfo->visual, mask, &attr);
+ if (!xwin)
+ _eglutFatal("failed to create a window");
+
+ XFree(visInfo);
+
+ /* set hints and properties */
+ {
+ XSizeHints sizehints;
+ sizehints.x = x;
+ sizehints.y = y;
+ sizehints.width = w;
+ sizehints.height = h;
+ sizehints.flags = USSize | USPosition;
+ XSetNormalHints(_eglut->native_dpy, xwin, &sizehints);
+ XSetStandardProperties(_eglut->native_dpy, xwin,
+ title, title, None, (char **) NULL, 0, &sizehints);
+ }
+
+ XMapWindow(_eglut->native_dpy, xwin);
+
+ win->native.u.window = xwin;
+ win->native.width = w;
+ win->native.height = h;
+}
+
+void
+_eglutNativeFiniWindow(struct eglut_window *win)
+{
+ XDestroyWindow(_eglut->native_dpy, win->native.u.window);
+}
+
+static int
+lookup_keysym(KeySym sym)
+{
+ int special;
+
+ switch (sym) {
+ case XK_F1:
+ special = EGLUT_KEY_F1;
+ break;
+ case XK_F2:
+ special = EGLUT_KEY_F2;
+ break;
+ case XK_F3:
+ special = EGLUT_KEY_F3;
+ break;
+ case XK_F4:
+ special = EGLUT_KEY_F4;
+ break;
+ case XK_F5:
+ special = EGLUT_KEY_F5;
+ break;
+ case XK_F6:
+ special = EGLUT_KEY_F6;
+ break;
+ case XK_F7:
+ special = EGLUT_KEY_F7;
+ break;
+ case XK_F8:
+ special = EGLUT_KEY_F8;
+ break;
+ case XK_F9:
+ special = EGLUT_KEY_F9;
+ break;
+ case XK_F10:
+ special = EGLUT_KEY_F10;
+ break;
+ case XK_F11:
+ special = EGLUT_KEY_F11;
+ break;
+ case XK_F12:
+ special = EGLUT_KEY_F12;
+ break;
+ case XK_KP_Left:
+ case XK_Left:
+ special = EGLUT_KEY_LEFT;
+ break;
+ case XK_KP_Up:
+ case XK_Up:
+ special = EGLUT_KEY_UP;
+ break;
+ case XK_KP_Right:
+ case XK_Right:
+ special = EGLUT_KEY_RIGHT;
+ break;
+ case XK_KP_Down:
+ case XK_Down:
+ special = EGLUT_KEY_DOWN;
+ break;
+ default:
+ special = -1;
+ break;
+ }
+
+ return special;
+}
+
+static void
+next_event(struct eglut_window *win)
+{
+ int redraw = 0;
+ XEvent event;
+
+ if (!XPending(_eglut->native_dpy)) {
+ if (_eglut->idle_cb)
+ _eglut->idle_cb();
+ return;
+ }
+
+ XNextEvent(_eglut->native_dpy, &event);
+
+ switch (event.type) {
+ case Expose:
+ redraw = 1;
+ break;
+ case ConfigureNotify:
+ win->native.width = event.xconfigure.width;
+ win->native.height = event.xconfigure.height;
+ if (win->reshape_cb)
+ win->reshape_cb(win->native.width, win->native.height);
+ break;
+ case KeyPress:
+ {
+ char buffer[1];
+ KeySym sym;
+ int r;
+
+ r = XLookupString(&event.xkey,
+ buffer, sizeof(buffer), &sym, NULL);
+ if (r && win->keyboard_cb) {
+ win->keyboard_cb(buffer[0]);
+ }
+ else if (!r && win->special_cb) {
+ r = lookup_keysym(sym);
+ if (r >= 0)
+ win->special_cb(r);
+ }
+ }
+ redraw = 1;
+ break;
+ default:
+ ; /*no-op*/
+ }
+
+ _eglut->redisplay = redraw;
+}
+
+void
+_eglutNativeEventLoop(void)
+{
+ while (1) {
+ struct eglut_window *win = _eglut->current;
+
+ next_event(win);
+
+ if (_eglut->redisplay) {
+ _eglut->redisplay = 0;
+
+ if (win->display_cb)
+ win->display_cb();
+ eglSwapBuffers(_eglut->dpy, win->surface);
+ }
+ }
+}
diff --git a/progs/egl/eglut/eglutint.h b/progs/egl/eglut/eglutint.h
new file mode 100644
index 0000000000..54d329f328
--- /dev/null
+++ b/progs/egl/eglut/eglutint.h
@@ -0,0 +1,78 @@
+#ifndef _EGLUTINT_H_
+#define _EGLUTINT_H_
+
+#include "EGL/egl.h"
+#include "eglut.h"
+
+struct eglut_window {
+ EGLConfig config;
+ EGLContext context;
+
+ /* initialized by native display */
+ struct {
+ union {
+ EGLNativeWindowType window;
+ EGLNativePixmapType pixmap;
+ EGLSurface surface; /* pbuffer or screen surface */
+ } u;
+ int width, height;
+ } native;
+
+ EGLSurface surface;
+
+ int index;
+
+ EGLUTreshapeCB reshape_cb;
+ EGLUTdisplayCB display_cb;
+ EGLUTkeyboardCB keyboard_cb;
+ EGLUTspecialCB special_cb;
+};
+
+struct eglut_state {
+ int api_mask;
+ int window_width, window_height;
+ const char *display_name;
+ int verbose;
+ int init_time;
+
+ EGLUTidleCB idle_cb;
+
+ int num_windows;
+
+ /* initialized by native display */
+ EGLNativeDisplayType native_dpy;
+ EGLint surface_type;
+
+ EGLDisplay dpy;
+ EGLint major, minor;
+
+ struct eglut_window *current;
+
+ int redisplay;
+};
+
+extern struct eglut_state *_eglut;
+
+void
+_eglutFatal(char *format, ...);
+
+int
+_eglutNow(void);
+
+void
+_eglutNativeInitDisplay(void);
+
+void
+_eglutNativeFiniDisplay(void);
+
+void
+_eglutNativeInitWindow(struct eglut_window *win, const char *title,
+ int x, int y, int w, int h);
+
+void
+_eglutNativeFiniWindow(struct eglut_window *win);
+
+void
+_eglutNativeEventLoop(void);
+
+#endif /* _EGLUTINT_H_ */
diff --git a/progs/egl/.gitignore b/progs/egl/opengl/.gitignore
index 7a13d4686a..49c3a511f3 100644
--- a/progs/egl/.gitignore
+++ b/progs/egl/opengl/.gitignore
@@ -1,12 +1,13 @@
demo1
demo2
demo3
-eglgears
+eglgears_x11
+eglgears_screen
eglinfo
eglscreen
-egltri
+egltri_x11
+egltri_screen
peglgears
xeglbindtex
xeglgears
xeglthreads
-xegl_tri
diff --git a/progs/egl/opengl/Makefile b/progs/egl/opengl/Makefile
new file mode 100644
index 0000000000..9a91df9906
--- /dev/null
+++ b/progs/egl/opengl/Makefile
@@ -0,0 +1,83 @@
+# progs/egl/Makefile
+
+TOP = ../../..
+include $(TOP)/configs/current
+
+
+INCLUDE_DIRS = -I$(TOP)/include
+
+HEADERS = $(TOP)/include/GLES/egl.h
+LIB_DEP = $(TOP)/$(LIB_DIR)/libEGL.so
+
+LIBS = -L$(TOP)/$(LIB_DIR) -lEGL -lGL -lm
+
+EGLUT_DIR = $(TOP)/progs/egl/eglut
+
+EGLUT_DEMOS = \
+ eglgears \
+ egltri
+
+EGLUT_X11_DEMOS := $(addsuffix _x11,$(EGLUT_DEMOS))
+EGLUT_SCREEN_DEMOS := $(addsuffix _screen,$(EGLUT_DEMOS))
+
+PROGRAMS = \
+ demo1 \
+ demo2 \
+ demo3 \
+ eglinfo \
+ eglscreen \
+ peglgears \
+ xeglgears \
+ xeglthreads
+
+
+.c.o:
+ $(CC) -c $(INCLUDE_DIRS) -I$(EGLUT_DIR) $(CFLAGS) $< -o $@
+
+
+
+default: $(PROGRAMS) $(EGLUT_X11_DEMOS) $(EGLUT_SCREEN_DEMOS)
+
+demo1: demo1.o $(HEADERS) $(LIB_DEP)
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB)
+
+demo2: demo2.o $(HEADERS) $(LIB_DEP)
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB)
+
+demo3: demo3.o $(HEADERS) $(LIB_DEP)
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB)
+
+eglinfo: eglinfo.o $(HEADERS) $(LIB_DEP)
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS)
+
+eglscreen: eglscreen.o $(HEADERS) $(LIB_DEP)
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB)
+
+peglgears: peglgears.o $(HEADERS) $(LIB_DEP)
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB) -lm
+
+xeglgears: xeglgears.o $(HEADERS) $(LIB_DEP)
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lm $(X11_LIBS)
+
+xeglthreads: xeglthreads.o $(HEADERS) $(LIB_DEP)
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lpthread -lm $(X11_LIBS)
+
+$(EGLUT_DIR)/libeglut-x11.a $(EGLUT_DIR)/libeglut-screen.a:
+ @$(MAKE) -C $(EGLUT_DIR)
+
+# define the rules for EGLUT demos
+define eglut-demo-rule
+$(1)_x11 $(1)_screen: $(1)_%: $(1).o $(EGLUT_DIR)/libeglut-%.a $(LIB_DEP)
+endef
+$(foreach demo, $(EGLUT_DEMOS), $(eval $(call eglut-demo-rule,$(demo))))
+
+# build EGLUT demos
+$(EGLUT_X11_DEMOS):
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -L$(EGLUT_DIR) -leglut-$* $(LIBS) -lX11
+$(EGLUT_SCREEN_DEMOS):
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -L$(EGLUT_DIR) -leglut-$* $(LIBS)
+
+clean:
+ -rm -f *.o *~
+ -rm -f $(PROGRAMS) $(EGLUT_X11_DEMOS) $(EGLUT_SCREEN_DEMOS)
+ @$(MAKE) -C $(EGLUT_DIR) clean
diff --git a/progs/egl/demo1.c b/progs/egl/opengl/demo1.c
index d892734ee5..d892734ee5 100644
--- a/progs/egl/demo1.c
+++ b/progs/egl/opengl/demo1.c
diff --git a/progs/egl/demo2.c b/progs/egl/opengl/demo2.c
index b9e92f62ac..b9e92f62ac 100644
--- a/progs/egl/demo2.c
+++ b/progs/egl/opengl/demo2.c
diff --git a/progs/egl/demo3.c b/progs/egl/opengl/demo3.c
index 64b9ee652c..64b9ee652c 100644
--- a/progs/egl/demo3.c
+++ b/progs/egl/opengl/demo3.c
diff --git a/progs/egl/eglgears.c b/progs/egl/opengl/eglgears.c
index 63490953ae..28da9c0ac7 100644
--- a/progs/egl/eglgears.c
+++ b/progs/egl/opengl/eglgears.c
@@ -27,78 +27,16 @@
* Program runs for 5 seconds then exits, outputing framerate to console
*/
-#define EGL_EGLEXT_PROTOTYPES
-
-#include <assert.h>
#include <math.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
#include <GL/gl.h>
#include <EGL/egl.h>
-#include <EGL/eglext.h>
-
-#define MAX_CONFIGS 10
-#define MAX_MODES 100
-
-#define BENCHMARK
-
-#ifdef BENCHMARK
-
-/* XXX this probably isn't very portable */
-
-#include <sys/time.h>
-#include <unistd.h>
-
-/* return current time (in seconds) */
-static double
-current_time(void)
-{
- struct timeval tv;
-#ifdef __VMS
- (void) gettimeofday(&tv, NULL );
-#else
- struct timezone tz;
- (void) gettimeofday(&tv, &tz);
-#endif
- return (double) tv.tv_sec + tv.tv_usec / 1000000.0;
-}
-
-#else /*BENCHMARK*/
-
-/* dummy */
-static double
-current_time(void)
-{
- /* update this function for other platforms! */
- static double t = 0.0;
- static int warn = 1;
- if (warn) {
- fprintf(stderr, "Warning: current_time() not implemented!!\n");
- warn = 0;
- }
- return t += 1.0;
-}
-
-#endif /*BENCHMARK*/
-
-
-#ifndef M_PI
-#define M_PI 3.14159265
-#endif
+#include "eglut.h"
static GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0;
static GLint gear1, gear2, gear3;
static GLfloat angle = 0.0;
-#if 0
-static GLfloat eyesep = 5.0; /* Eye separation. */
-static GLfloat fix_point = 40.0; /* Fixation point distance. */
-static GLfloat left, right, asp; /* Stereo frustum params. */
-#endif
-
-
/*
*
* Draw a gear wheel. You'll probably want to call this function when
@@ -270,6 +208,22 @@ draw(void)
}
+static void
+idle(void)
+{
+ static double t0 = -1.;
+ double dt, t = eglutGet(EGLUT_ELAPSED_TIME) / 1000.0;
+ if (t0 < 0.0)
+ t0 = t;
+ dt = t - t0;
+ t0 = t;
+
+ angle += 70.0 * dt; /* 70 degrees per second */
+ angle = fmod(angle, 360.0); /* prevents eventual overflow */
+
+ eglutPostRedisplay();
+}
+
/* new window size or exposure */
static void
reshape(int width, int height)
@@ -325,158 +279,23 @@ init(void)
glEnable(GL_NORMALIZE);
}
-
-
-
-static void run_gears(EGLDisplay dpy, EGLSurface surf, int ttr)
-{
- double st = current_time();
- double ct = st;
- int frames = 0;
- GLfloat seconds, fps;
-
- while (ct - st < ttr)
- {
- double tt = current_time();
- double dt = tt - ct;
- ct = tt;
-
- /* advance rotation for next frame */
- angle += 70.0 * dt; /* 70 degrees per second */
- if (angle > 3600.0)
- angle -= 3600.0;
-
- draw();
-
- eglSwapBuffers(dpy, surf);
-
-
- frames++;
- }
-
- seconds = ct - st;
- fps = frames / seconds;
- printf("%d frames in %3.1f seconds = %6.3f FPS\n", frames, seconds, fps);
-
-}
-
-
int
main(int argc, char *argv[])
{
- int maj, min;
- EGLContext ctx;
- EGLSurface screen_surf;
- EGLConfig configs[MAX_CONFIGS];
- EGLint numConfigs, i;
- EGLBoolean b;
- EGLDisplay d;
- EGLint screenAttribs[10];
- EGLModeMESA mode[MAX_MODES];
- EGLScreenMESA screen;
- EGLint count;
- EGLint chosenMode = 0;
- GLboolean printInfo = GL_FALSE;
- EGLint width = 0, height = 0;
-
- /* parse cmd line args */
- for (i = 1; i < argc; i++)
- {
- if (strcmp(argv[i], "-info") == 0)
- {
- printInfo = GL_TRUE;
- }
- else
- printf("Warning: unknown parameter: %s\n", argv[i]);
- }
-
- /* DBR : Create EGL context/surface etc */
- d = eglGetDisplay(EGL_DEFAULT_DISPLAY);
- assert(d);
-
- if (!eglInitialize(d, &maj, &min)) {
- printf("eglgears: eglInitialize failed\n");
- exit(1);
- }
-
- printf("eglgears: EGL version = %d.%d\n", maj, min);
- printf("eglgears: EGL_VENDOR = %s\n", eglQueryString(d, EGL_VENDOR));
-
- /* XXX use ChooseConfig */
- eglGetConfigs(d, configs, MAX_CONFIGS, &numConfigs);
- eglGetScreensMESA(d, &screen, 1, &count);
-
- if (!eglGetModesMESA(d, screen, mode, MAX_MODES, &count) || count == 0) {
- printf("eglgears: eglGetModesMESA failed!\n");
- return 0;
- }
-
- /* Print list of modes, and find the one to use */
- printf("eglgears: Found %d modes:\n", count);
- for (i = 0; i < count; i++) {
- EGLint w, h;
- eglGetModeAttribMESA(d, mode[i], EGL_WIDTH, &w);
- eglGetModeAttribMESA(d, mode[i], EGL_HEIGHT, &h);
- printf("%3d: %d x %d\n", i, w, h);
- if (w > width && h > height) {
- width = w;
- height = h;
- chosenMode = i;
- }
- }
- printf("eglgears: Using screen mode/size %d: %d x %d\n", chosenMode, width, height);
-
- eglBindAPI(EGL_OPENGL_API);
- ctx = eglCreateContext(d, configs[0], EGL_NO_CONTEXT, NULL);
- if (ctx == EGL_NO_CONTEXT) {
- printf("eglgears: failed to create context\n");
- return 0;
- }
-
- /* build up screenAttribs array */
- i = 0;
- screenAttribs[i++] = EGL_WIDTH;
- screenAttribs[i++] = width;
- screenAttribs[i++] = EGL_HEIGHT;
- screenAttribs[i++] = height;
- screenAttribs[i++] = EGL_NONE;
-
- screen_surf = eglCreateScreenSurfaceMESA(d, configs[0], screenAttribs);
- if (screen_surf == EGL_NO_SURFACE) {
- printf("eglgears: failed to create screen surface\n");
- return 0;
- }
-
- b = eglShowScreenSurfaceMESA(d, screen, screen_surf, mode[chosenMode]);
- if (!b) {
- printf("eglgears: show surface failed\n");
- return 0;
- }
-
- b = eglMakeCurrent(d, screen_surf, screen_surf, ctx);
- if (!b) {
- printf("eglgears: make current failed\n");
- return 0;
- }
-
- if (printInfo)
- {
- printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
- printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
- printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR));
- printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS));
- }
-
- init();
- reshape(width, height);
+ eglutInitWindowSize(300, 300);
+ eglutInitAPIMask(EGLUT_OPENGL_BIT);
+ eglutInit(argc, argv);
- glDrawBuffer( GL_BACK );
+ eglutCreateWindow("eglgears");
- run_gears(d, screen_surf, 5.0);
-
- eglDestroySurface(d, screen_surf);
- eglDestroyContext(d, ctx);
- eglTerminate(d);
+ eglutIdleFunc(idle);
+ eglutReshapeFunc(reshape);
+ eglutDisplayFunc(draw);
+
+ init();
+ glDrawBuffer(GL_BACK);
- return 0;
+ eglutMainLoop();
+
+ return 0;
}
diff --git a/progs/egl/eglinfo.c b/progs/egl/opengl/eglinfo.c
index 961fd9ccc7..961fd9ccc7 100644
--- a/progs/egl/eglinfo.c
+++ b/progs/egl/opengl/eglinfo.c
diff --git a/progs/egl/eglscreen.c b/progs/egl/opengl/eglscreen.c
index 520f76ea03..520f76ea03 100644
--- a/progs/egl/eglscreen.c
+++ b/progs/egl/opengl/eglscreen.c
diff --git a/progs/es1/screen/tri.c b/progs/egl/opengl/egltri.c
index bab9499944..fb1dde3529 100644
--- a/progs/es1/screen/tri.c
+++ b/progs/egl/opengl/egltri.c
@@ -1,21 +1,16 @@
/*
- * 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
@@ -24,45 +19,36 @@
* 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"
+/*
+ * Draw a triangle with X/EGL.
+ * Brian Paul
+ * 3 June 2008
+ */
-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);
-}
+#include <math.h>
+#include <stdlib.h>
+#include <string.h>
+#include <GL/gl.h>
-static void tri_reshape(int width, int height)
-{
- GLfloat ar = (GLfloat) width / (GLfloat) height;
+#include "eglut.h"
- glViewport(0, 0, (GLint) width, (GLint) height);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glFrustumf(-ar, ar, -1, 1, 5.0, 60.0);
+static GLfloat view_rotx = 0.0, view_roty = 0.0, view_rotz = 0.0;
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTranslatef(0.0, 0.0, -10.0);
-}
-static void tri_draw(void *data)
+static void
+draw(void)
{
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 }
+ static const GLfloat colors[3][3] = {
+ { 1, 0, 0 },
+ { 0, 1, 0 },
+ { 0, 0, 1 }
};
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@@ -74,7 +60,7 @@ static void tri_draw(void *data)
{
glVertexPointer(2, GL_FLOAT, 0, verts);
- glColorPointer(4, GL_FLOAT, 0, colors);
+ glColorPointer(3, GL_FLOAT, 0, colors);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
@@ -87,43 +73,69 @@ static void tri_draw(void *data)
glPopMatrix();
}
-static void tri_run(void)
+
+/* new window size or exposure */
+static void
+reshape(int width, int height)
+{
+ GLfloat ar = (GLfloat) width / (GLfloat) height;
+
+ glViewport(0, 0, (GLint) width, (GLint) height);
+
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glFrustum(-ar, ar, -1, 1, 5.0, 60.0);
+
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ glTranslatef(0.0, 0.0, -10.0);
+}
+
+
+static void
+init(void)
{
- winsysRun(3.0, tri_draw, NULL);
+ glClearColor(0.4, 0.4, 0.4, 0.0);
}
-int main(int argc, char *argv[])
+
+static void
+special_key(int special)
{
- 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]);
- }
+ switch (special) {
+ case EGLUT_KEY_LEFT:
+ view_roty += 5.0;
+ break;
+ case EGLUT_KEY_RIGHT:
+ view_roty -= 5.0;
+ break;
+ case EGLUT_KEY_UP:
+ view_rotx += 5.0;
+ break;
+ case EGLUT_KEY_DOWN:
+ view_rotx -= 5.0;
+ break;
+ default:
+ break;
}
+}
- if (!winsysInitScreen())
- exit(1);
- winsysQueryScreenSize(&width, &height);
+int
+main(int argc, char *argv[])
+{
+ eglutInitWindowSize(300, 300);
+ eglutInitAPIMask(EGLUT_OPENGL_BIT);
+ eglutInit(argc, argv);
- 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));
- }
+ eglutCreateWindow("egltri");
+
+ eglutReshapeFunc(reshape);
+ eglutDisplayFunc(draw);
+ eglutSpecialFunc(special_key);
- tri_init();
- tri_reshape(width, height);
- tri_run();
+ init();
- winsysFiniScreen();
+ eglutMainLoop();
return 0;
}
diff --git a/progs/egl/peglgears.c b/progs/egl/opengl/peglgears.c
index 212d1acf69..212d1acf69 100644
--- a/progs/egl/peglgears.c
+++ b/progs/egl/opengl/peglgears.c
diff --git a/progs/egl/xeglgears.c b/progs/egl/opengl/xeglgears.c
index a6a977d9ff..a6a977d9ff 100644
--- a/progs/egl/xeglgears.c
+++ b/progs/egl/opengl/xeglgears.c
diff --git a/progs/egl/xeglthreads.c b/progs/egl/opengl/xeglthreads.c
index 5787faecb9..5787faecb9 100644
--- a/progs/egl/xeglthreads.c
+++ b/progs/egl/opengl/xeglthreads.c
diff --git a/progs/egl/opengles1/.gitignore b/progs/egl/opengles1/.gitignore
new file mode 100644
index 0000000000..135e3deb35
--- /dev/null
+++ b/progs/egl/opengles1/.gitignore
@@ -0,0 +1,15 @@
+bindtex
+drawtex_x11
+drawtex_screen
+es1_info
+gears_x11
+gears_screen
+msaa
+pbuffer
+render_tex
+texture_from_pixmap
+torus_x11
+torus_screen
+tri_x11
+tri_screen
+two_win
diff --git a/progs/egl/opengles1/Makefile b/progs/egl/opengles1/Makefile
new file mode 100644
index 0000000000..554cff9e6b
--- /dev/null
+++ b/progs/egl/opengles1/Makefile
@@ -0,0 +1,102 @@
+# progs/egl/opengles1/Makefile
+
+TOP = ../../..
+include $(TOP)/configs/current
+
+
+INCLUDE_DIRS = \
+ -I$(TOP)/include \
+
+HEADERS = $(TOP)/include/GLES/egl.h
+
+
+ES1_LIB_DEPS = \
+ $(TOP)/$(LIB_DIR)/libEGL.so \
+ $(TOP)/$(LIB_DIR)/libGLESv1_CM.so
+
+
+ES1_LIBS = \
+ -L$(TOP)/$(LIB_DIR) -lEGL \
+ -L$(TOP)/$(LIB_DIR) -lGLESv1_CM $(LIBDRM_LIB) -lX11
+
+EGLUT_DIR = $(TOP)/progs/egl/eglut
+
+EGLUT_DEMOS = \
+ drawtex \
+ gears \
+ torus \
+ tri
+
+EGLUT_X11_DEMOS := $(addsuffix _x11,$(EGLUT_DEMOS))
+EGLUT_SCREEN_DEMOS := $(addsuffix _screen,$(EGLUT_DEMOS))
+
+PROGRAMS = \
+ bindtex \
+ es1_info \
+ msaa \
+ pbuffer \
+ render_tex \
+ texture_from_pixmap \
+ two_win
+
+
+.c.o:
+ $(CC) -c $(INCLUDE_DIRS) -I$(EGLUT_DIR) $(CFLAGS) $< -o $@
+
+
+
+default: $(PROGRAMS) $(EGLUT_X11_DEMOS) $(EGLUT_SCREEN_DEMOS)
+
+
+
+bindtex: bindtex.o $(ES1_LIB_DEPS)
+ $(CC) $(CFLAGS) bindtex.o $(ES1_LIBS) -o $@
+
+
+es1_info: es1_info.o $(ES1_LIB_DEPS)
+ $(CC) $(CFLAGS) es1_info.o $(ES1_LIBS) -o $@
+
+
+msaa: msaa.o $(ES1_LIB_DEPS)
+ $(CC) $(CFLAGS) msaa.o $(ES1_LIBS) -o $@
+
+
+pbuffer: pbuffer.o $(ES1_LIB_DEPS)
+ $(CC) $(CFLAGS) pbuffer.o $(ES1_LIBS) -o $@
+
+
+render_tex: render_tex.o $(ES1_LIB_DEPS)
+ $(CC) $(CFLAGS) render_tex.o $(ES1_LIBS) -o $@
+
+
+texture_from_pixmap: texture_from_pixmap.o $(ES1_LIB_DEPS)
+ $(CC) $(CFLAGS) texture_from_pixmap.o $(ES1_LIBS) -o $@
+
+torus: torus.o $(ES1_LIB_DEPS)
+ $(CC) $(CFLAGS) torus.o $(ES1_LIBS) -o $@
+
+
+two_win: two_win.o $(ES1_LIB_DEPS)
+ $(CC) $(CFLAGS) two_win.o $(ES1_LIBS) -o $@
+
+
+$(EGLUT_DIR)/libeglut-x11.a $(EGLUT_DIR)/libeglut-screen.a:
+ @$(MAKE) -C $(EGLUT_DIR)
+
+# define the rules for EGLUT demos
+define eglut-demo-rule
+$(1)_x11 $(1)_screen: $(1)_%: $(1).o $(EGLUT_DIR)/libeglut-%.a $(ES1_LIB_DEPS)
+endef
+$(foreach demo, $(EGLUT_DEMOS), $(eval $(call eglut-demo-rule,$(demo))))
+
+# build EGLUT demos
+$(EGLUT_X11_DEMOS):
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -L$(EGLUT_DIR) -leglut-$* $(ES1_LIBS) -lX11
+$(EGLUT_SCREEN_DEMOS):
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -L$(EGLUT_DIR) -leglut-$* $(ES1_LIBS)
+
+
+clean:
+ -rm -f *.o *~
+ -rm -f $(PROGRAMS) $(EGLUT_X11_DEMOS) $(EGLUT_SCREEN_DEMOS)
+ @$(MAKE) -C $(EGLUT_DIR) clean
diff --git a/progs/es1/xegl/bindtex.c b/progs/egl/opengles1/bindtex.c
index c243b5941b..c243b5941b 100644
--- a/progs/es1/xegl/bindtex.c
+++ b/progs/egl/opengles1/bindtex.c
diff --git a/progs/egl/opengles1/drawtex.c b/progs/egl/opengles1/drawtex.c
new file mode 100644
index 0000000000..e9ac015340
--- /dev/null
+++ b/progs/egl/opengles1/drawtex.c
@@ -0,0 +1,217 @@
+/*
+ * Copyright (C) 2008 Tunsgten Graphics,Inc. All Rights Reserved.
+ */
+
+/*
+ * Test GL_OES_draw_texture
+ * Brian Paul
+ * August 2008
+ */
+
+#define GL_GLEXT_PROTOTYPES
+
+#include <math.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <GLES/gl.h>
+#include <GLES/glext.h>
+
+#include "eglut.h"
+
+
+static GLfloat view_posx = 10.0, view_posy = 20.0;
+static GLfloat width = 200, height = 200;
+static GLboolean animate = GL_FALSE;
+static int win;
+
+
+static void
+draw(void)
+{
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ glDrawTexfOES(view_posx, view_posy, 0.0, width, height);
+}
+
+
+/* new window size or exposure */
+static void
+reshape(int width, int height)
+{
+ GLfloat ar = (GLfloat) width / (GLfloat) height;
+
+ glViewport(0, 0, (GLint) width, (GLint) height);
+
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+
+#ifdef GL_VERSION_ES_CM_1_0
+ glFrustumf(-ar, ar, -1, 1, 5.0, 60.0);
+#else
+ glFrustum(-ar, ar, -1, 1, 5.0, 60.0);
+#endif
+
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ glTranslatef(0.0, 0.0, -15.0);
+}
+
+
+static float
+dist(GLuint i, GLuint j, float x, float y)
+{
+ return sqrt((i-x) * (i-x) + (j-y) * (j-y));
+}
+
+static void
+make_smile_texture(void)
+{
+#define SZ 128
+ GLenum Filter = GL_LINEAR;
+ GLubyte image[SZ][SZ][4];
+ GLuint i, j;
+ GLint cropRect[4];
+
+ for (i = 0; i < SZ; i++) {
+ for (j = 0; j < SZ; j++) {
+ GLfloat d_mouth = dist(i, j, SZ/2, SZ/2);
+ GLfloat d_rt_eye = dist(i, j, SZ*3/4, SZ*3/4);
+ GLfloat d_lt_eye = dist(i, j, SZ*3/4, SZ*1/4);
+ if (d_rt_eye < SZ / 8 || d_lt_eye < SZ / 8) {
+ image[i][j][0] = 20;
+ image[i][j][1] = 50;
+ image[i][j][2] = 255;
+ image[i][j][3] = 255;
+ }
+ else if (i < SZ/2 && d_mouth < SZ/3) {
+ image[i][j][0] = 255;
+ image[i][j][1] = 20;
+ image[i][j][2] = 20;
+ image[i][j][3] = 255;
+ }
+ else {
+ image[i][j][0] = 200;
+ image[i][j][1] = 200;
+ image[i][j][2] = 200;
+ image[i][j][3] = 255;
+ }
+ }
+ }
+
+ glActiveTexture(GL_TEXTURE0); /* unit 0 */
+ glBindTexture(GL_TEXTURE_2D, 42);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, SZ, SZ, 0,
+ GL_RGBA, GL_UNSIGNED_BYTE, image);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, Filter);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, Filter);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+
+ cropRect[0] = 0;
+ cropRect[1] = 0;
+ cropRect[2] = SZ;
+ cropRect[3] = SZ;
+ glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, cropRect);
+#undef SZ
+}
+
+
+
+static void
+init(void)
+{
+ const char *ext = (char *) glGetString(GL_EXTENSIONS);
+
+ if (!strstr(ext, "GL_OES_draw_texture")) {
+ fprintf(stderr, "Sorry, this program requires GL_OES_draw_texture");
+ exit(1);
+ }
+
+ glClearColor(0.4, 0.4, 0.4, 0.0);
+
+ make_smile_texture();
+ glEnable(GL_TEXTURE_2D);
+}
+
+
+static void
+idle(void)
+{
+ if (animate) {
+ view_posx += 1.0;
+ view_posy += 2.0;
+ eglutPostRedisplay();
+ }
+}
+
+static void
+key(unsigned char key)
+{
+ switch (key) {
+ case ' ':
+ animate = !animate;
+ break;
+ case 'w':
+ width -= 1.0f;
+ break;
+ case 'W':
+ width += 1.0f;
+ break;
+ case 'h':
+ height -= 1.0f;
+ break;
+ case 'H':
+ height += 1.0f;
+ break;
+ case 27:
+ eglutDestroyWindow(win);
+ exit(0);
+ break;
+ default:
+ break;
+ }
+}
+
+static void
+special_key(int key)
+{
+ switch (key) {
+ case EGLUT_KEY_LEFT:
+ view_posx -= 1.0;
+ break;
+ case EGLUT_KEY_RIGHT:
+ view_posx += 1.0;
+ break;
+ case EGLUT_KEY_UP:
+ view_posy += 1.0;
+ break;
+ case EGLUT_KEY_DOWN:
+ view_posy -= 1.0;
+ break;
+ default:
+ break;
+ }
+}
+
+int
+main(int argc, char *argv[])
+{
+ eglutInitWindowSize(400, 300);
+ eglutInitAPIMask(EGLUT_OPENGL_ES1_BIT);
+ eglutInit(argc, argv);
+
+ win = eglutCreateWindow("drawtex");
+
+ eglutIdleFunc(idle);
+ eglutReshapeFunc(reshape);
+ eglutDisplayFunc(draw);
+ eglutKeyboardFunc(key);
+ eglutSpecialFunc(special_key);
+
+ init();
+
+ eglutMainLoop();
+
+ return 0;
+}
diff --git a/progs/es1/xegl/es1_info.c b/progs/egl/opengles1/es1_info.c
index 93816b5215..93816b5215 100644
--- a/progs/es1/xegl/es1_info.c
+++ b/progs/egl/opengles1/es1_info.c
diff --git a/progs/es1/screen/gears.c b/progs/egl/opengles1/gears.c
index c7625826b9..8462a4871a 100644
--- a/progs/es1/screen/gears.c
+++ b/progs/egl/opengles1/gears.c
@@ -28,7 +28,7 @@
#include <assert.h>
#include <GLES/gl.h>
-#include "winsys.h"
+#include "eglut.h"
#ifndef M_PI
#define M_PI 3.14159265
@@ -247,7 +247,7 @@ draw_gear(const struct gear *gear)
static void
-gears_draw(void *data)
+gears_draw(void)
{
static const GLfloat red[4] = { 0.8, 0.1, 0.0, 1.0 };
static const GLfloat green[4] = { 0.0, 0.8, 0.2, 1.0 };
@@ -288,11 +288,6 @@ gears_draw(void *data)
glPopMatrix();
glPopMatrix();
-
- /* advance rotation for next frame */
- angle += 0.5; /* 0.5 degree per frame */
- if (angle > 3600.0)
- angle -= 3600.0;
}
@@ -348,27 +343,41 @@ gears_reshape(int width, int height)
}
-static void gears_run(void)
+static void
+gears_idle(void)
{
- winsysRun(5.0, gears_draw, NULL);
+ static double t0 = -1.;
+ double dt, t = eglutGet(EGLUT_ELAPSED_TIME) / 1000.0;
+ if (t0 < 0.0)
+ t0 = t;
+ dt = t - t0;
+ t0 = t;
+
+ angle += 70.0 * dt; /* 70 degrees per second */
+ angle = fmod(angle, 360.0); /* prevents eventual overflow */
+
+ eglutPostRedisplay();
}
int
main(int argc, char *argv[])
{
- EGLint width, height;
+ eglutInitWindowSize(300, 300);
+ eglutInitAPIMask(EGLUT_OPENGL_ES1_BIT);
+ eglutInit(argc, argv);
- if (!winsysInitScreen())
- exit(1);
- winsysQueryScreenSize(&width, &height);
+ eglutCreateWindow("gears");
+
+ eglutIdleFunc(gears_idle);
+ eglutReshapeFunc(gears_reshape);
+ eglutDisplayFunc(gears_draw);
gears_init();
- gears_reshape(width, height);
- gears_run();
- gears_fini();
- winsysFiniScreen();
+ eglutMainLoop();
+
+ gears_fini();
return 0;
}
diff --git a/progs/es1/xegl/msaa.c b/progs/egl/opengles1/msaa.c
index b4c6c63217..b4c6c63217 100644
--- a/progs/es1/xegl/msaa.c
+++ b/progs/egl/opengles1/msaa.c
diff --git a/progs/es1/xegl/pbuffer.c b/progs/egl/opengles1/pbuffer.c
index 011c2af58f..60f864445a 100644
--- a/progs/es1/xegl/pbuffer.c
+++ b/progs/egl/opengles1/pbuffer.c
@@ -168,6 +168,8 @@ draw_both(EGLDisplay egl_dpy, EGLSurface egl_surf, EGLSurface egl_pbuf,
glReadPixels(0, 0, WinWidth, WinHeight, GL_RGBA, GL_UNSIGNED_BYTE, wbuf);
printf("Window[%d,%d] = 0x%08x\n", x, y, wbuf[y*WinWidth+x]);
+ eglSwapBuffers(egl_dpy, egl_surf);
+
/* then draw to pbuffer */
if (!eglMakeCurrent(egl_dpy, egl_pbuf, egl_pbuf, egl_ctx)) {
printf("Error: eglMakeCurrent(pbuffer) failed\n");
@@ -177,7 +179,6 @@ draw_both(EGLDisplay egl_dpy, EGLSurface egl_surf, EGLSurface egl_pbuf,
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++) {
diff --git a/progs/es1/xegl/render_tex.c b/progs/egl/opengles1/render_tex.c
index 0200fa4cb0..0200fa4cb0 100644
--- a/progs/es1/xegl/render_tex.c
+++ b/progs/egl/opengles1/render_tex.c
diff --git a/progs/egl/opengles1/texture_from_pixmap.c b/progs/egl/opengles1/texture_from_pixmap.c
new file mode 100644
index 0000000000..79b9474a57
--- /dev/null
+++ b/progs/egl/opengles1/texture_from_pixmap.c
@@ -0,0 +1,578 @@
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.9
+ *
+ * Copyright (C) 2010 LunarG Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ * Chia-I Wu <olv@lunarg.com>
+ */
+
+/*
+ * This demo uses EGL_KHR_image_pixmap and GL_OES_EGL_image to demonstrate
+ * texture-from-pixmap.
+ */
+
+#include <assert.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h> /* for usleep */
+#include <sys/time.h> /* for gettimeofday */
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/keysym.h>
+#include <GLES/gl.h>
+#include <GLES/glext.h>
+#include <EGL/egl.h>
+#include <EGL/eglext.h>
+
+struct app_data {
+ /* native */
+ Display *xdpy;
+ Window canvas, cube;
+ Pixmap pix;
+ unsigned int width, height, depth;
+ GC fg, bg;
+
+ /* EGL */
+ EGLDisplay dpy;
+ EGLContext ctx;
+ EGLSurface surf;
+ EGLImageKHR img;
+
+ /* OpenGL ES */
+ GLuint texture;
+
+ PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR;
+ PFNEGLDESTROYIMAGEKHRPROC eglDestroyImageKHR;
+ PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES;
+
+ /* app state */
+ Bool loop;
+ Bool redraw, reshape;
+
+ struct {
+ Bool active;
+ unsigned long next_frame; /* in ms */
+ float view_rotx;
+ float view_roty;
+ float view_rotz;
+
+ } animate;
+
+ struct {
+ Bool active;
+ int x1, y1;
+ int x2, y2;
+ } paint;
+};
+
+static void
+gl_redraw(void)
+{
+ const GLfloat verts[4][2] = {
+ { -1, -1 },
+ { 1, -1 },
+ { 1, 1 },
+ { -1, 1 }
+ };
+ const GLfloat texcoords[4][2] = {
+ { 0, 1 },
+ { 1, 1 },
+ { 1, 0 },
+ { 0, 0 }
+ };
+ const GLfloat faces[6][4] = {
+ { 0, 0, 1, 0 },
+ { 90, 0, 1, 0 },
+ { 180, 0, 1, 0 },
+ { 270, 0, 1, 0 },
+ { 90, 1, 0, 0 },
+ { -90, 1, 0, 0 }
+ };
+ GLint i;
+
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ glVertexPointer(2, GL_FLOAT, 0, verts);
+ glTexCoordPointer(2, GL_FLOAT, 0, texcoords);
+
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+
+ for (i = 0; i < 6; i++) {
+ glPushMatrix();
+ glRotatef(faces[i][0], faces[i][1], faces[i][2], faces[i][3]);
+ glTranslatef(0, 0, 1.0);
+ glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+ glPopMatrix();
+ }
+
+ glDisableClientState(GL_VERTEX_ARRAY);
+ glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+}
+
+static void
+gl_reshape(int width, int height)
+{
+ GLfloat ar = (GLfloat) width / (GLfloat) height;
+
+ glViewport(0, 0, width, height);
+
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glFrustumf(-ar, ar, -1, 1, 5.0, 60.0);
+
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ glTranslatef(0.0, 0.0, -10.0);
+}
+
+static void
+app_redraw(struct app_data *data)
+{
+ /* pixmap has changed */
+ if (data->reshape || data->paint.active) {
+ eglWaitNative(EGL_CORE_NATIVE_ENGINE);
+
+ if (data->reshape) {
+ data->glEGLImageTargetTexture2DOES(GL_TEXTURE_2D,
+ (GLeglImageOES) data->img);
+ }
+ }
+
+ XCopyArea(data->xdpy, data->pix, data->canvas, data->fg,
+ 0, 0, data->width, data->height, 0, 0);
+
+ glPushMatrix();
+ glRotatef(data->animate.view_rotx, 1, 0, 0);
+ glRotatef(data->animate.view_roty, 0, 1, 0);
+ glRotatef(data->animate.view_rotz, 0, 0, 1);
+ gl_redraw();
+ glPopMatrix();
+
+ eglSwapBuffers(data->dpy, data->surf);
+}
+
+static void
+app_reshape(struct app_data *data)
+{
+ const EGLint img_attribs[] = {
+ EGL_IMAGE_PRESERVED_KHR, EGL_TRUE,
+ EGL_NONE
+ };
+
+ XResizeWindow(data->xdpy, data->cube, data->width, data->height);
+ XMoveWindow(data->xdpy, data->cube, data->width, 0);
+
+ if (data->img)
+ data->eglDestroyImageKHR(data->dpy, data->img);
+ if (data->pix)
+ XFreePixmap(data->xdpy, data->pix);
+
+ data->pix = XCreatePixmap(data->xdpy, data->canvas, data->width, data->height, data->depth);
+ XFillRectangle(data->xdpy, data->pix, data->bg, 0, 0, data->width, data->height);
+
+ data->img = data->eglCreateImageKHR(data->dpy, EGL_NO_CONTEXT,
+ EGL_NATIVE_PIXMAP_KHR, (EGLClientBuffer) data->pix, img_attribs);
+
+ gl_reshape(data->width, data->height);
+}
+
+static void
+app_toggle_animate(struct app_data *data)
+{
+ data->animate.active = !data->animate.active;
+
+ if (data->animate.active) {
+ struct timeval tv;
+
+ gettimeofday(&tv, NULL);
+ data->animate.next_frame = tv.tv_sec * 1000 + tv.tv_usec / 1000;
+ }
+}
+
+static void
+app_next_event(struct app_data *data)
+{
+ XEvent event;
+
+ data->reshape = False;
+ data->redraw = False;
+ data->paint.active = False;
+
+ if (data->animate.active) {
+ struct timeval tv;
+ unsigned long now;
+
+ gettimeofday(&tv, NULL);
+ now = tv.tv_sec * 1000 + tv.tv_usec / 1000;
+
+ /* wait for next frame */
+ if (!XPending(data->xdpy) && now < data->animate.next_frame) {
+ usleep((data->animate.next_frame - now) * 1000);
+ gettimeofday(&tv, NULL);
+ now = tv.tv_sec * 1000 + tv.tv_usec / 1000;
+ }
+
+ while (now >= data->animate.next_frame) {
+ data->animate.view_rotx += 1.0;
+ data->animate.view_roty += 2.0;
+ data->animate.view_rotz += 1.5;
+
+ /* 30fps */
+ data->animate.next_frame += 1000 / 30;
+ }
+
+ /* check again in case there were events when sleeping */
+ if (!XPending(data->xdpy)) {
+ data->redraw = True;
+ return;
+ }
+ }
+
+ XNextEvent(data->xdpy, &event);
+
+ switch (event.type) {
+ case ConfigureNotify:
+ data->width = event.xconfigure.width / 2;
+ data->height = event.xconfigure.height;
+ data->reshape = True;
+ break;
+ case Expose:
+ data->redraw = True;
+ break;
+ case KeyPress:
+ {
+ int code;
+
+ code = XLookupKeysym(&event.xkey, 0);
+ switch (code) {
+ case XK_a:
+ app_toggle_animate(data);
+ break;
+ case XK_Escape:
+ data->loop = False;
+ break;
+ default:
+ break;
+ }
+ }
+ break;
+ case ButtonPress:
+ data->paint.x1 = data->paint.x2 = event.xbutton.x;
+ data->paint.y1 = data->paint.y2 = event.xbutton.y;
+ break;
+ case ButtonRelease:
+ data->paint.active = False;
+ break;
+ case MotionNotify:
+ data->paint.x1 = data->paint.x2;
+ data->paint.y1 = data->paint.y2;
+ data->paint.x2 = event.xmotion.x;
+ data->paint.y2 = event.xmotion.y;
+ data->paint.active = True;
+ break;
+ default:
+ break;
+ }
+
+ if (data->paint.active || data->reshape)
+ data->redraw = True;
+}
+
+static void
+app_init_gl(struct app_data *data)
+{
+ glClearColor(0.1, 0.1, 0.3, 0.0);
+ glColor4f(1.0, 1.0, 1.0, 1.0);
+
+ glGenTextures(1, &data->texture);
+
+ glBindTexture(GL_TEXTURE_2D, data->texture);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+
+ glEnable(GL_TEXTURE_2D);
+ glEnable(GL_DEPTH_TEST);
+}
+
+static Bool
+app_init_exts(struct app_data *data)
+{
+ const char *exts;
+
+ exts = eglQueryString(data->dpy, EGL_EXTENSIONS);
+ data->eglCreateImageKHR =
+ (PFNEGLCREATEIMAGEKHRPROC) eglGetProcAddress("eglCreateImageKHR");
+ data->eglDestroyImageKHR =
+ (PFNEGLDESTROYIMAGEKHRPROC) eglGetProcAddress("eglDestroyImageKHR");
+ if (!exts || !strstr(exts, "EGL_KHR_image_pixmap") ||
+ !data->eglCreateImageKHR || !data->eglDestroyImageKHR) {
+ printf("EGL does not support EGL_KHR_image_pixmap\n");
+ return False;
+ }
+
+ exts = (const char *) glGetString(GL_EXTENSIONS);
+ data->glEGLImageTargetTexture2DOES = (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC)
+ eglGetProcAddress("glEGLImageTargetTexture2DOES");
+ if (!exts || !strstr(exts, "GL_OES_EGL_image") ||
+ !data->glEGLImageTargetTexture2DOES) {
+ printf("OpenGL ES does not support GL_OES_EGL_image\n");
+ return False;
+ }
+
+ return True;
+}
+
+static void
+app_run(struct app_data *data)
+{
+ Window root;
+ int x, y;
+ unsigned int border;
+
+ if (!eglMakeCurrent(data->dpy, data->surf, data->surf, data->ctx))
+ return;
+
+ if (!app_init_exts(data))
+ return;
+
+ printf("Draw something on the left with the mouse!\n");
+
+ app_init_gl(data);
+
+ if (!XGetGeometry(data->xdpy, data->canvas, &root, &x, &y,
+ &data->width, &data->height, &border, &data->depth))
+ return;
+ data->width /= 2;
+
+ app_reshape(data);
+
+ XMapWindow(data->xdpy, data->canvas);
+ XMapWindow(data->xdpy, data->cube);
+
+ app_toggle_animate(data);
+ data->loop = True;
+
+ while (data->loop) {
+ app_next_event(data);
+
+ if (data->reshape)
+ app_reshape(data);
+ if (data->paint.active) {
+ XDrawLine(data->xdpy, data->pix, data->fg,
+ data->paint.x1, data->paint.y1,
+ data->paint.x2, data->paint.y2);
+ }
+
+ if (data->redraw)
+ app_redraw(data);
+ }
+
+ eglMakeCurrent(data->dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
+}
+
+static Bool
+make_x_window(struct app_data *data, const char *name,
+ int x, int y, int width, int height)
+{
+ static const EGLint attribs[] = {
+ EGL_RED_SIZE, 1,
+ EGL_GREEN_SIZE, 1,
+ EGL_BLUE_SIZE, 1,
+ EGL_DEPTH_SIZE, 1,
+ EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT,
+ EGL_NONE
+ };
+ static const EGLint ctx_attribs[] = {
+ EGL_CONTEXT_CLIENT_VERSION, 1,
+ EGL_NONE
+ };
+ int scrnum;
+ XSetWindowAttributes attr;
+ unsigned long mask;
+ Window root;
+ Window win;
+ XVisualInfo *visInfo, visTemplate;
+ int num_visuals;
+ EGLConfig config;
+ EGLint num_configs;
+ EGLint vid;
+
+ scrnum = DefaultScreen( data->xdpy );
+ root = RootWindow( data->xdpy, scrnum );
+
+ if (!eglChooseConfig( data->dpy, attribs, &config, 1, &num_configs)) {
+ printf("Error: couldn't get an EGL visual config\n");
+ exit(1);
+ }
+
+ assert(config);
+ assert(num_configs > 0);
+
+ if (!eglGetConfigAttrib(data->dpy, config, EGL_NATIVE_VISUAL_ID, &vid)) {
+ printf("Error: eglGetConfigAttrib() failed\n");
+ exit(1);
+ }
+
+ /* The X window visual must match the EGL config */
+ visTemplate.visualid = vid;
+ visInfo = XGetVisualInfo(data->xdpy, VisualIDMask, &visTemplate, &num_visuals);
+ if (!visInfo) {
+ printf("Error: couldn't get X visual\n");
+ exit(1);
+ }
+
+ /* window attributes */
+ attr.background_pixel = 0;
+ attr.border_pixel = 0;
+ attr.colormap = XCreateColormap( data->xdpy, root, visInfo->visual, AllocNone);
+ attr.event_mask = StructureNotifyMask | ExposureMask |
+ KeyPressMask | ButtonPressMask | ButtonMotionMask;
+ mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
+
+ win = XCreateWindow( data->xdpy, root, 0, 0, width * 2, height,
+ 0, visInfo->depth, InputOutput,
+ visInfo->visual, mask, &attr );
+
+ /* set hints and properties */
+ {
+ XSizeHints sizehints;
+ sizehints.x = x;
+ sizehints.y = y;
+ sizehints.width = width;
+ sizehints.height = height;
+ sizehints.flags = USSize | USPosition;
+ XSetNormalHints(data->xdpy, win, &sizehints);
+ XSetStandardProperties(data->xdpy, win, name, name,
+ None, (char **)NULL, 0, &sizehints);
+ }
+
+ data->canvas = win;
+
+ attr.event_mask = 0x0;
+ win = XCreateWindow( data->xdpy, win, width, 0, width, height,
+ 0, visInfo->depth, InputOutput,
+ visInfo->visual, mask, &attr );
+ data->cube = win;
+
+ eglBindAPI(EGL_OPENGL_ES_API);
+
+ data->ctx = eglCreateContext(data->dpy, config, EGL_NO_CONTEXT, ctx_attribs );
+ if (!data->ctx) {
+ printf("Error: eglCreateContext failed\n");
+ exit(1);
+ }
+
+ data->surf = eglCreateWindowSurface(data->dpy, config, data->cube, NULL);
+ if (!data->surf) {
+ printf("Error: eglCreateWindowSurface failed\n");
+ exit(1);
+ }
+
+ XFree(visInfo);
+
+ return (data->canvas && data->cube && data->ctx && data->surf);
+}
+
+static void
+app_fini(struct app_data *data)
+{
+ if (data->img)
+ data->eglDestroyImageKHR(data->dpy, data->img);
+ if (data->pix)
+ XFreePixmap(data->xdpy, data->pix);
+
+ if (data->fg)
+ XFreeGC(data->xdpy, data->fg);
+ if (data->bg)
+ XFreeGC(data->xdpy, data->bg);
+
+ if (data->surf)
+ eglDestroySurface(data->dpy, data->surf);
+ if (data->ctx)
+ eglDestroyContext(data->dpy, data->ctx);
+
+ if (data->cube)
+ XDestroyWindow(data->xdpy, data->cube);
+ if (data->canvas)
+ XDestroyWindow(data->xdpy, data->canvas);
+
+ if (data->dpy)
+ eglTerminate(data->dpy);
+ if (data->xdpy)
+ XCloseDisplay(data->xdpy);
+}
+
+static Bool
+app_init(struct app_data *data, int argc, char **argv)
+{
+ XGCValues gc_vals;
+
+ memset(data, 0, sizeof(*data));
+
+ data->xdpy = XOpenDisplay(NULL);
+ if (!data->xdpy)
+ goto fail;
+
+ data->dpy = eglGetDisplay(data->xdpy);
+ if (!data->dpy || !eglInitialize(data->dpy, NULL, NULL))
+ goto fail;
+
+ if (!make_x_window(data, "EGLImage TFP", 0, 0, 300, 300))
+ goto fail;
+
+ gc_vals.function = GXcopy;
+ gc_vals.foreground = WhitePixel(data->xdpy, DefaultScreen(data->xdpy));
+ gc_vals.line_width = 3;
+ gc_vals.line_style = LineSolid;
+ gc_vals.fill_style = FillSolid;
+
+ data->fg = XCreateGC(data->xdpy, data->canvas,
+ GCFunction | GCForeground | GCLineWidth | GCLineStyle | GCFillStyle,
+ &gc_vals);
+ gc_vals.foreground = BlackPixel(data->xdpy, DefaultScreen(data->xdpy));
+ data->bg = XCreateGC(data->xdpy, data->canvas,
+ GCFunction | GCForeground | GCLineWidth | GCLineStyle | GCFillStyle,
+ &gc_vals);
+ if (!data->fg || !data->bg)
+ goto fail;
+
+ return True;
+
+fail:
+ app_fini(data);
+ return False;
+}
+
+int
+main(int argc, char **argv)
+{
+ struct app_data data;
+
+ if (app_init(&data, argc, argv)) {
+ app_run(&data);
+ app_fini(&data);
+ }
+
+ return 0;
+}
diff --git a/progs/es1/xegl/torus.c b/progs/egl/opengles1/torus.c
index 9438a4fe59..8f262b53d6 100644
--- a/progs/es1/xegl/torus.c
+++ b/progs/egl/opengles1/torus.c
@@ -13,14 +13,9 @@
#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>
+#include "eglut.h"
static const struct {
GLenum internalFormat;
@@ -43,6 +38,8 @@ static const struct {
static GLfloat view_rotx = 0.0, view_roty = 0.0, view_rotz = 0.0;
static GLint tex_format = NUM_CPAL_FORMATS;
+static GLboolean animate = GL_TRUE;
+static int win;
static void
@@ -364,293 +361,88 @@ init(void)
}
-/*
- * 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)
+idle(void)
{
- 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);
+ if (animate) {
+ view_rotx += 1.0;
+ view_roty += 2.0;
+ eglutPostRedisplay();
}
-
- XFree(visInfo);
-
- *winRet = win;
- *ctxRet = ctx;
}
-
static void
-event_loop(Display *dpy, Window win,
- EGLDisplay egl_dpy, EGLSurface egl_surf)
+key(unsigned char key)
{
- 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*/
+ switch (key) {
+ case ' ':
+ animate = !animate;
+ break;
+ case 't':
+ {
+ GLint size;
+ tex_format = (tex_format + 1) % (NUM_CPAL_FORMATS + 1);
+ if (tex_format < NUM_CPAL_FORMATS) {
+ size = make_cpal_texture(tex_format);
+ printf("Using %s (%d bytes)\n",
+ cpal_formats[tex_format].name, size);
+ }
+ else {
+ size = make_texture();
+ printf("Using uncompressed texture (%d bytes)\n", size);
}
- }
-
- if (anim) {
- view_rotx += 1.0;
- view_roty += 2.0;
- redraw = 1;
- }
- if (redraw) {
- draw();
- eglSwapBuffers(egl_dpy, egl_surf);
+ eglutPostRedisplay();
}
+ break;
+ case 27:
+ eglutDestroyWindow(win);
+ exit(0);
+ break;
+ default:
+ break;
}
}
-
static void
-usage(void)
+special_key(int key)
{
- printf("Usage:\n");
- printf(" -display <displayname> set the display to run on\n");
- printf(" -info display OpenGL renderer info\n");
+ switch (key) {
+ case EGLUT_KEY_LEFT:
+ view_roty += 5.0;
+ break;
+ case EGLUT_KEY_RIGHT:
+ view_roty -= 5.0;
+ break;
+ case EGLUT_KEY_UP:
+ view_rotx += 5.0;
+ break;
+ case EGLUT_KEY_DOWN:
+ view_rotx -= 5.0;
+ break;
+ default:
+ break;
+ }
}
-
int
main(int argc, char *argv[])
{
- 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);
+ eglutInitWindowSize(300, 300);
+ eglutInitAPIMask(EGLUT_OPENGL_ES1_BIT);
+ eglutInit(argc, argv);
- make_x_window(x_dpy, egl_dpy,
- "torus", 0, 0, winWidth, winHeight,
- &win, &egl_ctx, &egl_surf);
+ win = eglutCreateWindow("torus");
- 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));
- }
+ eglutIdleFunc(idle);
+ eglutReshapeFunc(reshape);
+ eglutDisplayFunc(draw);
+ eglutKeyboardFunc(key);
+ eglutSpecialFunc(special_key);
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);
+ eglutMainLoop();
return 0;
}
diff --git a/progs/egl/opengles1/tri.c b/progs/egl/opengles1/tri.c
new file mode 100644
index 0000000000..01ad9bd37e
--- /dev/null
+++ b/progs/egl/opengles1/tri.c
@@ -0,0 +1,211 @@
+/*
+ * Copyright (C) 2008 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*
+ * Draw a triangle with X/EGL and OpenGL ES 1.x
+ * Brian Paul
+ * 5 June 2008
+ */
+
+#define USE_FIXED_POINT 0
+
+
+#include <assert.h>
+#include <math.h>
+#include <stdio.h>
+#include <GLES/gl.h> /* use OpenGL ES 1.x */
+#include <GLES/glext.h>
+#include <EGL/egl.h>
+
+#include "eglut.h"
+
+
+#define FLOAT_TO_FIXED(X) ((X) * 65535.0)
+
+
+
+static GLfloat view_rotx = 0.0, view_roty = 0.0, view_rotz = 0.0;
+
+
+static void
+draw(void)
+{
+#if USE_FIXED_POINT
+ static const GLfixed verts[3][2] = {
+ { -65536, -65536 },
+ { 65536, -65536 },
+ { 0, 65536 }
+ };
+ static const GLfixed colors[3][4] = {
+ { 65536, 0, 0, 65536 },
+ { 0, 65536, 0 , 65536},
+ { 0, 0, 65536 , 65536}
+ };
+#else
+ static const GLfloat verts[3][2] = {
+ { -1, -1 },
+ { 1, -1 },
+ { 0, 1 }
+ };
+ static const GLfloat colors[3][4] = {
+ { 1, 0, 0, 1 },
+ { 0, 1, 0, 1 },
+ { 0, 0, 1, 1 }
+ };
+#endif
+
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ glPushMatrix();
+ glRotatef(view_rotx, 1, 0, 0);
+ glRotatef(view_roty, 0, 1, 0);
+ glRotatef(view_rotz, 0, 0, 1);
+
+ {
+#if USE_FIXED_POINT
+ glVertexPointer(2, GL_FIXED, 0, verts);
+ glColorPointer(4, GL_FIXED, 0, colors);
+#else
+ glVertexPointer(2, GL_FLOAT, 0, verts);
+ glColorPointer(4, GL_FLOAT, 0, colors);
+#endif
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glEnableClientState(GL_COLOR_ARRAY);
+
+ /* draw triangle */
+ glDrawArrays(GL_TRIANGLES, 0, 3);
+
+ /* draw some points */
+ glPointSizex(FLOAT_TO_FIXED(15.5));
+ glDrawArrays(GL_POINTS, 0, 3);
+
+ glDisableClientState(GL_VERTEX_ARRAY);
+ glDisableClientState(GL_COLOR_ARRAY);
+ }
+
+ if (0) {
+ /* test code */
+ GLfixed size;
+ glGetFixedv(GL_POINT_SIZE, &size);
+ printf("GL_POINT_SIZE = 0x%x %f\n", size, size / 65536.0);
+ }
+
+ glPopMatrix();
+}
+
+
+/* new window size or exposure */
+static void
+reshape(int width, int height)
+{
+ GLfloat ar = (GLfloat) width / (GLfloat) height;
+
+ glViewport(0, 0, (GLint) width, (GLint) height);
+
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+#ifdef GL_VERSION_ES_CM_1_0
+ glFrustumf(-ar, ar, -1, 1, 5.0, 60.0);
+#else
+ glFrustum(-ar, ar, -1, 1, 5.0, 60.0);
+#endif
+
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ glTranslatef(0.0, 0.0, -10.0);
+}
+
+
+static void
+test_query_matrix(void)
+{
+ PFNGLQUERYMATRIXXOESPROC procQueryMatrixx;
+ typedef void (*voidproc)();
+ GLfixed mantissa[16];
+ GLint exponent[16];
+ GLbitfield rv;
+ int i;
+
+ procQueryMatrixx = (PFNGLQUERYMATRIXXOESPROC) eglGetProcAddress("glQueryMatrixxOES");
+ assert(procQueryMatrixx);
+ /* Actually try out this one */
+ rv = (*procQueryMatrixx)(mantissa, exponent);
+ for (i = 0; i < 16; i++) {
+ if (rv & (1<<i)) {
+ printf("matrix[%d] invalid\n", i);
+ }
+ else {
+ printf("matrix[%d] = %f * 2^(%d)\n", i, mantissa[i]/65536.0, exponent[i]);
+ }
+ }
+ assert(!eglGetProcAddress("glFoo"));
+}
+
+
+static void
+init(void)
+{
+ glClearColor(0.4, 0.4, 0.4, 0.0);
+
+ if (0)
+ test_query_matrix();
+}
+
+static void
+special_key(int special)
+{
+ switch (special) {
+ case EGLUT_KEY_LEFT:
+ view_roty += 5.0;
+ break;
+ case EGLUT_KEY_RIGHT:
+ view_roty -= 5.0;
+ break;
+ case EGLUT_KEY_UP:
+ view_rotx += 5.0;
+ break;
+ case EGLUT_KEY_DOWN:
+ view_rotx -= 5.0;
+ break;
+ default:
+ break;
+ }
+}
+
+int
+main(int argc, char *argv[])
+{
+ eglutInitWindowSize(300, 300);
+ eglutInitAPIMask(EGLUT_OPENGL_ES1_BIT);
+ eglutInit(argc, argv);
+
+ eglutCreateWindow("tri");
+
+ eglutReshapeFunc(reshape);
+ eglutDisplayFunc(draw);
+ eglutSpecialFunc(special_key);
+
+ init();
+
+ eglutMainLoop();
+
+ return 0;
+}
diff --git a/progs/es1/xegl/two_win.c b/progs/egl/opengles1/two_win.c
index 4785e5304d..4785e5304d 100644
--- a/progs/es1/xegl/two_win.c
+++ b/progs/egl/opengles1/two_win.c
diff --git a/progs/egl/opengles2/.gitignore b/progs/egl/opengles2/.gitignore
new file mode 100644
index 0000000000..6158cc6e68
--- /dev/null
+++ b/progs/egl/opengles2/.gitignore
@@ -0,0 +1,3 @@
+es2_info.c
+es2_info
+tri
diff --git a/progs/es2/xegl/Makefile b/progs/egl/opengles2/Makefile
index 5bb167c1c6..710c4d8c13 100644
--- a/progs/es2/xegl/Makefile
+++ b/progs/egl/opengles2/Makefile
@@ -1,4 +1,4 @@
-# progs/es2/xegl/Makefile
+# progs/egl/opengles2/Makefile
TOP = ../../..
include $(TOP)/configs/current
@@ -33,7 +33,7 @@ default: $(PROGRAMS)
-es2_info.c: ../../es1/xegl/es1_info.c
+es2_info.c: ../opengles1/es1_info.c
cp -f $^ $@
es2_info: es2_info.o $(ES2_LIB_DEPS)
diff --git a/progs/es2/xegl/tri.c b/progs/egl/opengles2/tri.c
index 8981d8a7e2..8981d8a7e2 100644
--- a/progs/es2/xegl/tri.c
+++ b/progs/egl/opengles2/tri.c
diff --git a/progs/openvg/.gitignore b/progs/egl/openvg/.gitignore
index 9b05e1e81d..3e1733c8c8 100644
--- a/progs/openvg/.gitignore
+++ b/progs/egl/openvg/.gitignore
@@ -1,5 +1,7 @@
-demos/lion
-demos/sp
+lion_x11
+lion_screen
+sp_x11
+sp_screen
trivial/arc
trivial/cap
trivial/clear
diff --git a/progs/egl/openvg/Makefile b/progs/egl/openvg/Makefile
new file mode 100644
index 0000000000..5a10cc8055
--- /dev/null
+++ b/progs/egl/openvg/Makefile
@@ -0,0 +1,55 @@
+# progs/egl/openvg/Makefile
+
+TOP = ../../..
+include $(TOP)/configs/current
+
+VG_LIBS=-lm -lEGL -lOpenVG
+INCLUDE_DIRS = -I$(TOP)/include
+
+EGLUT_DIR = $(TOP)/progs/egl/eglut
+
+EGLUT_DEMOS = \
+ sp
+
+EGLUT_X11_DEMOS := $(addsuffix _x11,$(EGLUT_DEMOS))
+EGLUT_SCREEN_DEMOS := $(addsuffix _screen,$(EGLUT_DEMOS))
+
+PROGRAMS = \
+ lion_x11 \
+ lion_screen
+
+.c.o:
+ $(CC) -c $(INCLUDE_DIRS) -I$(EGLUT_DIR) $(CFLAGS) $< -o $@
+
+
+
+default: $(PROGRAMS) $(EGLUT_X11_DEMOS) $(EGLUT_SCREEN_DEMOS)
+
+lion_x11: lion.o lion-render.o $(EGLUT_DIR)/libeglut-x11.a
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ lion.o lion-render.o \
+ -L$(EGLUT_DIR) -leglut-x11 $(VG_LIBS) -lX11
+
+lion_screen: lion.o lion-render.o $(EGLUT_DIR)/libeglut-screen.a
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ lion.o lion-render.o \
+ -L$(EGLUT_DIR) -leglut-screen $(VG_LIBS)
+
+
+$(EGLUT_DIR)/libeglut-x11.a $(EGLUT_DIR)/libeglut-screen.a:
+ @$(MAKE) -C $(EGLUT_DIR)
+
+# define the rules for EGLUT demos
+define eglut-demo-rule
+$(1)_x11 $(1)_screen: $(1)_%: $(1).o $(EGLUT_DIR)/libeglut-%.a
+endef
+$(foreach demo, $(EGLUT_DEMOS), $(eval $(call eglut-demo-rule,$(demo))))
+
+# build EGLUT demos
+$(EGLUT_X11_DEMOS):
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -L$(EGLUT_DIR) -leglut-$* $(VG_LIBS) -lX11
+$(EGLUT_SCREEN_DEMOS):
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -L$(EGLUT_DIR) -leglut-$* $(VG_LIBS)
+
+clean:
+ rm -f *.o *~
+ rm -f $(EGLUT_X11_DEMOS) $(EGLUT_SCREEN_DEMOS)
+ @$(MAKE) -C $(EGLUT_DIR) clean
diff --git a/progs/openvg/demos/lion-render.c b/progs/egl/openvg/lion-render.c
index f3f151f552..f3f151f552 100644
--- a/progs/openvg/demos/lion-render.c
+++ b/progs/egl/openvg/lion-render.c
diff --git a/progs/openvg/demos/lion-render.h b/progs/egl/openvg/lion-render.h
index c4c020b7ed..c4c020b7ed 100644
--- a/progs/openvg/demos/lion-render.h
+++ b/progs/egl/openvg/lion-render.h
diff --git a/progs/egl/openvg/lion.c b/progs/egl/openvg/lion.c
new file mode 100644
index 0000000000..c5dba4fcea
--- /dev/null
+++ b/progs/egl/openvg/lion.c
@@ -0,0 +1,65 @@
+#include <VG/openvg.h>
+#include <EGL/egl.h>
+
+#include "lion-render.h"
+#include "eglut.h"
+
+static VGint width, height;
+struct lion *lion = 0;
+VGfloat angle = 0;
+
+static void
+draw(void)
+{
+ vgClear(0, 0, width, height);
+
+ vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
+ vgLoadIdentity();
+ vgTranslate(width/2, height/2);
+ vgRotate(angle);
+ vgTranslate(-width/2, -height/2);
+
+ lion_render(lion);
+
+ ++angle;
+ eglutPostRedisplay();
+}
+
+
+/* new window size or exposure */
+static void
+reshape(int w, int h)
+{
+ width = w;
+ height = h;
+}
+
+
+static void
+init(void)
+{
+ float clear_color[4] = {1.0, 1.0, 1.0, 1.0};
+ vgSetfv(VG_CLEAR_COLOR, 4, clear_color);
+
+ lion = lion_create();
+}
+
+
+int
+main(int argc, char *argv[])
+{
+ eglutInitWindowSize(350, 450);
+ eglutInitAPIMask(EGLUT_OPENVG_BIT);
+ eglutInit(argc, argv);
+
+ eglutCreateWindow("Lion Example");
+
+ eglutReshapeFunc(reshape);
+ eglutDisplayFunc(draw);
+
+ init();
+
+ eglutMainLoop();
+
+ return 0;
+}
diff --git a/progs/openvg/demos/sp.c b/progs/egl/openvg/sp.c
index 424ec47d69..a20c0a3b4e 100644
--- a/progs/openvg/demos/sp.c
+++ b/progs/egl/openvg/sp.c
@@ -1,13 +1,9 @@
-#include "eglcommon.h"
-
#include <VG/openvg.h>
#include <VG/vgu.h>
-#include <stdio.h>
#include <math.h>
-#include <stdlib.h>
#include <string.h>
-#include <X11/keysym.h>
+#include "eglut.h"
#define ELEMENTS(x) (sizeof(x)/sizeof((x)[0]))
@@ -475,36 +471,13 @@ reshape(int w, int h)
{
}
-static int
-key_press(unsigned key)
-{
- switch(key) {
- case XK_Right:
-
- break;
- case XK_Left:
- break;
- case XK_Up:
- break;
- case XK_Down:
- break;
- case 'a':
- break;
- case 's':
- break;
- default:
- break;
- }
- return VG_FALSE;
-}
-
static void
draw(void)
{
VGint i;
VGfloat save_matrix[9];
- vgClear(0, 0, window_width(), window_height());
+ vgClear(0, 0, eglutGetWindowWidth(), eglutGetWindowHeight());
vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
vgLoadIdentity();
@@ -532,6 +505,18 @@ draw(void)
int main(int argc, char **argv)
{
- set_window_size(400, 400);
- return run(argc, argv, init, reshape, draw, key_press);
+ eglutInitWindowSize(400, 400);
+ eglutInitAPIMask(EGLUT_OPENVG_BIT);
+ eglutInit(argc, argv);
+
+ eglutCreateWindow("sp");
+
+ eglutReshapeFunc(reshape);
+ eglutDisplayFunc(draw);
+
+ init();
+
+ eglutMainLoop();
+
+ return 0;
}
diff --git a/progs/openvg/trivial/Makefile b/progs/egl/openvg/trivial/Makefile
index fcb3484377..8f6d7abe89 100644
--- a/progs/openvg/trivial/Makefile
+++ b/progs/egl/openvg/trivial/Makefile
@@ -1,7 +1,8 @@
+# progs/egl/openvg/trivial/Makefile
# These programs aren't intended to be included with the normal distro.
# They're not too interesting but they're good for testing.
-TOP = ../../../
+TOP = ../../../..
include $(TOP)/configs/current
INCLUDES = -I. -I$(TOP)/include
diff --git a/progs/openvg/trivial/arc.c b/progs/egl/openvg/trivial/arc.c
index db686bea6b..db686bea6b 100644
--- a/progs/openvg/trivial/arc.c
+++ b/progs/egl/openvg/trivial/arc.c
diff --git a/progs/openvg/trivial/cap.c b/progs/egl/openvg/trivial/cap.c
index cd84fe3ac0..cd84fe3ac0 100644
--- a/progs/openvg/trivial/cap.c
+++ b/progs/egl/openvg/trivial/cap.c
diff --git a/progs/openvg/trivial/clear.c b/progs/egl/openvg/trivial/clear.c
index efb6bf4182..efb6bf4182 100644
--- a/progs/openvg/trivial/clear.c
+++ b/progs/egl/openvg/trivial/clear.c
diff --git a/progs/openvg/trivial/coord.c b/progs/egl/openvg/trivial/coord.c
index 81f7cb6fc9..81f7cb6fc9 100644
--- a/progs/openvg/trivial/coord.c
+++ b/progs/egl/openvg/trivial/coord.c
diff --git a/progs/openvg/trivial/dash.c b/progs/egl/openvg/trivial/dash.c
index 2e84ddbd4e..2e84ddbd4e 100644
--- a/progs/openvg/trivial/dash.c
+++ b/progs/egl/openvg/trivial/dash.c
diff --git a/progs/openvg/demos/eglcommon.c b/progs/egl/openvg/trivial/eglcommon.c
index 0316e596c6..0316e596c6 100644
--- a/progs/openvg/demos/eglcommon.c
+++ b/progs/egl/openvg/trivial/eglcommon.c
diff --git a/progs/openvg/demos/eglcommon.h b/progs/egl/openvg/trivial/eglcommon.h
index 958dae9f98..958dae9f98 100644
--- a/progs/openvg/demos/eglcommon.h
+++ b/progs/egl/openvg/trivial/eglcommon.h
diff --git a/progs/openvg/trivial/ellipse.c b/progs/egl/openvg/trivial/ellipse.c
index 4c7d4904f8..4c7d4904f8 100644
--- a/progs/openvg/trivial/ellipse.c
+++ b/progs/egl/openvg/trivial/ellipse.c
diff --git a/progs/openvg/trivial/filter.c b/progs/egl/openvg/trivial/filter.c
index d96257a933..d96257a933 100644
--- a/progs/openvg/trivial/filter.c
+++ b/progs/egl/openvg/trivial/filter.c
diff --git a/progs/openvg/trivial/gradorigin.c b/progs/egl/openvg/trivial/gradorigin.c
index b376263fe5..b376263fe5 100644
--- a/progs/openvg/trivial/gradorigin.c
+++ b/progs/egl/openvg/trivial/gradorigin.c
diff --git a/progs/openvg/trivial/lineto.c b/progs/egl/openvg/trivial/lineto.c
index 94e2981811..94e2981811 100644
--- a/progs/openvg/trivial/lineto.c
+++ b/progs/egl/openvg/trivial/lineto.c
diff --git a/progs/openvg/trivial/lingrad.c b/progs/egl/openvg/trivial/lingrad.c
index bcaad1f101..bcaad1f101 100644
--- a/progs/openvg/trivial/lingrad.c
+++ b/progs/egl/openvg/trivial/lingrad.c
diff --git a/progs/openvg/trivial/lookup.c b/progs/egl/openvg/trivial/lookup.c
index a103ba4488..a103ba4488 100644
--- a/progs/openvg/trivial/lookup.c
+++ b/progs/egl/openvg/trivial/lookup.c
diff --git a/progs/openvg/trivial/mask.c b/progs/egl/openvg/trivial/mask.c
index e5c00c5699..e5c00c5699 100644
--- a/progs/openvg/trivial/mask.c
+++ b/progs/egl/openvg/trivial/mask.c
diff --git a/progs/openvg/trivial/mask4.c b/progs/egl/openvg/trivial/mask4.c
index fe6db39648..fe6db39648 100644
--- a/progs/openvg/trivial/mask4.c
+++ b/progs/egl/openvg/trivial/mask4.c
diff --git a/progs/openvg/trivial/path3.c b/progs/egl/openvg/trivial/path3.c
index 5ce600f65a..5ce600f65a 100644
--- a/progs/openvg/trivial/path3.c
+++ b/progs/egl/openvg/trivial/path3.c
diff --git a/progs/openvg/trivial/radialgrad.c b/progs/egl/openvg/trivial/radialgrad.c
index cf3b1d522d..cf3b1d522d 100644
--- a/progs/openvg/trivial/radialgrad.c
+++ b/progs/egl/openvg/trivial/radialgrad.c
diff --git a/progs/openvg/trivial/readpixels.c b/progs/egl/openvg/trivial/readpixels.c
index c8e286db9a..c8e286db9a 100644
--- a/progs/openvg/trivial/readpixels.c
+++ b/progs/egl/openvg/trivial/readpixels.c
diff --git a/progs/openvg/trivial/roundedrect.c b/progs/egl/openvg/trivial/roundedrect.c
index c80a4ed299..c80a4ed299 100644
--- a/progs/openvg/trivial/roundedrect.c
+++ b/progs/egl/openvg/trivial/roundedrect.c
diff --git a/progs/openvg/trivial/star-nonzero.c b/progs/egl/openvg/trivial/star-nonzero.c
index 012fbd3929..012fbd3929 100644
--- a/progs/openvg/trivial/star-nonzero.c
+++ b/progs/egl/openvg/trivial/star-nonzero.c
diff --git a/progs/openvg/trivial/star-oddeven.c b/progs/egl/openvg/trivial/star-oddeven.c
index 17311cf720..17311cf720 100644
--- a/progs/openvg/trivial/star-oddeven.c
+++ b/progs/egl/openvg/trivial/star-oddeven.c
diff --git a/progs/openvg/trivial/stroke.c b/progs/egl/openvg/trivial/stroke.c
index 58ae5b7bc8..58ae5b7bc8 100644
--- a/progs/openvg/trivial/stroke.c
+++ b/progs/egl/openvg/trivial/stroke.c
diff --git a/progs/openvg/trivial/stroke2.c b/progs/egl/openvg/trivial/stroke2.c
index ce950c1886..ce950c1886 100644
--- a/progs/openvg/trivial/stroke2.c
+++ b/progs/egl/openvg/trivial/stroke2.c
diff --git a/progs/openvg/trivial/vguarc.c b/progs/egl/openvg/trivial/vguarc.c
index 8d971d5c09..8d971d5c09 100644
--- a/progs/openvg/trivial/vguarc.c
+++ b/progs/egl/openvg/trivial/vguarc.c
diff --git a/progs/egl/xegl_tri.c b/progs/egl/xegl_tri.c
deleted file mode 100644
index 1f1a005a21..0000000000
--- a/progs/egl/xegl_tri.c
+++ /dev/null
@@ -1,361 +0,0 @@
-/*
- * Copyright (C) 2008 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-/*
- * Draw a triangle with X/EGL.
- * Brian Paul
- * 3 June 2008
- */
-
-
-#include <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 <GL/gl.h> /* using full OpenGL for now */
-#include <GLES/egl.h>
-
-
-static GLfloat view_rotx = 0.0, view_roty = 0.0, view_rotz = 0.0;
-
-
-static void
-draw(void)
-{
- static const GLfloat verts[3][2] = {
- { -1, -1 },
- { 1, -1 },
- { 0, 1 }
- };
- static const GLfloat colors[3][3] = {
- { 1, 0, 0 },
- { 0, 1, 0 },
- { 0, 0, 1 }
- };
-
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- glPushMatrix();
- glRotatef(view_rotx, 1, 0, 0);
- glRotatef(view_roty, 0, 1, 0);
- glRotatef(view_rotz, 0, 0, 1);
-
- {
- glVertexPointer(2, GL_FLOAT, 0, verts);
- glColorPointer(3, GL_FLOAT, 0, colors);
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_COLOR_ARRAY);
-
- glDrawArrays(GL_TRIANGLES, 0, 3);
-
- glDisableClientState(GL_VERTEX_ARRAY);
- glDisableClientState(GL_COLOR_ARRAY);
- }
-
- glPopMatrix();
-}
-
-
-/* new window size or exposure */
-static void
-reshape(int width, int height)
-{
- GLfloat ar = (GLfloat) width / (GLfloat) height;
-
- glViewport(0, 0, (GLint) width, (GLint) height);
-
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glFrustum(-ar, ar, -1, 1, 5.0, 60.0);
-
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTranslatef(0.0, 0.0, -10.0);
-}
-
-
-static void
-init(void)
-{
- glClearColor(0.4, 0.4, 0.4, 0.0);
-}
-
-
-/*
- * 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_BIT,
- 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) ||
- !num_configs) {
- printf("Error: couldn't get an EGL visual config\n");
- exit(1);
- }
-
- assert(config);
- assert(num_configs > 0);
-
- if (!eglGetConfigAttrib(egl_dpy, config, EGL_NATIVE_VISUAL_ID, &vid)) {
- printf("Error: eglGetConfigAttrib() failed\n");
- exit(1);
- }
-
- /* The X window visual must match the EGL config */
- visTemplate.visualid = vid;
- visInfo = XGetVisualInfo(x_dpy, VisualIDMask, &visTemplate, &num_visuals);
- if (!visInfo) {
- printf("Error: couldn't get X visual\n");
- exit(1);
- }
-
- /* window attributes */
- attr.background_pixel = 0;
- attr.border_pixel = 0;
- attr.colormap = XCreateColormap( x_dpy, root, visInfo->visual, AllocNone);
- attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
- mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
-
- win = XCreateWindow( x_dpy, root, 0, 0, width, height,
- 0, visInfo->depth, InputOutput,
- visInfo->visual, mask, &attr );
-
- /* set hints and properties */
- {
- XSizeHints sizehints;
- sizehints.x = x;
- sizehints.y = y;
- sizehints.width = width;
- sizehints.height = height;
- sizehints.flags = USSize | USPosition;
- XSetNormalHints(x_dpy, win, &sizehints);
- XSetStandardProperties(x_dpy, win, name, name,
- None, (char **)NULL, 0, &sizehints);
- }
-
- eglBindAPI(EGL_OPENGL_API);
-
- ctx = eglCreateContext(egl_dpy, config, EGL_NO_CONTEXT, NULL );
- if (!ctx) {
- printf("Error: glXCreateContext failed\n");
- exit(1);
- }
-
- *surfRet = eglCreateWindowSurface(egl_dpy, config, win, NULL);
-
- if (!*surfRet) {
- printf("Error: eglCreateWindowSurface failed\n");
- exit(1);
- }
-
- XFree(visInfo);
-
- *winRet = win;
- *ctxRet = ctx;
-}
-
-
-static void
-event_loop(Display *dpy, Window win,
- EGLDisplay egl_dpy, EGLSurface egl_surf)
-{
- while (1) {
- int redraw = 0;
- XEvent event;
-
- XNextEvent(dpy, &event);
-
- switch (event.type) {
- case Expose:
- redraw = 1;
- break;
- case ConfigureNotify:
- reshape(event.xconfigure.width, event.xconfigure.height);
- break;
- case KeyPress:
- {
- char buffer[10];
- int r, code;
- code = XLookupKeysym(&event.xkey, 0);
- if (code == XK_Left) {
- view_roty += 5.0;
- }
- else if (code == XK_Right) {
- view_roty -= 5.0;
- }
- else if (code == XK_Up) {
- view_rotx += 5.0;
- }
- else if (code == XK_Down) {
- view_rotx -= 5.0;
- }
- else {
- r = XLookupString(&event.xkey, buffer, sizeof(buffer),
- NULL, NULL);
- if (buffer[0] == 27) {
- /* escape */
- return;
- }
- }
- }
- redraw = 1;
- break;
- default:
- ; /*no-op*/
- }
-
- if (redraw) {
- draw();
- eglSwapBuffers(egl_dpy, egl_surf);
- }
- }
-}
-
-
-static void
-usage(void)
-{
- printf("Usage:\n");
- printf(" -display <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);
-
- make_x_window(x_dpy, egl_dpy,
- "xegl_tri", 0, 0, winWidth, winHeight,
- &win, &egl_ctx, &egl_surf);
-
- XMapWindow(x_dpy, win);
- if (!eglMakeCurrent(egl_dpy, egl_surf, egl_surf, egl_ctx)) {
- printf("Error: eglMakeCurrent() failed\n");
- return -1;
- }
-
- if (printInfo) {
- printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
- printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
- printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR));
- }
-
- init();
-
- /* Set initial projection/viewing transformation.
- * We can't be sure we'll get a ConfigureNotify event when the window
- * first appears.
- */
- reshape(winWidth, winHeight);
-
- event_loop(x_dpy, win, egl_dpy, egl_surf);
-
- eglDestroyContext(egl_dpy, egl_ctx);
- eglDestroySurface(egl_dpy, egl_surf);
- eglTerminate(egl_dpy);
-
-
- XDestroyWindow(x_dpy, win);
- XCloseDisplay(x_dpy);
-
- return 0;
-}
diff --git a/progs/es1/.gitignore b/progs/es1/.gitignore
deleted file mode 100644
index 5e29a6b5fa..0000000000
--- a/progs/es1/.gitignore
+++ /dev/null
@@ -1,11 +0,0 @@
-screen/gears
-screen/tri
-xegl/bindtex
-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
deleted file mode 100644
index 4ba2f9a7dc..0000000000
--- a/progs/es1/screen/Makefile
+++ /dev/null
@@ -1,32 +0,0 @@
-# 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/winsys.c b/progs/es1/screen/winsys.c
deleted file mode 100644
index 84d00471eb..0000000000
--- a/progs/es1/screen/winsys.c
+++ /dev/null
@@ -1,272 +0,0 @@
-/*
- * Copyright (C) 2009 Chia-I Wu <olv@0xlab.org>
- *
- * Based on eglgears by
- * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-#include <sys/time.h>
-
-#define EGL_EGLEXT_PROTOTYPES
-
-#include <EGL/egl.h>
-#include <EGL/eglext.h>
-
-#include "winsys.h"
-
-#define MAX_MODES 100
-
-static struct {
- EGLBoolean verbose;
-
- EGLDisplay dpy;
- EGLConfig conf;
-
- EGLScreenMESA screen;
- EGLModeMESA mode;
- EGLint width, height;
-
- EGLContext ctx;
- EGLSurface surf;
-} screen;
-
-
-static EGLBoolean
-init_screen(void)
-{
- EGLModeMESA modes[MAX_MODES];
- EGLint num_screens, num_modes;
- EGLint width, height, best_mode;
- EGLint i;
-
- if (!eglGetScreensMESA(screen.dpy, &screen.screen, 1, &num_screens) ||
- !num_screens) {
- printf("eglGetScreensMESA failed\n");
- return EGL_FALSE;
- }
-
- if (!eglGetModesMESA(screen.dpy, screen.screen, modes, MAX_MODES,
- &num_modes) ||
- !num_modes) {
- printf("eglGetModesMESA failed!\n");
- return EGL_FALSE;
- }
-
- printf("Found %d modes:\n", num_modes);
-
- best_mode = 0;
- width = 0;
- height = 0;
- for (i = 0; i < num_modes; i++) {
- EGLint w, h;
- eglGetModeAttribMESA(screen.dpy, modes[i], EGL_WIDTH, &w);
- eglGetModeAttribMESA(screen.dpy, modes[i], EGL_HEIGHT, &h);
- printf("%3d: %d x %d\n", i, w, h);
- if (w > width && h > height) {
- width = w;
- height = h;
- best_mode = i;
- }
- }
-
- screen.mode = modes[best_mode];
- screen.width = width;
- screen.height = height;
-
- return EGL_TRUE;
-}
-
-
-static EGLBoolean
-init_display(void)
-{
- EGLint maj, min;
- const char *exts;
- const EGLint attribs[] = {
- EGL_SURFACE_TYPE, 0x0, /* should be EGL_SCREEN_BIT_MESA */
- EGL_RENDERABLE_TYPE, 0x0, /* should be EGL_OPENGL_ES_BIT */
- EGL_NONE
- };
- EGLint num_configs;
-
- screen.dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
- if (!screen.dpy) {
- printf("eglGetDisplay failed\n");
- return EGL_FALSE;
- }
-
- if (!eglInitialize(screen.dpy, &maj, &min)) {
- printf("eglInitialize failed\n");
- return EGL_FALSE;
- }
-
- printf("EGL_VERSION = %s\n", eglQueryString(screen.dpy, EGL_VERSION));
- printf("EGL_VENDOR = %s\n", eglQueryString(screen.dpy, EGL_VENDOR));
-
- exts = eglQueryString(screen.dpy, EGL_EXTENSIONS);
- assert(exts);
-
- if (!strstr(exts, "EGL_MESA_screen_surface")) {
- printf("EGL_MESA_screen_surface is not supported\n");
- return EGL_FALSE;
- }
-
- if (!eglChooseConfig(screen.dpy, attribs, &screen.conf, 1,
- &num_configs) ||
- !num_configs) {
- printf("eglChooseConfig failed\n");
- return EGL_FALSE;
- }
-
- return EGL_TRUE;
-}
-
-
-EGLBoolean
-winsysInitScreen(void)
-{
- EGLint surf_attribs[20];
- EGLint i;
- EGLBoolean ok;
-
- if (!init_display())
- goto fail;
- if (!init_screen())
- goto fail;
-
- /* create context */
- screen.ctx = eglCreateContext(screen.dpy, screen.conf,
- EGL_NO_CONTEXT, NULL);
- if (screen.ctx == EGL_NO_CONTEXT) {
- printf("eglCreateContext failed\n");
- goto fail;
- }
-
- i = 0;
- surf_attribs[i++] = EGL_WIDTH;
- surf_attribs[i++] = screen.width;
- surf_attribs[i++] = EGL_HEIGHT;
- surf_attribs[i++] = screen.height;
- surf_attribs[i++] = EGL_NONE;
-
- /* create surface */
- printf("Using screen size: %d x %d\n", screen.width, screen.height);
- screen.surf = eglCreateScreenSurfaceMESA(screen.dpy, screen.conf,
- surf_attribs);
- if (screen.surf == EGL_NO_SURFACE) {
- printf("eglCreateScreenSurfaceMESA failed\n");
- goto fail;
- }
-
- ok = eglMakeCurrent(screen.dpy, screen.surf, screen.surf, screen.ctx);
- if (!ok) {
- printf("eglMakeCurrent failed\n");
- goto fail;
- }
-
- ok = eglShowScreenSurfaceMESA(screen.dpy, screen.screen,
- screen.surf, screen.mode);
- if (!ok) {
- printf("eglShowScreenSurfaceMESA failed\n");
- goto fail;
- }
-
- return EGL_TRUE;
-
-fail:
- winsysFiniScreen();
- return EGL_FALSE;
-}
-
-
-EGLBoolean
-winsysQueryScreenSize(EGLint *width, EGLint *height)
-{
- if (!screen.dpy)
- return EGL_FALSE;
-
- if (width)
- *width = screen.width;
- if (height)
- *height = screen.height;
-
- return EGL_TRUE;
-}
-
-
-void
-winsysFiniScreen(void)
-{
- if (screen.dpy) {
- eglMakeCurrent(screen.dpy, EGL_NO_SURFACE, EGL_NO_SURFACE,
- EGL_NO_CONTEXT);
- if (screen.surf != EGL_NO_SURFACE)
- eglDestroySurface(screen.dpy, screen.surf);
- if (screen.ctx != EGL_NO_CONTEXT)
- eglDestroyContext(screen.dpy, screen.ctx);
- eglTerminate(screen.dpy);
-
- memset(&screen, 0, sizeof(screen));
- }
-}
-
-
-void
-winsysSwapBuffers(void)
-{
- eglSwapBuffers(screen.dpy, screen.surf);
-}
-
-
-/* return current time (in seconds) */
-double
-winsysNow(void)
-{
- struct timeval tv;
- gettimeofday(&tv, NULL);
- return (double) tv.tv_sec + tv.tv_usec / 1000000.0;
-}
-
-
-void
-winsysRun(double seconds, void (*draw_frame)(void *data), void *data)
-{
- double begin, end, last_frame, duration;
- EGLint num_frames = 0;
-
- begin = winsysNow();
- end = begin + seconds;
-
- last_frame = begin;
- while (last_frame < end) {
- draw_frame(data);
- winsysSwapBuffers();
- last_frame = winsysNow();
- num_frames++;
- }
-
- duration = last_frame - begin;
- printf("%d frames in %3.1f seconds = %6.3f FPS\n",
- num_frames, duration, (double) num_frames / duration);
-}
diff --git a/progs/es1/screen/winsys.h b/progs/es1/screen/winsys.h
deleted file mode 100644
index 679c7e0bd6..0000000000
--- a/progs/es1/screen/winsys.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (C) 2009 Chia-I Wu <olv@0xlab.org>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#ifndef _WINSYS_H_
-#define _WINSYS_H_
-
-#include <EGL/egl.h>
-
-EGLBoolean winsysInitScreen(void);
-EGLBoolean winsysQueryScreenSize(EGLint *width, EGLint *height);
-void winsysFiniScreen(void);
-
-void winsysSwapBuffers(void);
-double winsysNow(void);
-
-void winsysRun(double seconds, void (*draw_frame)(void *data), void *data);
-
-#endif /* _WINSYS_H_ */
diff --git a/progs/es1/xegl/Makefile b/progs/es1/xegl/Makefile
deleted file mode 100644
index 6869c44306..0000000000
--- a/progs/es1/xegl/Makefile
+++ /dev/null
@@ -1,82 +0,0 @@
-# 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 = \
- bindtex \
- drawtex \
- es1_info \
- msaa \
- pbuffer \
- render_tex \
- torus \
- tri \
- two_win
-
-
-.c.o:
- $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $< -o $@
-
-
-
-default: $(PROGRAMS)
-
-
-
-bindtex: bindtex.o $(ES1_LIB_DEPS)
- $(CC) $(CFLAGS) bindtex.o $(ES1_LIBS) -o $@
-
-
-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
deleted file mode 100644
index ca0615e267..0000000000
--- a/progs/es1/xegl/drawtex.c
+++ /dev/null
@@ -1,427 +0,0 @@
-/*
- * Copyright (C) 2008 Tunsgten Graphics,Inc. All Rights Reserved.
- */
-
-/*
- * Test GL_OES_draw_texture
- * Brian Paul
- * August 2008
- */
-
-#define GL_GLEXT_PROTOTYPES
-
-#include <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/tri.c b/progs/es1/xegl/tri.c
deleted file mode 100644
index 42a978207c..0000000000
--- a/progs/es1/xegl/tri.c
+++ /dev/null
@@ -1,470 +0,0 @@
-/*
- * Copyright (C) 2008 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-/*
- * Draw a triangle with X/EGL and OpenGL ES 1.x
- * Brian Paul
- * 5 June 2008
- */
-
-#define USE_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/es2/.gitignore b/progs/es2/.gitignore
deleted file mode 100644
index 7d5c16936c..0000000000
--- a/progs/es2/.gitignore
+++ /dev/null
@@ -1,3 +0,0 @@
-xegl/es2_info.c
-xegl/es2_info
-xegl/tri
diff --git a/progs/fpglsl/dowhile.glsl b/progs/fpglsl/dowhile.glsl
new file mode 100644
index 0000000000..ed9d729675
--- /dev/null
+++ b/progs/fpglsl/dowhile.glsl
@@ -0,0 +1,8 @@
+void main() {
+ float sum = 0.0;
+ do {
+ sum += 0.1;
+ break;
+ } while (true);
+ gl_FragColor = vec4(sum);
+}
diff --git a/progs/fpglsl/dowhile2.glsl b/progs/fpglsl/dowhile2.glsl
new file mode 100644
index 0000000000..f3e00b8e86
--- /dev/null
+++ b/progs/fpglsl/dowhile2.glsl
@@ -0,0 +1,10 @@
+void main() {
+ float sum = 0.0;
+ do {
+ sum += 0.1;
+ if (sum < 0.499999)
+ continue;
+ break;
+ } while (true);
+ gl_FragColor = vec4(sum);
+}
diff --git a/progs/fpglsl/for.glsl b/progs/fpglsl/for.glsl
new file mode 100644
index 0000000000..862ca8bd6c
--- /dev/null
+++ b/progs/fpglsl/for.glsl
@@ -0,0 +1,11 @@
+uniform int KernelSizeInt;
+
+void main() {
+ int i;
+ vec4 sum = vec4(0.0);
+ for (i = 0; i < KernelSizeInt; ++i) {
+ sum.g += 0.25;
+ }
+ sum.a = 1.0;
+ gl_FragColor = sum;
+}
diff --git a/progs/fpglsl/forbreak.glsl b/progs/fpglsl/forbreak.glsl
new file mode 100644
index 0000000000..0b8d957cb0
--- /dev/null
+++ b/progs/fpglsl/forbreak.glsl
@@ -0,0 +1,13 @@
+uniform int KernelSizeInt;
+
+void main() {
+ int i;
+ vec4 sum = vec4(0.0);
+ for (i = 0; i < KernelSizeInt; ++i) {
+ sum.g += 0.25;
+ if (i > 0)
+ break;
+ }
+ sum.a = 1.0;
+ gl_FragColor = sum;
+}
diff --git a/progs/fpglsl/fp-tri.c b/progs/fpglsl/fp-tri.c
index c9b08fbbad..8af09845dd 100644
--- a/progs/fpglsl/fp-tri.c
+++ b/progs/fpglsl/fp-tri.c
@@ -129,6 +129,11 @@ static void setup_uniforms()
}
{
+ GLint loci = glGetUniformLocationARB(program, "KernelSizeInt");
+ if (loci >= 0)
+ glUniform1i(loci, 4);
+ }
+ {
GLint loc1f = glGetUniformLocationARB(program, "KernelValue1f");
GLint loc2f = glGetUniformLocationARB(program, "KernelValue2f");
GLint loc4f = glGetUniformLocationARB(program, "KernelValue4f");
diff --git a/progs/fpglsl/simpleif.glsl b/progs/fpglsl/simpleif.glsl
new file mode 100644
index 0000000000..922421b410
--- /dev/null
+++ b/progs/fpglsl/simpleif.glsl
@@ -0,0 +1,6 @@
+void main() {
+ // this should always be true
+ if (gl_FragCoord.x >= 0.0) {
+ gl_FragColor = vec4(0.5, 0.0, 0.5, 1.0);
+ }
+}
diff --git a/progs/fpglsl/while.glsl b/progs/fpglsl/while.glsl
new file mode 100644
index 0000000000..05fb860ddc
--- /dev/null
+++ b/progs/fpglsl/while.glsl
@@ -0,0 +1,7 @@
+void main() {
+ float sum = 0.0;
+ while (sum < 0.499999) {
+ sum += 0.1;
+ }
+ gl_FragColor = vec4(sum);
+}
diff --git a/progs/fpglsl/while2.glsl b/progs/fpglsl/while2.glsl
new file mode 100644
index 0000000000..19c8904e28
--- /dev/null
+++ b/progs/fpglsl/while2.glsl
@@ -0,0 +1,9 @@
+void main() {
+ float sum = 0.0;
+ while (true) {
+ sum += 0.1;
+ if (sum > 0.8)
+ break;
+ }
+ gl_FragColor = vec4(sum);
+}
diff --git a/progs/gallium/python/retrace/interpreter.py b/progs/gallium/python/retrace/interpreter.py
index b30469dfae..1a96181255 100755
--- a/progs/gallium/python/retrace/interpreter.py
+++ b/progs/gallium/python/retrace/interpreter.py
@@ -551,7 +551,6 @@ class Context(Object):
data = vbuf.buffer.read()
values = unpack_from(format, data, offset)
sys.stdout.write('\t\t{' + ', '.join(map(str, values)) + '},\n')
- assert len(values) == velem.nr_components
sys.stdout.write('\t},\n')
sys.stdout.flush()
diff --git a/progs/gallium/python/samples/tri.py b/progs/gallium/python/samples/tri.py
index d7fbdb10ac..8cc272db81 100644
--- a/progs/gallium/python/samples/tri.py
+++ b/progs/gallium/python/samples/tri.py
@@ -30,19 +30,19 @@
from gallium import *
-def make_image(surface):
- data = surface.get_tile_rgba8(0, 0, surface.width, surface.height)
+def make_image(ctx, surface):
+ data = ctx.surface_read_rgba8(surface, 0, 0, surface.width, surface.height)
import Image
outimage = Image.fromstring('RGBA', (surface.width, surface.height), data, "raw", 'RGBA', 0, 1)
return outimage
-def save_image(filename, surface):
- outimage = make_image(surface)
+def save_image(ctx, surface, filename):
+ outimage = make_image(ctx, surface)
outimage.save(filename, "PNG")
-def show_image(surface):
- outimage = make_image(surface)
+def show_image(ctx, surface):
+ outimage = make_image(ctx, surface)
import Tkinter as tk
from PIL import Image, ImageTk
@@ -128,6 +128,7 @@ def test(dev):
scissor.maxy = height
ctx.set_scissor(scissor)
+ # clip
clip = Clip()
clip.nr = 0
ctx.set_clip(clip)
@@ -216,10 +217,10 @@ def test(dev):
ctx.flush()
- show_image(cbuf)
- #show_image(zbuf)
- #save_image('cbuf.png', cbuf)
- #save_image('zbuf.png', zbuf)
+ show_image(ctx, cbuf)
+ show_image(ctx, zbuf)
+ save_image(ctx, cbuf, 'cbuf.png')
+ save_image(ctx, zbuf, 'zbuf.png')
diff --git a/progs/gallium/python/tests/base.py b/progs/gallium/python/tests/base.py
index bd82f50811..d8cf84db36 100755
--- a/progs/gallium/python/tests/base.py
+++ b/progs/gallium/python/tests/base.py
@@ -43,18 +43,9 @@ from gallium import *
# Enumerate all pixel formats
formats = {}
for name, value in globals().items():
- if name.startswith("PIPE_FORMAT_") and isinstance(value, int):
+ if name.startswith("PIPE_FORMAT_") and isinstance(value, int) and name not in ("PIPE_FORMAT_NONE", "PIPE_FORMAT_COUNT"):
formats[value] = name
-def is_depth_stencil_format(format):
- # FIXME: make and use binding to util_format_is_depth_or_stencil
- return format in (
- PIPE_FORMAT_Z32_UNORM,
- PIPE_FORMAT_S8Z24_UNORM,
- PIPE_FORMAT_X8Z24_UNORM,
- PIPE_FORMAT_Z16_UNORM,
- )
-
def make_image(width, height, rgba):
import Image
outimage = Image.new(
@@ -125,18 +116,18 @@ class Test:
def run(self):
result = TestResult()
self._run(result)
- result.summary()
+ result.report()
- def assert_rgba(self, surface, x, y, w, h, expected_rgba, pixel_tol=4.0/256, surface_tol=0.85):
+ def assert_rgba(self, ctx, surface, x, y, w, h, expected_rgba, pixel_tol=4.0/256, surface_tol=0.85):
total = h*w
- different = surface.compare_tile_rgba(x, y, w, h, expected_rgba, tol=pixel_tol)
+ different = ctx.surface_compare_rgba(surface, x, y, w, h, expected_rgba, tol=pixel_tol)
if different:
sys.stderr.write("%u out of %u pixels differ\n" % (different, total))
if float(total - different)/float(total) < surface_tol:
if 0:
rgba = FloatArray(h*w*4)
- surface.get_tile_rgba(x, y, w, h, rgba)
+ ctx.surface_read_rgba(surface, x, y, w, h, rgba)
show_image(w, h, Result=rgba, Expected=expected_rgba)
save_image(w, h, rgba, "result.png")
save_image(w, h, expected_rgba, "expected.png")
@@ -259,7 +250,7 @@ class TestResult:
sys.stdout.write("SKIP\n")
sys.stdout.flush()
self.skipped += 1
- #self.log_result(test, 'skip')
+ self.log_result(test, 'skip')
def test_failed(self, test):
sys.stdout.write("FAIL\n")
@@ -305,11 +296,16 @@ class TestResult:
self.rows.append(row)
- def summary(self):
+ def report(self):
sys.stdout.write("%u tests, %u passed, %u skipped, %u failed\n\n" % (self.tests, self.passed, self.skipped, self.failed))
sys.stdout.flush()
name, ext = os.path.splitext(os.path.basename(sys.argv[0]))
+
+ tree = self.report_tree(name)
+ self.report_junit(name, stdout=tree)
+
+ def report_tree(self, name):
filename = name + '.tsv'
stream = file(filename, 'wt')
@@ -320,6 +316,8 @@ class TestResult:
# rows
for row in self.rows:
+ if row[0] == 'skip':
+ continue
row += ['']*(len(self.names) - len(row))
stream.write('\t'.join(row) + '\n')
@@ -331,7 +329,7 @@ class TestResult:
import orngTree
except ImportError:
sys.stderr.write('Install Orange from http://www.ailab.si/orange/ for a classification tree.\n')
- return
+ return None
data = orange.ExampleTable(filename)
@@ -339,6 +337,63 @@ class TestResult:
orngTree.printTxt(tree, maxDepth=4)
- file(name+'.txt', 'wt').write(orngTree.dumpTree(tree))
+ text_tree = orngTree.dumpTree(tree)
+
+ file(name + '.txt', 'wt').write(text_tree)
orngTree.printDot(tree, fileName=name+'.dot', nodeShape='ellipse', leafShape='box')
+
+ return text_tree
+
+ def report_junit(self, name, stdout=None, stderr=None):
+ """Write test results in ANT's junit XML format, to use with Hudson CI.
+
+ See also:
+ - http://fisheye.hudson-ci.org/browse/Hudson/trunk/hudson/main/core/src/test/resources/hudson/tasks/junit
+ - http://www.junit.org/node/399
+ - http://wiki.apache.org/ant/Proposals/EnhancedTestReports
+ """
+
+ stream = file(name + '.xml', 'wt')
+
+ stream.write('<?xml version="1.0" encoding="UTF-8" ?>\n')
+ stream.write('<testsuite name="%s">\n' % self.escape_xml(name))
+ stream.write(' <properties>\n')
+ stream.write(' </properties>\n')
+
+ names = self.names[1:]
+
+ for row in self.rows:
+
+ test_name = ' '.join(['%s=%s' % pair for pair in zip(self.names[1:], row[1:])])
+
+ stream.write(' <testcase name="%s">\n' % (self.escape_xml(test_name)))
+
+ result = row[0]
+ if result == 'pass':
+ pass
+ elif result == 'skip':
+ stream.write(' <skipped/>\n')
+ else:
+ stream.write(' <failure/>\n')
+
+ stream.write(' </testcase>\n')
+
+ if stdout:
+ stream.write(' <system-out>%s</system-out>\n' % self.escape_xml(stdout))
+ if stderr:
+ stream.write(' <system-err>%s</system-err>\n' % self.escape_xml(stderr))
+
+ stream.write('</testsuite>\n')
+
+ stream.close()
+
+ def escape_xml(self, s):
+ '''Escape a XML string.'''
+ s = s.replace('&', '&amp;')
+ s = s.replace('<', '&lt;')
+ s = s.replace('>', '&gt;')
+ s = s.replace('"', '&quot;')
+ s = s.replace("'", '&apos;')
+ return s
+
diff --git a/progs/gallium/python/tests/surface_copy.py b/progs/gallium/python/tests/surface_copy.py
index a3f1b3e130..3eefa690bd 100755
--- a/progs/gallium/python/tests/surface_copy.py
+++ b/progs/gallium/python/tests/surface_copy.py
@@ -27,6 +27,9 @@
##########################################################################
+import os
+import random
+
from gallium import *
from base import *
@@ -56,6 +59,7 @@ class TextureTest(TestCase):
def test(self):
dev = self.dev
+ ctx = self.ctx
target = self.target
format = self.format
@@ -67,6 +71,14 @@ class TextureTest(TestCase):
level = self.level
zslice = self.zslice
+ tex_usage = PIPE_TEXTURE_USAGE_SAMPLER
+ geom_flags = 0
+ if not dev.is_format_supported(format, target, tex_usage, geom_flags):
+ raise TestSkip
+
+ if not dev.is_format_supported(format, target, tex_usage, geom_flags):
+ raise TestSkip
+
# textures
dst_texture = dev.texture_create(
target = target,
@@ -75,10 +87,8 @@ class TextureTest(TestCase):
height = height,
depth = depth,
last_level = last_level,
- tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET,
+ tex_usage = tex_usage,
)
- if dst_texture is None:
- raise TestSkip
dst_surface = dst_texture.get_surface(face = face, level = level, zslice = zslice)
@@ -94,60 +104,33 @@ class TextureTest(TestCase):
src_surface = src_texture.get_surface()
- x = 0
- y = 0
w = dst_surface.width
h = dst_surface.height
- # ???
- stride = pf_get_stride(texture->format, w)
- size = pf_get_nblocksy(texture->format) * stride
+ stride = util_format_get_stride(format, w)
+ size = util_format_get_nblocksy(format, h) * stride
src_raw = os.urandom(size)
- src_surface.put_tile_raw(0, 0, w, h, src_raw, stride)
+ ctx.surface_write_raw(src_surface, 0, 0, w, h, src_raw, stride)
- ctx = self.dev.context_create()
-
ctx.surface_copy(dst_surface, 0, 0,
src_surface, 0, 0, w, h)
- ctx.flush()
-
- dst_raw = dst_surface.get_tile_raw(0, 0, w, h)
+ dst_raw = ctx.surface_read_raw(dst_surface, 0, 0, w, h)
if dst_raw != src_raw:
raise TestFailure
-
def main():
dev = Device()
+ ctx = dev.context_create()
suite = TestSuite()
targets = [
PIPE_TEXTURE_2D,
PIPE_TEXTURE_CUBE,
- #PIPE_TEXTURE_3D,
- ]
-
- formats = [
- PIPE_FORMAT_B8G8R8A8_UNORM,
- PIPE_FORMAT_B8G8R8X8_UNORM,
- PIPE_FORMAT_B8G8R8A8_SRGB,
- PIPE_FORMAT_B5G6R5_UNORM,
- PIPE_FORMAT_B5G5R5A1_UNORM,
- PIPE_FORMAT_B4G4R4A4_UNORM,
- PIPE_FORMAT_Z32_UNORM,
- PIPE_FORMAT_S8Z24_UNORM,
- PIPE_FORMAT_X8Z24_UNORM,
- PIPE_FORMAT_Z16_UNORM,
- PIPE_FORMAT_S8_UNORM,
- PIPE_FORMAT_A8_UNORM,
- PIPE_FORMAT_L8_UNORM,
- PIPE_FORMAT_DXT1_RGB,
- PIPE_FORMAT_DXT1_RGBA,
- PIPE_FORMAT_DXT3_RGBA,
- PIPE_FORMAT_DXT5_RGBA,
+ PIPE_TEXTURE_3D,
]
sizes = [64, 32, 16, 8, 4, 2, 1]
@@ -164,35 +147,52 @@ def main():
PIPE_TEX_FACE_NEG_Z,
]
- for target in targets:
- for format in formats:
- for size in sizes:
- if target == PIPE_TEXTURE_3D:
- depth = size
- else:
- depth = 1
- for face in faces:
- if target != PIPE_TEXTURE_CUBE and face:
- continue
- levels = lods(size)
- for last_level in range(levels):
- for level in range(0, last_level + 1):
- zslice = 0
- while zslice < depth >> level:
- test = TextureTest(
- dev = dev,
- target = target,
- format = format,
- width = size,
- height = size,
- depth = depth,
- last_level = last_level,
- face = face,
- level = level,
- zslice = zslice,
- )
- suite.add_test(test)
- zslice = (zslice + 1)*2 - 1
+ try:
+ n = int(sys.argv[1])
+ except:
+ n = 10000
+
+ for i in range(n):
+ format = random.choice(formats.keys())
+ if not util_format_is_depth_or_stencil(format):
+ is_depth_or_stencil = util_format_is_depth_or_stencil(format)
+
+ if is_depth_or_stencil:
+ target = PIPE_TEXTURE_2D
+ else:
+ target = random.choice(targets)
+
+ size = random.choice(sizes)
+
+ if target == PIPE_TEXTURE_3D:
+ depth = size
+ else:
+ depth = 1
+
+ if target == PIPE_TEXTURE_CUBE:
+ face = random.choice(faces)
+ else:
+ face = PIPE_TEX_FACE_POS_X
+
+ levels = lods(size)
+ last_level = random.randint(0, levels - 1)
+ level = random.randint(0, last_level)
+ zslice = random.randint(0, max(depth >> level, 1) - 1)
+
+ test = TextureTest(
+ dev = dev,
+ ctx = ctx,
+ target = target,
+ format = format,
+ width = size,
+ height = size,
+ depth = depth,
+ last_level = last_level,
+ face = face,
+ level = level,
+ zslice = zslice,
+ )
+ suite.add_test(test)
suite.run()
diff --git a/progs/gallium/python/tests/texture_sample.py b/progs/gallium/python/tests/texture_blit.py
index 49545c2e07..a68c081931 100755
--- a/progs/gallium/python/tests/texture_sample.py
+++ b/progs/gallium/python/tests/texture_blit.py
@@ -28,6 +28,8 @@
##########################################################################
+import random
+
from gallium import *
from base import *
@@ -115,6 +117,7 @@ class TextureColorSampleTest(TestCase):
def test(self):
dev = self.dev
+ ctx = self.ctx
target = self.target
format = self.format
@@ -125,6 +128,8 @@ class TextureColorSampleTest(TestCase):
face = self.face
level = self.level
zslice = self.zslice
+ minz = 0.0
+ maxz = 1.0
tex_usage = PIPE_TEXTURE_USAGE_SAMPLER
geom_flags = 0
@@ -136,8 +141,6 @@ class TextureColorSampleTest(TestCase):
if not dev.is_format_supported(format, target, tex_usage, geom_flags):
raise TestSkip
- ctx = self.dev.context_create()
-
# disabled blending/masking
blend = Blend()
blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE
@@ -155,7 +158,6 @@ class TextureColorSampleTest(TestCase):
rasterizer = Rasterizer()
rasterizer.front_winding = PIPE_WINDING_CW
rasterizer.cull_mode = PIPE_WINDING_NONE
- rasterizer.bypass_vs_clip_and_viewport = 1
ctx.set_rasterizer(rasterizer)
# samplers
@@ -183,14 +185,45 @@ class TextureColorSampleTest(TestCase):
)
expected_rgba = FloatArray(height*width*4)
- texture.get_surface(
+ surface = texture.get_surface(
face = face,
level = level,
zslice = zslice,
- ).sample_rgba(expected_rgba)
+ )
+
+ ctx.surface_sample_rgba(surface, expected_rgba, True)
ctx.set_fragment_sampler_texture(0, texture)
+ # viewport
+ viewport = Viewport()
+ scale = FloatArray(4)
+ scale[0] = width
+ scale[1] = height
+ scale[2] = (maxz - minz) / 2.0
+ scale[3] = 1.0
+ viewport.scale = scale
+ translate = FloatArray(4)
+ translate[0] = 0.0
+ translate[1] = 0.0
+ translate[2] = (maxz - minz) / 2.0
+ translate[3] = 0.0
+ viewport.translate = translate
+ ctx.set_viewport(viewport)
+
+ # scissor
+ scissor = Scissor()
+ scissor.minx = 0
+ scissor.miny = 0
+ scissor.maxx = width
+ scissor.maxy = height
+ ctx.set_scissor(scissor)
+
+ # clip
+ clip = Clip()
+ clip.nr = 0
+ ctx.set_clip(clip)
+
# framebuffer
cbuf_tex = dev.texture_create(
PIPE_FORMAT_B8G8R8A8_UNORM,
@@ -265,8 +298,8 @@ class TextureColorSampleTest(TestCase):
for i in range(0, 4):
j = 8*i
- verts[j + 0] = pos[i][0] # x
- verts[j + 1] = pos[i][1] # y
+ verts[j + 0] = pos[i][0]/float(width) # x
+ verts[j + 1] = pos[i][1]/float(height) # y
verts[j + 2] = 0.0 # z
verts[j + 3] = 1.0 # w
verts[j + 4] = tex[i][0] # s
@@ -283,7 +316,7 @@ class TextureColorSampleTest(TestCase):
cbuf = cbuf_tex.get_surface()
- self.assert_rgba(cbuf, x, y, w, h, expected_rgba, 4.0/256, 0.85)
+ self.assert_rgba(ctx, cbuf, x, y, w, h, expected_rgba, 4.0/256, 0.85)
class TextureDepthSampleTest(TestCase):
@@ -302,6 +335,7 @@ class TextureDepthSampleTest(TestCase):
def test(self):
dev = self.dev
+ ctx = self.ctx
target = self.target
format = self.format
@@ -312,6 +346,8 @@ class TextureDepthSampleTest(TestCase):
face = self.face
level = self.level
zslice = self.zslice
+ minz = 0.0
+ maxz = 1.0
tex_usage = PIPE_TEXTURE_USAGE_SAMPLER
geom_flags = 0
@@ -323,8 +359,6 @@ class TextureDepthSampleTest(TestCase):
if not dev.is_format_supported(format, target, tex_usage, geom_flags):
raise TestSkip
- ctx = self.dev.context_create()
-
# disabled blending/masking
blend = Blend()
blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE
@@ -345,9 +379,24 @@ class TextureDepthSampleTest(TestCase):
rasterizer = Rasterizer()
rasterizer.front_winding = PIPE_WINDING_CW
rasterizer.cull_mode = PIPE_WINDING_NONE
- rasterizer.bypass_vs_clip_and_viewport = 1
ctx.set_rasterizer(rasterizer)
+ # viewport
+ viewport = Viewport()
+ scale = FloatArray(4)
+ scale[0] = width
+ scale[1] = height
+ scale[2] = (maxz - minz) / 2.0
+ scale[3] = 1.0
+ viewport.scale = scale
+ translate = FloatArray(4)
+ translate[0] = 0.0
+ translate[1] = 0.0
+ translate[2] = (maxz - minz) / 2.0
+ translate[3] = 0.0
+ viewport.translate = translate
+ ctx.set_viewport(viewport)
+
# samplers
sampler = Sampler()
sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE
@@ -373,14 +422,29 @@ class TextureDepthSampleTest(TestCase):
)
expected_rgba = FloatArray(height*width*4)
- texture.get_surface(
+ surface = texture.get_surface(
face = face,
level = level,
zslice = zslice,
- ).sample_rgba(expected_rgba)
+ )
+
+ ctx.surface_sample_rgba(surface, expected_rgba, True)
ctx.set_fragment_sampler_texture(0, texture)
+ # scissor
+ scissor = Scissor()
+ scissor.minx = 0
+ scissor.miny = 0
+ scissor.maxx = width
+ scissor.maxy = height
+ ctx.set_scissor(scissor)
+
+ # clip
+ clip = Clip()
+ clip.nr = 0
+ ctx.set_clip(clip)
+
# framebuffer
cbuf_tex = dev.texture_create(
PIPE_FORMAT_B8G8R8A8_UNORM,
@@ -464,8 +528,8 @@ class TextureDepthSampleTest(TestCase):
for i in range(0, 4):
j = 8*i
- verts[j + 0] = pos[i][0] # x
- verts[j + 1] = pos[i][1] # y
+ verts[j + 0] = pos[i][0]/float(width) # x
+ verts[j + 1] = pos[i][1]/float(height) # y
verts[j + 2] = 0.0 # z
verts[j + 3] = 1.0 # w
verts[j + 4] = tex[i][0] # s
@@ -482,13 +546,16 @@ class TextureDepthSampleTest(TestCase):
zsbuf = zsbuf_tex.get_surface()
- self.assert_rgba(zsbuf, x, y, w, h, expected_rgba, 4.0/256, 0.85)
+ self.assert_rgba(ctx, zsbuf, x, y, w, h, expected_rgba, 4.0/256, 0.85)
def main():
+ random.seed(0xdead3eef)
+
dev = Device()
+ ctx = dev.context_create()
suite = TestSuite()
targets = [
@@ -497,32 +564,9 @@ def main():
PIPE_TEXTURE_3D,
]
- color_formats = [
- PIPE_FORMAT_B8G8R8A8_UNORM,
- PIPE_FORMAT_B8G8R8X8_UNORM,
- #PIPE_FORMAT_B8G8R8A8_SRGB,
- PIPE_FORMAT_B5G6R5_UNORM,
- PIPE_FORMAT_B5G5R5A1_UNORM,
- PIPE_FORMAT_B4G4R4A4_UNORM,
- PIPE_FORMAT_A8_UNORM,
- PIPE_FORMAT_L8_UNORM,
- PIPE_FORMAT_UYVY,
- PIPE_FORMAT_DXT1_RGB,
- #PIPE_FORMAT_DXT1_RGBA,
- #PIPE_FORMAT_DXT3_RGBA,
- #PIPE_FORMAT_DXT5_RGBA,
- ]
-
- depth_formats = [
- PIPE_FORMAT_Z32_UNORM,
- PIPE_FORMAT_S8Z24_UNORM,
- PIPE_FORMAT_X8Z24_UNORM,
- PIPE_FORMAT_Z16_UNORM,
- ]
-
- sizes = [64, 32, 16, 8, 4, 2, 1]
+ #sizes = [64, 32, 16, 8, 4, 2, 1]
#sizes = [1020, 508, 252, 62, 30, 14, 6, 3]
- #sizes = [64]
+ sizes = [64]
#sizes = [63]
faces = [
@@ -534,45 +578,46 @@ def main():
PIPE_TEX_FACE_NEG_Z,
]
- for format in color_formats:
- for target in targets:
- for size in sizes:
- if target == PIPE_TEXTURE_3D:
- depth = size
- else:
- depth = 1
- for face in faces:
- if target != PIPE_TEXTURE_CUBE and face:
- continue
- levels = lods(size)
- for last_level in range(levels):
- for level in range(0, last_level + 1):
- zslice = 0
- while zslice < depth >> level:
- test = TextureColorSampleTest(
- dev = dev,
- target = target,
- format = format,
- width = size,
- height = size,
- depth = depth,
- last_level = last_level,
- face = face,
- level = level,
- zslice = zslice,
- )
- suite.add_test(test)
- zslice = (zslice + 1)*2 - 1
- for format in depth_formats:
- target = PIPE_TEXTURE_2D
- depth = 1
- face = 0
- last_level = 0
- level = 0
- zslice = 0
- for size in sizes:
- test = TextureDepthSampleTest(
+ try:
+ n = int(sys.argv[1])
+ except:
+ n = 10000
+
+ for i in range(n):
+ format = random.choice(formats.keys())
+ if not util_format_is_depth_or_stencil(format):
+ is_depth_or_stencil = util_format_is_depth_or_stencil(format)
+
+ if is_depth_or_stencil:
+ target = PIPE_TEXTURE_2D
+ else:
+ target = random.choice(targets)
+
+ size = random.choice(sizes)
+
+ if target == PIPE_TEXTURE_3D:
+ depth = size
+ else:
+ depth = 1
+
+ if target == PIPE_TEXTURE_CUBE:
+ face = random.choice(faces)
+ else:
+ face = PIPE_TEX_FACE_POS_X
+
+ levels = lods(size)
+ last_level = random.randint(0, levels - 1)
+ level = random.randint(0, last_level)
+ zslice = random.randint(0, max(depth >> level, 1) - 1)
+
+ if is_depth_or_stencil:
+ klass = TextureDepthSampleTest
+ else:
+ klass = TextureColorSampleTest
+
+ test = klass(
dev = dev,
+ ctx = ctx,
target = target,
format = format,
width = size,
diff --git a/progs/gallium/python/tests/texture_render.py b/progs/gallium/python/tests/texture_render.py
index 1e26639db6..12def7ec72 100755
--- a/progs/gallium/python/tests/texture_render.py
+++ b/progs/gallium/python/tests/texture_render.py
@@ -258,10 +258,10 @@ def main():
PIPE_FORMAT_B5G5R5A1_UNORM,
PIPE_FORMAT_B4G4R4A4_UNORM,
#PIPE_FORMAT_Z32_UNORM,
- #PIPE_FORMAT_S8Z24_UNORM,
+ #PIPE_FORMAT_S8_USCALED_Z24_UNORM,
#PIPE_FORMAT_X8Z24_UNORM,
#PIPE_FORMAT_Z16_UNORM,
- #PIPE_FORMAT_S8_UNORM,
+ #PIPE_FORMAT_S8_USCALED,
PIPE_FORMAT_A8_UNORM,
PIPE_FORMAT_L8_UNORM,
#PIPE_FORMAT_DXT1_RGB,
diff --git a/progs/gallium/python/tests/texture_transfer.py b/progs/gallium/python/tests/texture_transfer.py
index 7da00e4255..639d3d362c 100755
--- a/progs/gallium/python/tests/texture_transfer.py
+++ b/progs/gallium/python/tests/texture_transfer.py
@@ -29,6 +29,7 @@
import os
+import random
from gallium import *
from base import *
@@ -59,6 +60,7 @@ class TextureTest(TestCase):
def test(self):
dev = self.dev
+ ctx = self.ctx
target = self.target
format = self.format
@@ -70,8 +72,12 @@ class TextureTest(TestCase):
level = self.level
zslice = self.zslice
- tex_usage = 0
+ tex_usage = PIPE_TEXTURE_USAGE_SAMPLER
+ geom_flags = 0
+ if not dev.is_format_supported(format, target, tex_usage, geom_flags):
+ raise TestSkip
+ # textures
texture = dev.texture_create(
target = target,
format = format,
@@ -81,20 +87,17 @@ class TextureTest(TestCase):
last_level = last_level,
tex_usage = tex_usage,
)
- if texture is None:
- raise TestSkip
surface = texture.get_surface(face, level, zslice)
- # ???
- stride = pf_get_stride(texture->format, w)
- size = pf_get_nblocksy(texture->format) * stride
+ stride = util_format_get_stride(format, surface.width)
+ size = util_format_get_nblocksy(format, surface.height) * stride
in_raw = os.urandom(size)
- surface.put_tile_raw(0, 0, surface.width, surface.height, in_raw, stride)
+ ctx.surface_write_raw(surface, 0, 0, surface.width, surface.height, in_raw, stride)
- out_raw = surface.get_tile_raw(0, 0, surface.width, surface.height)
+ out_raw = ctx.surface_read_raw(surface, 0, 0, surface.width, surface.height)
if in_raw != out_raw:
raise TestFailure
@@ -102,6 +105,7 @@ class TextureTest(TestCase):
def main():
dev = Device()
+ ctx = dev.context_create()
suite = TestSuite()
targets = [
@@ -110,26 +114,6 @@ def main():
PIPE_TEXTURE_3D,
]
- formats = [
- PIPE_FORMAT_B8G8R8A8_UNORM,
- PIPE_FORMAT_B8G8R8X8_UNORM,
- PIPE_FORMAT_B8G8R8A8_SRGB,
- PIPE_FORMAT_B5G6R5_UNORM,
- PIPE_FORMAT_B5G5R5A1_UNORM,
- PIPE_FORMAT_B4G4R4A4_UNORM,
- PIPE_FORMAT_Z32_UNORM,
- PIPE_FORMAT_S8Z24_UNORM,
- PIPE_FORMAT_X8Z24_UNORM,
- PIPE_FORMAT_Z16_UNORM,
- PIPE_FORMAT_S8_UNORM,
- PIPE_FORMAT_A8_UNORM,
- PIPE_FORMAT_L8_UNORM,
- PIPE_FORMAT_DXT1_RGB,
- PIPE_FORMAT_DXT1_RGBA,
- PIPE_FORMAT_DXT3_RGBA,
- PIPE_FORMAT_DXT5_RGBA,
- ]
-
sizes = [64, 32, 16, 8, 4, 2, 1]
#sizes = [1020, 508, 252, 62, 30, 14, 6, 3]
#sizes = [64]
@@ -144,35 +128,52 @@ def main():
PIPE_TEX_FACE_NEG_Z,
]
- for target in targets:
- for format in formats:
- for size in sizes:
- if target == PIPE_TEXTURE_3D:
- depth = size
- else:
- depth = 1
- for face in faces:
- if target != PIPE_TEXTURE_CUBE and face:
- continue
- levels = lods(size)
- for last_level in range(levels):
- for level in range(0, last_level + 1):
- zslice = 0
- while zslice < depth >> level:
- test = TextureTest(
- dev = dev,
- target = target,
- format = format,
- width = size,
- height = size,
- depth = depth,
- last_level = last_level,
- face = face,
- level = level,
- zslice = zslice,
- )
- suite.add_test(test)
- zslice = (zslice + 1)*2 - 1
+ try:
+ n = int(sys.argv[1])
+ except:
+ n = 10000
+
+ for i in range(n):
+ format = random.choice(formats.keys())
+ if not util_format_is_depth_or_stencil(format):
+ is_depth_or_stencil = util_format_is_depth_or_stencil(format)
+
+ if is_depth_or_stencil:
+ target = PIPE_TEXTURE_2D
+ else:
+ target = random.choice(targets)
+
+ size = random.choice(sizes)
+
+ if target == PIPE_TEXTURE_3D:
+ depth = size
+ else:
+ depth = 1
+
+ if target == PIPE_TEXTURE_CUBE:
+ face = random.choice(faces)
+ else:
+ face = PIPE_TEX_FACE_POS_X
+
+ levels = lods(size)
+ last_level = random.randint(0, levels - 1)
+ level = random.randint(0, last_level)
+ zslice = random.randint(0, max(depth >> level, 1) - 1)
+
+ test = TextureTest(
+ dev = dev,
+ ctx = ctx,
+ target = target,
+ format = format,
+ width = size,
+ height = size,
+ depth = depth,
+ last_level = last_level,
+ face = face,
+ level = level,
+ zslice = zslice,
+ )
+ suite.add_test(test)
suite.run()
diff --git a/progs/gallium/raw/SConscript b/progs/gallium/raw/SConscript
new file mode 100644
index 0000000000..073b97951e
--- /dev/null
+++ b/progs/gallium/raw/SConscript
@@ -0,0 +1,17 @@
+Import('*')
+
+env = env.Clone()
+
+env.Prepend(LIBPATH = [graw.dir])
+env.Prepend(LIBS = [graw.name])
+
+progs = [
+ 'clear'
+]
+
+for prog in progs:
+ env.Program(
+ target = prog,
+ source = prog + '.c',
+ )
+
diff --git a/progs/gallium/raw/clear.c b/progs/gallium/raw/clear.c
new file mode 100644
index 0000000000..5ef5254edc
--- /dev/null
+++ b/progs/gallium/raw/clear.c
@@ -0,0 +1,95 @@
+/* Display a cleared blue window. This demo has no dependencies on
+ * any utility code, just the graw interface and gallium.
+ */
+
+#include "state_tracker/graw.h"
+#include "pipe/p_screen.h"
+#include "pipe/p_context.h"
+#include "pipe/p_state.h"
+#include "pipe/p_defines.h"
+#include <unistd.h> /* for sleep() */
+
+#include "util/u_debug.h" /* debug_dump_surface_bmp() */
+
+enum pipe_format formats[] = {
+ PIPE_FORMAT_R8G8B8A8_UNORM,
+ PIPE_FORMAT_B8G8R8A8_UNORM,
+ PIPE_FORMAT_NONE
+};
+
+static const int WIDTH = 300;
+static const int HEIGHT = 300;
+
+int main( int argc, char *argv[] )
+{
+ struct pipe_screen *screen;
+ struct pipe_context *pipe;
+ struct pipe_surface *surf;
+ struct pipe_framebuffer_state fb;
+ struct pipe_texture *tex, templat;
+ void *window = NULL;
+ float clear_color[4] = {1,0,1,1};
+ int i;
+
+ screen = graw_init();
+ if (screen == NULL)
+ exit(1);
+
+ for (i = 0;
+ window == NULL && formats[i] != PIPE_FORMAT_NONE;
+ i++) {
+
+ window = graw_create_window(0,0,300,300, formats[i]);
+ }
+
+ if (window == NULL)
+ exit(2);
+
+ pipe = screen->context_create(screen, NULL);
+ if (pipe == NULL)
+ exit(3);
+
+ templat.target = PIPE_TEXTURE_2D;
+ templat.format = formats[i];
+ templat.width0 = WIDTH;
+ templat.height0 = HEIGHT;
+ templat.depth0 = 1;
+ templat.last_level = 0;
+ templat.nr_samples = 1;
+ templat.tex_usage = (PIPE_TEXTURE_USAGE_RENDER_TARGET |
+ PIPE_TEXTURE_USAGE_DISPLAY_TARGET);
+
+ tex = screen->texture_create(screen,
+ &templat);
+ if (tex == NULL)
+ exit(4);
+
+ surf = screen->get_tex_surface(screen, tex, 0, 0, 0,
+ PIPE_TEXTURE_USAGE_RENDER_TARGET |
+ PIPE_TEXTURE_USAGE_DISPLAY_TARGET);
+ if (surf == NULL)
+ exit(5);
+
+ memset(&fb, 0, sizeof fb);
+ fb.nr_cbufs = 1;
+ fb.width = WIDTH;
+ fb.height = HEIGHT;
+ fb.cbufs[0] = surf;
+
+ pipe->set_framebuffer_state(pipe, &fb);
+ pipe->clear(pipe, PIPE_CLEAR_COLOR, clear_color, 0, 0);
+ pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL);
+
+ /* At the moment, libgraw includes/makes available all the symbols
+ * from gallium/auxiliary, including these debug helpers. Will
+ * eventually want to bless some of these paths, and lock the
+ * others down so they aren't accessible from test programs.
+ */
+ if (0)
+ debug_dump_surface_bmp(pipe, "result.bmp", surf);
+
+ screen->flush_frontbuffer(screen, surf, window);
+
+ sleep(100);
+ return 0;
+}
diff --git a/progs/gallium/trivial/.gitignore b/progs/gallium/trivial/.gitignore
new file mode 100644
index 0000000000..af6cdedbeb
--- /dev/null
+++ b/progs/gallium/trivial/.gitignore
@@ -0,0 +1,3 @@
+tri
+quad-tex
+result.bmp
diff --git a/progs/gallium/trivial/Makefile b/progs/gallium/trivial/Makefile
new file mode 100644
index 0000000000..2b8af1ac06
--- /dev/null
+++ b/progs/gallium/trivial/Makefile
@@ -0,0 +1,44 @@
+# progs/gallium/simple/Makefile
+
+TOP = ../../..
+include $(TOP)/configs/current
+
+INCLUDES = \
+ -I. \
+ -I$(TOP)/src/gallium/include \
+ -I$(TOP)/src/gallium/auxiliary \
+ -I$(TOP)/src/gallium/drivers \
+ -I$(TOP)/src/gallium/winsys \
+ $(PROG_INCLUDES)
+
+LINKS = \
+ $(TOP)/src/gallium/drivers/trace/libtrace.a \
+ $(TOP)/src/gallium/winsys/sw/null/libws_null.a \
+ $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \
+ $(GALLIUM_AUXILIARIES) \
+ $(PROG_LINKS)
+
+SOURCES = \
+ tri.c \
+ quad-tex.c
+
+OBJECTS = $(SOURCES:.c=.o)
+
+PROGS = $(OBJECTS:.o=)
+
+##### TARGETS #####
+
+default: $(PROGS)
+
+clean:
+ -rm -f $(PROGS)
+ -rm -f *.o
+ -rm -f result.bmp
+
+##### RULES #####
+
+$(OBJECTS): %.o: %.c
+ $(CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) $(PROG_DEFINES) $< -o $@
+
+$(PROGS): %: %.o
+ $(CC) $(LDFLAGS) $< $(LINKS) -lm -lpthread -o $@
diff --git a/progs/gallium/trivial/quad-tex.c b/progs/gallium/trivial/quad-tex.c
new file mode 100644
index 0000000000..553f5582e7
--- /dev/null
+++ b/progs/gallium/trivial/quad-tex.c
@@ -0,0 +1,346 @@
+/**************************************************************************
+ *
+ * Copyright © 2010 Jakob Bornecrantz
+ *
+ * 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.
+ *
+ **************************************************************************/
+
+
+#define USE_TRACE 0
+#define WIDTH 300
+#define HEIGHT 300
+#define NEAR 30
+#define FAR 1000
+#define FLIP 0
+
+/* pipe_*_state structs */
+#include "pipe/p_state.h"
+/* pipe_context */
+#include "pipe/p_context.h"
+/* pipe_screen */
+#include "pipe/p_screen.h"
+/* PIPE_* */
+#include "pipe/p_defines.h"
+/* TGSI_SEMANTIC_{POSITION|GENERIC} */
+#include "pipe/p_shader_tokens.h"
+/* pipe_buffer_* helpers */
+#include "util/u_inlines.h"
+
+/* constant state object helper */
+#include "cso_cache/cso_context.h"
+
+/* u_sampler_view_default_template */
+#include "util/u_sampler.h"
+/* debug_dump_surface_bmp */
+#include "util/u_debug.h"
+/* util_draw_vertex_buffer helper */
+#include "util/u_draw_quad.h"
+/* FREE & CALLOC_STRUCT */
+#include "util/u_memory.h"
+/* util_make_[fragment|vertex]_passthrough_shader */
+#include "util/u_simple_shaders.h"
+
+/* softpipe software driver */
+#include "softpipe/sp_public.h"
+
+/* null software winsys */
+#include "sw/null/null_sw_winsys.h"
+
+/* traceing support see src/gallium/drivers/trace/README for more info. */
+#if USE_TRACE
+#include "trace/tr_screen.h"
+#include "trace/tr_context.h"
+#endif
+
+struct program
+{
+ struct pipe_screen *screen;
+ struct pipe_context *pipe;
+ struct cso_context *cso;
+
+ struct pipe_blend_state blend;
+ struct pipe_depth_stencil_alpha_state depthstencil;
+ struct pipe_rasterizer_state rasterizer;
+ struct pipe_sampler_state sampler;
+ struct pipe_viewport_state viewport;
+ struct pipe_framebuffer_state framebuffer;
+ struct pipe_vertex_element velem[2];
+
+ void *vs;
+ void *fs;
+
+ float clear_color[4];
+
+ struct pipe_buffer *vbuf;
+ struct pipe_texture *target;
+ struct pipe_texture *tex;
+ struct pipe_sampler_view *view;
+};
+
+static void init_prog(struct program *p)
+{
+ /* create the software rasterizer */
+ p->screen = softpipe_create_screen(null_sw_create());
+#if USE_TRACE
+ p->screen = trace_screen_create(p->screen);
+#endif
+ p->pipe = p->screen->context_create(p->screen, NULL);
+ p->cso = cso_create_context(p->pipe);
+
+ /* set clear color */
+ p->clear_color[0] = 0.3;
+ p->clear_color[1] = 0.1;
+ p->clear_color[2] = 0.3;
+ p->clear_color[3] = 1.0;
+
+ /* vertex buffer */
+ {
+ float vertices[4][2][4] = {
+ {
+ { 0.9f, 0.9f, 0.0f, 1.0f },
+ { 1.0f, 1.0f, 0.0f, 1.0f }
+ },
+ {
+ { -0.9f, 0.9f, 0.0f, 1.0f },
+ { 0.0f, 1.0f, 0.0f, 1.0f }
+ },
+ {
+ { -0.9f, -0.9f, 0.0f, 1.0f },
+ { 0.0f, 0.0f, 1.0f, 1.0f }
+ },
+ {
+ { 0.9f, -0.9f, 0.0f, 1.0f },
+ { 1.0f, 0.0f, 1.0f, 1.0f }
+ }
+ };
+
+ p->vbuf = pipe_buffer_create(p->screen, 16, PIPE_BUFFER_USAGE_VERTEX, sizeof(vertices));
+ pipe_buffer_write(p->screen, p->vbuf, 0, sizeof(vertices), vertices);
+ }
+
+ /* render target texture */
+ {
+ struct pipe_texture tmplt;
+ memset(&tmplt, 0, sizeof(tmplt));
+ tmplt.target = PIPE_TEXTURE_2D;
+ tmplt.format = PIPE_FORMAT_B8G8R8A8_UNORM; /* All drivers support this */
+ tmplt.width0 = WIDTH;
+ tmplt.height0 = HEIGHT;
+ tmplt.depth0 = 1;
+ tmplt.last_level = 0;
+ tmplt.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET;
+
+ p->target = p->screen->texture_create(p->screen, &tmplt);
+ }
+
+ /* sampler texture */
+ {
+ uint32_t *ptr;
+ struct pipe_transfer *t;
+ struct pipe_texture t_tmplt;
+ struct pipe_sampler_view v_tmplt;
+
+ memset(&t_tmplt, 0, sizeof(t_tmplt));
+ t_tmplt.target = PIPE_TEXTURE_2D;
+ t_tmplt.format = PIPE_FORMAT_B8G8R8A8_UNORM; /* All drivers support this */
+ t_tmplt.width0 = 2;
+ t_tmplt.height0 = 2;
+ t_tmplt.depth0 = 1;
+ t_tmplt.last_level = 0;
+ t_tmplt.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET;
+
+ p->tex = p->screen->texture_create(p->screen, &t_tmplt);
+
+ t = p->pipe->get_tex_transfer(p->pipe, p->tex,
+ 0, 0, 0, /* face, level, zslice */
+ PIPE_TRANSFER_WRITE,
+ 0, 0, 2, 2); /* x, y, width, height */
+
+ ptr = p->pipe->transfer_map(p->pipe, t);
+ ptr[0] = 0xffff0000;
+ ptr[1] = 0xff0000ff;
+ ptr[2] = 0xff00ff00;
+ ptr[3] = 0xffffff00;
+ p->pipe->transfer_unmap(p->pipe, t);
+
+ p->pipe->tex_transfer_destroy(p->pipe, t);
+
+ u_sampler_view_default_template(&v_tmplt, p->tex, p->tex->format);
+
+ p->view = p->pipe->create_sampler_view(p->pipe, p->tex, &v_tmplt);
+ }
+
+ /* disabled blending/masking */
+ memset(&p->blend, 0, sizeof(p->blend));
+ p->blend.rt[0].colormask = PIPE_MASK_RGBA;
+
+ /* no-op depth/stencil/alpha */
+ memset(&p->depthstencil, 0, sizeof(p->depthstencil));
+
+ /* rasterizer */
+ memset(&p->rasterizer, 0, sizeof(p->rasterizer));
+ p->rasterizer.front_winding = PIPE_WINDING_CW;
+ p->rasterizer.cull_mode = PIPE_WINDING_NONE;
+ p->rasterizer.gl_rasterization_rules = 1;
+
+ /* sampler */
+ memset(&p->sampler, 0, sizeof(p->sampler));
+ p->sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
+ p->sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
+ p->sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
+ p->sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE;
+ p->sampler.min_img_filter = PIPE_TEX_MIPFILTER_LINEAR;
+ p->sampler.mag_img_filter = PIPE_TEX_MIPFILTER_LINEAR;
+ p->sampler.normalized_coords = 1;
+
+ /* drawing destination */
+ memset(&p->framebuffer, 0, sizeof(p->framebuffer));
+ p->framebuffer.width = WIDTH;
+ p->framebuffer.height = HEIGHT;
+ p->framebuffer.nr_cbufs = 1;
+ p->framebuffer.cbufs[0] = p->screen->get_tex_surface(p->screen, p->target, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE);
+
+ /* viewport, depth isn't really needed */
+ {
+ float x = 0;
+ float y = 0;
+ float z = FAR;
+ float half_width = (float)WIDTH / 2.0f;
+ float half_height = (float)HEIGHT / 2.0f;
+ float half_depth = ((float)FAR - (float)NEAR) / 2.0f;
+ float scale, bias;
+
+ if (FLIP) {
+ scale = -1.0f;
+ bias = (float)HEIGHT;
+ } else {
+ scale = 1.0f;
+ bias = 0.0f;
+ }
+
+ p->viewport.scale[0] = half_width;
+ p->viewport.scale[1] = half_height * scale;
+ p->viewport.scale[2] = half_depth;
+ p->viewport.scale[3] = 1.0f;
+
+ p->viewport.translate[0] = half_width + x;
+ p->viewport.translate[1] = (half_height + y) * scale + bias;
+ p->viewport.translate[2] = half_depth + z;
+ p->viewport.translate[3] = 0.0f;
+ }
+
+ /* vertex elements state */
+ memset(p->velem, 0, sizeof(p->velem));
+ p->velem[0].src_offset = 0 * 4 * sizeof(float); /* offset 0, first element */
+ p->velem[0].instance_divisor = 0;
+ p->velem[0].vertex_buffer_index = 0;
+ p->velem[0].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
+
+ p->velem[1].src_offset = 1 * 4 * sizeof(float); /* offset 16, second element */
+ p->velem[1].instance_divisor = 0;
+ p->velem[1].vertex_buffer_index = 0;
+ p->velem[1].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
+
+ /* vertex shader */
+ {
+ const uint semantic_names[] = { TGSI_SEMANTIC_POSITION,
+ TGSI_SEMANTIC_GENERIC };
+ const uint semantic_indexes[] = { 0, 0 };
+ p->vs = util_make_vertex_passthrough_shader(p->pipe, 2, semantic_names, semantic_indexes);
+ }
+
+ /* fragment shader */
+ p->fs = util_make_fragment_tex_shader(p->pipe, TGSI_TEXTURE_2D);
+}
+
+static void close_prog(struct program *p)
+{
+ /* unset bound textures as well */
+ cso_set_fragment_sampler_views(p->cso, 0, NULL);
+
+ /* unset all state */
+ cso_release_all(p->cso);
+
+ p->pipe->delete_vs_state(p->pipe, p->vs);
+ p->pipe->delete_fs_state(p->pipe, p->fs);
+
+ pipe_surface_reference(&p->framebuffer.cbufs[0], NULL);
+ pipe_sampler_view_reference(&p->view, NULL);
+ pipe_texture_reference(&p->target, NULL);
+ pipe_texture_reference(&p->tex, NULL);
+ pipe_buffer_reference(&p->vbuf, NULL);
+
+ cso_destroy_context(p->cso);
+ p->pipe->destroy(p->pipe);
+ p->screen->destroy(p->screen);
+
+ FREE(p);
+}
+
+static void draw(struct program *p)
+{
+ /* set the render target */
+ cso_set_framebuffer(p->cso, &p->framebuffer);
+
+ /* clear the render target */
+ p->pipe->clear(p->pipe, PIPE_CLEAR_COLOR, p->clear_color, 0, 0);
+
+ /* set misc state we care about */
+ cso_set_blend(p->cso, &p->blend);
+ cso_set_depth_stencil_alpha(p->cso, &p->depthstencil);
+ cso_set_rasterizer(p->cso, &p->rasterizer);
+ cso_set_viewport(p->cso, &p->viewport);
+
+ /* sampler */
+ cso_single_sampler(p->cso, 0, &p->sampler);
+ cso_single_sampler_done(p->cso);
+
+ /* texture sampler view */
+ cso_set_fragment_sampler_views(p->cso, 1, &p->view);
+
+ /* shaders */
+ cso_set_fragment_shader_handle(p->cso, p->fs);
+ cso_set_vertex_shader_handle(p->cso, p->vs);
+
+ /* vertex element data */
+ cso_set_vertex_elements(p->cso, 2, p->velem);
+
+ util_draw_vertex_buffer(p->pipe,
+ p->vbuf, 0,
+ PIPE_PRIM_QUADS,
+ 4, /* verts */
+ 2); /* attribs/vert */
+
+ p->pipe->flush(p->pipe, PIPE_FLUSH_RENDER_CACHE, NULL);
+
+ debug_dump_surface_bmp(p->pipe, "result.bmp", p->framebuffer.cbufs[0]);
+}
+
+int main(int argc, char** argv)
+{
+ struct program *p = CALLOC_STRUCT(program);
+
+ init_prog(p);
+ draw(p);
+ close_prog(p);
+
+ return 0;
+}
diff --git a/progs/gallium/trivial/tri.c b/progs/gallium/trivial/tri.c
new file mode 100644
index 0000000000..cae1bdb1b1
--- /dev/null
+++ b/progs/gallium/trivial/tri.c
@@ -0,0 +1,278 @@
+/**************************************************************************
+ *
+ * Copyright © 2010 Jakob Bornecrantz
+ *
+ * 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.
+ *
+ **************************************************************************/
+
+
+#define USE_TRACE 0
+#define WIDTH 300
+#define HEIGHT 300
+#define NEAR 30
+#define FAR 1000
+#define FLIP 0
+
+/* pipe_*_state structs */
+#include "pipe/p_state.h"
+/* pipe_context */
+#include "pipe/p_context.h"
+/* pipe_screen */
+#include "pipe/p_screen.h"
+/* PIPE_* */
+#include "pipe/p_defines.h"
+/* TGSI_SEMANTIC_{POSITION|GENERIC} */
+#include "pipe/p_shader_tokens.h"
+/* pipe_buffer_* helpers */
+#include "util/u_inlines.h"
+
+/* constant state object helper */
+#include "cso_cache/cso_context.h"
+
+/* debug_dump_surface_bmp */
+#include "util/u_debug.h"
+/* util_draw_vertex_buffer helper */
+#include "util/u_draw_quad.h"
+/* FREE & CALLOC_STRUCT */
+#include "util/u_memory.h"
+/* util_make_[fragment|vertex]_passthrough_shader */
+#include "util/u_simple_shaders.h"
+
+/* softpipe software driver */
+#include "softpipe/sp_public.h"
+
+/* null software winsys */
+#include "sw/null/null_sw_winsys.h"
+
+/* traceing support see src/gallium/drivers/trace/README for more info. */
+#if USE_TRACE
+#include "trace/tr_screen.h"
+#include "trace/tr_context.h"
+#endif
+
+struct program
+{
+ struct pipe_screen *screen;
+ struct pipe_context *pipe;
+ struct cso_context *cso;
+
+ struct pipe_blend_state blend;
+ struct pipe_depth_stencil_alpha_state depthstencil;
+ struct pipe_rasterizer_state rasterizer;
+ struct pipe_viewport_state viewport;
+ struct pipe_framebuffer_state framebuffer;
+ struct pipe_vertex_element velem[2];
+
+ void *vs;
+ void *fs;
+
+ float clear_color[4];
+
+ struct pipe_buffer *vbuf;
+ struct pipe_texture *target;
+};
+
+static void init_prog(struct program *p)
+{
+ /* create the software rasterizer */
+ p->screen = softpipe_create_screen(null_sw_create());
+#if USE_TRACE
+ p->screen = trace_screen_create(p->screen);
+#endif
+ p->pipe = p->screen->context_create(p->screen, NULL);
+ p->cso = cso_create_context(p->pipe);
+
+ /* set clear color */
+ p->clear_color[0] = 0.3;
+ p->clear_color[1] = 0.1;
+ p->clear_color[2] = 0.3;
+ p->clear_color[3] = 1.0;
+
+ /* vertex buffer */
+ {
+ float vertices[4][2][4] = {
+ {
+ { 0.0f, -0.9f, 0.0f, 1.0f },
+ { 1.0f, 0.0f, 0.0f, 1.0f }
+ },
+ {
+ { -0.9f, 0.9f, 0.0f, 1.0f },
+ { 0.0f, 1.0f, 0.0f, 1.0f }
+ },
+ {
+ { 0.9f, 0.9f, 0.0f, 1.0f },
+ { 0.0f, 0.0f, 1.0f, 1.0f }
+ }
+ };
+
+ p->vbuf = pipe_buffer_create(p->screen, 16, PIPE_BUFFER_USAGE_VERTEX, sizeof(vertices));
+ pipe_buffer_write(p->screen, p->vbuf, 0, sizeof(vertices), vertices);
+ }
+
+ /* render target texture */
+ {
+ struct pipe_texture tmplt;
+ memset(&tmplt, 0, sizeof(tmplt));
+ tmplt.target = PIPE_TEXTURE_2D;
+ tmplt.format = PIPE_FORMAT_B8G8R8A8_UNORM; /* All drivers support this */
+ tmplt.width0 = WIDTH;
+ tmplt.height0 = HEIGHT;
+ tmplt.depth0 = 1;
+ tmplt.last_level = 0;
+ tmplt.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET;
+
+ p->target = p->screen->texture_create(p->screen, &tmplt);
+ }
+
+ /* disabled blending/masking */
+ memset(&p->blend, 0, sizeof(p->blend));
+ p->blend.rt[0].colormask = PIPE_MASK_RGBA;
+
+ /* no-op depth/stencil/alpha */
+ memset(&p->depthstencil, 0, sizeof(p->depthstencil));
+
+ /* rasterizer */
+ memset(&p->rasterizer, 0, sizeof(p->rasterizer));
+ p->rasterizer.front_winding = PIPE_WINDING_CW;
+ p->rasterizer.cull_mode = PIPE_WINDING_NONE;
+ p->rasterizer.gl_rasterization_rules = 1;
+
+ /* drawing destination */
+ memset(&p->framebuffer, 0, sizeof(p->framebuffer));
+ p->framebuffer.width = WIDTH;
+ p->framebuffer.height = HEIGHT;
+ p->framebuffer.nr_cbufs = 1;
+ p->framebuffer.cbufs[0] = p->screen->get_tex_surface(p->screen, p->target, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE);
+
+ /* viewport, depth isn't really needed */
+ {
+ float x = 0;
+ float y = 0;
+ float z = FAR;
+ float half_width = (float)WIDTH / 2.0f;
+ float half_height = (float)HEIGHT / 2.0f;
+ float half_depth = ((float)FAR - (float)NEAR) / 2.0f;
+ float scale, bias;
+
+ if (FLIP) {
+ scale = -1.0f;
+ bias = (float)HEIGHT;
+ } else {
+ scale = 1.0f;
+ bias = 0.0f;
+ }
+
+ p->viewport.scale[0] = half_width;
+ p->viewport.scale[1] = half_height * scale;
+ p->viewport.scale[2] = half_depth;
+ p->viewport.scale[3] = 1.0f;
+
+ p->viewport.translate[0] = half_width + x;
+ p->viewport.translate[1] = (half_height + y) * scale + bias;
+ p->viewport.translate[2] = half_depth + z;
+ p->viewport.translate[3] = 0.0f;
+ }
+
+ /* vertex elements state */
+ memset(p->velem, 0, sizeof(p->velem));
+ p->velem[0].src_offset = 0 * 4 * sizeof(float); /* offset 0, first element */
+ p->velem[0].instance_divisor = 0;
+ p->velem[0].vertex_buffer_index = 0;
+ p->velem[0].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
+
+ p->velem[1].src_offset = 1 * 4 * sizeof(float); /* offset 16, second element */
+ p->velem[1].instance_divisor = 0;
+ p->velem[1].vertex_buffer_index = 0;
+ p->velem[1].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
+
+ /* vertex shader */
+ {
+ const uint semantic_names[] = { TGSI_SEMANTIC_POSITION,
+ TGSI_SEMANTIC_COLOR };
+ const uint semantic_indexes[] = { 0, 0 };
+ p->vs = util_make_vertex_passthrough_shader(p->pipe, 2, semantic_names, semantic_indexes);
+ }
+
+ /* fragment shader */
+ p->fs = util_make_fragment_passthrough_shader(p->pipe);
+}
+
+static void close_prog(struct program *p)
+{
+ /* unset all state */
+ cso_release_all(p->cso);
+
+ p->pipe->delete_vs_state(p->pipe, p->vs);
+ p->pipe->delete_fs_state(p->pipe, p->fs);
+
+ pipe_surface_reference(&p->framebuffer.cbufs[0], NULL);
+ pipe_texture_reference(&p->target, NULL);
+ pipe_buffer_reference(&p->vbuf, NULL);
+
+ cso_destroy_context(p->cso);
+ p->pipe->destroy(p->pipe);
+ p->screen->destroy(p->screen);
+
+ FREE(p);
+}
+
+static void draw(struct program *p)
+{
+ /* set the render target */
+ cso_set_framebuffer(p->cso, &p->framebuffer);
+
+ /* clear the render target */
+ p->pipe->clear(p->pipe, PIPE_CLEAR_COLOR, p->clear_color, 0, 0);
+
+ /* set misc state we care about */
+ cso_set_blend(p->cso, &p->blend);
+ cso_set_depth_stencil_alpha(p->cso, &p->depthstencil);
+ cso_set_rasterizer(p->cso, &p->rasterizer);
+ cso_set_viewport(p->cso, &p->viewport);
+
+ /* shaders */
+ cso_set_fragment_shader_handle(p->cso, p->fs);
+ cso_set_vertex_shader_handle(p->cso, p->vs);
+
+ /* vertex element data */
+ cso_set_vertex_elements(p->cso, 2, p->velem);
+
+ util_draw_vertex_buffer(p->pipe,
+ p->vbuf, 0,
+ PIPE_PRIM_TRIANGLES,
+ 3, /* verts */
+ 2); /* attribs/vert */
+
+ p->pipe->flush(p->pipe, PIPE_FLUSH_RENDER_CACHE, NULL);
+
+ debug_dump_surface_bmp(p->pipe, "result.bmp", p->framebuffer.cbufs[0]);
+}
+
+int main(int argc, char** argv)
+{
+ struct program *p = CALLOC_STRUCT(program);
+
+ init_prog(p);
+ draw(p);
+ close_prog(p);
+
+ return 0;
+}
diff --git a/progs/gallium/unit/Makefile b/progs/gallium/unit/Makefile
new file mode 100644
index 0000000000..f3dbd7695c
--- /dev/null
+++ b/progs/gallium/unit/Makefile
@@ -0,0 +1,44 @@
+# progs/gallium/simple/Makefile
+
+TOP = ../../..
+include $(TOP)/configs/current
+
+INCLUDES = \
+ -I. \
+ -I$(TOP)/src/gallium/include \
+ -I$(TOP)/src/gallium/auxiliary \
+ -I$(TOP)/src/gallium/drivers \
+ -I$(TOP)/src/gallium/winsys \
+ $(PROG_INCLUDES)
+
+LINKS = \
+ $(TOP)/src/gallium/drivers/trace/libtrace.a \
+ $(TOP)/src/gallium/winsys/sw/null/libws_null.a \
+ $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \
+ $(GALLIUM_AUXILIARIES) \
+ $(PROG_LINKS)
+
+SOURCES = \
+ u_format_test.c \
+ u_half_test.c
+
+OBJECTS = $(SOURCES:.c=.o)
+
+PROGS = $(OBJECTS:.o=)
+
+##### TARGETS #####
+
+default: $(PROGS)
+
+clean:
+ -rm -f $(PROGS)
+ -rm -f *.o
+ -rm -f result.bmp
+
+##### RULES #####
+
+$(OBJECTS): %.o: %.c
+ $(CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) $(PROG_DEFINES) $< -o $@
+
+$(PROGS): %: %.o
+ $(CC) $(LDFLAGS) $< $(LINKS) -lm -lpthread -ldl -o $@
diff --git a/progs/gallium/unit/SConscript b/progs/gallium/unit/SConscript
index 9891440df6..0db3bb687c 100644
--- a/progs/gallium/unit/SConscript
+++ b/progs/gallium/unit/SConscript
@@ -5,7 +5,8 @@ env = env.Clone()
env.Prepend(LIBS = [gallium])
progs = [
- 'u_format_test'
+ 'u_format_test',
+ 'u_half_test'
]
for prog in progs:
@@ -13,6 +14,8 @@ for prog in progs:
target = prog,
source = prog + '.c',
)
+
+ env.InstallProgram(prog)
# http://www.scons.org/wiki/UnitTests
test_alias = env.Alias('unit', [prog], prog[0].abspath)
diff --git a/progs/gallium/unit/u_format_test.c b/progs/gallium/unit/u_format_test.c
index 2dfba5538b..cfde6af75e 100644
--- a/progs/gallium/unit/u_format_test.c
+++ b/progs/gallium/unit/u_format_test.c
@@ -28,565 +28,226 @@
#include <stdlib.h>
#include <stdio.h>
+#include <float.h>
+#include "util/u_half.h"
#include "util/u_format.h"
-#include "util/u_format_pack.h"
+#include "util/u_format_tests.h"
+#include "util/u_format_s3tc.h"
-#define MAX_PACKED_BYTES 16
+static boolean
+compare_float(float x, float y)
+{
+ float error = y - x;
+
+ if (error < 0.0f)
+ error = -error;
+
+ if (error > FLT_EPSILON) {
+ return FALSE;
+ }
+
+ return TRUE;
+}
-/**
- * A (packed, unpacked) color pair.
- */
-struct util_format_test_case
+static void
+print_packed(const struct util_format_description *format_desc,
+ const char *prefix,
+ const uint8_t *packed,
+ const char *suffix)
{
- enum pipe_format format;
+ unsigned i;
+ const char *sep = "";
- /**
- * Mask of the bits that actually meaningful data. Used to mask out the
- * "X" channels.
- */
- uint8_t mask[MAX_PACKED_BYTES];
+ printf("%s", prefix);
+ for (i = 0; i < format_desc->block.bits/8; ++i) {
+ printf("%s%02x", sep, packed[i]);
+ sep = " ";
+ }
+ printf("%s", suffix);
+}
- uint8_t packed[MAX_PACKED_BYTES];
- /**
- * RGBA.
- */
- double unpacked[4];
-};
+static void
+print_unpacked_rgba_doubl(const struct util_format_description *format_desc,
+ const char *prefix,
+ const double unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4],
+ const char *suffix)
+{
+ unsigned i, j;
+ const char *sep = "";
+
+ printf("%s", prefix);
+ for (i = 0; i < format_desc->block.height; ++i) {
+ for (j = 0; j < format_desc->block.width; ++j) {
+ printf("%s{%f, %f, %f, %f}", sep, unpacked[i][j][0], unpacked[i][j][1], unpacked[i][j][2], unpacked[i][j][3]);
+ sep = ", ";
+ }
+ sep = ",\n";
+ }
+ printf("%s", suffix);
+}
-/*
- * Helper macros to create the packed bytes for longer words.
- */
+static void
+print_unpacked_rgba_float(const struct util_format_description *format_desc,
+ const char *prefix,
+ float unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4],
+ const char *suffix)
+{
+ unsigned i, j;
+ const char *sep = "";
+
+ printf("%s", prefix);
+ for (i = 0; i < format_desc->block.height; ++i) {
+ for (j = 0; j < format_desc->block.width; ++j) {
+ printf("%s{%f, %f, %f, %f}", sep, unpacked[i][j][0], unpacked[i][j][1], unpacked[i][j][2], unpacked[i][j][3]);
+ sep = ", ";
+ }
+ sep = ",\n";
+ }
+ printf("%s", suffix);
+}
-#define PACKED_1x8(x) {x, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
-#define PACKED_2x8(x, y) {x, y, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
-#define PACKED_3x8(x, y, z) {x, y, z, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
-#define PACKED_4x8(x, y, z, w) {x, y, z, w, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
-#define PACKED_1x16(x) {(x) & 0xff, (x) >> 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
-#define PACKED_2x16(x, y) {(x) & 0xff, (x) >> 8, (y) & 0xff, (y) >> 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
-#define PACKED_3x16(x, y, z) {(x) & 0xff, (x) >> 8, (y) & 0xff, (y) >> 8, (z) & 0xff, (z) >> 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
-#define PACKED_4x16(x, y, z, w) {(x) & 0xff, (x) >> 8, (y) & 0xff, (y) >> 8, (z) & 0xff, (z) >> 8, (w) & 0xff, (w) >> 8, 0, 0, 0, 0, 0, 0, 0, 0}
+static void
+print_unpacked_rgba_8unorm(const struct util_format_description *format_desc,
+ const char *prefix,
+ uint8_t unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4],
+ const char *suffix)
+{
+ unsigned i, j;
+ const char *sep = "";
+
+ printf("%s", prefix);
+ for (i = 0; i < format_desc->block.height; ++i) {
+ for (j = 0; j < format_desc->block.width; ++j) {
+ printf("%s{0x%02x, 0x%02x, 0x%02x, 0x%02x}", sep, unpacked[i][j][0], unpacked[i][j][1], unpacked[i][j][2], unpacked[i][j][3]);
+ sep = ", ";
+ }
+ }
+ printf("%s", suffix);
+}
-#define PACKED_1x32(x) {(x) & 0xff, ((x) >> 8) & 0xff, ((x) >> 16) & 0xff, (x) >> 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
-#define PACKED_2x32(x, y) {(x) & 0xff, ((x) >> 8) & 0xff, ((x) >> 16) & 0xff, (x) >> 24, (y) & 0xff, ((y) >> 8) & 0xff, ((y) >> 16) & 0xff, (y) >> 24, 0, 0, 0, 0, 0, 0, 0, 0}
-#define PACKED_3x32(x, y, z) {(x) & 0xff, ((x) >> 8) & 0xff, ((x) >> 16) & 0xff, (x) >> 24, (y) & 0xff, ((y) >> 8) & 0xff, ((y) >> 16) & 0xff, (y) >> 24, (z) & 0xff, ((z) >> 8) & 0xff, ((z) >> 16) & 0xff, (z) >> 24, 0, 0, 0, 0}
-#define PACKED_4x32(x, y, z, w) {(x) & 0xff, ((x) >> 8) & 0xff, ((x) >> 16) & 0xff, (x) >> 24, (y) & 0xff, ((y) >> 8) & 0xff, ((y) >> 16) & 0xff, (y) >> 24, (z) & 0xff, ((z) >> 8) & 0xff, ((z) >> 16) & 0xff, (z) >> 24, (w) & 0xff, ((w) >> 8) & 0xff, ((w) >> 16) & 0xff, (w) >> 24}
+static void
+print_unpacked_z_float(const struct util_format_description *format_desc,
+ const char *prefix,
+ float unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH],
+ const char *suffix)
+{
+ unsigned i, j;
+ const char *sep = "";
+
+ printf("%s", prefix);
+ for (i = 0; i < format_desc->block.height; ++i) {
+ for (j = 0; j < format_desc->block.width; ++j) {
+ printf("%s%f", sep, unpacked[i][j]);
+ sep = ", ";
+ }
+ sep = ",\n";
+ }
+ printf("%s", suffix);
+}
-/**
- * Test cases.
- *
- * These were manually entered. We could generate these
- *
- * To keep this to a we cover only the corner cases, which should produce
- * good enough coverage since that pixel format transformations are afine for
- * non SRGB formats.
- */
-static const struct util_format_test_case
-test_cases[] =
+
+static void
+print_unpacked_z_32unorm(const struct util_format_description *format_desc,
+ const char *prefix,
+ uint32_t unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH],
+ const char *suffix)
{
+ unsigned i, j;
+ const char *sep = "";
+
+ printf("%s", prefix);
+ for (i = 0; i < format_desc->block.height; ++i) {
+ for (j = 0; j < format_desc->block.width; ++j) {
+ printf("%s0x%08x", sep, unpacked[i][j]);
+ sep = ", ";
+ }
+ }
+ printf("%s", suffix);
+}
+
- /*
- * 32-bit rendertarget formats
- */
-
- {PIPE_FORMAT_B8G8R8A8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), {0.0, 0.0, 0.0, 0.0}},
- {PIPE_FORMAT_B8G8R8A8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x000000ff), {0.0, 0.0, 1.0, 0.0}},
- {PIPE_FORMAT_B8G8R8A8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x0000ff00), {0.0, 1.0, 0.0, 0.0}},
- {PIPE_FORMAT_B8G8R8A8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00ff0000), {1.0, 0.0, 0.0, 0.0}},
- {PIPE_FORMAT_B8G8R8A8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xff000000), {0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_B8G8R8A8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xffffffff), {1.0, 1.0, 1.0, 1.0}},
-
- {PIPE_FORMAT_B8G8R8X8_UNORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0x00000000), {0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_B8G8R8X8_UNORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0x000000ff), {0.0, 0.0, 1.0, 1.0}},
- {PIPE_FORMAT_B8G8R8X8_UNORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0x0000ff00), {0.0, 1.0, 0.0, 1.0}},
- {PIPE_FORMAT_B8G8R8X8_UNORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0x00ff0000), {1.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_B8G8R8X8_UNORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0xff000000), {0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_B8G8R8X8_UNORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0xffffffff), {1.0, 1.0, 1.0, 1.0}},
-
- {PIPE_FORMAT_A8R8G8B8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), {0.0, 0.0, 0.0, 0.0}},
- {PIPE_FORMAT_A8R8G8B8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x000000ff), {0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_A8R8G8B8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x0000ff00), {1.0, 0.0, 0.0, 0.0}},
- {PIPE_FORMAT_A8R8G8B8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00ff0000), {0.0, 1.0, 0.0, 0.0}},
- {PIPE_FORMAT_A8R8G8B8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xff000000), {0.0, 0.0, 1.0, 0.0}},
- {PIPE_FORMAT_A8R8G8B8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xffffffff), {1.0, 1.0, 1.0, 1.0}},
-
- {PIPE_FORMAT_X8R8G8B8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0x00000000), {0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_X8R8G8B8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0x000000ff), {0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_X8R8G8B8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0x0000ff00), {1.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_X8R8G8B8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0x00ff0000), {0.0, 1.0, 0.0, 1.0}},
- {PIPE_FORMAT_X8R8G8B8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0xff000000), {0.0, 0.0, 1.0, 1.0}},
- {PIPE_FORMAT_X8R8G8B8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0xffffffff), {1.0, 1.0, 1.0, 1.0}},
-
- {PIPE_FORMAT_A8B8G8R8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), {0.0, 0.0, 0.0, 0.0}},
- {PIPE_FORMAT_A8B8G8R8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x000000ff), {0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_A8B8G8R8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x0000ff00), {0.0, 0.0, 1.0, 0.0}},
- {PIPE_FORMAT_A8B8G8R8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00ff0000), {0.0, 1.0, 0.0, 0.0}},
- {PIPE_FORMAT_A8B8G8R8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xff000000), {1.0, 0.0, 0.0, 0.0}},
- {PIPE_FORMAT_A8B8G8R8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xffffffff), {1.0, 1.0, 1.0, 1.0}},
-
- {PIPE_FORMAT_X8B8G8R8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0x00000000), {0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_X8B8G8R8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0x000000ff), {0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_X8B8G8R8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0x0000ff00), {0.0, 0.0, 1.0, 1.0}},
- {PIPE_FORMAT_X8B8G8R8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0x00ff0000), {0.0, 1.0, 0.0, 1.0}},
- {PIPE_FORMAT_X8B8G8R8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0xff000000), {1.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_X8B8G8R8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0xffffffff), {1.0, 1.0, 1.0, 1.0}},
-
- {PIPE_FORMAT_R10G10B10A2_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), {0.0, 0.0, 0.0, 0.0}},
- {PIPE_FORMAT_R10G10B10A2_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x000003ff), {1.0, 0.0, 0.0, 0.0}},
- {PIPE_FORMAT_R10G10B10A2_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x000ffc00), {0.0, 1.0, 0.0, 0.0}},
- {PIPE_FORMAT_R10G10B10A2_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x3ff00000), {0.0, 0.0, 1.0, 0.0}},
- {PIPE_FORMAT_R10G10B10A2_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xc0000000), {0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R10G10B10A2_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xffffffff), {1.0, 1.0, 1.0, 1.0}},
-
- /*
- * 16-bit rendertarget formats
- */
-
- {PIPE_FORMAT_B5G5R5A1_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x0000), {0.0, 0.0, 0.0, 0.0}},
- {PIPE_FORMAT_B5G5R5A1_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x001f), {0.0, 0.0, 1.0, 0.0}},
- {PIPE_FORMAT_B5G5R5A1_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x03e0), {0.0, 1.0, 0.0, 0.0}},
- {PIPE_FORMAT_B5G5R5A1_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x7c00), {1.0, 0.0, 0.0, 0.0}},
- {PIPE_FORMAT_B5G5R5A1_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x8000), {0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_B5G5R5A1_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xffff), {1.0, 1.0, 1.0, 1.0}},
-
- {PIPE_FORMAT_B4G4R4A4_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x0000), {0.0, 0.0, 0.0, 0.0}},
- {PIPE_FORMAT_B4G4R4A4_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x000f), {0.0, 0.0, 1.0, 0.0}},
- {PIPE_FORMAT_B4G4R4A4_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x00f0), {0.0, 1.0, 0.0, 0.0}},
- {PIPE_FORMAT_B4G4R4A4_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x0f00), {1.0, 0.0, 0.0, 0.0}},
- {PIPE_FORMAT_B4G4R4A4_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xf000), {0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_B4G4R4A4_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xffff), {1.0, 1.0, 1.0, 1.0}},
-
- {PIPE_FORMAT_B5G6R5_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x0000), {0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_B5G6R5_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x001f), {0.0, 0.0, 1.0, 1.0}},
- {PIPE_FORMAT_B5G6R5_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x07e0), {0.0, 1.0, 0.0, 1.0}},
- {PIPE_FORMAT_B5G6R5_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xf800), {1.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_B5G6R5_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xffff), {1.0, 1.0, 1.0, 1.0}},
-
- /*
- * Luminance/intensity/alpha formats
- */
-
- {PIPE_FORMAT_L8_UNORM, PACKED_1x8(0xff), PACKED_1x8(0x00), {0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_L8_UNORM, PACKED_1x8(0xff), PACKED_1x8(0xff), {1.0, 1.0, 1.0, 1.0}},
-
- {PIPE_FORMAT_A8_UNORM, PACKED_1x8(0xff), PACKED_1x8(0x00), {0.0, 0.0, 0.0, 0.0}},
- {PIPE_FORMAT_A8_UNORM, PACKED_1x8(0xff), PACKED_1x8(0xff), {0.0, 0.0, 0.0, 1.0}},
-
- {PIPE_FORMAT_I8_UNORM, PACKED_1x8(0xff), PACKED_1x8(0x00), {0.0, 0.0, 0.0, 0.0}},
- {PIPE_FORMAT_I8_UNORM, PACKED_1x8(0xff), PACKED_1x8(0xff), {1.0, 1.0, 1.0, 1.0}},
-
- {PIPE_FORMAT_L8A8_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x0000), {0.0, 0.0, 0.0, 0.0}},
- {PIPE_FORMAT_L8A8_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x00ff), {1.0, 1.0, 1.0, 0.0}},
- {PIPE_FORMAT_L8A8_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xff00), {0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_L8A8_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xffff), {1.0, 1.0, 1.0, 1.0}},
-
- {PIPE_FORMAT_L16_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x0000), {0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_L16_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xffff), {1.0, 1.0, 1.0, 1.0}},
-
- /*
- * TODO: SRGB formats
- */
-
- /*
- * Mixed-signed formats
- */
-
- {PIPE_FORMAT_R8SG8SB8UX8U_NORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0x00000000), { 0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R8SG8SB8UX8U_NORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0x0000007f), { 1.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R8SG8SB8UX8U_NORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0x00000081), {-1.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R8SG8SB8UX8U_NORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0x00007f00), { 0.0, 1.0, 0.0, 1.0}},
- {PIPE_FORMAT_R8SG8SB8UX8U_NORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0x00008100), { 0.0, -1.0, 0.0, 1.0}},
- {PIPE_FORMAT_R8SG8SB8UX8U_NORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0x00ff0000), { 0.0, 0.0, 1.0, 1.0}},
- {PIPE_FORMAT_R8SG8SB8UX8U_NORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0xff000000), { 0.0, 0.0, 0.0, 1.0}},
-
- {PIPE_FORMAT_R5SG5SB6U_NORM, PACKED_1x16(0xffff), PACKED_1x16(0x0000), { 0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R5SG5SB6U_NORM, PACKED_1x16(0xffff), PACKED_1x16(0x000f), { 1.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R5SG5SB6U_NORM, PACKED_1x16(0xffff), PACKED_1x16(0x0011), {-1.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R5SG5SB6U_NORM, PACKED_1x16(0xffff), PACKED_1x16(0x01e0), { 0.0, 1.0, 0.0, 1.0}},
- {PIPE_FORMAT_R5SG5SB6U_NORM, PACKED_1x16(0xffff), PACKED_1x16(0x0220), { 0.0, -1.0, 0.0, 1.0}},
- {PIPE_FORMAT_R5SG5SB6U_NORM, PACKED_1x16(0xffff), PACKED_1x16(0xfc00), { 0.0, 0.0, 1.0, 1.0}},
-
- /*
- * TODO: Depth-stencil formats
- */
-
- /*
- * TODO: YUV formats
- */
-
- /*
- * TODO: Compressed formats
- */
-
- /*
- * Standard 8-bit integer formats
- */
-
- {PIPE_FORMAT_R8_UNORM, PACKED_1x8(0xff), PACKED_1x8(0x00), {0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R8_UNORM, PACKED_1x8(0xff), PACKED_1x8(0xff), {1.0, 0.0, 0.0, 1.0}},
-
- {PIPE_FORMAT_R8G8_UNORM, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x00, 0x00), {0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R8G8_UNORM, PACKED_2x8(0xff, 0xff), PACKED_2x8(0xff, 0x00), {1.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R8G8_UNORM, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x00, 0xff), {0.0, 1.0, 0.0, 1.0}},
- {PIPE_FORMAT_R8G8_UNORM, PACKED_2x8(0xff, 0xff), PACKED_2x8(0xff, 0xff), {1.0, 1.0, 0.0, 1.0}},
-
- {PIPE_FORMAT_R8G8B8_UNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x00, 0x00), {0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R8G8B8_UNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0xff, 0x00, 0x00), {1.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R8G8B8_UNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0xff, 0x00), {0.0, 1.0, 0.0, 1.0}},
- {PIPE_FORMAT_R8G8B8_UNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x00, 0xff), {0.0, 0.0, 1.0, 1.0}},
- {PIPE_FORMAT_R8G8B8_UNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0xff, 0xff, 0xff), {1.0, 1.0, 1.0, 1.0}},
-
- {PIPE_FORMAT_R8G8B8A8_UNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0x00), {0.0, 0.0, 0.0, 0.0}},
- {PIPE_FORMAT_R8G8B8A8_UNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0xff, 0x00, 0x00, 0x00), {1.0, 0.0, 0.0, 0.0}},
- {PIPE_FORMAT_R8G8B8A8_UNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0xff, 0x00, 0x00), {0.0, 1.0, 0.0, 0.0}},
- {PIPE_FORMAT_R8G8B8A8_UNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0xff, 0x00), {0.0, 0.0, 1.0, 0.0}},
- {PIPE_FORMAT_R8G8B8A8_UNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0xff), {0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R8G8B8A8_UNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0xff, 0xff, 0xff, 0xff), {1.0, 1.0, 1.0, 1.0}},
-
- {PIPE_FORMAT_R8_USCALED, PACKED_1x8(0xff), PACKED_1x8(0x00), { 0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R8_USCALED, PACKED_1x8(0xff), PACKED_1x8(0xff), {255.0, 0.0, 0.0, 1.0}},
-
- {PIPE_FORMAT_R8G8_USCALED, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x00, 0x00), { 0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R8G8_USCALED, PACKED_2x8(0xff, 0xff), PACKED_2x8(0xff, 0x00), {255.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R8G8_USCALED, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x00, 0xff), { 0.0, 255.0, 0.0, 1.0}},
- {PIPE_FORMAT_R8G8_USCALED, PACKED_2x8(0xff, 0xff), PACKED_2x8(0xff, 0xff), {255.0, 255.0, 0.0, 1.0}},
-
- {PIPE_FORMAT_R8G8B8_USCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x00, 0x00), { 0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R8G8B8_USCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0xff, 0x00, 0x00), {255.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R8G8B8_USCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0xff, 0x00), { 0.0, 255.0, 0.0, 1.0}},
- {PIPE_FORMAT_R8G8B8_USCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x00, 0xff), { 0.0, 0.0, 255.0, 1.0}},
- {PIPE_FORMAT_R8G8B8_USCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0xff, 0xff, 0xff), {255.0, 255.0, 255.0, 1.0}},
-
- {PIPE_FORMAT_R8G8B8A8_USCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0x00), { 0.0, 0.0, 0.0, 0.0}},
- {PIPE_FORMAT_R8G8B8A8_USCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0xff, 0x00, 0x00, 0x00), {255.0, 0.0, 0.0, 0.0}},
- {PIPE_FORMAT_R8G8B8A8_USCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0xff, 0x00, 0x00), { 0.0, 255.0, 0.0, 0.0}},
- {PIPE_FORMAT_R8G8B8A8_USCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0xff, 0x00), { 0.0, 0.0, 255.0, 0.0}},
- {PIPE_FORMAT_R8G8B8A8_USCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0xff), { 0.0, 0.0, 0.0, 255.0}},
- {PIPE_FORMAT_R8G8B8A8_USCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0xff, 0xff, 0xff, 0xff), {255.0, 255.0, 255.0, 255.0}},
-
- {PIPE_FORMAT_R8_SNORM, PACKED_1x8(0xff), PACKED_1x8(0x00), { 0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R8_SNORM, PACKED_1x8(0xff), PACKED_1x8(0x7f), { 1.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R8_SNORM, PACKED_1x8(0xff), PACKED_1x8(0x81), {-1.0, 0.0, 0.0, 1.0}},
-
- {PIPE_FORMAT_R8G8_SNORM, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x00, 0x00), { 0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R8G8_SNORM, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x7f, 0x00), { 1.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R8G8_SNORM, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x81, 0x00), {-1.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R8G8_SNORM, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x00, 0x7f), { 0.0, 1.0, 0.0, 1.0}},
- {PIPE_FORMAT_R8G8_SNORM, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x00, 0x81), { 0.0, -1.0, 0.0, 1.0}},
-
- {PIPE_FORMAT_R8G8B8_SNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x00, 0x00), { 0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R8G8B8_SNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x7f, 0x00, 0x00), { 1.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R8G8B8_SNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x81, 0x00, 0x00), {-1.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R8G8B8_SNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x7f, 0x00), { 0.0, 1.0, 0.0, 1.0}},
- {PIPE_FORMAT_R8G8B8_SNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x81, 0x00), { 0.0, -1.0, 0.0, 1.0}},
- {PIPE_FORMAT_R8G8B8_SNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x00, 0x7f), { 0.0, 0.0, 1.0, 1.0}},
- {PIPE_FORMAT_R8G8B8_SNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x00, 0x81), { 0.0, 0.0, -1.0, 1.0}},
-
- {PIPE_FORMAT_R8G8B8A8_SNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0x00), { 0.0, 0.0, 0.0, 0.0}},
- {PIPE_FORMAT_R8G8B8A8_SNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x7f, 0x00, 0x00, 0x00), { 1.0, 0.0, 0.0, 0.0}},
- {PIPE_FORMAT_R8G8B8A8_SNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x81, 0x00, 0x00, 0x00), {-1.0, 0.0, 0.0, 0.0}},
- {PIPE_FORMAT_R8G8B8A8_SNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x7f, 0x00, 0x00), { 0.0, 1.0, 0.0, 0.0}},
- {PIPE_FORMAT_R8G8B8A8_SNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x81, 0x00, 0x00), { 0.0, -1.0, 0.0, 0.0}},
- {PIPE_FORMAT_R8G8B8A8_SNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x7f, 0x00), { 0.0, 0.0, 1.0, 0.0}},
- {PIPE_FORMAT_R8G8B8A8_SNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x81, 0x00), { 0.0, 0.0, -1.0, 0.0}},
- {PIPE_FORMAT_R8G8B8A8_SNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0x7f), { 0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R8G8B8A8_SNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0x81), { 0.0, 0.0, 0.0, -1.0}},
-
- {PIPE_FORMAT_R8_SSCALED, PACKED_1x8(0xff), PACKED_1x8(0x00), { 0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R8_SSCALED, PACKED_1x8(0xff), PACKED_1x8(0x7f), { 127.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R8_SSCALED, PACKED_1x8(0xff), PACKED_1x8(0x80), {-128.0, 0.0, 0.0, 1.0}},
-
- {PIPE_FORMAT_R8G8_SSCALED, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x00, 0x00), { 0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R8G8_SSCALED, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x7f, 0x00), { 127.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R8G8_SSCALED, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x80, 0x00), {-128.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R8G8_SSCALED, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x00, 0x7f), { 0.0, 127.0, 0.0, 1.0}},
- {PIPE_FORMAT_R8G8_SSCALED, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x00, 0x80), { 0.0, -128.0, 0.0, 1.0}},
-
- {PIPE_FORMAT_R8G8B8_SSCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x00, 0x00), { 0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R8G8B8_SSCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x7f, 0x00, 0x00), { 127.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R8G8B8_SSCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x80, 0x00, 0x00), {-128.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R8G8B8_SSCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x7f, 0x00), { 0.0, 127.0, 0.0, 1.0}},
- {PIPE_FORMAT_R8G8B8_SSCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x80, 0x00), { 0.0, -128.0, 0.0, 1.0}},
- {PIPE_FORMAT_R8G8B8_SSCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x00, 0x7f), { 0.0, 0.0, 127.0, 1.0}},
- {PIPE_FORMAT_R8G8B8_SSCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x00, 0x80), { 0.0, 0.0, -128.0, 1.0}},
-
- {PIPE_FORMAT_R8G8B8A8_SSCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0x00), { 0.0, 0.0, 0.0, 0.0}},
- {PIPE_FORMAT_R8G8B8A8_SSCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x7f, 0x00, 0x00, 0x00), { 127.0, 0.0, 0.0, 0.0}},
- {PIPE_FORMAT_R8G8B8A8_SSCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x80, 0x00, 0x00, 0x00), {-128.0, 0.0, 0.0, 0.0}},
- {PIPE_FORMAT_R8G8B8A8_SSCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x7f, 0x00, 0x00), { 0.0, 127.0, 0.0, 0.0}},
- {PIPE_FORMAT_R8G8B8A8_SSCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x80, 0x00, 0x00), { 0.0, -128.0, 0.0, 0.0}},
- {PIPE_FORMAT_R8G8B8A8_SSCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x7f, 0x00), { 0.0, 0.0, 127.0, 0.0}},
- {PIPE_FORMAT_R8G8B8A8_SSCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x80, 0x00), { 0.0, 0.0, -128.0, 0.0}},
- {PIPE_FORMAT_R8G8B8A8_SSCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0x7f), { 0.0, 0.0, 0.0, 127.0}},
- {PIPE_FORMAT_R8G8B8A8_SSCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0x80), { 0.0, 0.0, 0.0, -128.0}},
-
- /*
- * Standard 16-bit integer formats
- */
-
- {PIPE_FORMAT_R16_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x0000), {0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R16_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xffff), {1.0, 0.0, 0.0, 1.0}},
-
- {PIPE_FORMAT_R16G16_UNORM, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x0000, 0x0000), {0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R16G16_UNORM, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0xffff, 0x0000), {1.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R16G16_UNORM, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x0000, 0xffff), {0.0, 1.0, 0.0, 1.0}},
- {PIPE_FORMAT_R16G16_UNORM, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0xffff, 0xffff), {1.0, 1.0, 0.0, 1.0}},
-
- {PIPE_FORMAT_R16G16B16_UNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x0000, 0x0000), {0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R16G16B16_UNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0xffff, 0x0000, 0x0000), {1.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R16G16B16_UNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0xffff, 0x0000), {0.0, 1.0, 0.0, 1.0}},
- {PIPE_FORMAT_R16G16B16_UNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x0000, 0xffff), {0.0, 0.0, 1.0, 1.0}},
- {PIPE_FORMAT_R16G16B16_UNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0xffff, 0xffff, 0xffff), {1.0, 1.0, 1.0, 1.0}},
-
- {PIPE_FORMAT_R16G16B16A16_UNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x0000, 0x0000), {0.0, 0.0, 0.0, 0.0}},
- {PIPE_FORMAT_R16G16B16A16_UNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0xffff, 0x0000, 0x0000, 0x0000), {1.0, 0.0, 0.0, 0.0}},
- {PIPE_FORMAT_R16G16B16A16_UNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0xffff, 0x0000, 0x0000), {0.0, 1.0, 0.0, 0.0}},
- {PIPE_FORMAT_R16G16B16A16_UNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0xffff, 0x0000), {0.0, 0.0, 1.0, 0.0}},
- {PIPE_FORMAT_R16G16B16A16_UNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x0000, 0xffff), {0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R16G16B16A16_UNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), {1.0, 1.0, 1.0, 1.0}},
-
- {PIPE_FORMAT_R16_USCALED, PACKED_1x16(0xffff), PACKED_1x16(0x0000), { 0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R16_USCALED, PACKED_1x16(0xffff), PACKED_1x16(0xffff), {65535.0, 0.0, 0.0, 1.0}},
-
- {PIPE_FORMAT_R16G16_USCALED, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x0000, 0x0000), { 0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R16G16_USCALED, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0xffff, 0x0000), {65535.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R16G16_USCALED, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x0000, 0xffff), { 0.0, 65535.0, 0.0, 1.0}},
- {PIPE_FORMAT_R16G16_USCALED, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0xffff, 0xffff), {65535.0, 65535.0, 0.0, 1.0}},
-
- {PIPE_FORMAT_R16G16B16_USCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x0000, 0x0000), { 0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R16G16B16_USCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0xffff, 0x0000, 0x0000), {65535.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R16G16B16_USCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0xffff, 0x0000), { 0.0, 65535.0, 0.0, 1.0}},
- {PIPE_FORMAT_R16G16B16_USCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x0000, 0xffff), { 0.0, 0.0, 65535.0, 1.0}},
- {PIPE_FORMAT_R16G16B16_USCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0xffff, 0xffff, 0xffff), {65535.0, 65535.0, 65535.0, 1.0}},
-
- {PIPE_FORMAT_R16G16B16A16_USCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x0000, 0x0000), { 0.0, 0.0, 0.0, 0.0}},
- {PIPE_FORMAT_R16G16B16A16_USCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0xffff, 0x0000, 0x0000, 0x0000), {65535.0, 0.0, 0.0, 0.0}},
- {PIPE_FORMAT_R16G16B16A16_USCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0xffff, 0x0000, 0x0000), { 0.0, 65535.0, 0.0, 0.0}},
- {PIPE_FORMAT_R16G16B16A16_USCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0xffff, 0x0000), { 0.0, 0.0, 65535.0, 0.0}},
- {PIPE_FORMAT_R16G16B16A16_USCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x0000, 0xffff), { 0.0, 0.0, 0.0, 65535.0}},
- {PIPE_FORMAT_R16G16B16A16_USCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), {65535.0, 65535.0, 65535.0, 65535.0}},
-
- {PIPE_FORMAT_R16_SNORM, PACKED_1x16(0xffff), PACKED_1x16(0x0000), { 0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R16_SNORM, PACKED_1x16(0xffff), PACKED_1x16(0x7fff), { 1.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R16_SNORM, PACKED_1x16(0xffff), PACKED_1x16(0x8001), { -1.0, 0.0, 0.0, 1.0}},
-
- {PIPE_FORMAT_R16G16_SNORM, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x0000, 0x0000), { 0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R16G16_SNORM, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x7fff, 0x0000), { 1.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R16G16_SNORM, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x8001, 0x0000), { -1.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R16G16_SNORM, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x0000, 0x7fff), { 0.0, 1.0, 0.0, 1.0}},
- {PIPE_FORMAT_R16G16_SNORM, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x0000, 0x8001), { 0.0, -1.0, 0.0, 1.0}},
-
- {PIPE_FORMAT_R16G16B16_SNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x0000, 0x0000), { 0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R16G16B16_SNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x7fff, 0x0000, 0x0000), { 1.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R16G16B16_SNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x8001, 0x0000, 0x0000), { -1.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R16G16B16_SNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x7fff, 0x0000), { 0.0, 1.0, 0.0, 1.0}},
- {PIPE_FORMAT_R16G16B16_SNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x8001, 0x0000), { 0.0, -1.0, 0.0, 1.0}},
- {PIPE_FORMAT_R16G16B16_SNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x0000, 0x7fff), { 0.0, 0.0, 1.0, 1.0}},
- {PIPE_FORMAT_R16G16B16_SNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x0000, 0x8001), { 0.0, 0.0, -1.0, 1.0}},
-
- {PIPE_FORMAT_R16G16B16A16_SNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x0000, 0x0000), { 0.0, 0.0, 0.0, 0.0}},
- {PIPE_FORMAT_R16G16B16A16_SNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x7fff, 0x0000, 0x0000, 0x0000), { 1.0, 0.0, 0.0, 0.0}},
- {PIPE_FORMAT_R16G16B16A16_SNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x8001, 0x0000, 0x0000, 0x0000), { -1.0, 0.0, 0.0, 0.0}},
- {PIPE_FORMAT_R16G16B16A16_SNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x7fff, 0x0000, 0x0000), { 0.0, 1.0, 0.0, 0.0}},
- {PIPE_FORMAT_R16G16B16A16_SNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x8001, 0x0000, 0x0000), { 0.0, -1.0, 0.0, 0.0}},
- {PIPE_FORMAT_R16G16B16A16_SNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x7fff, 0x0000), { 0.0, 0.0, 1.0, 0.0}},
- {PIPE_FORMAT_R16G16B16A16_SNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x8001, 0x0000), { 0.0, 0.0, -1.0, 0.0}},
- {PIPE_FORMAT_R16G16B16A16_SNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x0000, 0x7fff), { 0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R16G16B16A16_SNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x0000, 0x8001), { 0.0, 0.0, 0.0, -1.0}},
-
- {PIPE_FORMAT_R16_SSCALED, PACKED_1x16(0xffff), PACKED_1x16(0x0000), { 0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R16_SSCALED, PACKED_1x16(0xffff), PACKED_1x16(0x7fff), { 32767.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R16_SSCALED, PACKED_1x16(0xffff), PACKED_1x16(0x8000), {-32768.0, 0.0, 0.0, 1.0}},
-
- {PIPE_FORMAT_R16G16_SSCALED, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x0000, 0x0000), { 0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R16G16_SSCALED, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x7fff, 0x0000), { 32767.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R16G16_SSCALED, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x8000, 0x0000), {-32768.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R16G16_SSCALED, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x0000, 0x7fff), { 0.0, 32767.0, 0.0, 1.0}},
- {PIPE_FORMAT_R16G16_SSCALED, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x0000, 0x8000), { 0.0, -32768.0, 0.0, 1.0}},
-
- {PIPE_FORMAT_R16G16B16_SSCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x0000, 0x0000), { 0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R16G16B16_SSCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x7fff, 0x0000, 0x0000), { 32767.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R16G16B16_SSCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x8000, 0x0000, 0x0000), {-32768.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R16G16B16_SSCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x7fff, 0x0000), { 0.0, 32767.0, 0.0, 1.0}},
- {PIPE_FORMAT_R16G16B16_SSCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x8000, 0x0000), { 0.0, -32768.0, 0.0, 1.0}},
- {PIPE_FORMAT_R16G16B16_SSCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x0000, 0x7fff), { 0.0, 0.0, 32767.0, 1.0}},
- {PIPE_FORMAT_R16G16B16_SSCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x0000, 0x8000), { 0.0, 0.0, -32768.0, 1.0}},
-
- {PIPE_FORMAT_R16G16B16A16_SSCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x0000, 0x0000), { 0.0, 0.0, 0.0, 0.0}},
- {PIPE_FORMAT_R16G16B16A16_SSCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x7fff, 0x0000, 0x0000, 0x0000), { 32767.0, 0.0, 0.0, 0.0}},
- {PIPE_FORMAT_R16G16B16A16_SSCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x8000, 0x0000, 0x0000, 0x0000), {-32768.0, 0.0, 0.0, 0.0}},
- {PIPE_FORMAT_R16G16B16A16_SSCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x7fff, 0x0000, 0x0000), { 0.0, 32767.0, 0.0, 0.0}},
- {PIPE_FORMAT_R16G16B16A16_SSCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x8000, 0x0000, 0x0000), { 0.0, -32768.0, 0.0, 0.0}},
- {PIPE_FORMAT_R16G16B16A16_SSCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x7fff, 0x0000), { 0.0, 0.0, 32767.0, 0.0}},
- {PIPE_FORMAT_R16G16B16A16_SSCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x8000, 0x0000), { 0.0, 0.0, -32768.0, 0.0}},
- {PIPE_FORMAT_R16G16B16A16_SSCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x0000, 0x7fff), { 0.0, 0.0, 0.0, 32767.0}},
- {PIPE_FORMAT_R16G16B16A16_SSCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x0000, 0x8000), { 0.0, 0.0, 0.0, -32768.0}},
-
- /*
- * Standard 32-bit integer formats
- *
- * NOTE: We can't accurately represent integers larger than +/-0x1000000
- * with single precision floats, so that's as far as we test.
- */
-
- {PIPE_FORMAT_R32_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), {0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R32_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xffffffff), {1.0, 0.0, 0.0, 1.0}},
-
- {PIPE_FORMAT_R32G32_UNORM, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0x00000000), {0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R32G32_UNORM, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0xffffffff, 0x00000000), {1.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R32G32_UNORM, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0xffffffff), {0.0, 1.0, 0.0, 1.0}},
- {PIPE_FORMAT_R32G32_UNORM, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0xffffffff, 0xffffffff), {1.0, 1.0, 0.0, 1.0}},
-
- {PIPE_FORMAT_R32G32B32_UNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0x00000000), {0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R32G32B32_UNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0xffffffff, 0x00000000, 0x00000000), {1.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R32G32B32_UNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0xffffffff, 0x00000000), {0.0, 1.0, 0.0, 1.0}},
- {PIPE_FORMAT_R32G32B32_UNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0xffffffff), {0.0, 0.0, 1.0, 1.0}},
- {PIPE_FORMAT_R32G32B32_UNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), {1.0, 1.0, 1.0, 1.0}},
-
- {PIPE_FORMAT_R32G32B32A32_UNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0x00000000), {0.0, 0.0, 0.0, 0.0}},
- {PIPE_FORMAT_R32G32B32A32_UNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0xffffffff, 0x00000000, 0x00000000, 0x00000000), {1.0, 0.0, 0.0, 0.0}},
- {PIPE_FORMAT_R32G32B32A32_UNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0xffffffff, 0x00000000, 0x00000000), {0.0, 1.0, 0.0, 0.0}},
- {PIPE_FORMAT_R32G32B32A32_UNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0xffffffff, 0x00000000), {0.0, 0.0, 1.0, 0.0}},
- {PIPE_FORMAT_R32G32B32A32_UNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0xffffffff), {0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R32G32B32A32_UNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), {1.0, 1.0, 1.0, 1.0}},
-
- {PIPE_FORMAT_R32_USCALED, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), { 0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R32_USCALED, PACKED_1x32(0xffffffff), PACKED_1x32(0x01000000), {16777216.0, 0.0, 0.0, 1.0}},
-
- {PIPE_FORMAT_R32G32_USCALED, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0x00000000), { 0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R32G32_USCALED, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x01000000, 0x00000000), {16777216.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R32G32_USCALED, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0x01000000), { 0.0, 16777216.0, 0.0, 1.0}},
- {PIPE_FORMAT_R32G32_USCALED, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x01000000, 0x01000000), {16777216.0, 16777216.0, 0.0, 1.0}},
-
- {PIPE_FORMAT_R32G32B32_USCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0x00000000), { 0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R32G32B32_USCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x01000000, 0x00000000, 0x00000000), {16777216.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R32G32B32_USCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x01000000, 0x00000000), { 0.0, 16777216.0, 0.0, 1.0}},
- {PIPE_FORMAT_R32G32B32_USCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0x01000000), { 0.0, 0.0, 16777216.0, 1.0}},
- {PIPE_FORMAT_R32G32B32_USCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x01000000, 0x01000000, 0x01000000), {16777216.0, 16777216.0, 16777216.0, 1.0}},
-
- {PIPE_FORMAT_R32G32B32A32_USCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0x00000000), { 0.0, 0.0, 0.0, 0.0}},
- {PIPE_FORMAT_R32G32B32A32_USCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x01000000, 0x00000000, 0x00000000, 0x00000000), {16777216.0, 0.0, 0.0, 0.0}},
- {PIPE_FORMAT_R32G32B32A32_USCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x01000000, 0x00000000, 0x00000000), { 0.0, 16777216.0, 0.0, 0.0}},
- {PIPE_FORMAT_R32G32B32A32_USCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x01000000, 0x00000000), { 0.0, 0.0, 16777216.0, 0.0}},
- {PIPE_FORMAT_R32G32B32A32_USCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0x01000000), { 0.0, 0.0, 0.0, 16777216.0}},
- {PIPE_FORMAT_R32G32B32A32_USCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x01000000, 0x01000000, 0x01000000, 0x01000000), {16777216.0, 16777216.0, 16777216.0, 16777216.0}},
-
- {PIPE_FORMAT_R32_SNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), { 0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R32_SNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x7fffffff), { 1.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R32_SNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x80000001), { -1.0, 0.0, 0.0, 1.0}},
-
- {PIPE_FORMAT_R32G32_SNORM, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0x00000000), { 0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R32G32_SNORM, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x7fffffff, 0x00000000), { 1.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R32G32_SNORM, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x80000001, 0x00000000), { -1.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R32G32_SNORM, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0x7fffffff), { 0.0, 1.0, 0.0, 1.0}},
- {PIPE_FORMAT_R32G32_SNORM, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0x80000001), { 0.0, -1.0, 0.0, 1.0}},
-
- {PIPE_FORMAT_R32G32B32_SNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0x00000000), { 0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R32G32B32_SNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x7fffffff, 0x00000000, 0x00000000), { 1.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R32G32B32_SNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x80000001, 0x00000000, 0x00000000), { -1.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R32G32B32_SNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x7fffffff, 0x00000000), { 0.0, 1.0, 0.0, 1.0}},
- {PIPE_FORMAT_R32G32B32_SNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x80000001, 0x00000000), { 0.0, -1.0, 0.0, 1.0}},
- {PIPE_FORMAT_R32G32B32_SNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0x7fffffff), { 0.0, 0.0, 1.0, 1.0}},
- {PIPE_FORMAT_R32G32B32_SNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0x80000001), { 0.0, 0.0, -1.0, 1.0}},
-
- {PIPE_FORMAT_R32G32B32A32_SNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0x00000000), { 0.0, 0.0, 0.0, 0.0}},
- {PIPE_FORMAT_R32G32B32A32_SNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x7fffffff, 0x00000000, 0x00000000, 0x00000000), { 1.0, 0.0, 0.0, 0.0}},
- {PIPE_FORMAT_R32G32B32A32_SNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x80000001, 0x00000000, 0x00000000, 0x00000000), { -1.0, 0.0, 0.0, 0.0}},
- {PIPE_FORMAT_R32G32B32A32_SNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x7fffffff, 0x00000000, 0x00000000), { 0.0, 1.0, 0.0, 0.0}},
- {PIPE_FORMAT_R32G32B32A32_SNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x80000001, 0x00000000, 0x00000000), { 0.0, -1.0, 0.0, 0.0}},
- {PIPE_FORMAT_R32G32B32A32_SNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x7fffffff, 0x00000000), { 0.0, 0.0, 1.0, 0.0}},
- {PIPE_FORMAT_R32G32B32A32_SNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x80000001, 0x00000000), { 0.0, 0.0, -1.0, 0.0}},
- {PIPE_FORMAT_R32G32B32A32_SNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0x7fffffff), { 0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R32G32B32A32_SNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0x80000001), { 0.0, 0.0, 0.0, -1.0}},
-
- {PIPE_FORMAT_R32_SSCALED, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), { 0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R32_SSCALED, PACKED_1x32(0xffffffff), PACKED_1x32(0x01000000), { 16777216.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R32_SSCALED, PACKED_1x32(0xffffffff), PACKED_1x32(0xff000000), {-16777216.0, 0.0, 0.0, 1.0}},
-
- {PIPE_FORMAT_R32G32_SSCALED, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0x00000000), { 0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R32G32_SSCALED, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x01000000, 0x00000000), { 16777216.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R32G32_SSCALED, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0xff000000, 0x00000000), {-16777216.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R32G32_SSCALED, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0x01000000), { 0.0, 16777216.0, 0.0, 1.0}},
- {PIPE_FORMAT_R32G32_SSCALED, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0xff000000), { 0.0, -16777216.0, 0.0, 1.0}},
-
- {PIPE_FORMAT_R32G32B32_SSCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0x00000000), { 0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R32G32B32_SSCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x01000000, 0x00000000, 0x00000000), { 16777216.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R32G32B32_SSCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0xff000000, 0x00000000, 0x00000000), {-16777216.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R32G32B32_SSCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x01000000, 0x00000000), { 0.0, 16777216.0, 0.0, 1.0}},
- {PIPE_FORMAT_R32G32B32_SSCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0xff000000, 0x00000000), { 0.0, -16777216.0, 0.0, 1.0}},
- {PIPE_FORMAT_R32G32B32_SSCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0x01000000), { 0.0, 0.0, 16777216.0, 1.0}},
- {PIPE_FORMAT_R32G32B32_SSCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0xff000000), { 0.0, 0.0, -16777216.0, 1.0}},
-
- {PIPE_FORMAT_R32G32B32A32_SSCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0x00000000), { 0.0, 0.0, 0.0, 0.0}},
- {PIPE_FORMAT_R32G32B32A32_SSCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x01000000, 0x00000000, 0x00000000, 0x00000000), { 16777216.0, 0.0, 0.0, 0.0}},
- {PIPE_FORMAT_R32G32B32A32_SSCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0xff000000, 0x00000000, 0x00000000, 0x00000000), {-16777216.0, 0.0, 0.0, 0.0}},
- {PIPE_FORMAT_R32G32B32A32_SSCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x01000000, 0x00000000, 0x00000000), { 0.0, 16777216.0, 0.0, 0.0}},
- {PIPE_FORMAT_R32G32B32A32_SSCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0xff000000, 0x00000000, 0x00000000), { 0.0, -16777216.0, 0.0, 0.0}},
- {PIPE_FORMAT_R32G32B32A32_SSCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x01000000, 0x00000000), { 0.0, 0.0, 16777216.0, 0.0}},
- {PIPE_FORMAT_R32G32B32A32_SSCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0xff000000, 0x00000000), { 0.0, 0.0, -16777216.0, 0.0}},
- {PIPE_FORMAT_R32G32B32A32_SSCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0x01000000), { 0.0, 0.0, 0.0, 16777216.0}},
- {PIPE_FORMAT_R32G32B32A32_SSCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0xff000000), { 0.0, 0.0, 0.0, -16777216.0}},
-
- /*
- * Standard 32-bit float formats
- */
-
- {PIPE_FORMAT_R32_FLOAT, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), { 0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R32_FLOAT, PACKED_1x32(0xffffffff), PACKED_1x32(0x3f800000), { 1.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R32_FLOAT, PACKED_1x32(0xffffffff), PACKED_1x32(0xbf800000), { -1.0, 0.0, 0.0, 1.0}},
-
- {PIPE_FORMAT_R32G32_FLOAT, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0x00000000), { 0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R32G32_FLOAT, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x3f800000, 0x00000000), { 1.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R32G32_FLOAT, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0xbf800000, 0x00000000), {-1.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R32G32_FLOAT, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0x3f800000), { 0.0, 1.0, 0.0, 1.0}},
- {PIPE_FORMAT_R32G32_FLOAT, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0xbf800000), { 0.0, -1.0, 0.0, 1.0}},
- {PIPE_FORMAT_R32G32_FLOAT, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x3f800000, 0x3f800000), { 1.0, 1.0, 0.0, 1.0}},
-
- {PIPE_FORMAT_R32G32B32_FLOAT, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0x00000000), { 0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R32G32B32_FLOAT, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x3f800000, 0x00000000, 0x00000000), { 1.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R32G32B32_FLOAT, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0xbf800000, 0x00000000, 0x00000000), {-1.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R32G32B32_FLOAT, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x3f800000, 0x00000000), { 0.0, 1.0, 0.0, 1.0}},
- {PIPE_FORMAT_R32G32B32_FLOAT, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0xbf800000, 0x00000000), { 0.0, -1.0, 0.0, 1.0}},
- {PIPE_FORMAT_R32G32B32_FLOAT, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0x3f800000), { 0.0, 0.0, 1.0, 1.0}},
- {PIPE_FORMAT_R32G32B32_FLOAT, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0xbf800000), { 0.0, 0.0, -1.0, 1.0}},
- {PIPE_FORMAT_R32G32B32_FLOAT, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x3f800000, 0x3f800000, 0x3f800000), { 1.0, 1.0, 1.0, 1.0}},
-
- {PIPE_FORMAT_R32G32B32A32_FLOAT, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0x00000000), { 0.0, 0.0, 0.0, 0.0}},
- {PIPE_FORMAT_R32G32B32A32_FLOAT, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x3f800000, 0x00000000, 0x00000000, 0x00000000), { 1.0, 0.0, 0.0, 0.0}},
- {PIPE_FORMAT_R32G32B32A32_FLOAT, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0xbf800000, 0x00000000, 0x00000000, 0x00000000), {-1.0, 0.0, 0.0, 0.0}},
- {PIPE_FORMAT_R32G32B32A32_FLOAT, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x3f800000, 0x00000000, 0x00000000), { 0.0, 1.0, 0.0, 0.0}},
- {PIPE_FORMAT_R32G32B32A32_FLOAT, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0xbf800000, 0x00000000, 0x00000000), { 0.0, -1.0, 0.0, 0.0}},
- {PIPE_FORMAT_R32G32B32A32_FLOAT, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x3f800000, 0x00000000), { 0.0, 0.0, 1.0, 0.0}},
- {PIPE_FORMAT_R32G32B32A32_FLOAT, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0xbf800000, 0x00000000), { 0.0, 0.0, -1.0, 0.0}},
- {PIPE_FORMAT_R32G32B32A32_FLOAT, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0x3f800000), { 0.0, 0.0, 0.0, 1.0}},
- {PIPE_FORMAT_R32G32B32A32_FLOAT, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0xbf800000), { 0.0, 0.0, 0.0, -1.0}},
- {PIPE_FORMAT_R32G32B32A32_FLOAT, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000), { 1.0, 1.0, 1.0, 1.0}},
-};
+static void
+print_unpacked_s_8uscaled(const struct util_format_description *format_desc,
+ const char *prefix,
+ uint8_t unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH],
+ const char *suffix)
+{
+ unsigned i, j;
+ const char *sep = "";
+
+ printf("%s", prefix);
+ for (i = 0; i < format_desc->block.height; ++i) {
+ for (j = 0; j < format_desc->block.width; ++j) {
+ printf("%s0x%02x", sep, unpacked[i][j]);
+ sep = ", ";
+ }
+ }
+ printf("%s", suffix);
+}
static boolean
-test_format_unpack_4f(const struct util_format_test_case *test)
+test_format_fetch_rgba_float(const struct util_format_description *format_desc,
+ const struct util_format_test_case *test)
{
- float unpacked[4];
- unsigned i;
+ float unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4] = { { { 0 } } };
+ unsigned i, j, k;
boolean success;
- util_format_unpack_4f(test->format, unpacked, test->packed);
+ success = TRUE;
+ for (i = 0; i < format_desc->block.height; ++i) {
+ for (j = 0; j < format_desc->block.width; ++j) {
+ format_desc->fetch_rgba_float(unpacked[i][j], test->packed, j, i);
+ for (k = 0; k < 4; ++k) {
+ if (!compare_float(test->unpacked[i][j][k], unpacked[i][j][k])) {
+ success = FALSE;
+ }
+ }
+ }
+ }
+
+ if (!success) {
+ print_unpacked_rgba_float(format_desc, "FAILED: ", unpacked, " obtained\n");
+ print_unpacked_rgba_doubl(format_desc, " ", test->unpacked, " expected\n");
+ }
+
+ return success;
+}
+
+
+static boolean
+test_format_unpack_rgba_float(const struct util_format_description *format_desc,
+ const struct util_format_test_case *test)
+{
+ float unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4] = { { { 0 } } };
+ unsigned i, j, k;
+ boolean success;
+
+ format_desc->unpack_rgba_float(&unpacked[0][0][0], sizeof unpacked[0],
+ test->packed, 0,
+ format_desc->block.width, format_desc->block.height);
success = TRUE;
- for (i = 0; i < 4; ++i)
- if (test->unpacked[i] != unpacked[i])
- success = FALSE;
+ for (i = 0; i < format_desc->block.height; ++i) {
+ for (j = 0; j < format_desc->block.width; ++j) {
+ for (k = 0; k < 4; ++k) {
+ if (!compare_float(test->unpacked[i][j][k], unpacked[i][j][k])) {
+ success = FALSE;
+ }
+ }
+ }
+ }
if (!success) {
- printf("FAILED: (%f %f %f %f) obtained\n", unpacked[0], unpacked[1], unpacked[2], unpacked[3]);
- printf(" (%f %f %f %f) expected\n", test->unpacked[0], test->unpacked[1], test->unpacked[2], test->unpacked[3]);
+ print_unpacked_rgba_float(format_desc, "FAILED: ", unpacked, " obtained\n");
+ print_unpacked_rgba_doubl(format_desc, " ", test->unpacked, " expected\n");
}
return success;
@@ -594,69 +255,148 @@ test_format_unpack_4f(const struct util_format_test_case *test)
static boolean
-test_format_pack_4f(const struct util_format_test_case *test)
+test_format_pack_rgba_float(const struct util_format_description *format_desc,
+ const struct util_format_test_case *test)
{
- uint8_t packed[MAX_PACKED_BYTES];
- unsigned i;
+ float unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4];
+ uint8_t packed[UTIL_FORMAT_MAX_PACKED_BYTES];
+ unsigned i, j, k;
boolean success;
+ if (test->format == PIPE_FORMAT_DXT1_RGBA) {
+ /*
+ * Skip S3TC as packed representation is not canonical.
+ *
+ * TODO: Do a round trip conversion.
+ */
+ return TRUE;
+ }
+
memset(packed, 0, sizeof packed);
+ for (i = 0; i < format_desc->block.height; ++i) {
+ for (j = 0; j < format_desc->block.width; ++j) {
+ for (k = 0; k < 4; ++k) {
+ unpacked[i][j][k] = (float) test->unpacked[i][j][k];
+ }
+ }
+ }
- util_format_pack_4f(test->format, packed, test->unpacked[0], test->unpacked[1], test->unpacked[2], test->unpacked[3]);
+ format_desc->pack_rgba_float(packed, 0,
+ &unpacked[0][0][0], sizeof unpacked[0],
+ format_desc->block.width, format_desc->block.height);
success = TRUE;
- for (i = 0; i < MAX_PACKED_BYTES; ++i)
+ for (i = 0; i < format_desc->block.bits/8; ++i)
if ((test->packed[i] & test->mask[i]) != (packed[i] & test->mask[i]))
success = FALSE;
if (!success) {
- /* TODO: print more than 4 bytes */
- printf("FAILED: (%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x) obtained\n",
- packed[0], packed[1], packed[2], packed[3],
- packed[4], packed[5], packed[6], packed[7],
- packed[8], packed[9], packed[10], packed[11],
- packed[12], packed[13], packed[14], packed[15]);
- printf(" (%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x) expected\n",
- test->packed[0], test->packed[1], test->packed[2], test->packed[3],
- test->packed[4], test->packed[5], test->packed[6], test->packed[7],
- test->packed[8], test->packed[9], test->packed[10], test->packed[11],
- test->packed[12], test->packed[13], test->packed[14], test->packed[15]);
+ print_packed(format_desc, "FAILED: ", packed, " obtained\n");
+ print_packed(format_desc, " ", test->packed, " expected\n");
}
return success;
}
-static void
-convert_4f_to_4ub(uint8_t *dst, const double *src)
+static boolean
+convert_float_to_8unorm(uint8_t *dst, const double *src)
{
unsigned i;
+ boolean accurate = TRUE;
+
+ for (i = 0; i < UTIL_FORMAT_MAX_UNPACKED_HEIGHT*UTIL_FORMAT_MAX_UNPACKED_WIDTH*4; ++i) {
+ if (src[i] < 0.0) {
+ accurate = FALSE;
+ dst[i] = 0;
+ }
+ else if (src[i] > 1.0) {
+ accurate = FALSE;
+ dst[i] = 255;
+ }
+ else {
+ dst[i] = src[i] * 255.0;
+ }
+ }
+
+ return accurate;
+}
+
- for (i = 0; i < 4; ++i)
- dst[i] = CLAMP(src[i], 0.0, 1.0) * 255.0;
+static boolean
+test_format_unpack_rgba_8unorm(const struct util_format_description *format_desc,
+ const struct util_format_test_case *test)
+{
+ uint8_t unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4] = { { { 0 } } };
+ uint8_t expected[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4] = { { { 0 } } };
+ unsigned i, j, k;
+ boolean success;
+
+ format_desc->unpack_rgba_8unorm(&unpacked[0][0][0], sizeof unpacked[0],
+ test->packed, 0,
+ format_desc->block.width, format_desc->block.height);
+
+ convert_float_to_8unorm(&expected[0][0][0], &test->unpacked[0][0][0]);
+
+ success = TRUE;
+ for (i = 0; i < format_desc->block.height; ++i) {
+ for (j = 0; j < format_desc->block.width; ++j) {
+ for (k = 0; k < 4; ++k) {
+ if (expected[i][j][k] != unpacked[i][j][k]) {
+ success = FALSE;
+ }
+ }
+ }
+ }
+
+ if (!success) {
+ print_unpacked_rgba_8unorm(format_desc, "FAILED: ", unpacked, " obtained\n");
+ print_unpacked_rgba_8unorm(format_desc, " ", expected, " expected\n");
+ }
+
+ return success;
}
static boolean
-test_format_unpack_4ub(const struct util_format_test_case *test)
+test_format_pack_rgba_8unorm(const struct util_format_description *format_desc,
+ const struct util_format_test_case *test)
{
- uint8_t unpacked[4];
- uint8_t expected[4];
+ uint8_t unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4];
+ uint8_t packed[UTIL_FORMAT_MAX_PACKED_BYTES];
unsigned i;
boolean success;
- util_format_unpack_4ub(test->format, unpacked, test->packed);
+ if (test->format == PIPE_FORMAT_DXT1_RGBA) {
+ /*
+ * Skip S3TC as packed representation is not canonical.
+ *
+ * TODO: Do a round trip conversion.
+ */
+ return TRUE;
+ }
- convert_4f_to_4ub(expected, test->unpacked);
+ if (!convert_float_to_8unorm(&unpacked[0][0][0], &test->unpacked[0][0][0])) {
+ /*
+ * Skip test cases which cannot be represented by four unorm bytes.
+ */
+ return TRUE;
+ }
+
+ memset(packed, 0, sizeof packed);
+
+ format_desc->pack_rgba_8unorm(packed, 0,
+ &unpacked[0][0][0], sizeof unpacked[0],
+ format_desc->block.width, format_desc->block.height);
success = TRUE;
- for (i = 0; i < 4; ++i)
- if (expected[i] != unpacked[i])
+ for (i = 0; i < format_desc->block.bits/8; ++i)
+ if ((test->packed[i] & test->mask[i]) != (packed[i] & test->mask[i]))
success = FALSE;
if (!success) {
- printf("FAILED: (0x%02x 0x%02x 0x%02x 0x%02x) obtained\n", unpacked[0], unpacked[1], unpacked[2], unpacked[3]);
- printf(" (0x%02x 0x%02x 0x%02x 0x%02x) expected\n", expected[0], expected[1], expected[2], expected[3]);
+ print_packed(format_desc, "FAILED: ", packed, " obtained\n");
+ print_packed(format_desc, " ", test->packed, " expected\n");
}
return success;
@@ -664,36 +404,216 @@ test_format_unpack_4ub(const struct util_format_test_case *test)
static boolean
-test_format_pack_4ub(const struct util_format_test_case *test)
+test_format_unpack_z_float(const struct util_format_description *format_desc,
+ const struct util_format_test_case *test)
{
- uint8_t unpacked[4];
- uint8_t packed[MAX_PACKED_BYTES];
- unsigned i;
+ float unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH] = { { 0 } };
+ unsigned i, j;
boolean success;
- convert_4f_to_4ub(unpacked, test->unpacked);
+ format_desc->unpack_z_float(&unpacked[0][0], sizeof unpacked[0],
+ test->packed, 0,
+ format_desc->block.width, format_desc->block.height);
+
+ success = TRUE;
+ for (i = 0; i < format_desc->block.height; ++i) {
+ for (j = 0; j < format_desc->block.width; ++j) {
+ if (!compare_float(test->unpacked[i][j][0], unpacked[i][j])) {
+ success = FALSE;
+ }
+ }
+ }
+
+ if (!success) {
+ print_unpacked_z_float(format_desc, "FAILED: ", unpacked, " obtained\n");
+ print_unpacked_rgba_doubl(format_desc, " ", test->unpacked, " expected\n");
+ }
+
+ return success;
+}
+
+
+static boolean
+test_format_pack_z_float(const struct util_format_description *format_desc,
+ const struct util_format_test_case *test)
+{
+ float unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH];
+ uint8_t packed[UTIL_FORMAT_MAX_PACKED_BYTES];
+ unsigned i, j;
+ boolean success;
+
+ memset(packed, 0, sizeof packed);
+ for (i = 0; i < format_desc->block.height; ++i) {
+ for (j = 0; j < format_desc->block.width; ++j) {
+ unpacked[i][j] = (float) test->unpacked[i][j][0];
+ if (test->unpacked[i][j][1]) {
+ return TRUE;
+ }
+ }
+ }
+
+ format_desc->pack_z_float(packed, 0,
+ &unpacked[0][0], sizeof unpacked[0],
+ format_desc->block.width, format_desc->block.height);
+
+ success = TRUE;
+ for (i = 0; i < format_desc->block.bits/8; ++i)
+ if ((test->packed[i] & test->mask[i]) != (packed[i] & test->mask[i]))
+ success = FALSE;
+
+ if (!success) {
+ print_packed(format_desc, "FAILED: ", packed, " obtained\n");
+ print_packed(format_desc, " ", test->packed, " expected\n");
+ }
+
+ return success;
+}
+
+
+static boolean
+test_format_unpack_z_32unorm(const struct util_format_description *format_desc,
+ const struct util_format_test_case *test)
+{
+ uint32_t unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH] = { { 0 } };
+ uint32_t expected[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH] = { { 0 } };
+ unsigned i, j;
+ boolean success;
+
+ format_desc->unpack_z_32unorm(&unpacked[0][0], sizeof unpacked[0],
+ test->packed, 0,
+ format_desc->block.width, format_desc->block.height);
+
+ for (i = 0; i < format_desc->block.height; ++i) {
+ for (j = 0; j < format_desc->block.width; ++j) {
+ expected[i][j] = test->unpacked[i][j][0] * 0xffffffff;
+ }
+ }
+
+ success = TRUE;
+ for (i = 0; i < format_desc->block.height; ++i) {
+ for (j = 0; j < format_desc->block.width; ++j) {
+ if (expected[i][j] != unpacked[i][j]) {
+ success = FALSE;
+ }
+ }
+ }
+
+ if (!success) {
+ print_unpacked_z_32unorm(format_desc, "FAILED: ", unpacked, " obtained\n");
+ print_unpacked_z_32unorm(format_desc, " ", expected, " expected\n");
+ }
+
+ return success;
+}
+
+
+static boolean
+test_format_pack_z_32unorm(const struct util_format_description *format_desc,
+ const struct util_format_test_case *test)
+{
+ uint32_t unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH];
+ uint8_t packed[UTIL_FORMAT_MAX_PACKED_BYTES];
+ unsigned i, j;
+ boolean success;
+
+ for (i = 0; i < format_desc->block.height; ++i) {
+ for (j = 0; j < format_desc->block.width; ++j) {
+ unpacked[i][j] = test->unpacked[i][j][0] * 0xffffffff;
+ if (test->unpacked[i][j][1]) {
+ return TRUE;
+ }
+ }
+ }
memset(packed, 0, sizeof packed);
- util_format_pack_4ub(test->format, packed, unpacked[0], unpacked[1], unpacked[2], unpacked[3]);
+ format_desc->pack_z_32unorm(packed, 0,
+ &unpacked[0][0], sizeof unpacked[0],
+ format_desc->block.width, format_desc->block.height);
success = TRUE;
- for (i = 0; i < MAX_PACKED_BYTES; ++i)
+ for (i = 0; i < format_desc->block.bits/8; ++i)
if ((test->packed[i] & test->mask[i]) != (packed[i] & test->mask[i]))
success = FALSE;
if (!success) {
- /* TODO: print more than 4 bytes */
- printf("FAILED: (%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x) obtained\n",
- packed[0], packed[1], packed[2], packed[3],
- packed[4], packed[5], packed[6], packed[7],
- packed[8], packed[9], packed[10], packed[11],
- packed[12], packed[13], packed[14], packed[15]);
- printf(" (%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x) expected\n",
- test->packed[0], test->packed[1], test->packed[2], test->packed[3],
- test->packed[4], test->packed[5], test->packed[6], test->packed[7],
- test->packed[8], test->packed[9], test->packed[10], test->packed[11],
- test->packed[12], test->packed[13], test->packed[14], test->packed[15]);
+ print_packed(format_desc, "FAILED: ", packed, " obtained\n");
+ print_packed(format_desc, " ", test->packed, " expected\n");
+ }
+
+ return success;
+}
+
+
+static boolean
+test_format_unpack_s_8uscaled(const struct util_format_description *format_desc,
+ const struct util_format_test_case *test)
+{
+ uint8_t unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH] = { { 0 } };
+ uint8_t expected[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH] = { { 0 } };
+ unsigned i, j;
+ boolean success;
+
+ format_desc->unpack_s_8uscaled(&unpacked[0][0], sizeof unpacked[0],
+ test->packed, 0,
+ format_desc->block.width, format_desc->block.height);
+
+ for (i = 0; i < format_desc->block.height; ++i) {
+ for (j = 0; j < format_desc->block.width; ++j) {
+ expected[i][j] = test->unpacked[i][j][1];
+ }
+ }
+
+ success = TRUE;
+ for (i = 0; i < format_desc->block.height; ++i) {
+ for (j = 0; j < format_desc->block.width; ++j) {
+ if (expected[i][j] != unpacked[i][j]) {
+ success = FALSE;
+ }
+ }
+ }
+
+ if (!success) {
+ print_unpacked_s_8uscaled(format_desc, "FAILED: ", unpacked, " obtained\n");
+ print_unpacked_s_8uscaled(format_desc, " ", expected, " expected\n");
+ }
+
+ return success;
+}
+
+
+static boolean
+test_format_pack_s_8uscaled(const struct util_format_description *format_desc,
+ const struct util_format_test_case *test)
+{
+ uint8_t unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH];
+ uint8_t packed[UTIL_FORMAT_MAX_PACKED_BYTES];
+ unsigned i, j;
+ boolean success;
+
+ for (i = 0; i < format_desc->block.height; ++i) {
+ for (j = 0; j < format_desc->block.width; ++j) {
+ unpacked[i][j] = test->unpacked[i][j][1];
+ if (test->unpacked[i][j][0]) {
+ return TRUE;
+ }
+ }
+ }
+
+ memset(packed, 0, sizeof packed);
+
+ format_desc->pack_s_8uscaled(packed, 0,
+ &unpacked[0][0], sizeof unpacked[0],
+ format_desc->block.width, format_desc->block.height);
+
+ success = TRUE;
+ for (i = 0; i < format_desc->block.bits/8; ++i)
+ if ((test->packed[i] & test->mask[i]) != (packed[i] & test->mask[i]))
+ success = FALSE;
+
+ if (!success) {
+ print_packed(format_desc, "FAILED: ", packed, " obtained\n");
+ print_packed(format_desc, " ", test->packed, " expected\n");
}
return success;
@@ -701,26 +621,29 @@ test_format_pack_4ub(const struct util_format_test_case *test)
typedef boolean
-(*test_func_t)(const struct util_format_test_case *test);
+(*test_func_t)(const struct util_format_description *format_desc,
+ const struct util_format_test_case *test);
static boolean
-test_one(test_func_t func, const char *suffix)
+test_one_func(const struct util_format_description *format_desc,
+ test_func_t func,
+ const char *suffix)
{
- enum pipe_format last_format = PIPE_FORMAT_NONE;
unsigned i;
bool success = TRUE;
- for (i = 0; i < sizeof(test_cases)/sizeof(test_cases[0]); ++i) {
- if (test_cases[i].format != last_format) {
- const struct util_format_description *format_desc;
- format_desc = util_format_description(test_cases[i].format);
- printf("Testing %s.%s ...\n", format_desc->name, suffix);
- last_format = test_cases[i].format;
- }
+ printf("Testing util_format_%s_%s ...\n",
+ format_desc->short_name, suffix);
- if (!func(&test_cases[i]))
- success = FALSE;
+ for (i = 0; i < util_format_nr_test_cases; ++i) {
+ const struct util_format_test_case *test = &util_format_test_cases[i];
+
+ if (test->format == format_desc->format) {
+ if (!func(format_desc, &util_format_test_cases[i])) {
+ success = FALSE;
+ }
+ }
}
return success;
@@ -730,19 +653,44 @@ test_one(test_func_t func, const char *suffix)
static boolean
test_all(void)
{
+ enum pipe_format format;
bool success = TRUE;
- if (!test_one(&test_format_pack_4f, "pack_4f"))
- success = FALSE;
+ for (format = 1; format < PIPE_FORMAT_COUNT; ++format) {
+ const struct util_format_description *format_desc;
- if (!test_one(&test_format_unpack_4f, "unpack_4f"))
- success = FALSE;
+ format_desc = util_format_description(format);
+ if (!format_desc) {
+ continue;
+ }
- if (!test_one(&test_format_pack_4ub, "pack_4ub"))
- success = FALSE;
+ if (format_desc->layout == UTIL_FORMAT_LAYOUT_S3TC &&
+ !util_format_s3tc_enabled) {
+ continue;
+ }
- if (!test_one(&test_format_unpack_4ub, "unpack_4ub"))
- success = FALSE;
+# define TEST_ONE_FUNC(name) \
+ if (format_desc->name) { \
+ if (!test_one_func(format_desc, &test_format_##name, #name)) { \
+ success = FALSE; \
+ } \
+ }
+
+ TEST_ONE_FUNC(fetch_rgba_float);
+ TEST_ONE_FUNC(pack_rgba_float);
+ TEST_ONE_FUNC(unpack_rgba_float);
+ TEST_ONE_FUNC(pack_rgba_8unorm);
+ TEST_ONE_FUNC(unpack_rgba_8unorm);
+
+ TEST_ONE_FUNC(unpack_z_32unorm);
+ TEST_ONE_FUNC(pack_z_32unorm);
+ TEST_ONE_FUNC(unpack_z_float);
+ TEST_ONE_FUNC(pack_z_float);
+ TEST_ONE_FUNC(unpack_s_8uscaled);
+ TEST_ONE_FUNC(pack_s_8uscaled);
+
+# undef TEST_ONE_FUNC
+ }
return success;
}
@@ -752,6 +700,8 @@ int main(int argc, char **argv)
{
boolean success;
+ util_format_s3tc_init();
+
success = test_all();
return success ? 0 : 1;
diff --git a/progs/gallium/unit/u_half_test.c b/progs/gallium/unit/u_half_test.c
new file mode 100644
index 0000000000..00bda7f50a
--- /dev/null
+++ b/progs/gallium/unit/u_half_test.c
@@ -0,0 +1,32 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <float.h>
+
+#include "util/u_math.h"
+#include "util/u_half.h"
+
+int
+main(int argc, char **argv)
+{
+ unsigned i;
+ unsigned roundtrip_fails = 0;
+ for(i = 0; i < 1 << 16; ++i)
+ {
+ uint16_t h = (uint16_t) i;
+ union fi f;
+ uint16_t rh;
+ f.ui = util_half_to_floatui(h);
+ rh = util_floatui_to_half(f.ui);
+ if(h != rh)
+ {
+ printf("Roundtrip failed: %x -> %x = %f -> %x\n", h, f.ui, f.f, rh);
+ ++roundtrip_fails;
+ }
+ }
+
+ if(roundtrip_fails)
+ printf("Failure! %u/65536 half floats failed a conversion to float and back.\n", roundtrip_fails);
+ else
+ printf("Success!\n");
+ return 0;
+}
diff --git a/progs/glsl/Makefile b/progs/glsl/Makefile
index 3b5a5959ae..6030c8002f 100644
--- a/progs/glsl/Makefile
+++ b/progs/glsl/Makefile
@@ -26,6 +26,7 @@ PROG_SOURCES = \
convolutions.c \
deriv.c \
fragcoord.c \
+ fsraytrace.c \
identity.c \
linktest.c \
mandelbrot.c \
@@ -46,7 +47,8 @@ PROG_SOURCES = \
trirast.c \
twoside.c \
vert-or-frag-only.c \
- vert-tex.c
+ vert-tex.c \
+ vsraytrace.c
UTIL_HEADERS = \
extfuncs.h \
diff --git a/progs/glsl/SConscript b/progs/glsl/SConscript
index 8f2ebcf69c..02884e5a71 100644
--- a/progs/glsl/SConscript
+++ b/progs/glsl/SConscript
@@ -8,6 +8,7 @@ progs = [
'convolutions',
'deriv',
'fragcoord',
+ 'fsraytrace',
'identity',
'linktest',
'mandelbrot',
@@ -27,6 +28,7 @@ progs = [
'twoside',
'vert-or-frag-only',
'vert-tex',
+ 'vsraytrace',
]
for prog in progs:
diff --git a/progs/glsl/fsraytrace.c b/progs/glsl/fsraytrace.c
new file mode 100644
index 0000000000..af72a99099
--- /dev/null
+++ b/progs/glsl/fsraytrace.c
@@ -0,0 +1,412 @@
+/* -*- mode: c; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; coding: utf-8-unix -*- */
+/*
+ Copyright (c) 2010 Kristóf Ralovich
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+*/
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <GL/glew.h>
+#include <GL/glut.h>
+#include "shaderutil.h"
+#include <math.h>
+
+static int Win;
+static int WinWidth = 512, WinHeight = 512;
+static int mouseGrabbed = 0;
+static GLuint vertShader;
+static GLuint fragShader;
+static GLuint program;
+static float rot[9] = {1,0,0, 0,1,0, 0,0,1};
+
+static const char* vsSource =
+ "varying vec2 rayDir; \n"
+ " \n"
+ "void main() \n"
+ "{ \n"
+ " rayDir = gl_MultiTexCoord0.xy - vec2(0.5,0.5); \n"
+ " gl_Position = gl_ProjectionMatrix * gl_Vertex; \n"
+ "}\n";
+
+static const char* fsSource =
+ "const float INF = 9999.9; \n"
+ "const float EPSILON = 0.00001; \n"
+ "const vec3 lightPos = vec3(0.0, 8.0, 1.0); \n"
+ "const vec4 backgroundColor = vec4(0.2,0.3,0.4,1); \n"
+ " \n"
+ "varying vec2 rayDir; \n"
+ " \n"
+ "uniform mat3 rot; \n"
+ " \n"
+ "struct Ray \n"
+ "{ \n"
+ "vec3 orig; \n"
+ "vec3 dir; \n"
+ "}; \n"
+ " \n"
+ "struct Sphere \n"
+ "{ \n"
+ " vec3 c; \n"
+ " float r; \n"
+ "}; \n"
+ " \n"
+ "struct Isec \n"
+ "{ \n"
+ " float t; \n"
+ " int idx; \n"
+ " vec3 hit; \n"
+ " vec3 n; \n"
+ "}; \n"
+ " \n"
+#ifdef __APPLE__
+ "Sphere spheres0 = Sphere( vec3(0.0,0.0,-1.0), 0.5 ); \n"
+ "Sphere spheres1 = Sphere( vec3(-3.0,0.0,-1.0), 1.5 ); \n"
+ "Sphere spheres2 = Sphere( vec3(0.0,3.0,-1.0), 0.5 ); \n"
+ "Sphere spheres3 = Sphere( vec3(2.0,0.0,-1.0), 1.0 ); \n"
+#else
+ "const Sphere spheres0 = Sphere( vec3(0.0,0.0,-1.0), 0.5 ); \n"
+ "const Sphere spheres1 = Sphere( vec3(-3.0,0.0,-1.0), 1.5 ); \n"
+ "const Sphere spheres2 = Sphere( vec3(0.0,3.0,-1.0), 0.5 ); \n"
+ "const Sphere spheres3 = Sphere( vec3(2.0,0.0,-1.0), 1.0 ); \n"
+#endif
+ " \n"
+ "// Mesa intel gen4 generates \"unsupported IR in fragment shader 13\" for\n"
+ "// sqrt, let's work around. \n"
+ "float \n"
+ "sqrt_hack(float f2) \n"
+ "{ \n"
+ " vec3 v = vec3(f2,0.0,0.0); \n"
+ " return length(v); \n"
+ "} \n"
+ " \n"
+ "void \n"
+ "intersect(const in Ray ray, \n"
+ " const in Sphere sph, \n"
+ " const in int idx, \n"
+ " inout Isec isec) \n"
+ "{ \n"
+ " // Project both o and the sphere to the plane perpendicular to d \n"
+ " // and containing c. Let x be the point where the ray intersects \n"
+ " // the plane. If |x-c| < r, the ray intersects the sphere. \n"
+ " vec3 o = ray.orig; \n"
+ " vec3 d = ray.dir; \n"
+ " vec3 n = -d; \n"
+ " vec3 c = sph.c; \n"
+ " float r = sph.r; \n"
+ " float t = dot(c-o,n)/dot(n,d); \n"
+ " vec3 x = o+d*t; \n"
+ " float e = length(x-c); \n"
+ " if(e > r) \n"
+ " { \n"
+ " // no intersection \n"
+ " return; \n"
+ " } \n"
+ " \n"
+ " // Apply Pythagorean theorem on the (intersection,x,c) triangle \n"
+ " // to get the distance between c and the intersection. \n"
+ "#ifndef BUGGY_INTEL_GEN4_GLSL \n"
+ " float f = sqrt(r*r - e*e); \n"
+ "#else \n"
+ " float f = sqrt_hack(r*r - e*e); \n"
+ "#endif \n"
+ " float dist = t - f; \n"
+ " if(dist < 0.0) \n"
+ " { \n"
+ " // inside the sphere \n"
+ " return; \n"
+ " } \n"
+ " \n"
+ " if(dist < EPSILON) \n"
+ " return; \n"
+ " \n"
+ " if(dist > isec.t) \n"
+ " return; \n"
+ " \n"
+ " isec.t = dist; \n"
+ " isec.idx = idx; \n"
+ " \n"
+ " isec.hit = ray.orig + ray.dir * isec.t; \n"
+ " isec.n = (isec.hit - c) / r; \n"
+ "} \n"
+ " \n"
+ "Isec \n"
+ "intersect(const in Ray ray, \n"
+ " const in float max_t /*= INF*/) \n"
+ "{ \n"
+ " Isec nearest; \n"
+ " nearest.t = max_t; \n"
+ " nearest.idx = -1; \n"
+ " \n"
+ " intersect(ray, spheres0, 0, nearest); \n"
+ " intersect(ray, spheres1, 1, nearest); \n"
+ " intersect(ray, spheres2, 2, nearest); \n"
+ " intersect(ray, spheres3, 3, nearest); \n"
+ " \n"
+ " return nearest; \n"
+ "} \n"
+ " \n"
+ "vec4 \n"
+ "idx2color(const in int idx) \n"
+ "{ \n"
+ " vec4 diff; \n"
+ " if(idx == 0) \n"
+ " diff = vec4(1.0, 0.0, 0.0, 0.0); \n"
+ " else if(idx == 1) \n"
+ " diff = vec4(0.0, 1.0, 0.0, 0.0); \n"
+ " else if(idx == 2) \n"
+ " diff = vec4(0.0, 0.0, 1.0, 0.0); \n"
+ " else if(idx == 3) \n"
+ " diff = vec4(1.0, 1.0, 0.0, 0.0); \n"
+ " return diff; \n"
+ "} \n"
+ " \n"
+ "vec4 \n"
+ "trace0(const in Ray ray) \n"
+ "{ \n"
+ " Isec isec = intersect(ray, INF); \n"
+ " \n"
+ " if(isec.idx == -1) \n"
+ " { \n"
+ " return backgroundColor; \n"
+ " } \n"
+ " \n"
+ " vec4 diff = idx2color(isec.idx); \n"
+ " \n"
+ " vec3 N = isec.n; \n"
+ " vec3 L = normalize(lightPos-isec.hit); \n"
+ " vec3 camera_dir = normalize(ray.orig - isec.hit); \n"
+ " return dot(N,L)*diff + pow( \n"
+ " clamp(dot(reflect(-L,N),camera_dir),0.0,1.0),16.0); \n"
+ "} \n"
+ " \n"
+ "vec4 \n"
+ "trace1(const in Ray ray) \n"
+ "{ \n"
+ " Isec isec = intersect(ray, INF); \n"
+ " \n"
+ " if(isec.idx == -1) \n"
+ " { \n"
+ " return backgroundColor; \n"
+ " } \n"
+ " \n"
+ " Ray reflRay = Ray(isec.hit, reflect(ray.dir, isec.n)); \n"
+ " \n"
+ " vec4 reflCol = trace0(reflRay); \n"
+ " \n"
+ " vec4 diff = idx2color(isec.idx) + reflCol; \n"
+ " \n"
+ " vec3 N = isec.n; \n"
+ " vec3 L = normalize(lightPos-isec.hit); \n"
+ " vec3 camera_dir = normalize(ray.orig - isec.hit); \n"
+ " return dot(N,L)*diff + pow( \n"
+ " clamp(dot(reflect(-L,N),camera_dir),0.0,1.0),16.0); \n"
+ "} \n"
+ " \n"
+ "void main() \n"
+ "{ \n"
+ " const float z = -0.5; \n"
+ " const vec3 cameraPos = vec3(0,0,3); \n"
+ " Ray r = Ray(cameraPos, normalize(vec3(rayDir, z) * rot)); \n"
+ " gl_FragColor = trace1(r); \n"
+ "}\n";
+
+static
+float
+deg2rad(const float degree)
+{
+ return( degree * 0.017453292519943295769236907684886F);
+}
+
+static void
+rotate_xy(float* mat3, const float degreesAroundX, const float degreesAroundY)
+{
+ const float rad1 = deg2rad(degreesAroundX);
+ const float c1 = cosf(rad1);
+ const float s1 = sinf(rad1);
+ const float rad2 = deg2rad(degreesAroundY);
+ const float c2 = cosf(rad2);
+ const float s2 = sinf(rad2);
+ mat3[0] = c2; mat3[3] = 0.0F; mat3[6] = s2;
+ mat3[1] = s1*s2; mat3[4] = c1; mat3[7] = -s1*c2;
+ mat3[2] = -c1*s2;mat3[5] = s1; mat3[8] = c1*c2;
+}
+
+static void
+identity(float* mat3)
+{
+ mat3[0] = 1.0F; mat3[3] = 0.0F; mat3[6] = 0.0F;
+ mat3[1] = 0.0F; mat3[4] = 1.0F; mat3[7] = 0.0F;
+ mat3[2] = 0.0F; mat3[5] = 0.0F; mat3[8] = 1.0F;
+}
+
+static void
+Draw(void)
+{
+ GLint location = glGetUniformLocation(program, "rot");
+ static const float m = -10.F;
+ static const float p = 10.F;
+ static const float d = -0.5F;
+
+ glUseProgram(program);
+ glUniformMatrix3fv(location, 1, 0, rot);
+
+ glBegin(GL_QUADS);
+ {
+ glTexCoord2f(0.0F, 0.0F); glVertex3f(m, m, d);
+ glTexCoord2f(1.0F, 0.0F); glVertex3f(p, m, d);
+ glTexCoord2f(1.0F, 1.0F); glVertex3f(p, p, d);
+ glTexCoord2f(0.0F, 1.0F); glVertex3f(m, p, d);
+ }
+ glEnd();
+ glUseProgram(0);
+
+ glutSwapBuffers();
+
+ {
+ static int frames = 0;
+ static int t0 = 0;
+ static int t1 = 0;
+ float dt;
+ frames++;
+ t1 = glutGet(GLUT_ELAPSED_TIME);
+ dt = (float)(t1-t0)/1000.0F;
+ if(dt >= 5.0F)
+ {
+ float fps = (float)frames / dt;
+ printf("%f FPS (%d frames in %f seconds)\n", fps, frames, dt);
+ frames = 0;
+ t0 = t1;
+ }
+ }
+}
+
+
+static void
+Reshape(int width, int height)
+{
+ WinWidth = width;
+ WinHeight = height;
+ glViewport(0, 0, width, height);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glOrtho(-10, 10, -10, 10, -1, 1);
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+}
+
+
+static void
+Key(unsigned char key, int x, int y)
+{
+ (void) x;
+ (void) y;
+ switch (key) {
+ case 27:
+ glutDestroyWindow(Win);
+ exit(0);
+ break;
+ }
+ glutPostRedisplay();
+}
+
+
+static
+void
+drag(int x, int y)
+{
+ float scale = 1.5F;
+ if(mouseGrabbed)
+ {
+ static GLfloat xRot = 0, yRot = 0;
+ xRot = (float)(x - WinWidth/2) / scale;
+ yRot = (float)(y - WinHeight/2) / scale;
+ identity(rot);
+ rotate_xy(rot, yRot, xRot);
+ glutPostRedisplay();
+ }
+}
+
+
+static
+void
+mouse(int button, int state, int x, int y)
+{
+ mouseGrabbed = (state == GLUT_DOWN);
+}
+
+
+static void
+Init(void)
+{
+ glDisable(GL_DEPTH_TEST);
+
+ if(!ShadersSupported())
+ {
+ fprintf(stderr, "Shaders are not supported!\n");
+ exit(-1);
+ }
+
+ vertShader = CompileShaderText(GL_VERTEX_SHADER, vsSource);
+ fragShader = CompileShaderText(GL_FRAGMENT_SHADER, fsSource);
+ program = LinkShaders(vertShader, fragShader);
+ glUseProgram(0);
+
+ if(glGetError() != 0)
+ {
+ fprintf(stderr, "Shaders were not loaded!\n");
+ exit(-1);
+ }
+
+ if(!glIsShader(vertShader))
+ {
+ fprintf(stderr, "Vertex shader failed!\n");
+ exit(-1);
+ }
+
+ if(!glIsProgram(program))
+ {
+ fprintf(stderr, "Shader program failed!\n");
+ exit(-1);
+ }
+
+ printf("GL_RENDERER = %s\n",(const char *) glGetString(GL_RENDERER));
+}
+
+
+int
+main(int argc, char *argv[])
+{
+ glutInitWindowSize(WinWidth, WinHeight);
+ glutInit(&argc, argv);
+ glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
+ Win = glutCreateWindow(argv[0]);
+ glewInit();
+ glutReshapeFunc(Reshape);
+ glutKeyboardFunc(Key);
+ glutDisplayFunc(Draw);
+ glutMouseFunc(mouse);
+ glutMotionFunc(drag);
+ glutIdleFunc(Draw);
+ Init();
+ glutMainLoop();
+ return 0;
+}
+
diff --git a/progs/glsl/vsraytrace.c b/progs/glsl/vsraytrace.c
new file mode 100644
index 0000000000..64d928883e
--- /dev/null
+++ b/progs/glsl/vsraytrace.c
@@ -0,0 +1,401 @@
+/* -*- mode: c; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; coding: utf-8-unix -*- */
+/*
+ Copyright (c) 2010 Kristóf Ralovich
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+*/
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <GL/glew.h>
+#include <GL/glut.h>
+#include "shaderutil.h"
+#include <math.h>
+
+static int Win;
+static int WinWidth = 256, WinHeight = 256;
+static GLboolean mouseGrabbed = GL_FALSE;
+static GLuint vertShader;
+static GLuint program;
+float rot[9] = {1,0,0, 0,1,0, 0,0,1};
+
+static const char* vsSource =
+ "const float INF = 9999.9; \n"
+ "const float EPSILON = 0.00001; \n"
+ "const vec3 lightPos = vec3(0.0, 8.0, 1.0); \n"
+ "const vec4 backgroundColor = vec4(0.2,0.3,0.4,1); \n"
+ " \n"
+ "uniform mat3 rot; \n"
+ " \n"
+ "struct Ray \n"
+ "{ \n"
+ "vec3 orig; \n"
+ "vec3 dir; \n"
+ "}; \n"
+ " \n"
+ "struct Sphere \n"
+ "{ \n"
+ " vec3 c; \n"
+ " float r; \n"
+ "}; \n"
+ " \n"
+ "struct Isec \n"
+ "{ \n"
+ " float t; \n"
+ " int idx; \n"
+ " vec3 hit; \n"
+ " vec3 n; \n"
+ "}; \n"
+ " \n"
+#ifdef __APPLE__
+ "Sphere spheres0 = Sphere( vec3(0.0,0.0,-1.0), 0.5 ); \n"
+ "Sphere spheres1 = Sphere( vec3(-3.0,0.0,-1.0), 1.5 ); \n"
+ "Sphere spheres2 = Sphere( vec3(0.0,3.0,-1.0), 0.5 ); \n"
+ "Sphere spheres3 = Sphere( vec3(2.0,0.0,-1.0), 1.0 ); \n"
+#else
+ "const Sphere spheres0 = Sphere( vec3(0.0,0.0,-1.0), 0.5 ); \n"
+ "const Sphere spheres1 = Sphere( vec3(-3.0,0.0,-1.0), 1.5 ); \n"
+ "const Sphere spheres2 = Sphere( vec3(0.0,3.0,-1.0), 0.5 ); \n"
+ "const Sphere spheres3 = Sphere( vec3(2.0,0.0,-1.0), 1.0 ); \n"
+#endif
+ " \n"
+ "// Mesa intel gen4 generates \"unsupported IR in fragment shader 13\" for\n"
+ "// sqrt, let's work around. \n"
+ "float \n"
+ "sqrt_hack(float f2) \n"
+ "{ \n"
+ " vec3 v = vec3(f2,0.0,0.0); \n"
+ " return length(v); \n"
+ "} \n"
+ " \n"
+ "void \n"
+ "intersect(const in Ray ray, \n"
+ " const in Sphere sph, \n"
+ " const in int idx, \n"
+ " inout Isec isec) \n"
+ "{ \n"
+ " // Project both o and the sphere to the plane perpendicular to d \n"
+ " // and containing c. Let x be the point where the ray intersects \n"
+ " // the plane. If |x-c| < r, the ray intersects the sphere. \n"
+ " vec3 o = ray.orig; \n"
+ " vec3 d = ray.dir; \n"
+ " vec3 n = -d; \n"
+ " vec3 c = sph.c; \n"
+ " float r = sph.r; \n"
+ " float t = dot(c-o,n)/dot(n,d); \n"
+ " vec3 x = o+d*t; \n"
+ " float e = length(x-c); \n"
+ " if(e > r) \n"
+ " { \n"
+ " // no intersection \n"
+ " return; \n"
+ " } \n"
+ " \n"
+ " // Apply Pythagorean theorem on the (intersection,x,c) triangle \n"
+ " // to get the distance between c and the intersection. \n"
+ "#define BUGGY_INTEL_GEN4_GLSL 1 \n"
+ "#ifndef BUGGY_INTEL_GEN4_GLSL \n"
+ " float f = sqrt(r*r - e*e); \n"
+ "#else \n"
+ " float f = sqrt_hack(r*r - e*e); \n"
+ "#endif \n"
+ " float dist = t - f; \n"
+ " if(dist < 0.0) \n"
+ " { \n"
+ " // inside the sphere \n"
+ " return; \n"
+ " } \n"
+ " \n"
+ " if(dist < EPSILON) \n"
+ " return; \n"
+ " \n"
+ " if(dist > isec.t) \n"
+ " return; \n"
+ " \n"
+ " isec.t = dist; \n"
+ " isec.idx = idx; \n"
+ " \n"
+ " isec.hit = ray.orig + ray.dir * isec.t; \n"
+ " isec.n = (isec.hit - c) / r; \n"
+ "} \n"
+ " \n"
+ "Isec \n"
+ "intersect(const in Ray ray, \n"
+ " const in float max_t /*= INF*/) \n"
+ "{ \n"
+ " Isec nearest; \n"
+ " nearest.t = max_t; \n"
+ " nearest.idx = -1; \n"
+ " \n"
+ " intersect(ray, spheres0, 0, nearest); \n"
+ " intersect(ray, spheres1, 1, nearest); \n"
+ " intersect(ray, spheres2, 2, nearest); \n"
+ " intersect(ray, spheres3, 3, nearest); \n"
+ " \n"
+ " return nearest; \n"
+ "} \n"
+ " \n"
+ "vec4 \n"
+ "idx2color(const in int idx) \n"
+ "{ \n"
+ " vec4 diff; \n"
+ " if(idx == 0) \n"
+ " diff = vec4(1.0, 0.0, 0.0, 0.0); \n"
+ " else if(idx == 1) \n"
+ " diff = vec4(0.0, 1.0, 0.0, 0.0); \n"
+ " else if(idx == 2) \n"
+ " diff = vec4(0.0, 0.0, 1.0, 0.0); \n"
+ " else if(idx == 3) \n"
+ " diff = vec4(1.0, 1.0, 0.0, 0.0); \n"
+ " return diff; \n"
+ "} \n"
+ " \n"
+ "vec4 \n"
+ "trace0(const in Ray ray) \n"
+ "{ \n"
+ " Isec isec = intersect(ray, INF); \n"
+ " \n"
+ " if(isec.idx == -1) \n"
+ " { \n"
+ " return backgroundColor; \n"
+ " } \n"
+ " \n"
+ " vec4 diff = idx2color(isec.idx); \n"
+ " \n"
+ " vec3 N = isec.n; \n"
+ " vec3 L = normalize(lightPos-isec.hit); \n"
+ " vec3 camera_dir = normalize(ray.orig - isec.hit); \n"
+ " return dot(N,L)*diff + pow( \n"
+ " clamp(dot(reflect(-L,N),camera_dir),0.0,1.0),16.0); \n"
+ "} \n"
+ " \n"
+ "vec4 \n"
+ "trace1(const in Ray ray) \n"
+ "{ \n"
+ " Isec isec = intersect(ray, INF); \n"
+ " \n"
+ " if(isec.idx == -1) \n"
+ " { \n"
+ " return backgroundColor; \n"
+ " } \n"
+ " \n"
+ " Ray reflRay = Ray(isec.hit, reflect(ray.dir, isec.n)); \n"
+ " \n"
+ " vec4 reflCol = trace0(reflRay); \n"
+ " \n"
+ " vec4 diff = idx2color(isec.idx) + reflCol; \n"
+ " \n"
+ " vec3 N = isec.n; \n"
+ " vec3 L = normalize(lightPos-isec.hit); \n"
+ " vec3 camera_dir = normalize(ray.orig - isec.hit); \n"
+ " return dot(N,L)*diff + pow( \n"
+ " clamp(dot(reflect(-L,N),camera_dir),0.0,1.0),16.0); \n"
+ "} \n"
+ " \n"
+ "void main() \n"
+ "{ \n"
+ " const vec3 cameraPos = vec3(0,0,3); \n"
+ " vec3 rayDir = normalize(vec3(gl_Vertex.x, gl_Vertex.y, -1.0) * rot);\n"
+ " Ray ray = Ray(cameraPos, rayDir); \n"
+ " gl_Position = gl_Vertex; \n"
+ " gl_FrontColor = trace1(ray); \n"
+ "}\n";
+
+
+static
+float
+deg2rad(const float degree)
+{
+ return( degree * 0.017453292519943295769236907684886F);
+}
+
+static void
+rotate_xy(float* mat3, const float degreesAroundX, const float degreesAroundY)
+{
+ const float rad1 = deg2rad(degreesAroundX);
+ const float c1 = cosf(rad1);
+ const float s1 = sinf(rad1);
+ const float rad2 = deg2rad(degreesAroundY);
+ const float c2 = cosf(rad2);
+ const float s2 = sinf(rad2);
+ mat3[0] = c2; mat3[3] = 0.0F; mat3[6] = s2;
+ mat3[1] = s1*s2; mat3[4] = c1; mat3[7] = -s1*c2;
+ mat3[2] = -c1*s2;mat3[5] = s1; mat3[8] = c1*c2;
+}
+
+static void
+identity(float* mat3)
+{
+ mat3[0] = 1.0F; mat3[3] = 0.0F; mat3[6] = 0.0F;
+ mat3[1] = 0.0F; mat3[4] = 1.0F; mat3[7] = 0.0F;
+ mat3[2] = 0.0F; mat3[5] = 0.0F; mat3[8] = 1.0F;
+}
+
+static void
+Draw(void)
+{
+ const float w = 0.5F * WinWidth;
+ const float h = 0.5F * WinHeight;
+ int x,y;
+
+ GLint location = glGetUniformLocation(program, "rot");
+
+ glUseProgram(program);
+ glUniformMatrix3fv(location, 1, 0, rot);
+ glBegin(GL_POINTS);
+ for(y = 0; y < WinHeight; y++)
+ {
+ for(x = 0; x < WinWidth; x++)
+ {
+ const float posx = x / w - 1.0F;
+ const float posy = y / h - 1.0F;
+ glVertex2f(posx, posy);
+ }
+ }
+ glEnd();
+ glUseProgram(0);
+
+ glutSwapBuffers();
+
+ {
+ static int frames = 0;
+ static int t0 = 0;
+ static int t1 = 0;
+ float dt;
+ frames++;
+ t1 = glutGet(GLUT_ELAPSED_TIME);
+ dt = (float)(t1-t0)/1000.0F;
+ if (dt >= 5.0F)
+ {
+ float fps = (float)frames / dt;
+ printf("%f FPS (%d frames in %f seconds)\n", fps, frames, dt);
+ frames = 0;
+ t0 = t1;
+ }
+ }
+}
+
+
+static void
+Reshape(int width, int height)
+{
+ WinWidth = width;
+ WinHeight = height;
+ glViewport(0, 0, width, height);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+}
+
+
+static void
+Key(unsigned char key, int x, int y)
+{
+ if(key == 27)
+ {
+ glutDestroyWindow(Win);
+ exit(0);
+ }
+ glutPostRedisplay();
+}
+
+
+static
+void
+drag(int x, int y)
+{
+ float scale = 1.5F;
+ if(mouseGrabbed)
+ {
+ static GLfloat xRot = 0, yRot = 0;
+ xRot = (float)(x - WinWidth/2) / scale;
+ yRot = (float)(y - WinHeight/2) / scale;
+ identity(rot);
+ rotate_xy(rot, yRot, xRot);
+ glutPostRedisplay();
+ }
+}
+
+
+static
+void
+mouse(int button, int state, int x, int y)
+{
+ mouseGrabbed = (state == GLUT_DOWN);
+}
+
+
+static void
+Init(void)
+{
+ glDisable(GL_DEPTH_TEST);
+
+ if(!ShadersSupported())
+ {
+ fprintf(stderr, "Shaders are not supported!\n");
+ exit(-1);
+ }
+
+ vertShader = CompileShaderText(GL_VERTEX_SHADER, vsSource);
+ program = LinkShaders(vertShader, 0);
+ glUseProgram(0);
+
+ if(glGetError() != 0)
+ {
+ fprintf(stderr, "Shaders were not loaded!\n");
+ exit(-1);
+ }
+
+ if(!glIsShader(vertShader))
+ {
+ fprintf(stderr, "Vertex shader failed!\n");
+ exit(-1);
+ }
+
+ if(!glIsProgram(program))
+ {
+ fprintf(stderr, "Shader program failed!\n");
+ exit(-1);
+ }
+
+ printf("GL_RENDERER = %s\n",(const char *) glGetString(GL_RENDERER));
+}
+
+
+int
+main(int argc, char *argv[])
+{
+ glutInitWindowSize(WinWidth, WinHeight);
+ glutInit(&argc, argv);
+ glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
+ Win = glutCreateWindow(argv[0]);
+ glewInit();
+ glutReshapeFunc(Reshape);
+ glutKeyboardFunc(Key);
+ glutDisplayFunc(Draw);
+ glutIdleFunc(Draw);
+ glutMouseFunc(mouse);
+ glutMotionFunc(drag);
+ Init();
+ glutMainLoop();
+ return 0;
+}
+
diff --git a/progs/objviewer/skybox.c b/progs/objviewer/skybox.c
index 4e30742e20..93331b9c16 100644
--- a/progs/objviewer/skybox.c
+++ b/progs/objviewer/skybox.c
@@ -88,9 +88,9 @@ LoadSkyBoxCubeTexture(const char *filePosX,
return 0;
if (!load(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, fileNegX, GL_TRUE, GL_TRUE))
return 0;
- if (!load(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, filePosY, 1+GL_FALSE, GL_TRUE))
+ if (!load(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, filePosY, GL_TRUE, GL_TRUE))
return 0;
- if (!load(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, fileNegY, 1+GL_FALSE, GL_TRUE))
+ if (!load(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, fileNegY, GL_TRUE, GL_TRUE))
return 0;
if (!load(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, filePosZ, GL_TRUE, GL_TRUE))
return 0;
diff --git a/progs/openvg/demos/Makefile b/progs/openvg/demos/Makefile
deleted file mode 100644
index 89b0ce441b..0000000000
--- a/progs/openvg/demos/Makefile
+++ /dev/null
@@ -1,39 +0,0 @@
-# progs/vg/Makefile
-
-TOP = ../../..
-include $(TOP)/configs/current
-
-VG_LIBS=-lm -pthread -lX11 -lEGL -lOpenVG
-INCLUDE_DIRS = -I$(TOP)/include
-
-PROGRAMS = \
- lion \
- sp
-
-.c.o:
- $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $< -o $@
-
-
-
-default: $(PROGRAMS)
-
-lion: lion.o lion-render.o
- $(CC) $(CFLAGS) lion.o lion-render.o -L$(TOP)/$(LIB_DIR) $(VG_LIBS) -o $@
-
-lion.o: lion.c lion-render.h $(HEADERS)
- $(CC) -c $(CFLAGS) -I$(TOP)/include lion.c
-lion-render.o: lion-render.c lion-render.h $(HEADERS)
- $(CC) -c $(CFLAGS) -I$(TOP)/include lion-render.c
-
-
-sp: sp.c eglcommon.o
- $(CC) $(INCLUDE_DIRS) $(CFLAGS) $^ -L$(TOP)/$(LIB_DIR) $(LIBS) $(VG_LIBS) $(APP_LIB_DEPS) -o $@
-
-eglcommon.o: eglcommon.c $(HEADERS)
- $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) eglcommon.c
-
-
-clean:
- rm -f *.o *~
- rm -f *.so
- rm -f $(PROGRAMS)
diff --git a/progs/openvg/demos/lion.c b/progs/openvg/demos/lion.c
deleted file mode 100644
index adb269bfd8..0000000000
--- a/progs/openvg/demos/lion.c
+++ /dev/null
@@ -1,289 +0,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>
-#include <VG/openvg.h>
-#include <GLES/egl.h>
-
-#include "lion-render.h"
-
-static VGint width, height;
-struct lion *lion = 0;
-VGfloat angle = 0;
-
-static void
-draw(void)
-{
- vgClear(0, 0, width, height);
-
- vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
- vgLoadIdentity();
- vgTranslate(width/2, height/2);
- vgRotate(angle);
- vgTranslate(-width/2, -height/2);
-
- lion_render(lion);
-
- ++angle;
-}
-
-
-/* new window size or exposure */
-static void
-reshape(int w, int h)
-{
- width = w;
- height = h;
-}
-
-
-static void
-init(void)
-{
- float clear_color[4] = {1.0, 1.0, 1.0, 1.0};
- vgSetfv(VG_CLEAR_COLOR, 4, clear_color);
-
- lion = lion_create();
-}
-
-
-/*
- * 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_RENDERABLE_TYPE, EGL_OPENVG_BIT,
- 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) ||
- !num_configs) {
- printf("Error: couldn't get an EGL visual config\n");
- exit(1);
- }
-
- assert(config);
-
- 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_OPENVG_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)
-{
- while (1) {
- XEvent event;
-
- while (XPending(dpy) > 0) {
- XNextEvent(dpy, &event);
-
- switch (event.type) {
- case Expose:
- break;
- case ConfigureNotify:
- reshape(event.xconfigure.width, event.xconfigure.height);
- break;
- case KeyPress:
- {
- char buffer[10];
- int r, code;
- code = XLookupKeysym(&event.xkey, 0);
- r = XLookupString(&event.xkey, buffer, sizeof(buffer),
- NULL, NULL);
- if (buffer[0] == 27) {
- /* escape */
- return;
- }
- }
- break;
- default:
- ; /*no-op*/
- }
- }
-
- 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 = 350, winHeight = 450;
- Display *x_dpy;
- Window win;
- EGLSurface egl_surf;
- EGLContext egl_ctx;
- EGLDisplay egl_dpy;
- char *dpyName = NULL;
- GLboolean printInfo = GL_FALSE;
- EGLint egl_major, egl_minor;
- int i;
- const char *s;
-
- for (i = 1; i < argc; i++) {
- if (strcmp(argv[i], "-display") == 0) {
- dpyName = argv[i+1];
- i++;
- }
- else if (strcmp(argv[i], "-info") == 0) {
- printInfo = GL_TRUE;
- }
- else {
- usage();
- return -1;
- }
- }
-
- x_dpy = XOpenDisplay(dpyName);
- if (!x_dpy) {
- printf("Error: couldn't open display %s\n",
- dpyName ? dpyName : getenv("DISPLAY"));
- return -1;
- }
-
- egl_dpy = eglGetDisplay(x_dpy);
- if (!egl_dpy) {
- printf("Error: eglGetDisplay() failed\n");
- return -1;
- }
-
- if (!eglInitialize(egl_dpy, &egl_major, &egl_minor)) {
- printf("Error: eglInitialize() failed\n");
- return -1;
- }
-
- s = eglQueryString(egl_dpy, EGL_VERSION);
- printf("EGL_VERSION = %s\n", s);
-
- make_x_window(x_dpy, egl_dpy,
- "Lion Example", 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("VG_RENDERER = %s\n", (char *) vgGetString(VG_RENDERER));
- printf("VG_VERSION = %s\n", (char *) vgGetString(VG_VERSION));
- printf("VG_VENDOR = %s\n", (char *) vgGetString(VG_VENDOR));
- }
-
- init();
-
- /* Set initial projection/viewing transformation.
- * We can't be sure we'll get a ConfigureNotify event when the window
- * first appears.
- */
- reshape(winWidth, winHeight);
-
- event_loop(x_dpy, win, egl_dpy, egl_surf);
-
- eglDestroyContext(egl_dpy, egl_ctx);
- eglDestroySurface(egl_dpy, egl_surf);
- eglTerminate(egl_dpy);
-
-
- XDestroyWindow(x_dpy, win);
- XCloseDisplay(x_dpy);
-
- return 0;
-}
diff --git a/progs/openvg/trivial/eglcommon.c b/progs/openvg/trivial/eglcommon.c
deleted file mode 100644
index 0316e596c6..0000000000
--- a/progs/openvg/trivial/eglcommon.c
+++ /dev/null
@@ -1,289 +0,0 @@
-#include "eglcommon.h"
-
-
-#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 <VG/openvg.h> /* using full OpenGL for now */
-#include <GLES/egl.h>
-
-
-static init_func init = 0;
-static draw_func draw = 0;
-static reshape_func reshape = 0;
-static key_func keyPress = 0;
-static VGint width = 300, height = 300;
-
-
-void set_window_size(int w, int h)
-{
- width = w;
- height = h;
-}
-
-/*
- * 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_RENDERABLE_TYPE, EGL_OPENVG_BIT,
- 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) ||
- !num_configs) {
- printf("Error: couldn't get an EGL visual config\n");
- exit(1);
- }
-
- assert(config);
-
- 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_OPENVG_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)
-{
- while (1) {
- int redraw = 0;
- XEvent event;
-
- XNextEvent(dpy, &event);
-
- switch (event.type) {
- case Expose:
- redraw = 1;
- break;
- case ConfigureNotify:
- if (reshape) {
- width = event.xconfigure.width;
- height = event.xconfigure.height;
- reshape(event.xconfigure.width, event.xconfigure.height);
- }
- break;
- case KeyPress:
- {
- char buffer[10];
- int r, code;
- code = XLookupKeysym(&event.xkey, 0);
- if (!keyPress || !keyPress(code)) {
- 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);
- }
- }
-}
-
-int window_width(void)
-{
- return width;
-}
-
-int window_height(void)
-{
- return height;
-}
-
-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 run(int argc, char **argv,
- init_func init_f,
- reshape_func resh_f,
- draw_func draw_f,
- key_func key_f)
-{
- const int winWidth = width, winHeight = height;
- 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;
-
- init = init_f;
- draw = draw_f;
- reshape = resh_f;
- keyPress = key_f;
-
- 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;
- }
- }
-
- x_dpy = XOpenDisplay(dpyName);
- if (!x_dpy) {
- printf("Error: couldn't open display %s\n",
- dpyName ? dpyName : getenv("DISPLAY"));
- return -1;
- }
-
- egl_dpy = eglGetDisplay(x_dpy);
- if (!egl_dpy) {
- printf("Error: eglGetDisplay() failed\n");
- return -1;
- }
-
- if (!eglInitialize(egl_dpy, &egl_major, &egl_minor)) {
- printf("Error: eglInitialize() failed\n");
- return -1;
- }
-
- s = eglQueryString(egl_dpy, EGL_VERSION);
- printf("EGL_VERSION = %s\n", s);
-
- make_x_window(x_dpy, egl_dpy,
- "OpenVG Example", 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("VG_RENDERER = %s\n", (char *) vgGetString(VG_RENDERER));
- printf("VG_VERSION = %s\n", (char *) vgGetString(VG_VERSION));
- printf("VG_VENDOR = %s\n", (char *) vgGetString(VG_VENDOR));
- }
-
- if (init)
- init();
-
- /* Set initial projection/viewing transformation.
- * We can't be sure we'll get a ConfigureNotify event when the window
- * first appears.
- */
- if (reshape)
- reshape(winWidth, winHeight);
-
- event_loop(x_dpy, win, egl_dpy, egl_surf);
-
- eglMakeCurrent(egl_dpy, 0, 0, 0);
- 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/openvg/trivial/eglcommon.h b/progs/openvg/trivial/eglcommon.h
deleted file mode 100644
index 958dae9f98..0000000000
--- a/progs/openvg/trivial/eglcommon.h
+++ /dev/null
@@ -1,20 +0,0 @@
-#ifndef EGLCOMMON_H
-#define EGLCOMMON_H
-
-typedef void (*init_func)();
-typedef void (*reshape_func)(int, int);
-typedef void (*draw_func)();
-typedef int (*key_func)(unsigned key);
-
-
-void set_window_size(int width, int height);
-int window_width(void);
-int window_height(void);
-
-int run(int argc, char **argv,
- init_func init,
- reshape_func resh,
- draw_func draw,
- key_func key);
-
-#endif
diff --git a/progs/samples/copy.c b/progs/samples/copy.c
index 391c637d6f..353a3a2e1a 100644
--- a/progs/samples/copy.c
+++ b/progs/samples/copy.c
@@ -25,6 +25,7 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
+#include <GL/glew.h>
#include <GL/glut.h>
@@ -35,7 +36,6 @@ GLint windW, windH;
char *fileName = 0;
PPMImage *image;
-float point[3];
float zoom;
GLint x, y;
@@ -97,27 +97,27 @@ static void Mouse(int button, int state, int mouseX, int mouseY)
static void Draw(void)
{
+ GLint src[3], dst[3];
glClear(GL_COLOR_BUFFER_BIT);
- point[0] = (windW / 2) - (image->sizeX / 2);
- point[1] = (windH / 2) - (image->sizeY / 2);
- point[2] = 0;
- glRasterPos3fv(point);
+ src[0] = (int) ((windW / 2.0) - (image->sizeX / 2.0));
+ src[1] = (int) ((windH / 2.0) - (image->sizeY / 2.0));
+ src[2] = 0;
+ glWindowPos3ivARB(src);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glPixelZoom(1.0, 1.0);
glDrawPixels(image->sizeX, image->sizeY, GL_RGB, GL_UNSIGNED_BYTE,
image->data);
- point[0] = (float)x;
- point[1] = windH - (float)y;
- point[2] = 0.0;
- glRasterPos3fv(point);
+ dst[0] = x;
+ dst[1] = windH - y;
+ dst[2] = 0;
+ glWindowPos3ivARB(dst);
glPixelZoom(zoom, zoom);
- glCopyPixels((windW/2)-(image->sizeX/2),
- (windH/2)-(image->sizeY/2),
+ glCopyPixels(src[0], src[1],
image->sizeX, image->sizeY, GL_COLOR);
glFlush();
@@ -170,8 +170,8 @@ int main(int argc, char **argv)
image = LoadPPM(fileName);
- windW = 300;
- windH = 300;
+ windW = 2*300;
+ windH = 2*300;
glutInitWindowPosition(0, 0); glutInitWindowSize( windW, windH);
type = GLUT_RGB;
@@ -182,6 +182,7 @@ int main(int argc, char **argv)
exit(1);
}
+ glewInit();
Init();
glutReshapeFunc(Reshape);
diff --git a/progs/samples/loadppm.c b/progs/samples/loadppm.c
index be056d6294..adae9b491e 100644
--- a/progs/samples/loadppm.c
+++ b/progs/samples/loadppm.c
@@ -9,7 +9,7 @@ static PPMImage *LoadPPM(const char *filename)
char buff[16];
PPMImage *result;
FILE *fp;
- int maxval;
+ int maxval, w, h;
fp = fopen(filename, "rb");
if (!fp)
@@ -37,11 +37,13 @@ static PPMImage *LoadPPM(const char *filename)
exit(1);
}
- if (fscanf(fp, "%lu %lu", &result->sizeX, &result->sizeY) != 2)
+ if (fscanf(fp, "%d %d", &w, &h) != 2)
{
fprintf(stderr, "Error loading image `%s'\n", filename);
exit(1);
}
+ result->sizeX = w;
+ result->sizeY = h;
if (fscanf(fp, "%d", &maxval) != 1)
{
diff --git a/progs/tests/fbotest1.c b/progs/tests/fbotest1.c
index 0cd7f95c35..a95fdff74c 100644
--- a/progs/tests/fbotest1.c
+++ b/progs/tests/fbotest1.c
@@ -36,8 +36,8 @@ Display( void )
/* draw to user framebuffer */
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, MyFB);
- glDrawBuffer(GL_COLOR_ATTACHMENT1_EXT);
- glReadBuffer(GL_COLOR_ATTACHMENT1_EXT);
+ glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
+ glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
@@ -161,7 +161,7 @@ Init( void )
assert(i == MyFB);
CheckError(__LINE__);
- glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT,
+ glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
GL_RENDERBUFFER_EXT, MyRB);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGB, Width, Height);
diff --git a/progs/tests/fbotest2.c b/progs/tests/fbotest2.c
index f9c506193f..faf0dd8748 100644
--- a/progs/tests/fbotest2.c
+++ b/progs/tests/fbotest2.c
@@ -33,15 +33,16 @@ CheckError(int line)
static void
Display( void )
{
- GLubyte *buffer = malloc(Width * Height * 4);
+ GLboolean copyPix = GL_FALSE;
+ GLboolean blitPix = GL_FALSE;
GLenum status;
CheckError(__LINE__);
/* draw to user framebuffer */
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, MyFB);
- glDrawBuffer(GL_COLOR_ATTACHMENT1_EXT);
- glReadBuffer(GL_COLOR_ATTACHMENT1_EXT);
+ glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
+ glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
@@ -63,16 +64,43 @@ Display( void )
glutSolidTeapot(2.0);
glPopMatrix();
- /* read from user framebuffer */
- glReadPixels(0, 0, Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
+ if (copyPix) {
+ glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, MyFB);
+ glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
+ glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0);
+ glDrawBuffer(GL_BACK);
- /* draw to window */
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
- glDisable(GL_DEPTH_TEST); /* in case window has depth buffer */
- glWindowPos2iARB(0, 0);
- glDrawPixels(Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
+ glDisable(GL_DEPTH_TEST); /* in case window has depth buffer */
+
+ glWindowPos2iARB(0, 0);
+ glCopyPixels(0, 0, Width, Height, GL_COLOR);
+ }
+ else if (blitPix) {
+ glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, MyFB);
+ glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
+ glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0);
+ glDrawBuffer(GL_BACK);
+
+ glDisable(GL_DEPTH_TEST); /* in case window has depth buffer */
+
+ glBlitFramebufferEXT(0, 0, Width, Height,
+ 0, 0, Width, Height,
+ GL_COLOR_BUFFER_BIT, GL_NEAREST);
+ }
+ else {
+ GLubyte *buffer = malloc(Width * Height * 4);
+ /* read from user framebuffer */
+ glReadPixels(0, 0, Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
+
+ /* draw to window */
+ glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
+ glDisable(GL_DEPTH_TEST); /* in case window has depth buffer */
+ glWindowPos2iARB(0, 0);
+ glDrawPixels(Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
+
+ free(buffer);
+ }
- free(buffer);
glutSwapBuffers();
CheckError(__LINE__);
}
@@ -163,7 +191,7 @@ Init( void )
glGenRenderbuffersEXT(1, &ColorRb);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, ColorRb);
assert(glIsRenderbufferEXT(ColorRb));
- glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT,
+ glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
GL_RENDERBUFFER_EXT, ColorRb);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGB, Width, Height);
diff --git a/progs/tests/fbotest3.c b/progs/tests/fbotest3.c
index 8e288b38b8..c176f82d2b 100644
--- a/progs/tests/fbotest3.c
+++ b/progs/tests/fbotest3.c
@@ -50,8 +50,8 @@ Display( void )
/* draw to user framebuffer */
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, MyFB);
- glDrawBuffer(GL_COLOR_ATTACHMENT1_EXT);
- glReadBuffer(GL_COLOR_ATTACHMENT1_EXT);
+ glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
+ glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
@@ -189,7 +189,7 @@ Init( void )
glGenRenderbuffersEXT(1, &ColorRb);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, ColorRb);
assert(glIsRenderbufferEXT(ColorRb));
- glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT,
+ glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
GL_RENDERBUFFER_EXT, ColorRb);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGB, Width, Height);
diff --git a/progs/tests/stencil_twoside.c b/progs/tests/stencil_twoside.c
index 7d871e5877..1010139a20 100644
--- a/progs/tests/stencil_twoside.c
+++ b/progs/tests/stencil_twoside.c
@@ -26,7 +26,7 @@
* \file stencil_twoside.c
*
* Simple test of GL_ATI_separate_stencil (or the OGL 2.0 equivalent) functionality.
- * Four squares are drawn
+ * Five squares (or six if stencil wrap is available) are drawn
* with different stencil modes, but all should be rendered with the same
* final color.
*/
@@ -37,7 +37,7 @@
#include <GL/glut.h>
static int use20syntax = 1;
-static int Width = 550;
+static int Width = 650;
static int Height = 200;
static const GLfloat Near = 5.0, Far = 25.0;
@@ -70,7 +70,7 @@ static void Display( void )
*/
glDisable(GL_STENCIL_TEST);
- glTranslatef(-6.0, 0, 0);
+ glTranslatef(-7.0, 0, 0);
glBegin(GL_QUADS);
glColor3f( 0.5, 0.5, 0.5 );
glVertex2f(-1, -1);
@@ -85,6 +85,9 @@ static void Display( void )
/* Draw the first two squares using incr for the affected face
*/
+ /*************************************************************************
+ * 2nd square
+ */
if (use20syntax) {
stencil_func_separate(GL_FRONT, GL_ALWAYS, 0, ~0);
stencil_func_separate(GL_BACK, GL_ALWAYS, 0, ~0);
@@ -98,8 +101,8 @@ static void Display( void )
glTranslatef(3.0, 0, 0);
glBegin(GL_QUADS);
glColor3f( 0.9, 0.9, 0.9 );
- /* this should be front facing */
for ( i = 0 ; i < (max_stencil + 5) ; i++ ) {
+ /* this should be front facing */
glVertex2f(-1, -1);
glVertex2f( 1, -1);
glVertex2f( 1, 1);
@@ -107,6 +110,7 @@ static void Display( void )
}
glEnd();
+ /* stencil vals should be equal to max_stencil */
glStencilFunc(GL_EQUAL, max_stencil, ~0);
glBegin(GL_QUADS);
glColor3f( 0.5, 0.5, 0.5 );
@@ -116,6 +120,9 @@ static void Display( void )
glVertex2f(-1, 1);
glEnd();
+ /*************************************************************************
+ * 3rd square
+ */
if (use20syntax) {
stencil_func_separate(GL_FRONT, GL_ALWAYS, 0, ~0);
stencil_func_separate(GL_BACK, GL_ALWAYS, 0, ~0);
@@ -129,9 +136,8 @@ static void Display( void )
glTranslatef(3.0, 0, 0);
glBegin(GL_QUADS);
glColor3f( 0.9, 0.9, 0.9 );
-
- /* this should be back facing */
for ( i = 0 ; i < (max_stencil + 5) ; i++ ) {
+ /* this should be back facing */
glVertex2f(-1, -1);
glVertex2f(-1, 1);
glVertex2f( 1, 1);
@@ -139,6 +145,7 @@ static void Display( void )
}
glEnd();
+ /* stencil vals should be equal to max_stencil */
glStencilFunc(GL_EQUAL, max_stencil, ~0);
glBegin(GL_QUADS);
glColor3f( 0.5, 0.5, 0.5 );
@@ -148,6 +155,9 @@ static void Display( void )
glVertex2f(-1, 1);
glEnd();
+ /*************************************************************************
+ * 4th square
+ */
if (use20syntax) {
stencil_func_separate(GL_FRONT, GL_NEVER, 0, ~0);
stencil_func_separate(GL_BACK, GL_ALWAYS, 0, ~0);
@@ -161,15 +171,13 @@ static void Display( void )
glTranslatef(3.0, 0, 0);
glBegin(GL_QUADS);
glColor3f( 0.9, 0.9, 0.9 );
-
- /* this should be back facing */
for ( i = 0 ; i < (max_stencil + 5) ; i++ ) {
- /* this should be back facing */
+ /* this should be back facing */
glVertex2f(-1, -1);
glVertex2f(-1, 1);
glVertex2f( 1, 1);
glVertex2f( 1, -1);
- /* this should be front facing */
+ /* this should be front facing */
glVertex2f(-1, -1);
glVertex2f( 1, -1);
glVertex2f( 1, 1);
@@ -177,6 +185,7 @@ static void Display( void )
}
glEnd();
+ /* stencil vals should be equal to max_stencil */
glStencilFunc(GL_EQUAL, max_stencil, ~0);
glBegin(GL_QUADS);
glColor3f( 0.5, 0.5, 0.5 );
@@ -186,6 +195,9 @@ static void Display( void )
glVertex2f(-1, 1);
glEnd();
+ /*************************************************************************
+ * 5th square
+ */
if (use20syntax) {
stencil_func_separate(GL_FRONT, GL_ALWAYS, 0, ~0);
stencil_func_separate(GL_BACK, GL_ALWAYS, 0, ~0);
@@ -193,21 +205,19 @@ static void Display( void )
else {
stencil_func_separate_ati(GL_ALWAYS, GL_ALWAYS, 0, ~0);
}
- stencil_op_separate(GL_FRONT, GL_KEEP, GL_KEEP, GL_DECR);
- stencil_op_separate(GL_BACK, GL_KEEP, GL_KEEP, GL_INCR);
+ stencil_op_separate(GL_FRONT, GL_KEEP, GL_KEEP, GL_INCR);
+ stencil_op_separate(GL_BACK, GL_KEEP, GL_KEEP, GL_DECR);
glTranslatef(3.0, 0, 0);
glBegin(GL_QUADS);
glColor3f( 0.9, 0.9, 0.9 );
-
- /* this should be back facing */
for ( i = 0 ; i < (max_stencil + 5) ; i++ ) {
- /* this should be back facing */
+ /* this should be back facing */
glVertex2f(-1, -1);
glVertex2f(-1, 1);
glVertex2f( 1, 1);
glVertex2f( 1, -1);
- /* this should be front facing */
+ /* this should be front facing */
glVertex2f(-1, -1);
glVertex2f( 1, -1);
glVertex2f( 1, 1);
@@ -224,6 +234,47 @@ static void Display( void )
glVertex2f(-1, 1);
glEnd();
+ /*************************************************************************
+ * 6th square
+ */
+ if (glutExtensionSupported("GL_EXT_stencil_wrap")) {
+ if (use20syntax) {
+ stencil_func_separate(GL_FRONT, GL_ALWAYS, 0, ~0);
+ stencil_func_separate(GL_BACK, GL_ALWAYS, 0, ~0);
+ }
+ else {
+ stencil_func_separate_ati(GL_ALWAYS, GL_ALWAYS, 0, ~0);
+ }
+ stencil_op_separate(GL_FRONT, GL_KEEP, GL_KEEP, GL_KEEP);
+ stencil_op_separate(GL_BACK, GL_KEEP, GL_KEEP, GL_INCR_WRAP);
+
+ glTranslatef(3.0, 0, 0);
+ glBegin(GL_QUADS);
+ glColor3f( 0.9, 0.9, 0.9 );
+ for ( i = 0 ; i < (max_stencil + 5) ; i++ ) {
+ /* this should be back facing */
+ glVertex2f(-1, -1);
+ glVertex2f(-1, 1);
+ glVertex2f( 1, 1);
+ glVertex2f( 1, -1);
+ /* this should be front facing */
+ glVertex2f(-1, -1);
+ glVertex2f( 1, -1);
+ glVertex2f( 1, 1);
+ glVertex2f(-1, 1);
+ }
+ glEnd();
+
+ glStencilFunc(GL_EQUAL, 260 - 255, ~0);
+ glBegin(GL_QUADS);
+ glColor3f( 0.5, 0.5, 0.5 );
+ glVertex2f(-1, -1);
+ glVertex2f( 1, -1);
+ glVertex2f( 1, 1);
+ glVertex2f(-1, 1);
+ glEnd();
+ }
+
glPopMatrix();
glutSwapBuffers();
@@ -278,7 +329,7 @@ static void Init( void )
stencil_func_separate_ati = (PFNGLSTENCILFUNCSEPARATEATIPROC) glutGetProcAddress( "glStencilFuncSeparateATI" );
stencil_op_separate = (PFNGLSTENCILOPSEPARATEPROC) glutGetProcAddress( "glStencilOpSeparate" );
- printf("\nAll 5 squares should be the same color.\n");
+ printf("\nAll 5 (or 6) squares should be the same color.\n");
}
diff --git a/progs/trivial/Makefile b/progs/trivial/Makefile
index b4a903cb68..a10748f948 100644
--- a/progs/trivial/Makefile
+++ b/progs/trivial/Makefile
@@ -11,6 +11,7 @@ include $(TOP)/configs/current
LIBS = -L$(TOP)/$(LIB_DIR) -l $(GLEW_LIB) -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) $(APP_LIB_DEPS)
SOURCES = \
+ clear-fbo-scissor.c \
clear-fbo-tex.c \
clear-fbo.c \
clear-scissor.c \
diff --git a/progs/trivial/SConscript b/progs/trivial/SConscript
index f480da047e..24b4f91fb0 100644
--- a/progs/trivial/SConscript
+++ b/progs/trivial/SConscript
@@ -1,7 +1,8 @@
Import('*')
progs = [
- 'clear-fbo-tex',
+ 'clear-fbo-scissor',
+ 'clear-fbo-tex',
'clear-fbo',
'clear-scissor',
'clear-undefined',
diff --git a/progs/trivial/clear-fbo-scissor.c b/progs/trivial/clear-fbo-scissor.c
new file mode 100644
index 0000000000..6a605e16a8
--- /dev/null
+++ b/progs/trivial/clear-fbo-scissor.c
@@ -0,0 +1,234 @@
+/*
+ * Use scissor to clear the four quadrants of the FBO to different
+ * colors. Then draw a grey triangle in the middle.
+ */
+
+
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include <string.h>
+#include <GL/glew.h>
+#include <GL/glut.h>
+#include <GL/glu.h>
+
+
+static int Width = 512, Height = 512;
+static GLuint MyFB, MyRB;
+static GLboolean UseTex = GL_FALSE;
+static GLboolean UseCopyPix = GL_FALSE;
+
+
+#define CheckError() \
+ do { \
+ GLenum err = glGetError(); \
+ if (err != GL_NO_ERROR) \
+ printf("Error: %s\n", gluErrorString(err)); \
+ assert(err == GL_NO_ERROR); \
+ } while (0)
+
+
+static void
+Init(void)
+{
+ GLenum status;
+
+ 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);
+
+ if (!glutExtensionSupported("GL_EXT_framebuffer_object")) {
+ printf("GL_EXT_framebuffer_object not found!\n");
+ exit(0);
+ }
+
+ glGenFramebuffersEXT(1, &MyFB);
+ glGenRenderbuffersEXT(1, &MyRB);
+
+ glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, MyFB);
+
+ if (UseTex) {
+ GLuint tex;
+ glGenTextures(1, &tex);
+ glBindTexture(GL_TEXTURE_2D, tex);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Width, Height, 0,
+ GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
+ GL_COLOR_ATTACHMENT0_EXT,
+ GL_TEXTURE_2D, tex, 0);
+ }
+ else {
+ glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, MyRB);
+
+ glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,
+ GL_COLOR_ATTACHMENT0_EXT,
+ GL_RENDERBUFFER_EXT, MyRB);
+
+ glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGB, Width, Height);
+ }
+
+ status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
+ if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
+ fprintf(stderr, "Framebuffer object is incomplete (0x%x)!\n", status);
+ }
+
+ glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
+}
+
+
+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, -1.0, 1.0);
+ glMatrixMode(GL_MODELVIEW);
+
+ Width = width;
+ Height = height;
+ if (!UseTex) {
+ glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGB, Width, Height);
+ }
+}
+
+
+static void
+Key(unsigned char key, int x, int y)
+{
+ if (key == 27) {
+ exit(0);
+ }
+ glutPostRedisplay();
+}
+
+
+static void
+Draw(void)
+{
+ GLboolean scissor = GL_TRUE;
+
+ /* draw to user framebuffer */
+ glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, MyFB);
+ glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
+ glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
+
+ glViewport(0, 0, Width, Height);
+ CheckError();
+
+ if (scissor) {
+ glEnable(GL_SCISSOR_TEST);
+
+ /* lower-left = red */
+ glClearColor(1, 0, 0, 0);
+ glScissor(0, 0, Width / 2, Height / 2);
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ /* lower-right = green */
+ glClearColor(0, 1, 0, 0);
+ glScissor(Width / 2, 0, Width - Width / 2, Height / 2);
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ /* upper-left = blue */
+ glClearColor(0, 0, 1, 0);
+ glScissor(0, Height / 2, Width / 2, Height - Height / 2);
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ /* upper-right = white */
+ glClearColor(1, 1, 1, 0);
+ glScissor(Width / 2, Height / 2, Width - Width / 2, Height - Height / 2);
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ glDisable(GL_SCISSOR_TEST);
+ }
+ else {
+ glClearColor(0, 1, 0, 0);
+ glClear(GL_COLOR_BUFFER_BIT);
+ }
+
+ CheckError();
+
+ /* gray triangle in middle, pointing up */
+ glColor3f(0.5, 0.5, 0.5);
+ glBegin(GL_TRIANGLES);
+ glVertex2f(Width/4, Height/4);
+ glVertex2f(Width*3/4, Height/4);
+ glVertex2f(Width/2, Height*3/4);
+ glVertex2f(-0.5, -0.5);
+ glVertex2f(+0.5, -0.5);
+ glVertex2f( 0.0, 0.7);
+ glEnd();
+
+ CheckError();
+
+ /* copy fbo to window */
+ glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, MyFB);
+ glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
+ glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0);
+ glDrawBuffer(GL_BACK);
+
+ if (UseCopyPix) {
+ glWindowPos2i(0, 0);
+ glCopyPixels(0, 0, Width, Height, GL_COLOR);
+ }
+ else {
+ GLubyte *buffer = malloc(Width * Height * 4);
+
+ /* read from user framebuffer */
+ glReadPixels(0, 0, Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
+
+ /* draw to window */
+ glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
+ glWindowPos2iARB(0, 0);
+ glDrawPixels(Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
+
+ free(buffer);
+ }
+
+ /* Bind normal framebuffer */
+ glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
+
+ glutSwapBuffers();
+
+ CheckError();
+}
+
+
+int
+main(int argc, char *argv[])
+{
+ int i;
+
+ glutInit(&argc, argv);
+ glutInitWindowPosition(100, 0);
+ glutInitWindowSize(Width, Height);
+ glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
+
+ for (i = 1; i < argc; i++) {
+ if (strcmp(argv[i], "-t") == 0)
+ UseTex = GL_TRUE;
+ else if (strcmp(argv[i], "-c") == 0)
+ UseCopyPix = GL_TRUE;
+ }
+
+ if (UseTex)
+ printf("Using render to texture\n");
+ else
+ printf("Using user-created render buffer\n");
+
+ if (!glutCreateWindow(argv[0])) {
+ exit(1);
+ }
+
+ glewInit();
+ Init();
+ glutReshapeFunc(Reshape);
+ glutKeyboardFunc(Key);
+ glutDisplayFunc(Draw);
+ glutMainLoop();
+ return 0;
+}
diff --git a/progs/trivial/tri-stencil.c b/progs/trivial/tri-stencil.c
index 9f68bca914..d66b68c415 100644
--- a/progs/trivial/tri-stencil.c
+++ b/progs/trivial/tri-stencil.c
@@ -77,6 +77,7 @@ static void Draw(void)
glStencilFunc(GL_ALWAYS, 1, 1);
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
+ /* red triangle (setting stencil to 1) */
glColor3ub(200, 0, 0);
glBegin(GL_POLYGON);
glVertex3i(-4, -4, 0);
@@ -88,6 +89,7 @@ static void Draw(void)
glStencilFunc(GL_EQUAL, 1, 1);
glStencilOp(GL_INCR, GL_KEEP, GL_DECR);
+ /* green quad (if over red, decr stencil to 0, else incr to 1) */
glColor3ub(0, 200, 0);
glBegin(GL_POLYGON);
glVertex3i(3, 3, 0);
@@ -101,6 +103,7 @@ static void Draw(void)
glStencilFunc(GL_EQUAL, 1, 1);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
+ /* blue quad (where stencil == 1) */
glColor3ub(0, 0, 200);
glBegin(GL_POLYGON);
glVertex3f(2.5, 2.5, 0);
diff --git a/progs/xdemos/Makefile b/progs/xdemos/Makefile
index d81caab4dd..2663015b2c 100644
--- a/progs/xdemos/Makefile
+++ b/progs/xdemos/Makefile
@@ -9,9 +9,9 @@ INCDIR = $(TOP)/include
LIB_DEP = $(TOP)/$(LIB_DIR)/$(GL_LIB_NAME)
# Add X11 and pthread libs to satisfy GNU gold.
-APP_LIB_DEPS += -lX11 -lpthread
+APP_LIB_DEPS += $(X11_LIBS) -lpthread
-LIBS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) -L$(libdir) $(APP_LIB_DEPS)
+LIBS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) $(APP_LIB_DEPS)
PROGS = \
corender \
diff --git a/progs/xdemos/omlsync.c b/progs/xdemos/omlsync.c
index a2baf4ad72..061d6c6861 100644
--- a/progs/xdemos/omlsync.c
+++ b/progs/xdemos/omlsync.c
@@ -249,11 +249,13 @@ int main(int argc, char *argv[])
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glRectf(0, 0, width, height);
- glXSwapBuffersMscOML(disp, winGL, 0, divisor, remainder);
-
- if (wait_interval) {
+ if (!wait_interval)
+ glXSwapBuffersMscOML(disp, winGL, 0, divisor,
+ remainder);
+ else {
glXWaitForMscOML(disp, winGL, msc + wait_interval,
- 0, 0, &ust, &msc, &sbc);
+ divisor, remainder, &ust, &msc, &sbc);
+ glXSwapBuffersMscOML(disp, winGL, 0, 0, 0);
}
}