[Piglit] [PATCH] copyteximage: Add testing for all texture targets and internal formats
Anuj Phogat
anuj.phogat at gmail.com
Mon Mar 26 15:15:42 PDT 2012
Signed-off-by: Anuj Phogat <anuj.phogat at gmail.com>
---
tests/texturing/copyteximage.c | 349 ++++++++++++++++++++++++++++------------
1 files changed, 248 insertions(+), 101 deletions(-)
diff --git a/tests/texturing/copyteximage.c b/tests/texturing/copyteximage.c
index e358f67..5b2b0cd 100644
--- a/tests/texturing/copyteximage.c
+++ b/tests/texturing/copyteximage.c
@@ -21,128 +21,275 @@
* IN THE SOFTWARE.
*/
-/**
- * Basic test of glCopyTexImage() for various internal formats.
+/*
+ * file copyteximage.c
+ *
+ * Test to verify functionality of glCopyTexImage() with various texture
+ * targets and texture internal formats.
*/
#include "piglit-util.h"
-#define TEX_SIZE 64
+#define TEX_SIZE 16
-static const GLenum formats[] = { GL_RGBA, GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_INTENSITY };
+int piglit_window_mode = GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_ALPHA;
-#define NUM_FORMATS (sizeof(formats) / sizeof(formats[0]))
+static const GLfloat fcolor[8][4] = {
+ /* GL_RED */
+ {0.5, 0.0, 0.0, 1.0},
+ /* GL_RG */
+ {0.5, 0.2, 0.0, 1.0},
+ /* GL_RGB */
+ {0.5, 0.2, 0.8, 1.0},
+ /* GL_RGBA8, GL_RGBA16, GL_RGBA16F, GL_RGBA32F */
+ {0.5, 0.2, 0.8, 0.4},
+ /* GL_LUMINANCE */
+ {0.5, 0.5, 0.5, 1},
+ /* GL_LUMINANCE_ALPHA */
+ {0.5, 0.5, 0.5, 0.4},
+ /* GL_INTENSITY */
+ {0.5, 0.5, 0.5, 0.5},
+ /* GL_DEPTH_COMPONENT */
+ {0.75, 0.75, 0.75, 1.0} };
-int piglit_width = TEX_SIZE*(NUM_FORMATS+1), piglit_height = TEX_SIZE;
-int piglit_window_mode = GLUT_DOUBLE | GLUT_RGB;
+static const struct {
+ GLenum format;
+ const GLvoid *expected;
+} test_vectors[] = {
+ { GL_RED, fcolor[0] },
+ { GL_RG, fcolor[1] },
+ /* Clamps the color values to [0, 1] */
+ { GL_RGB8, fcolor[2] },
+ { GL_RGB16, fcolor[2] },
-static GLboolean
-test(void)
-{
- static const GLfloat expected[NUM_FORMATS][2][4] = {
- /* GL_RGBA */
- {
- {0, 0, 0, 0},
- {1, 1, 1, 1}
- },
- /* GL_LUMINANCE */
- {
- {0, 0, 0, 0},
- {1, 1, 1, 1}
- },
- /* GL_LUMINANCE_ALPHA */
- {
- {0, 0, 0, 0},
- {1, 1, 1, 1}
- },
- /* GL_INTENSITY */
- {
- {0, 0, 0, 0},
- {1, 1, 1, 1}
- }
- };
- GLubyte buf[TEX_SIZE][TEX_SIZE][4];
- GLuint tex;
- GLboolean pass = GL_TRUE;
- int i, j;
-
- for (i = 0; i < TEX_SIZE; i++) {
- for (j = 0; j < TEX_SIZE; j++) {
- buf[i][j][0] = (i * 255) / (TEX_SIZE - 1);
- buf[i][j][1] = (j * 255) / (TEX_SIZE - 1);
- buf[i][j][2] = (buf[i][j][0] * buf[i][j][1]) / 255;
- buf[i][j][3] = 255;
- }
- }
+ /* Don't clamp color values to [0, 1] */
+ { GL_RGB16F, fcolor[2] },
+ { GL_RGB32F, fcolor[2] },
- /* glDrawPixels the image on left */
- glWindowPos2iARB(0, 0);
- glDrawPixels(TEX_SIZE, TEX_SIZE, GL_RGBA, GL_UNSIGNED_BYTE, buf);
-
- glGenTextures(1, &tex);
- glBindTexture(GL_TEXTURE_2D, tex);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-
- /* Do glCopyPixels and draw a texture quad for each format */
- for (i = 0; i < NUM_FORMATS; i++) {
- GLint x = TEX_SIZE * (i + 1);
- GLint y = 0;
- GLenum intFormat = formats[i];
-
- glCopyTexImage2D(GL_TEXTURE_2D, 0, intFormat, 0, 0, TEX_SIZE, TEX_SIZE, 0);
- if (glGetError()) {
- printf("Unexpected error for format 0x%x\n", intFormat);
- return GL_FALSE;
- }
-
- glViewport(x, y, TEX_SIZE, TEX_SIZE);
-
- glEnable(GL_TEXTURE_2D);
- glBegin(GL_POLYGON);
- glTexCoord2f(0, 0);
- glVertex2f(-1, -1);
- glTexCoord2f(1, 0);
- glVertex2f(1, -1);
- glTexCoord2f(1, 1);
- glVertex2f(1, 1);
- glTexCoord2f(0, 1);
- glVertex2f(-1, 1);
- glEnd();
-
- glDisable(GL_TEXTURE_2D);
-
- /* test lower-left pixel */
- if (!piglit_probe_pixel_rgb(x, y, expected[i][0]))
- pass = GL_FALSE;
- /* test upper-right pixel */
- if (!piglit_probe_pixel_rgb(x + TEX_SIZE - 1, y + TEX_SIZE - 1, expected[i][1]))
- pass = GL_FALSE;
- }
+ /* Clamps the color values to [0, 1] */
+ { GL_RGBA8, fcolor[3] },
+ { GL_RGBA16, fcolor[3] },
- glutSwapBuffers();
+ /* Don't clamp color values to [0, 1] */
+ { GL_RGBA16F, fcolor[3] },
+ { GL_RGBA32F, fcolor[3] },
- return pass;
-}
+ { GL_COMPRESSED_RED, fcolor[0] },
+ { GL_COMPRESSED_RG, fcolor[1] },
+ { GL_COMPRESSED_RGB, fcolor[2] },
+ { GL_COMPRESSED_RGBA, fcolor[3] },
+
+ { GL_LUMINANCE, fcolor[4] },
+ { GL_LUMINANCE_ALPHA, fcolor[5] },
+
+ { GL_INTENSITY, fcolor[6] },
+
+ { GL_DEPTH_COMPONENT, fcolor[7] },
+ { GL_DEPTH_COMPONENT16, fcolor[7] },
+ { GL_DEPTH_COMPONENT24, fcolor[7] },
+ { GL_DEPTH_COMPONENT32F, fcolor[7] },
+};
+static const GLenum target[] = {
+ GL_TEXTURE_1D,
+ GL_TEXTURE_2D,
+ GL_TEXTURE_CUBE_MAP };
+
+#define NUM_TARGETS (sizeof(target) / sizeof(target[0]))
+#define NUM_FORMATS (sizeof(test_vectors) / sizeof(test_vectors[0]))
+
+int piglit_width = TEX_SIZE * (NUM_FORMATS + 1), piglit_height = TEX_SIZE;
+static const float texCoords_1d[2] = { 0.0, 1.0 };
+static const float texCoords_2d[4][2] = {
+ { 0.0, 0.0 },
+ { 1.0, 0.0 },
+ { 1.0, 1.0 },
+ { 0.0, 1.0 } };
+
+GLboolean
+is_compressed_format(GLenum format)
+{
+ switch (format) {
+ case GL_COMPRESSED_RED:
+ case GL_COMPRESSED_RG:
+ case GL_COMPRESSED_RGB:
+ case GL_COMPRESSED_RGBA:
+ return GL_TRUE;
+ default:
+ return GL_FALSE;
+ }
+}
enum piglit_result
piglit_display(void)
{
- if (test())
- return PIGLIT_PASS;
- else
- return PIGLIT_FAIL;
-}
+ GLfloat buf_float_color[TEX_SIZE][TEX_SIZE][4];
+ GLuint tex;
+ GLboolean pass = GL_TRUE;
+ int i, j;
+ /* Texture data setup */
+ for (i = 0; i < TEX_SIZE; i++) {
+ for (j = 0; j < TEX_SIZE; j++) {
+ buf_float_color[i][j][0] = 0.5;
+ buf_float_color[i][j][1] = 0.2;
+ buf_float_color[i][j][2] = 0.8;
+ buf_float_color[i][j][3] = 0.4;
+ }
+ }
+
+ /* Do glCopyPixels and draw a textured rectangle for each format
+ * and each texture target
+ */
+ for (j = 0; j < NUM_TARGETS; j++) {
+
+ /* Draw a pixel rectangle with float color data. As per OpenGL 3.0
+ * specification integer formats are not allowed in glDrawPixels
+ */
+ glDrawPixels(TEX_SIZE, TEX_SIZE, GL_RGBA,
+ GL_FLOAT, buf_float_color);
+ /* Texture setup */
+ glGenTextures(1, &tex);
+ glBindTexture(target[j], tex);
+ glTexParameteri(target[j],
+ GL_TEXTURE_MIN_FILTER,
+ GL_NEAREST);
+ glTexParameteri(target[j],
+ GL_TEXTURE_MAG_FILTER,
+ GL_NEAREST);
+ glTexParameteri(target[j],
+ GL_GENERATE_MIPMAP,
+ GL_FALSE);
+
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+
+ for (i = 0; i < NUM_FORMATS; i++) {
+ GLint x = TEX_SIZE * (i + 1);
+ GLint y = 0;
+ GLfloat vertices_1d[2][2] = { {x, y},
+ {x + TEX_SIZE, y} };
+
+ if ((test_vectors[i].format == GL_RGBA16F ||
+ test_vectors[i].format == GL_RGBA32F) &&
+ !piglit_is_extension_supported("GL_ARB_texture_float"))
+ continue;
+
+ /* To avoid failures not related to this test case,
+ * loosen up the tolerence for compressed texture
+ * formats
+ */
+ if (is_compressed_format(test_vectors[i].format))
+ piglit_set_tolerance_for_bits(7, 7, 7, 7);
+ else
+ piglit_set_tolerance_for_bits(8, 8, 8, 8);
+
+ printf("Texture target = %s, Internal format = %s\n",
+ piglit_get_gl_enum_name(target[j]),
+ piglit_get_gl_enum_name(test_vectors[i].format));
+
+ switch(target[j]) {
+
+ case GL_TEXTURE_1D:
+ glCopyTexImage1D(GL_TEXTURE_1D, 0,
+ test_vectors[i].format,
+ 0, 0, TEX_SIZE, 0);
+ pass = piglit_check_gl_error(GL_NO_ERROR)
+ && pass;
+
+ glEnable(target[j]);
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glTexCoordPointer(1, GL_FLOAT, 0, texCoords_1d);
+ glVertexPointer(2, GL_FLOAT, 0, vertices_1d);
+
+ glDrawArrays(GL_LINES, 0, 2);
+ pass = piglit_probe_pixel_rgba(x, 0,
+ (const float*)test_vectors[i].expected)
+ && pass;
+ pass = piglit_probe_pixel_rgba(x +
+ TEX_SIZE - 1, 0,
+ (const float*)test_vectors[i].expected)
+ && pass;
+ break;
+
+ case GL_TEXTURE_2D:
+ glCopyTexImage2D(GL_TEXTURE_2D, 0,
+ test_vectors[i].format,
+ 0, 0, TEX_SIZE, TEX_SIZE, 0);
+ pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
+
+ glEnable(target[j]);
+ glTexCoordPointer(2, GL_FLOAT, 0, texCoords_2d);
+
+ piglit_draw_rect(x, y, TEX_SIZE, TEX_SIZE);
+ pass = piglit_probe_rect_rgba(x, y,
+ TEX_SIZE, TEX_SIZE,
+ (const float*)test_vectors[i].expected)
+ && pass;
+ break;
+
+ case GL_TEXTURE_CUBE_MAP:
+ glCopyTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X,
+ 0, test_vectors[i].format, 0, 0,
+ TEX_SIZE, TEX_SIZE, 0);
+ glCopyTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
+ 0, test_vectors[i].format, 0, 0,
+ TEX_SIZE, TEX_SIZE, 0);
+ glCopyTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
+ 0, test_vectors[i].format, 0, 0,
+ TEX_SIZE, TEX_SIZE, 0);
+ glCopyTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
+ 0, test_vectors[i].format, 0, 0,
+ TEX_SIZE, TEX_SIZE, 0);
+ glCopyTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
+ 0, test_vectors[i].format, 0, 0,
+ TEX_SIZE, TEX_SIZE, 0);
+ glCopyTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
+ 0, test_vectors[i].format, 0, 0,
+ TEX_SIZE, TEX_SIZE, 0);
+ pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
+
+ glEnable(target[j]);
+
+ /* Draw a rect with +X cubemap face as texture */
+ glTexCoordPointer(3, GL_FLOAT, 0,
+ cube_face_texcoords[0]);
+ piglit_draw_rect(x, y, TEX_SIZE, TEX_SIZE);
+ pass = piglit_probe_rect_rgba(x, y,
+ TEX_SIZE, TEX_SIZE,
+ (const float*)test_vectors[i].expected)
+ && pass;
+
+ /* Draw a rect with +Z cubemap face as texture */
+ glTexCoordPointer(3, GL_FLOAT, 0,
+ cube_face_texcoords[2]);
+ piglit_draw_rect(x, y, TEX_SIZE, TEX_SIZE);
+ pass = piglit_probe_rect_rgba(x, y,
+ TEX_SIZE, TEX_SIZE,
+ (const float*)test_vectors[i].expected)
+ && pass;
+ break;
+ }
+ glDisable(target[j]);
+ }
+ glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+ glDeleteTextures(1, &tex);
+ }
+ return (pass ? PIGLIT_PASS : PIGLIT_FAIL);
+}
void
piglit_init(int argc, char **argv)
{
- if ((piglit_get_gl_version() < 14) && !piglit_is_extension_supported("GL_ARB_window_pos")) {
- printf("Requires GL 1.4 or GL_ARB_window_pos");
- piglit_report_result(PIGLIT_SKIP);
- }
+ glClearColor(0.0, 0.0, 0.0, 1.0);
+ glClearDepth(0.75);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ glMatrixMode(GL_PROJECTION);
+ glPushMatrix();
+ glLoadIdentity();
+ glOrtho(0, piglit_width, 0, piglit_height, -1, 1);
+ glMatrixMode(GL_MODELVIEW);
+ glPushMatrix();
+ glLoadIdentity();
}
--
1.7.7.6
More information about the Piglit
mailing list