summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Paul <brianp@vmware.com>2010-03-10 08:42:01 -0700
committerBrian Paul <brianp@vmware.com>2010-03-10 08:42:28 -0700
commit30e2c46fd1308184ff92fc63f5cb36af31d90781 (patch)
tree6c60727d28e48b46a0014a49a572de4461d6f252
parent91297fad701607d00bb07d6058dd17e18d627633 (diff)
fbo-blit: also test glCopyPixels and glRead/DrawPixels()
But these new tests are temporarily disabled until some bugs in Mesa are fixed (so the test acts exactly as it did before).
-rw-r--r--tests/fbo/fbo-blit.c113
1 files changed, 95 insertions, 18 deletions
diff --git a/tests/fbo/fbo-blit.c b/tests/fbo/fbo-blit.c
index 5f4c7f0f..40259c31 100644
--- a/tests/fbo/fbo-blit.c
+++ b/tests/fbo/fbo-blit.c
@@ -22,7 +22,7 @@
*
* Authors:
* Eric Anholt <eric@anholt.net>
- *
+ * Brian Paul
*/
/** @file fbo-blit.c
@@ -30,6 +30,8 @@
* Tests EXT_framebuffer_blit with various combinations of window system and
* FBO objects. Because FBOs are generally stored inverted relative to
* window system frambuffers, this could catch flipping failures in blit paths.
+ *
+ * Brian added testing of glCopy/Read/DrawPixels().
*/
#include "piglit-util.h"
@@ -44,6 +46,30 @@ int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE;
#define FBO_SIZE 64
+enum copy_method {
+ COPY_PIXELS,
+ READ_DRAW_PIXELS,
+ BLIT_PIXELS
+};
+
+
+static const char *
+method_name(enum copy_method method)
+{
+ switch (method) {
+ case COPY_PIXELS:
+ return "glCopyPixels";
+ case READ_DRAW_PIXELS:
+ return "glReadPixels + glCopyPixels";
+ case BLIT_PIXELS:
+ return "glBlitFramebuffer";
+ default:
+ assert(0 && "bad copy method");
+ return NULL;
+ }
+}
+
+
static GLuint
make_fbo(int w, int h)
{
@@ -128,8 +154,45 @@ verify_color_rect(int start_x, int start_y, int w, int h)
return GL_TRUE;
}
-enum piglit_result
-piglit_display(void)
+
+static void
+copy(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
+ GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
+ enum copy_method method)
+{
+ if (method == COPY_PIXELS) {
+ GLsizei srcW = srcX1 - srcX0, srcH = srcY1 - srcY0;
+ GLsizei dstW = dstX1 - dstX0, dstH = dstY1 - dstY0;
+ glPixelZoom((float) dstW / (float) srcW,
+ (float) dstH / (float) srcH);
+ glWindowPos2i(dstX0, dstY0);
+ glCopyPixels(srcX0, srcY0, srcW, srcH, GL_COLOR);
+ }
+ else if (method == READ_DRAW_PIXELS) {
+ GLsizei srcW = srcX1 - srcX0, srcH = srcY1 - srcY0;
+ GLsizei dstW = dstX1 - dstX0, dstH = dstY1 - dstY0;
+ void *buf = malloc(srcW * srcH * 4);
+ glReadPixels(srcX0, srcY0, srcW, srcH,
+ GL_RGBA, GL_UNSIGNED_BYTE, buf);
+ glPixelZoom((float) dstW / (float) srcW,
+ (float) dstH / (float) srcH);
+ glWindowPos2i(dstX0, dstY0);
+ glDrawPixels(srcW, srcH, GL_RGBA, GL_UNSIGNED_BYTE, buf);
+ free(buf);
+ }
+ else if (method == BLIT_PIXELS) {
+ glBlitFramebufferEXT(srcX0, srcY0, srcX1, srcY1,
+ dstX0, dstY0, dstX1, dstY1,
+ GL_COLOR_BUFFER_BIT, GL_NEAREST);
+ }
+ else {
+ assert(0 && "invalid copy method");
+ }
+}
+
+
+static GLboolean
+run_test(enum copy_method method)
{
GLboolean pass = GL_TRUE;
GLuint fbo;
@@ -166,29 +229,23 @@ piglit_display(void)
*/
glBindFramebuffer(GL_DRAW_FRAMEBUFFER_EXT, 0);
glBindFramebuffer(GL_READ_FRAMEBUFFER_EXT, fbo);
- glBlitFramebufferEXT(x0, y0,
- x0 + SIZE, y0 + SIZE,
- x0, y1,
- x0 + SIZE, y1 + SIZE,
- GL_COLOR_BUFFER_BIT, GL_NEAREST);
+ copy(x0, y0, x0 + SIZE, y0 + SIZE,
+ x0, y1, x0 + SIZE, y1 + SIZE,
+ method);
/* WIN -> FBO */
glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, fbo);
glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, 0);
- glBlitFramebufferEXT(PAD, PAD,
- PAD + SIZE, PAD + SIZE,
- PAD, PAD * 2 + SIZE,
- PAD + SIZE, (PAD * 2 + SIZE) + SIZE,
- GL_COLOR_BUFFER_BIT, GL_NEAREST);
+ copy(x0, y0, x0 + SIZE, y0 + SIZE,
+ x0, y1, x0 + SIZE, y1 + SIZE,
+ method);
/* FBO(middle) -> WIN(top) back to verify WIN -> FBO */
glBindFramebuffer(GL_DRAW_FRAMEBUFFER_EXT, 0);
glBindFramebuffer(GL_READ_FRAMEBUFFER_EXT, fbo);
- glBlitFramebufferEXT(x0, y1,
- x0 + SIZE, y1 + SIZE,
- x0, y2,
- x0 + SIZE, y2 + SIZE,
- GL_COLOR_BUFFER_BIT, GL_NEAREST);
+ copy(x0, y1, x0 + SIZE, y1 + SIZE,
+ x0, y2, x0 + SIZE, y2 + SIZE,
+ method);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER_EXT, 0);
glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0);
@@ -197,11 +254,31 @@ piglit_display(void)
pass = verify_color_rect(PAD, y1, SIZE, SIZE) && pass;
pass = verify_color_rect(PAD, y2, SIZE, SIZE) && pass;
+ if (!pass) {
+ printf("fbo-blit: failure for %s\n", method_name(method));
+ }
+
glutSwapBuffers();
+ return pass;
+}
+
+
+enum piglit_result
+piglit_display(void)
+{
+ GLboolean pass = GL_TRUE;
+
+#if 0 /* enable after fixing some Mesa bugs */
+ pass = pass && run_test(COPY_PIXELS);
+ pass = pass && run_test(READ_DRAW_PIXELS);
+#endif
+ pass = pass && run_test(BLIT_PIXELS);
+
return pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE;
}
+
void
piglit_init(int argc, char **argv)
{