Add more structure constructor tests.
[piglit/hramrach.git] / tests / general / pbo-teximage.c
blob069b261614e175d587b1f6213c8dc07540a7366a
1 /*
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
13 * Software.
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.
23 * Authors:
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.h"
35 int piglit_width = 100, piglit_height = 100;
36 int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE;
38 enum piglit_result
39 piglit_display(void)
41 GLboolean pass = GL_TRUE;
42 static float red[] = {1.0, 0.0, 0.0, 0.0};
43 static float green[] = {0.0, 1.0, 0.0, 0.0};
44 static float blue[] = {0.0, 0.0, 1.0, 0.0};
45 float *pixels;
46 GLuint pbo, tex;
48 glClearColor(0.5, 0.5, 0.5, 0.0);
49 glClear(GL_COLOR_BUFFER_BIT);
51 glGenBuffersARB(1, &pbo);
52 glBindBufferARB(GL_PIXEL_UNPACK_BUFFER, pbo);
53 glBufferDataARB(GL_PIXEL_UNPACK_BUFFER, 4 * 4 * sizeof(float),
54 NULL, GL_STREAM_DRAW_ARB);
55 pixels = glMapBufferARB(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY_ARB);
57 memcpy(pixels + 0, red, sizeof(red));
58 memcpy(pixels + 4, green, sizeof(green));
59 memcpy(pixels + 8, blue, sizeof(blue));
60 memcpy(pixels + 12, red, sizeof(red));
62 glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER);
63 glGenTextures(1, &tex);
64 glBindTexture(GL_TEXTURE_2D, tex);
65 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
66 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
67 glTexImage2D(GL_TEXTURE_2D, 0,
68 GL_RGBA,
69 2, 2, 0,
70 GL_RGBA, GL_FLOAT, 0);
71 glBindBufferARB(GL_PIXEL_UNPACK_BUFFER, 0);
72 glDeleteBuffersARB(1, &pbo);
74 glEnable(GL_TEXTURE_2D);
75 glBegin(GL_TRIANGLE_FAN);
76 glTexCoord2f(0.0, 0.0); glVertex2f(10, 10);
77 glTexCoord2f(1.0, 0.0); glVertex2f(20, 10);
78 glTexCoord2f(1.0, 1.0); glVertex2f(20, 20);
79 glTexCoord2f(0.0, 1.0); glVertex2f(10, 20);
80 glEnd();
82 glDeleteTextures(1, &tex);
84 pass &= piglit_probe_pixel_rgb(12, 12, red);
85 pass &= piglit_probe_pixel_rgb(18, 12, green);
86 pass &= piglit_probe_pixel_rgb(12, 18, blue);
87 pass &= piglit_probe_pixel_rgb(18, 18, red);
89 glutSwapBuffers();
91 return pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE;
95 static void reshape(int width, int height)
97 piglit_width = width;
98 piglit_height = height;
100 piglit_ortho_projection(width, height, GL_FALSE);
103 void
104 piglit_init(int argc, char **argv)
106 reshape(piglit_width, piglit_height);
107 piglit_require_extension("GL_ARB_pixel_buffer_object");
108 glewInit();