summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolai Haehnle <nhaehnle@gmail.com>2009-02-14 21:40:34 +0100
committerNicolai Haehnle <nhaehnle@gmail.com>2009-02-14 21:40:34 +0100
commit6ca33468f716d996ccadf3887ab4f5046738228b (patch)
treebbf31c757152dc002d87be267820b3f52f91ec2c
parent047697a835e67ccbbd6aa5713dd8ff013303443c (diff)
New test: getteximage-simple
Upload a texture with random data, use it in rendering, and attempt to read the texture data back with glGetTexImage. This catches yet another r300+bufmgr regression that was found via Sauerbraten. Signed-off-by: Nicolai Haehnle <nhaehnle@gmail.com>
-rw-r--r--tests/all.tests1
-rw-r--r--tests/texturing/CMakeLists.txt1
-rw-r--r--tests/texturing/getteximage-simple.c132
3 files changed, 134 insertions, 0 deletions
diff --git a/tests/all.tests b/tests/all.tests
index 1b047b6e8..5bdab7052 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -91,6 +91,7 @@ texturing['copytexsubimage'] = PlainExecTest([testBinDir + 'copytexsubimage', '-
texturing['cubemap'] = PlainExecTest([testBinDir + 'cubemap', '-auto'])
texturing['gen-teximage'] = PlainExecTest([testBinDir + 'gen-teximage', '-auto'])
texturing['gen-texsubimage'] = PlainExecTest([testBinDir + 'gen-texsubimage', '-auto'])
+texturing['getteximage-simple'] = PlainExecTest([testBinDir + 'getteximage-simple', '-auto'])
texturing['lodbias'] = PlainExecTest([testBinDir + 'lodbias', '-auto'])
texturing['tex3d'] = PlainExecTest([testBinDir + 'tex3d'])
texturing['texdepth'] = PlainExecTest([testBinDir + 'texdepth', '-auto'])
diff --git a/tests/texturing/CMakeLists.txt b/tests/texturing/CMakeLists.txt
index 482b080f2..783b7af45 100644
--- a/tests/texturing/CMakeLists.txt
+++ b/tests/texturing/CMakeLists.txt
@@ -22,6 +22,7 @@ add_executable (copytexsubimage copytexsubimage.c)
add_executable (cubemap cubemap.c)
add_executable (gen-teximage gen-teximage.c)
add_executable (gen-texsubimage gen-texsubimage.c)
+add_executable (getteximage-simple getteximage-simple.c)
add_executable (lodbias lodbias.c)
add_executable (tex3d tex3d.c)
add_executable (texdepth texdepth.c)
diff --git a/tests/texturing/getteximage-simple.c b/tests/texturing/getteximage-simple.c
new file mode 100644
index 000000000..d2e823e02
--- /dev/null
+++ b/tests/texturing/getteximage-simple.c
@@ -0,0 +1,132 @@
+/**
+ * @file getteximage-simple.c
+ *
+ * Extremely basic test to check whether image data can be retrieved.
+ *
+ * Note that the texture is used in a full frame of rendering before
+ * the readback, to ensure that buffer manager related code for uploading
+ * texture images is executed before the readback.
+ *
+ * This used to crash for R300+bufmgr.
+ */
+
+#include "GL/glut.h"
+#include <assert.h>
+#include <string.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <math.h>
+
+#include "piglit-util.h"
+
+
+static int Automatic = 0;
+static int Width = 100, Height = 100;
+static GLubyte data[4096]; /* 64*16*4 */
+
+static int test_getteximage()
+{
+ GLubyte compare[4096];
+ int i;
+
+ glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, compare);
+
+ for(i = 0; i < 4096; ++i) {
+ if (data[i] != compare[i]) {
+ printf("GetTexImage() returns incorrect data in byte %i\n", i);
+ printf(" corresponding to (%i,%i) channel %i\n", i / 64, (i / 4) % 16, i % 4);
+ printf(" expected: %i\n", data[i]);
+ printf(" got: %i\n", compare[i]);
+ return 0;
+ }
+ }
+
+ return 1;
+}
+
+
+static void Display(void)
+{
+ int succ;
+
+ glClearColor(0.0, 0.0, 0.0, 1.0);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ glEnable(GL_TEXTURE_2D);
+ glBegin(GL_QUADS);
+ glTexCoord2f(0, 0);
+ glVertex2f(0, 0);
+ glTexCoord2f(1, 0);
+ glVertex2f(1, 0);
+ glTexCoord2f(1, 1);
+ glVertex2f(1, 1);
+ glTexCoord2f(0, 1);
+ glVertex2f(0, 1);
+ glEnd();
+
+ glutSwapBuffers();
+
+ succ = test_getteximage();
+ if (Automatic)
+ piglit_report_result(succ ? PIGLIT_SUCCESS : PIGLIT_FAILURE);
+}
+
+static void Reshape(int width, int height)
+{
+ Width = width;
+ Height = height;
+ glViewport(0, 0, width, height);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glOrtho(0.0, 1.0, 0.0, 1.0, -2.0, 6.0);
+ glScalef(1.0, 1.0, -1.0); // flip z-axis
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+}
+
+
+static void Key(unsigned char key, int x, int y)
+{
+ (void) x;
+ (void) y;
+ switch (key) {
+ case 27:
+ exit(0);
+ break;
+ }
+ glutPostRedisplay();
+}
+
+
+
+static void init()
+{
+ int i;
+
+ for(i = 0; i < 4096; ++i)
+ data[i] = rand() & 0xff;
+
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 64, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
+
+ Reshape(Width, Height);
+}
+
+
+int main(int argc, char**argv)
+{
+ glutInit(&argc, argv);
+ if (argc == 2 && !strcmp(argv[1], "-auto"))
+ Automatic = 1;
+ glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
+ glutInitWindowSize(Width, Height);
+ glutCreateWindow(argv[0]);
+ glutReshapeFunc(Reshape);
+ glutKeyboardFunc(Key);
+ glutDisplayFunc(Display);
+ init();
+ glutMainLoop();
+ return 0;
+}