tests/getteximage: test more texture sizes, including npot

This commit is contained in:
Brian Paul 2009-08-04 16:17:09 -06:00
parent a746ef28df
commit cd7a8225e8
1 changed files with 86 additions and 50 deletions

View File

@ -15,7 +15,7 @@ static int Win;
static void static void
TestGetTexImage(void) TestGetTexImage(GLboolean npot)
{ {
GLuint iter; GLuint iter;
GLubyte *data = (GLubyte *) malloc(1024 * 1024 * 4); GLubyte *data = (GLubyte *) malloc(1024 * 1024 * 4);
@ -27,8 +27,8 @@ TestGetTexImage(void)
for (iter = 0; iter < 8; iter++) { for (iter = 0; iter < 8; iter++) {
GLint p = (iter % 8) + 3; GLint p = (iter % 8) + 3;
GLint w = (1 << p); GLint w = npot ? (p * 20) : (1 << p);
GLint h = (1 << p); GLint h = npot ? (p * 10) : (1 << p);
GLuint i; GLuint i;
GLint level = 0; GLint level = 0;
@ -83,14 +83,27 @@ ColorsEqual(const GLubyte ref[4], const GLubyte act[4])
static void static void
TestGetTexImageRTT(void) TestGetTexImageRTT(GLboolean npot)
{ {
GLuint iter; GLuint iter;
printf("Render to texture + glGetTexImage:\n");
for (iter = 0; iter < 8; iter++) {
GLuint fb, tex; GLuint fb, tex;
GLint w = 512; GLint w, h;
GLint h = 256;
GLint level = 0; GLint level = 0;
if (npot) {
w = 200 + iter * 40;
h = 200 + iter * 12;
}
else {
w = 4 << iter;
h = 4 << iter;
}
glGenTextures(1, &tex); glGenTextures(1, &tex);
glGenFramebuffersEXT(1, &fb); glGenFramebuffersEXT(1, &fb);
@ -104,9 +117,11 @@ TestGetTexImageRTT(void)
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
GL_TEXTURE_2D, tex, level); GL_TEXTURE_2D, tex, level);
printf("Render to texture + glGetTexImage:\n"); glViewport(0, 0, w, h);
printf(" Testing %d x %d tex image\n", w, h); printf(" Testing %d x %d tex image\n", w, h);
for (iter = 0; iter < 8; iter++) { {
static const GLubyte blue[4] = {0, 0, 255, 255};
GLubyte color[4]; GLubyte color[4];
GLubyte *data2 = (GLubyte *) malloc(w * h * 4); GLubyte *data2 = (GLubyte *) malloc(w * h * 4);
GLuint i; GLuint i;
@ -123,16 +138,30 @@ TestGetTexImageRTT(void)
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
/* draw polygon over top half, in blue */
glColor4ubv(blue);
glRectf(0, 0.5, 1.0, 1.0);
/* get */ /* get */
glGetTexImage(GL_TEXTURE_2D, level, GL_RGBA, GL_UNSIGNED_BYTE, data2); glGetTexImage(GL_TEXTURE_2D, level, GL_RGBA, GL_UNSIGNED_BYTE, data2);
/* compare */ /* compare */
for (i = 0; i < w * h; i += 4) { for (i = 0; i < w * h; i += 4) {
if (i < w * h / 2) {
/* lower half */
if (!ColorsEqual(color, data2 + i * 4)) { if (!ColorsEqual(color, data2 + i * 4)) {
printf("Render to texture failure!\n"); printf("Render to texture failure (expected clear color)!\n");
abort(); abort();
} }
} }
else {
/* upper half */
if (!ColorsEqual(blue, data2 + i * 4)) {
printf("Render to texture failure (expected blue)!\n");
abort();
}
}
}
free(data2); free(data2);
} }
@ -141,6 +170,8 @@ TestGetTexImageRTT(void)
glDeleteFramebuffersEXT(1, &fb); glDeleteFramebuffersEXT(1, &fb);
glDeleteTextures(1, &tex); glDeleteTextures(1, &tex);
}
printf("Passed\n"); printf("Passed\n");
} }
@ -152,11 +183,16 @@ Draw(void)
{ {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
TestGetTexImage(); TestGetTexImage(GL_FALSE);
if (glutExtensionSupported("GL_ARB_texture_non_power_of_two"))
TestGetTexImage(GL_TRUE);
if (glutExtensionSupported("GL_EXT_framebuffer_object") || if (glutExtensionSupported("GL_EXT_framebuffer_object") ||
glutExtensionSupported("GL_ARB_framebuffer_object")) glutExtensionSupported("GL_ARB_framebuffer_object")) {
TestGetTexImageRTT(); TestGetTexImageRTT(GL_FALSE);
if (glutExtensionSupported("GL_ARB_texture_non_power_of_two"))
TestGetTexImageRTT(GL_TRUE);
}
glutDestroyWindow(Win); glutDestroyWindow(Win);
exit(0); exit(0);
@ -171,10 +207,10 @@ Reshape(int width, int height)
glViewport(0, 0, width, height); glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glLoadIdentity(); glLoadIdentity();
glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0); glOrtho(0, 1, 0, 1, -1, 1);
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); glLoadIdentity();
glTranslatef(0.0, 0.0, -15.0); glTranslatef(0.0, 0.0, 0.0);
} }