Initial  test always  used glGetTexImage into client memory for the various
texture targets.  Add case of reading into PBO in addition to client memory.
---
 tests/texturing/getteximage-targets.c | 334 ++++++++++++++++++++++++----------
 1 file changed, 242 insertions(+), 92 deletions(-)

diff --git a/tests/texturing/getteximage-targets.c 
b/tests/texturing/getteximage-targets.c
index 383ee03..0e964ac 100644
--- a/tests/texturing/getteximage-targets.c
+++ b/tests/texturing/getteximage-targets.c
@@ -48,22 +48,26 @@ static void init_layer_data(GLubyte *layer_data, int 
num_layers)
        int x, y, z, i, j;
 
        for (z = 0; z < num_layers; z++) {
-               GLubyte *data = layer_data + IMAGE_SIZE*z;
+               GLubyte *data = layer_data + IMAGE_SIZE * z;
 
                for (x = 0; x < IMAGE_WIDTH; x += 4) {
                        for (y = 0; y < IMAGE_HEIGHT; y += 4) {
-                               int r = (x+1) * 255 / (IMAGE_WIDTH - 1);
-                               int g = (y+1) * 255 / (IMAGE_HEIGHT - 1);
-                               int b = (z+1) * 255 / (num_layers-1);
+                               int r = (x + 1) * 255 / (IMAGE_WIDTH - 1);
+                               int g = (y + 1) * 255 / (IMAGE_HEIGHT - 1);
+                               int b = (z + 1) * 255 / (num_layers - 1);
                                int a = x ^ y ^ z;
 
                                /* each 4x4 block constains only one color (for 
S3TC) */
                                for (i = 0; i < 4; i++) {
                                        for (j = 0; j < 4; j++) {
-                                               data[((y+j)*IMAGE_WIDTH + 
x+i)*4 + 0] = r;
-                                               data[((y+j)*IMAGE_WIDTH + 
x+i)*4 + 1] = g;
-                                               data[((y+j)*IMAGE_WIDTH + 
x+i)*4 + 2] = b;
-                                               data[((y+j)*IMAGE_WIDTH + 
x+i)*4 + 3] = a;
+                                               data[((y + j) * IMAGE_WIDTH + x
+                                                     + i) * 4 + 0] = r;
+                                               data[((y + j) * IMAGE_WIDTH + x
+                                                     + i) * 4 + 1] = g;
+                                               data[((y + j) * IMAGE_WIDTH + x
+                                                     + i) * 4 + 2] = b;
+                                               data[((y + j) * IMAGE_WIDTH + x
+                                                     + i) * 4 + 3] = a;
                                        }
                                }
                        }
@@ -71,7 +75,8 @@ static void init_layer_data(GLubyte *layer_data, int 
num_layers)
        }
 }
 
-static void compare_layer(int layer, int num_elements, int tolerance,
+static bool
+compare_layer(int layer, int num_elements, int tolerance,
                          GLubyte *data, GLubyte *expected)
 {
        int i;
@@ -84,17 +89,232 @@ static void compare_layer(int layer, int num_elements, int 
tolerance,
                               (i / 4) / IMAGE_WIDTH, (i / 4) % IMAGE_HEIGHT, i 
% 4);
                        printf("    expected: %i\n", expected[i]);
                        printf("    got: %i\n", data[i]);
-                       piglit_report_result(PIGLIT_FAIL);
+                       return false;
                }
        }
+       return true;
 }
 
