cl: Don't use device_infos if num_device_infos == 0
[piglit.git] / tests / general / vbo-map-remap.c
blobff151a6293ce775754dd9bafad549132fecca1b5
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
21 * DEALINGS IN THE SOFTWARE.
23 * Authors:
24 * Ben Holmes <shranzel@hotmail.com>
27 #include "piglit-util-gl.h"
29 PIGLIT_GL_TEST_CONFIG_BEGIN
31 config.supports_gl_compat_version = 10;
33 config.window_width = 400;
34 config.window_height = 300;
35 config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
36 config.khr_no_error_support = PIGLIT_NO_ERRORS;
38 PIGLIT_GL_TEST_CONFIG_END
40 static GLuint vbo;
42 void
43 piglit_init(int argc, char **argv)
45 piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
47 piglit_require_extension("GL_ARB_vertex_buffer_object");
49 glGenBuffersARB(1, &vbo);
50 glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo);
51 glBufferDataARB(GL_ARRAY_BUFFER_ARB, 12 * sizeof(GLfloat),
52 NULL, GL_DYNAMIC_DRAW);
55 static void
56 vbo_write_floats_mapped(const float *varray, size_t count)
58 float *ptr = glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB);
60 if (ptr == NULL)
61 piglit_report_result(PIGLIT_FAIL);
63 memcpy(ptr, varray, count * sizeof(GLfloat));
65 if (!glUnmapBufferARB(GL_ARRAY_BUFFER_ARB))
66 piglit_report_result(PIGLIT_FAIL);
69 enum piglit_result
70 piglit_display(void)
72 GLfloat white[4] = {1.0, 1.0, 1.0, 0.0};
73 GLboolean pass = GL_TRUE;
74 GLfloat varray1[12] = {175, 125, 0,
75 175, 175, 0,
76 125, 125, 0,
77 125, 175, 0};
78 GLfloat varray2[12] = {275, 125, 0,
79 275, 175, 0,
80 225, 125, 0,
81 225, 175, 0};
82 GLenum err;
84 glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo);
86 glEnableClientState(GL_VERTEX_ARRAY);
87 glVertexPointer(3, GL_FLOAT, 0, 0);
89 vbo_write_floats_mapped(varray1, 12);
91 glClear(GL_COLOR_BUFFER_BIT);
92 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
94 vbo_write_floats_mapped(varray2, 12);
96 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
98 if ((err = glGetError()) != 0) {
99 printf("gl error: 0x%08x\n", err);
100 pass = GL_FALSE;
103 pass = pass && piglit_probe_pixel_rgb(250, 150, white);
104 pass = pass && piglit_probe_pixel_rgb(150, 150, white);
106 piglit_present_results();
108 glDisableClientState(GL_VERTEX_ARRAY);
110 return pass ? PIGLIT_PASS : PIGLIT_FAIL;