1 /*
2  * Copyright © 2009,2010 Intel Corporation
3  *
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:
10  *
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
13  * Software.
14  *
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
21  * IN THE SOFTWARE.
22  *
23  * Authors:
24  *    Eric Anholt <eric@anholt.net>
25  *
26  */
27 
28 /** @file pbo-teximage-tiling.c
29  *
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
32  * be on Intel.
33  */
34 
35 #include "piglit-util-gl.h"
36 
37 PIGLIT_GL_TEST_CONFIG_BEGIN
38 
39 	config.supports_gl_compat_version = 10;
40 
41 	config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
42 
43 PIGLIT_GL_TEST_CONFIG_END
44 
45 enum piglit_result
piglit_display(void)46 piglit_display(void)
47 {
48 	GLboolean pass = GL_TRUE;
49 	static float red[] = {1.0, 0.0, 0.0, 0.0};
50 	static float green[] = {0.0, 1.0, 0.0, 0.0};
51 	static float blue[]  = {0.0, 0.0, 1.0, 0.0};
52 	static float white[]  = {1.0, 1.0, 1.0, 0.0};
53 	uint32_t red_packed = 0x00ff0000;
54 	uint32_t green_packed = 0x0000ff00;
55 	uint32_t blue_packed = 0x000000ff;
56 	uint32_t white_packed = 0x00ffffff;
57 	uint32_t *pixels;
58 	GLuint pbo, tex;
59 
60 	glClearColor(0.5, 0.5, 0.5, 0.0);
61 	glClear(GL_COLOR_BUFFER_BIT);
62 
63 	glGenBuffersARB(1, &pbo);
64 	glBindBufferARB(GL_PIXEL_UNPACK_BUFFER, pbo);
65 	glBufferDataARB(GL_PIXEL_UNPACK_BUFFER, 128 * 2 * sizeof(uint32_t),
66 			NULL, GL_STREAM_DRAW_ARB);
67 	glPixelStorei(GL_UNPACK_ROW_LENGTH, 128);
68 
69 	pixels = glMapBufferARB(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY_ARB);
70 	pixels[0] = red_packed;
71 	pixels[1] = green_packed;
72 	pixels[128] = blue_packed;
73 	pixels[129] = white_packed;
74 	glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER);
75 
76 	glGenTextures(1, &tex);
77 	glBindTexture(GL_TEXTURE_2D, tex);
78 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
79 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
80 	glTexImage2D(GL_TEXTURE_2D, 0,
81 		     GL_RGBA,
82 		     2, 2, 0,
83 		     GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 0);
84 	glBindBufferARB(GL_PIXEL_UNPACK_BUFFER, 0);
85 	glDeleteBuffersARB(1, &pbo);
86 
87 	glEnable(GL_TEXTURE_2D);
88 	glBegin(GL_TRIANGLE_FAN);
89 	glTexCoord2f(0.0, 0.0); glVertex2f(10, 10);
90 	glTexCoord2f(1.0, 0.0); glVertex2f(20, 10);
91 	glTexCoord2f(1.0, 1.0); glVertex2f(20, 20);
92 	glTexCoord2f(0.0, 1.0); glVertex2f(10, 20);
93 	glEnd();
94 
95 	glDeleteTextures(1, &tex);
96 
97 	pass &= piglit_probe_pixel_rgb(12, 12, red);
98 	pass &= piglit_probe_pixel_rgb(18, 12, green);
99 	pass &= piglit_probe_pixel_rgb(12, 18, blue);
100 	pass &= piglit_probe_pixel_rgb(18, 18, white);
101 
102 	piglit_present_results();
103 
104 	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
105 }
106 
107 
reshape(int width,int height)108 static void reshape(int width, int height)
109 {
110 	piglit_width = width;
111 	piglit_height = height;
112 
113 	piglit_ortho_projection(width, height, GL_FALSE);
114 }
115 
116 void
piglit_init(int argc,char ** argv)117 piglit_init(int argc, char **argv)
118 {
119 	reshape(piglit_width, piglit_height);
120 	piglit_require_extension("GL_ARB_pixel_buffer_object");
121 }
122