2 * Copyright © 2009 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.c
30 * Tests that using a PBO as the unpack buffer for glTexImage works correctly.
33 #include "piglit-util-gl.h"
35 PIGLIT_GL_TEST_CONFIG_BEGIN
37 config
.supports_gl_compat_version
= 10;
39 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
;
41 PIGLIT_GL_TEST_CONFIG_END
46 GLboolean pass
= GL_TRUE
;
47 static float red
[] = {1.0, 0.0, 0.0, 0.0};
48 static float green
[] = {0.0, 1.0, 0.0, 0.0};
49 static float blue
[] = {0.0, 0.0, 1.0, 0.0};
53 glClearColor(0.5, 0.5, 0.5, 0.0);
54 glClear(GL_COLOR_BUFFER_BIT
);
56 glGenBuffersARB(1, &pbo
);
57 glBindBufferARB(GL_PIXEL_UNPACK_BUFFER
, pbo
);
58 glBufferDataARB(GL_PIXEL_UNPACK_BUFFER
, 4 * 4 * sizeof(float),
59 NULL
, GL_STREAM_DRAW_ARB
);
60 pixels
= glMapBufferARB(GL_PIXEL_UNPACK_BUFFER
, GL_WRITE_ONLY_ARB
);
62 memcpy(pixels
+ 0, red
, sizeof(red
));
63 memcpy(pixels
+ 4, green
, sizeof(green
));
64 memcpy(pixels
+ 8, blue
, sizeof(blue
));
65 memcpy(pixels
+ 12, red
, sizeof(red
));
67 glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER
);
68 glGenTextures(1, &tex
);
69 glBindTexture(GL_TEXTURE_2D
, tex
);
70 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
71 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
72 glTexImage2D(GL_TEXTURE_2D
, 0,
75 GL_RGBA
, GL_FLOAT
, 0);
76 glBindBufferARB(GL_PIXEL_UNPACK_BUFFER
, 0);
77 glDeleteBuffersARB(1, &pbo
);
79 glEnable(GL_TEXTURE_2D
);
80 glBegin(GL_TRIANGLE_FAN
);
81 glTexCoord2f(0.0, 0.0); glVertex2f(10, 10);
82 glTexCoord2f(1.0, 0.0); glVertex2f(20, 10);
83 glTexCoord2f(1.0, 1.0); glVertex2f(20, 20);
84 glTexCoord2f(0.0, 1.0); glVertex2f(10, 20);
87 glDeleteTextures(1, &tex
);
89 pass
&= piglit_probe_pixel_rgb(12, 12, red
);
90 pass
&= piglit_probe_pixel_rgb(18, 12, green
);
91 pass
&= piglit_probe_pixel_rgb(12, 18, blue
);
92 pass
&= piglit_probe_pixel_rgb(18, 18, red
);
94 piglit_present_results();
96 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
100 static void reshape(int width
, int height
)
102 piglit_width
= width
;
103 piglit_height
= height
;
105 piglit_ortho_projection(width
, height
, GL_FALSE
);
109 piglit_init(int argc
, char **argv
)
111 reshape(piglit_width
, piglit_height
);
112 piglit_require_extension("GL_ARB_pixel_buffer_object");