+bool
+getTexImage(bool doPBO, GLenum target, GLubyte data[][IMAGE_SIZE],
+           GLenum internalformat, int tolerance)
+{
+       int i, num_layers;
+       GLubyte data2[18][IMAGE_SIZE];
+       GLubyte *dataPBO=NULL;
+       GLuint packPBO;
+       bool pass = true;
+
+       /* Setup the PBO */
+       if (doPBO) {
+               glGenBuffers(1, &packPBO);
+               glBindBuffer(GL_PIXEL_PACK_BUFFER, packPBO);
+       } else {
+               glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
+               memset(data2, 123, sizeof(data2));
+       }
+       pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
+
+       switch (target) {
+       case GL_TEXTURE_1D:
+               glTexImage1D(GL_TEXTURE_1D, 0, internalformat, IMAGE_WIDTH, 0,
+                            GL_RGBA, GL_UNSIGNED_BYTE, data);
+               if (doPBO) {
+                       glBufferData(GL_PIXEL_PACK_BUFFER, IMAGE_WIDTH * 4,
+                                               NULL, GL_STREAM_READ);
+                       glGetTexImage(GL_TEXTURE_1D, 0, GL_RGBA,
+                                     GL_UNSIGNED_BYTE, NULL);
+                       dataPBO = (GLubyte *) glMapBufferRange(
+                                                      GL_PIXEL_PACK_BUFFER, 0,
+                                                      IMAGE_WIDTH * 4,
+                                                      GL_MAP_READ_BIT);
+               } else {
+                       glGetTexImage(GL_TEXTURE_1D, 0, GL_RGBA,
+                                     GL_UNSIGNED_BYTE, data2);
+                       dataPBO = data2[0];
+               }
+               pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
+               pass = compare_layer(0, IMAGE_WIDTH * 4, tolerance,
+                                    dataPBO, data[0]) && pass;
+               return pass;
+
+       case GL_TEXTURE_2D:
+       case GL_TEXTURE_RECTANGLE:
+               glTexImage2D(target, 0, internalformat, IMAGE_WIDTH,
+                            IMAGE_HEIGHT, 0,
+                            GL_RGBA, GL_UNSIGNED_BYTE, data);
+               if (doPBO) {
+                       glBufferData(GL_PIXEL_PACK_BUFFER, IMAGE_SIZE,
+                                    NULL, GL_STREAM_READ);
+                       glGetTexImage(target, 0, GL_RGBA, GL_UNSIGNED_BYTE,
+                                     NULL);
+                       dataPBO = (GLubyte *) glMapBufferRange(
+                                                      GL_PIXEL_PACK_BUFFER, 0,
+                                                      IMAGE_SIZE,
+                                                      GL_MAP_READ_BIT);
+               } else {
+                       glGetTexImage(target, 0, GL_RGBA, GL_UNSIGNED_BYTE,
+                                     data2);
+                       dataPBO = data2[0];
+               }
+               pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
+               pass = compare_layer(0, IMAGE_SIZE, tolerance, dataPBO, data[0])
+                                               && pass;
+               return pass;
+
+       case GL_TEXTURE_3D:
+               num_layers = 16;
+               glTexImage3D(GL_TEXTURE_3D, 0, internalformat,
+                            IMAGE_WIDTH, IMAGE_HEIGHT, num_layers, 0, GL_RGBA,
+                            GL_UNSIGNED_BYTE, data);
+               if (doPBO) {
+                       glBufferData(GL_PIXEL_PACK_BUFFER,
+                                    IMAGE_SIZE * num_layers,
+                                    NULL, GL_STREAM_READ);
+                       glGetTexImage(GL_TEXTURE_3D, 0, GL_RGBA,
+                                     GL_UNSIGNED_BYTE, NULL);
+                       dataPBO = (GLubyte *) glMapBufferRange(
+                                                   GL_PIXEL_PACK_BUFFER,
+                                                   0, IMAGE_SIZE * num_layers,
+                                                   GL_MAP_READ_BIT);
+               } else {
+                       glGetTexImage(GL_TEXTURE_3D, 0,
+                                     GL_RGBA, GL_UNSIGNED_BYTE, data2);
+                       dataPBO = data2[0];
+               }
+               pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
+               for (i = 0; i < num_layers; i++) {
+                       pass = compare_layer(i, IMAGE_SIZE, tolerance, dataPBO,
+                                            data[i]) && pass;
+                       dataPBO += IMAGE_SIZE;
+               }
+               return pass;
+
+       case GL_TEXTURE_CUBE_MAP:
+               for (i = 0; i < 6; i++) {
+                       glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0,
+                                    internalformat, IMAGE_WIDTH, IMAGE_HEIGHT,
+                                    0, GL_RGBA,
+                                    GL_UNSIGNED_BYTE, data[i]);
+               }
+               for (i = 0; i < 6; i++) {
+                       if (doPBO) {
+                               glBufferData(GL_PIXEL_PACK_BUFFER, IMAGE_SIZE,
+                                               NULL, GL_STREAM_READ);
+                               glGetTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i
+                                             , 0, GL_RGBA,
+                                             GL_UNSIGNED_BYTE, NULL);
+                               dataPBO = (GLubyte *) glMapBufferRange(
+                                                      GL_PIXEL_PACK_BUFFER, 0,
+                                                      IMAGE_SIZE,
+                                                      GL_MAP_READ_BIT);
+                       } else {
+                               glGetTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i
+                                             , 0, GL_RGBA,
+                                             GL_UNSIGNED_BYTE, data2[i]);
+                               dataPBO = data2[i];
+                       }
+                       pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
+                       pass = compare_layer(i, IMAGE_SIZE, tolerance, dataPBO,
+                                            data[i]) && pass;
+               }
+               return pass;
+
+       case GL_TEXTURE_1D_ARRAY:
+               num_layers = 7;
+               glTexImage2D(GL_TEXTURE_1D_ARRAY, 0, internalformat,
+                            IMAGE_WIDTH, num_layers, 0,
+                            GL_RGBA, GL_UNSIGNED_BYTE, data);
+               if (doPBO) {
+                       glBufferData(GL_PIXEL_PACK_BUFFER,
+                                    IMAGE_WIDTH * 4 * num_layers,
+                                    NULL, GL_STREAM_READ);
+                       glGetTexImage(GL_TEXTURE_1D_ARRAY, 0, GL_RGBA,
+                                     GL_UNSIGNED_BYTE, NULL);
+                       dataPBO = (GLubyte *) glMapBufferRange(
+                                                  GL_PIXEL_PACK_BUFFER, 0,
+                                                  IMAGE_WIDTH * 4 * num_layers,
+                                                  GL_MAP_READ_BIT);
+               } else {
+                       glGetTexImage(GL_TEXTURE_1D_ARRAY, 0, GL_RGBA,
+                                     GL_UNSIGNED_BYTE, data2);
+                       dataPBO = data2[0];
+               }
+               pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
+               pass = compare_layer(0, IMAGE_WIDTH * 4 * num_layers,
+                                    tolerance, dataPBO, data[0]) && pass;
+               return pass;
+
+       case GL_TEXTURE_2D_ARRAY:
+               num_layers = 7;
+               glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, internalformat,
+                            IMAGE_WIDTH, IMAGE_HEIGHT, num_layers, 0,
+                            GL_RGBA, GL_UNSIGNED_BYTE, data);
+               if (doPBO) {
+                       glBufferData(GL_PIXEL_PACK_BUFFER,
+                                    IMAGE_SIZE * num_layers,
+                                    NULL, GL_STREAM_READ);
+                       glGetTexImage(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA,
+                                     GL_UNSIGNED_BYTE, NULL);
+                       dataPBO = (GLubyte *) glMapBufferRange(
+                                                      GL_PIXEL_PACK_BUFFER, 0,
+                                                      IMAGE_SIZE * num_layers,
+                                                      GL_MAP_READ_BIT);
+               } else {
+                       glGetTexImage(GL_TEXTURE_2D_ARRAY, 0,
+                                     GL_RGBA, GL_UNSIGNED_BYTE, data2);
+                       dataPBO = data2[0];
+
+               }
+               pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
+               for (i = 0; i < num_layers; i++) {
+                       pass = compare_layer(i, IMAGE_SIZE, tolerance, dataPBO,
+                                            data[i]) && pass;
+                       dataPBO += IMAGE_SIZE;
+               }
+               return pass;
+
+       case GL_TEXTURE_CUBE_MAP_ARRAY:
+               num_layers = 6 * 3;
+               glTexImage3D(GL_TEXTURE_CUBE_MAP_ARRAY, 0, internalformat,
+                            IMAGE_WIDTH, IMAGE_HEIGHT, num_layers, 0, GL_RGBA,
+                            GL_UNSIGNED_BYTE, data);
+               if (doPBO) {
+                       glBufferData(GL_PIXEL_PACK_BUFFER,
+                                    IMAGE_SIZE * num_layers,
+                                    NULL, GL_STREAM_READ);
+                       glGetTexImage(GL_TEXTURE_CUBE_MAP_ARRAY, 0,
+                                     GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+                       dataPBO = (GLubyte *) glMapBufferRange(
+                                                      GL_PIXEL_PACK_BUFFER, 0,
+                                                      IMAGE_SIZE * num_layers,
+                                                      GL_MAP_READ_BIT);
+               } else {
+                       glGetTexImage(GL_TEXTURE_CUBE_MAP_ARRAY, 0,
+                                     GL_RGBA, GL_UNSIGNED_BYTE, data2);
+                       dataPBO = data2[0];
+               }
+               pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
+               for (i = 0; i < num_layers; i++) {
+                       pass = compare_layer(i, IMAGE_SIZE, tolerance, dataPBO,
+                                            data[i]) && pass;
+                       dataPBO += IMAGE_SIZE;
+               }
+               return pass;
+       }
+
+       puts("Invalid texture target.");
+       return false;
+
+}
 void piglit_init(int argc, char **argv)
 {
-       int i, tolerance = 0, num_layers;
+       int i;
        GLenum target = GL_TEXTURE_2D;
+       bool pass = true;
        GLenum internalformat = GL_RGBA8;
-       GLubyte data[18][IMAGE_SIZE], data2[18][IMAGE_SIZE];
+       int tolerance = 0;
+       GLubyte data[18][IMAGE_SIZE];
 
        for (i = 1; i < argc; i++) {
                if (strcmp(argv[i], "1D") == 0) {
@@ -133,89 +353,19 @@ void piglit_init(int argc, char **argv)
        }
 
        init_layer_data(data[0], 18);
-       memset(data2, 123, sizeof(data2));
 
-       printf("Testing %s\n", piglit_get_gl_enum_name(target));
+       printf("Testing %s into PBO\n", piglit_get_gl_enum_name(target));
 
-       switch (target) {
-       case GL_TEXTURE_1D:
-               glTexImage1D(GL_TEXTURE_1D, 0, internalformat, IMAGE_WIDTH, 0,
-                            GL_RGBA, GL_UNSIGNED_BYTE, data);
-               glGetTexImage(GL_TEXTURE_1D, 0, GL_RGBA, GL_UNSIGNED_BYTE, 
data2);
-               piglit_check_gl_error(GL_NO_ERROR);
-               compare_layer(0, 128, tolerance, data2[0], data[0]);
-               piglit_report_result(PIGLIT_PASS);
+       pass = getTexImage(true, target, data, internalformat, tolerance) &&
+                               pass;
+       printf("Testing %s into client array\n", 
piglit_get_gl_enum_name(target));
+       pass = getTexImage(false, target, data, internalformat, tolerance) &&
+                               pass;
 
-       case GL_TEXTURE_2D:
-       case GL_TEXTURE_RECTANGLE:
-               glTexImage2D(target, 0, internalformat, IMAGE_WIDTH, 
IMAGE_HEIGHT, 0,
-                            GL_RGBA, GL_UNSIGNED_BYTE, data);
-               glGetTexImage(target, 0, GL_RGBA, GL_UNSIGNED_BYTE, data2);
-               piglit_check_gl_error(GL_NO_ERROR);
-               compare_layer(0, IMAGE_SIZE, tolerance, data2[0], data[0]);
-               piglit_report_result(PIGLIT_PASS);
+       pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
 
-       case GL_TEXTURE_3D:
-               num_layers = 16;
-               glTexImage3D(GL_TEXTURE_3D, 0, internalformat,
-                            IMAGE_WIDTH, IMAGE_HEIGHT, num_layers, 0, GL_RGBA,
-                            GL_UNSIGNED_BYTE, data);
-               glGetTexImage(GL_TEXTURE_3D, 0,
-                             GL_RGBA, GL_UNSIGNED_BYTE, data2);
-               piglit_check_gl_error(GL_NO_ERROR);
-               for (i = 0; i < num_layers; i++) {
-                       compare_layer(i, IMAGE_SIZE, tolerance, data2[i], 
data[i]);
-               }
+       if (pass)
                piglit_report_result(PIGLIT_PASS);
-
-       case GL_TEXTURE_CUBE_MAP:
-               for (i = 0; i < 6; i++) {
-                       glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0,
-                                    internalformat, IMAGE_WIDTH, IMAGE_HEIGHT, 
0, GL_RGBA,
-                                    GL_UNSIGNED_BYTE, data[i]);
-               }
-               for (i = 0; i < 6; i++) {
-                       glGetTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0,
-                                     GL_RGBA, GL_UNSIGNED_BYTE, data2[i]);
-                       piglit_check_gl_error(GL_NO_ERROR);
-                       compare_layer(i, IMAGE_SIZE, tolerance, data2[i], 
data[i]);
-               }
-               piglit_report_result(PIGLIT_PASS);
-
-       case GL_TEXTURE_1D_ARRAY:
-               num_layers = 7;
-               glTexImage2D(GL_TEXTURE_1D_ARRAY, 0, internalformat, 
IMAGE_WIDTH, num_layers, 0,
-                            GL_RGBA, GL_UNSIGNED_BYTE, data);
-               glGetTexImage(GL_TEXTURE_1D_ARRAY, 0, GL_RGBA, 
GL_UNSIGNED_BYTE, data2);
-               piglit_check_gl_error(GL_NO_ERROR);
-               compare_layer(0, IMAGE_WIDTH*4*num_layers, tolerance, data2[0], 
data[0]);
-               piglit_report_result(PIGLIT_PASS);
-
-       case GL_TEXTURE_2D_ARRAY:
-               num_layers = 7;
-               glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, internalformat,
-                            IMAGE_WIDTH, IMAGE_HEIGHT, num_layers, 0, GL_RGBA, 
GL_UNSIGNED_BYTE, data);
-               glGetTexImage(GL_TEXTURE_2D_ARRAY, 0,
-                             GL_RGBA, GL_UNSIGNED_BYTE, data2);
-               piglit_check_gl_error(GL_NO_ERROR);
-               for (i = 0; i < num_layers; i++) {
-                       compare_layer(i, IMAGE_SIZE, tolerance, data2[i], 
data[i]);
-               }
-               piglit_report_result(PIGLIT_PASS);
-
-       case GL_TEXTURE_CUBE_MAP_ARRAY:
-               num_layers = 6*3;
-               glTexImage3D(GL_TEXTURE_CUBE_MAP_ARRAY, 0, internalformat,
-                            IMAGE_WIDTH, IMAGE_HEIGHT, num_layers, 0, GL_RGBA, 
GL_UNSIGNED_BYTE, data);
-               glGetTexImage(GL_TEXTURE_CUBE_MAP_ARRAY, 0,
-                             GL_RGBA, GL_UNSIGNED_BYTE, data2);
-               piglit_check_gl_error(GL_NO_ERROR);
-               for (i = 0; i < num_layers; i++) {
-                       compare_layer(i, IMAGE_SIZE, tolerance, data2[i], 
data[i]);
-               }
-               piglit_report_result(PIGLIT_PASS);
-       }
-
-       puts("Invalid texture target.");
-       piglit_report_result(PIGLIT_FAIL);
+       else
+               piglit_report_result(PIGLIT_FAIL);
 }
-- 
1.8.1.2

_______________________________________________
Piglit mailing list
Piglit@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/piglit

Reply via email to