2 * Copyright © 2009,2010 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 * Eric Anholt <eric@anholt.net>
28 /** @file pbo-teximage-tiling.c
30 * Tests that using a PBO as the unpack buffer for glTexImage works correctly
31 * when the stride is conveniently chosen to match what a tiled texture would
35 #include "piglit-util.h"
37 int piglit_width
= 100, piglit_height
= 100;
38 int piglit_window_mode
= GLUT_RGB
| GLUT_DOUBLE
;
43 GLboolean pass
= GL_TRUE
;
44 static float red
[] = {1.0, 0.0, 0.0, 0.0};
45 static float green
[] = {0.0, 1.0, 0.0, 0.0};
46 static float blue
[] = {0.0, 0.0, 1.0, 0.0};
47 static float white
[] = {1.0, 1.0, 1.0, 0.0};
48 uint32_t red_packed
= 0x00ff0000;
49 uint32_t green_packed
= 0x0000ff00;
50 uint32_t blue_packed
= 0x000000ff;
51 uint32_t white_packed
= 0x00ffffff;
55 glClearColor(0.5, 0.5, 0.5, 0.0);
56 glClear(GL_COLOR_BUFFER_BIT
);
58 glGenBuffersARB(1, &pbo
);
59 glBindBufferARB(GL_PIXEL_UNPACK_BUFFER
, pbo
);
60 glBufferDataARB(GL_PIXEL_UNPACK_BUFFER
, 128 * 2 * sizeof(uint32_t),
61 NULL
, GL_STREAM_DRAW_ARB
);
62 glPixelStorei(GL_UNPACK_ROW_LENGTH
, 128);
64 pixels
= glMapBufferARB(GL_PIXEL_UNPACK_BUFFER
, GL_WRITE_ONLY_ARB
);
65 pixels
[0] = red_packed
;
66 pixels
[1] = green_packed
;
67 pixels
[128] = blue_packed
;
68 pixels
[129] = white_packed
;
69 glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER
);
71 glGenTextures(1, &tex
);
72 glBindTexture(GL_TEXTURE_2D
, tex
);
73 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
74 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
75 glTexImage2D(GL_TEXTURE_2D
, 0,
78 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0);
79 glBindBufferARB(GL_PIXEL_UNPACK_BUFFER
, 0);
80 glDeleteBuffersARB(1, &pbo
);
82 glEnable(GL_TEXTURE_2D
);
83 glBegin(GL_TRIANGLE_FAN
);
84 glTexCoord2f(0.0, 0.0); glVertex2f(10, 10);
85 glTexCoord2f(1.0, 0.0); glVertex2f(20, 10);
86 glTexCoord2f(1.0, 1.0); glVertex2f(20, 20);
87 glTexCoord2f(0.0, 1.0); glVertex2f(10, 20);
90 glDeleteTextures(1, &tex
);
92 pass
&= piglit_probe_pixel_rgb(12, 12, red
);
93 pass
&= piglit_probe_pixel_rgb(18, 12, green
);
94 pass
&= piglit_probe_pixel_rgb(12, 18, blue
);
95 pass
&= piglit_probe_pixel_rgb(18, 18, white
);
99 return pass
? PIGLIT_SUCCESS
: PIGLIT_FAILURE
;
103 static void reshape(int width
, int height
)
105 piglit_width
= width
;
106 piglit_height
= height
;
108 piglit_ortho_projection(width
, height
, GL_FALSE
);
112 piglit_init(int argc
, char **argv
)
114 reshape(piglit_width
, piglit_height
);
115 piglit_require_extension("GL_ARB_pixel_buffer_object");