ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / amd_depth_clamp_separate / depth-clamp-range.c
blobb499184d0d8c105105cf2a2d01a99d03487b3ded
1 /*
2 * Copyright © 2018 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.
25 /** @file depth-clamp-range.c
27 * Tests that AMD_depth_clamp_separate enablement didn't break DepthRange
28 * functionality, and properly uses the min/max selection.
31 #include "piglit-util-gl.h"
33 PIGLIT_GL_TEST_CONFIG_BEGIN
35 config.supports_gl_core_version = 32;
36 config.supports_gl_compat_version = 32;
37 config.khr_no_error_support = PIGLIT_NO_ERRORS;
38 config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE
39 | PIGLIT_GL_VISUAL_DEPTH;
41 PIGLIT_GL_TEST_CONFIG_END
43 static GLuint program;
44 static GLint projection_loc;
46 static GLuint
47 make_program(void)
49 static const char *vs_text =
50 "#version 330 \n"
51 "in vec4 vertex; \n"
52 "uniform mat4 projection; \n"
53 "void main() \n"
54 "{ \n"
55 " gl_Position = projection * vertex; \n"
56 "} \n";
58 static const char *fs_text =
59 "#version 330 \n"
60 "void main() \n"
61 "{ \n"
62 " gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0); \n"
63 "} \n";
65 GLuint program = piglit_build_simple_program(vs_text, fs_text);
67 return program;
70 void
71 piglit_init(int argc, char **argv)
73 piglit_require_extension("GL_AMD_depth_clamp_separate");
74 program = make_program();
77 enum piglit_result
78 piglit_display(void)
80 GLboolean pass = GL_TRUE;
81 float white[3] = {1.0, 1.0, 1.0};
82 float clear[3] = {0.0, 0.0, 0.0};
84 glClearDepth(0.5);
85 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
86 glEnable(GL_DEPTH_TEST);
87 glDepthFunc(GL_LEQUAL);
89 glUseProgram(program);
91 projection_loc = glGetUniformLocation(program, "projection");
92 piglit_ortho_uniform(projection_loc, piglit_width, piglit_height);
94 /* Keep in mind that the ortho projection flips near and far's signs,
95 * so 1.0 to quad()'s z maps to glDepthRange's near, and -1.0 maps to
96 * glDepthRange's far.
99 /* Basic glDepthRange testing. */
100 glDisable(GL_DEPTH_CLAMP_NEAR_AMD);
101 glDisable(GL_DEPTH_CLAMP_FAR_AMD);
102 glDepthRange(0, 1);
103 piglit_draw_rect_z(0.5, 10, 10, 10, 10); /* .25 - drawn. */
105 glDepthRange(1, 0);
106 piglit_draw_rect_z(0.5, 10, 30, 10, 10); /* 0.75 - not drawn. */
108 /* Now, test that near depth clamping works.*/
109 glEnable(GL_DEPTH_CLAMP_NEAR_AMD);
110 glDepthRange(0.25, 1.0);
111 piglit_draw_rect_z(4, 30, 10, 10, 10); /* .25 - drawn. */
113 glDisable(GL_DEPTH_CLAMP_NEAR_AMD);
114 glEnable(GL_DEPTH_CLAMP_FAR_AMD);
115 glDepthRange(0.75, 1.0);
116 piglit_draw_rect_z(4, 30, 30, 10, 10); /* 0.75 - not drawn. */
118 /* Test that far clamping works.*/
119 glDepthRange(0.0, 0.25);
120 piglit_draw_rect_z(-4, 50, 10, 10, 10); /* .25 - drawn. */
122 glDepthRange(0.0, 0.75);
123 piglit_draw_rect_z(-4, 50, 30, 10, 10); /* 0.75 - not drawn. */
125 /* Now, flip near and far around and make sure that it's doing the
126 * min/max of near and far in the clamping.
129 /* Test that near (max) clamping works. */
130 glEnable(GL_DEPTH_CLAMP_NEAR_AMD);
131 glDepthRange(0.25, 0.0);
132 piglit_draw_rect_z(4, 70, 10, 10, 10); /* .25 - drawn. */
134 glDisable(GL_DEPTH_CLAMP_NEAR_AMD);
135 glEnable(GL_DEPTH_CLAMP_FAR_AMD);
136 glDepthRange(0.75, 0.0);
137 piglit_draw_rect_z(4, 70, 30, 10, 10); /* 0.75 - not drawn. */
139 /* Now, test far (min) clamping works. */
140 glDepthRange(1.0, 0.0);
141 piglit_draw_rect_z(-4, 90, 10, 10, 10); /* 0.0 - drawn. */
143 glDisable(GL_DEPTH_CLAMP_FAR_AMD);
144 glDepthRange(1.0, 0.75);
145 piglit_draw_rect_z(-4, 90, 30, 10, 10); /* 0.75 - drawn. */
147 pass = piglit_probe_pixel_rgb(15, 15, white) && pass;
148 pass = piglit_probe_pixel_rgb(15, 35, clear) && pass;
149 pass = piglit_probe_pixel_rgb(35, 15, white) && pass;
150 pass = piglit_probe_pixel_rgb(35, 35, clear) && pass;
151 pass = piglit_probe_pixel_rgb(55, 15, white) && pass;
152 pass = piglit_probe_pixel_rgb(55, 35, clear) && pass;
153 pass = piglit_probe_pixel_rgb(75, 15, white) && pass;
154 pass = piglit_probe_pixel_rgb(75, 35, clear) && pass;
155 pass = piglit_probe_pixel_rgb(95, 15, white) && pass;
156 pass = piglit_probe_pixel_rgb(95, 35, clear) && pass;
158 piglit_present_results();
160 return pass ? PIGLIT_PASS : PIGLIT_FAIL;