ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_sampler_objects / srgb-decode.c
blobc058162782199256ecc330231d566a827f9d0301
1 /*
2 * Copyright © 2012 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.
24 /**
25 * @file srgb-decode.c
27 * Tests interaction between GL_ARB_sampler_objects and
28 * GL_EXT_texture_sRGB_decode.
30 * From the GL_EXT_texture_sRGB_decode spec:
32 * "4) Should we add forward-looking support for
33 * ARB_sampler_objects?
35 * RESOLVED: YES
37 * If ARB_sampler_objects exists in the implementation, the
38 * sampler objects should also include this parameter per
39 * sampler."
42 #include "piglit-util-gl.h"
44 PIGLIT_GL_TEST_CONFIG_BEGIN
46 config.supports_gl_compat_version = 10;
48 config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
50 PIGLIT_GL_TEST_CONFIG_END
52 static bool
53 test_getter(GLuint sampler)
55 bool pass = true;
56 GLint i;
58 glGetSamplerParameteriv(sampler, GL_TEXTURE_SRGB_DECODE_EXT, &i);
59 if (i != GL_DECODE_EXT) {
60 fprintf(stderr, "Default sampler decode was %s, expected %s\n",
61 piglit_get_gl_enum_name(i), "GL_DECODE_EXT");
62 pass = false;
64 glSamplerParameteri(sampler, GL_TEXTURE_SRGB_DECODE_EXT,
65 GL_SKIP_DECODE_EXT);
66 glGetSamplerParameteriv(sampler, GL_TEXTURE_SRGB_DECODE_EXT, &i);
67 if (i != GL_SKIP_DECODE_EXT) {
68 fprintf(stderr, "Updated sampler decode was %s, expected %s\n",
69 piglit_get_gl_enum_name(i), "GL_SKIP_DECODE_EXT");
70 pass = false;
73 glSamplerParameteri(sampler, GL_TEXTURE_SRGB_DECODE_EXT, GL_DECODE_EXT);
75 return pass;
78 static bool
79 draw_and_test(int x, int y, const float *expected)
81 piglit_draw_rect_tex(x, y, piglit_width / 2, piglit_height / 2,
82 0, 0, 1, 1);
83 return piglit_probe_rect_rgba(x, y, piglit_width / 2, piglit_height / 2,
84 expected);
87 enum piglit_result
88 piglit_display(void)
90 bool pass = true;
91 GLuint tex, sampler, sampler2;
92 const float tex_data[4] = {0.2, 0.4, 0.6, 0.8};
93 float decoded_tex_data[4];
94 int i;
96 for (i = 0; i < 3; i++) {
97 decoded_tex_data[i] = piglit_srgb_to_linear(tex_data[i]);
99 decoded_tex_data[3] = tex_data[3];
101 glClear(GL_COLOR_BUFFER_BIT);
103 glGenTextures(1, &tex);
104 glBindTexture(GL_TEXTURE_2D, tex);
105 glTexImage2D(GL_TEXTURE_2D, 0, GL_SRGB8_ALPHA8, 1, 1, 0,
106 GL_RGBA, GL_FLOAT, tex_data);
108 glGenSamplers(1, &sampler);
110 pass = test_getter(sampler) && pass;
112 /* First, test statechanging the value of the flag between the
113 * bottom left and bottom right corners.
115 glEnable(GL_TEXTURE_2D);
116 glBindSampler(0, sampler);
117 pass = draw_and_test(0, 0, decoded_tex_data) && pass;
119 glSamplerParameteri(sampler, GL_TEXTURE_SRGB_DECODE_EXT,
120 GL_SKIP_DECODE_EXT);
121 pass = draw_and_test(piglit_width / 2, 0, tex_data) && pass;
123 /* Now, test statechanging the samplers themselves between top left
124 * and top right.
126 glGenSamplers(1, &sampler2);
127 glBindSampler(0, sampler2);
128 pass = draw_and_test(0, piglit_height / 2, decoded_tex_data) && pass;
130 glBindSampler(0, sampler);
131 pass = draw_and_test(piglit_width / 2, piglit_height / 2,
132 tex_data) && pass;
134 piglit_present_results();
136 glDeleteSamplers(1, &sampler);
137 glDeleteSamplers(1, &sampler2);
138 glDeleteTextures(1, &tex);
140 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
144 void
145 piglit_init(int argc, char **argv)
147 piglit_require_extension("GL_ARB_sampler_objects");
148 piglit_require_extension("GL_EXT_texture_sRGB");
149 piglit_require_extension("GL_EXT_texture_sRGB_decode");
151 piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);