Commit 6ca33468 authored by Nicolai Hähnle's avatar Nicolai Hähnle
Browse files

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 Hähnle's avatarNicolai Haehnle <nhaehnle@gmail.com>
parent 047697a8
......@@ -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'])
......
......@@ -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)
......
/**
* @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;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment