ext_framebuffer_object: setup max mipmap level to make fbo complete
[piglit.git] / tests / spec / arb_viewport_array / depth_range_indices.c
bloba0f58f456f8a9493924b9fea3ec0c8507257c62d
1 /*
2 * Copyright © 2013 LunarG, Inc.
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 * Author: Jon Ashburn <jon@lunarg.com>
26 /**
27 * Tests GL_ARB_viewport_array validity for indices.
28 * Use both valid and invalid parameters (index, first, count)
29 * for all these new API entry points:
30 * glDepthRangeArrayv, glDepthRangeIndexed, glGetDoublei_v
34 #include "piglit-util-gl.h"
35 #include <stdarg.h>
37 PIGLIT_GL_TEST_CONFIG_BEGIN
39 config.supports_gl_compat_version = 32;
40 config.supports_gl_core_version = 32;
41 config.supports_gl_es_version = 31;
43 config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
44 config.khr_no_error_support = PIGLIT_NO_ERRORS;
46 PIGLIT_GL_TEST_CONFIG_END
48 /**
49 * Test that DepthRangeArrayv, DepthRangeIndexed, GetDoublei_v give the
50 * "expected_error" gl error. Given the values for "first" and "count"
51 * or "index" in range [first, first+count).
53 static bool
54 check_dr_index(GLuint first, GLsizei count, GLenum expected_error)
56 #ifdef PIGLIT_USE_OPENGL
57 static const GLclampd dv[] = {0.213, 1.0};
58 GLclampd *mv, dvGet[2];
59 #else
60 static const GLfloat dv[] = {0.213, 1.0};
61 GLfloat *mv, dvGet[2];
62 #endif
63 unsigned int i;
64 bool pass = true;
65 const unsigned int numIterate = (expected_error == GL_NO_ERROR) ? count : 1;
67 mv = malloc(sizeof(*dv) * 2 * count);
68 if (mv == NULL)
69 return false;
70 for (i = 0; i < count; i++) {
71 mv[i * 2] = dv[0];
72 mv[i * 2 + 1] = dv[1];
74 #ifdef PIGLIT_USE_OPENGL
75 glDepthRangeArrayv(first, count, mv);
76 #else
77 glDepthRangeArrayfvOES(first, count, mv);
78 #endif
79 free(mv);
80 pass = piglit_check_gl_error(expected_error) && pass;
82 /* only iterate multiple indices for no error case */
83 for (i = count; i > count - numIterate; i--) {
84 #ifdef PIGLIT_USE_OPENGL
85 glDepthRangeIndexed(first + i - 1, dv[0], dv[1]);
86 pass = piglit_check_gl_error(expected_error) && pass;
87 glGetDoublei_v(GL_DEPTH_RANGE, first + i - 1, dvGet);
88 pass = piglit_check_gl_error(expected_error) && pass;
89 #else
90 glDepthRangeIndexedfOES(first + i - 1, dv[0], dv[1]);
91 pass = piglit_check_gl_error(expected_error) && pass;
92 glGetFloati_vOES(GL_DEPTH_RANGE, first + i - 1, dvGet);
93 pass = piglit_check_gl_error(expected_error) && pass;
94 #endif
97 return pass;
101 * Test first + count or index valid and invalid values.
102 * Valid range is 0 thru (MAX_VIEWPORTS-1).
104 static bool
105 test_dr_indices(GLint maxVP)
107 bool pass = true;
111 * valid largest range depth index
112 * OpenGL Core 4.3 Spec, section 13.6.1 ref:
113 * "Multiple viewports are available and are numbered zero
114 * through the value of MAX_VIEWPORTS minus one."
116 if (!check_dr_index(0, maxVP, GL_NO_ERROR)) {
117 printf("Got error for valid depth range, max range=%u\n",
118 maxVP);
119 pass = false;
122 if (!piglit_khr_no_error) {
124 * invalid count + first index for DepthRange
125 * OpenGL Spec Core 4.3 Spec, section 13.6.1 ref:
126 * "An INVALID_VALUE error is generated if first + count
127 * is greater than the valuue of MAX_VIEWPORTS."
129 if (!check_dr_index(maxVP - 2, 3, GL_INVALID_VALUE)) {
130 printf("Wrong error for invalid DepthRange index range\n");
131 pass = false;
135 * invalid count for DepthRange
136 * OpenGL Spec Core 4.3 Spec, section 13.6.1 ref:
137 * "An INVALID_VALUE error is generated if count is negative."
139 #ifdef PIGLIT_USE_OPENGL
140 glDepthRangeArrayv(0, -1, NULL);
141 #else
142 glDepthRangeArrayfvOES(0, -1, NULL);
143 #endif
144 if (!piglit_check_gl_error(GL_INVALID_VALUE)) {
145 printf("Wrong error for invalid DepthRange count\n");
146 pass = false;
150 return pass;
154 enum piglit_result
155 piglit_display(void)
157 return PIGLIT_FAIL;
160 void
161 piglit_init(int argc, char **argv)
163 bool pass = true;
164 GLint maxVP;
166 #ifdef PIGLIT_USE_OPENGL
167 piglit_require_extension("GL_ARB_viewport_array");
168 #else
169 piglit_require_extension("GL_OES_viewport_array");
170 #endif
172 glGetIntegerv(GL_MAX_VIEWPORTS, &maxVP);
173 if (!piglit_check_gl_error(GL_NO_ERROR)) {
174 piglit_report_result(PIGLIT_FAIL);
175 } else {
176 pass = test_dr_indices(maxVP) && pass;
177 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
178 piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);