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
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
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?
37 * If ARB_sampler_objects exists in the implementation, the
38 * sampler objects should also include this parameter per
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
53 test_getter(GLuint sampler
)
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");
64 glSamplerParameteri(sampler
, GL_TEXTURE_SRGB_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");
73 glSamplerParameteri(sampler
, GL_TEXTURE_SRGB_DECODE_EXT
, GL_DECODE_EXT
);
79 draw_and_test(int x
, int y
, const float *expected
)
81 piglit_draw_rect_tex(x
, y
, piglit_width
/ 2, piglit_height
/ 2,
83 return piglit_probe_rect_rgba(x
, y
, piglit_width
/ 2, piglit_height
/ 2,
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];
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
,
121 pass
= draw_and_test(piglit_width
/ 2, 0, tex_data
) && pass
;
123 /* Now, test statechanging the samplers themselves between top left
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,
134 piglit_present_results();
136 glDeleteSamplers(1, &sampler
);
137 glDeleteSamplers(1, &sampler2
);
138 glDeleteTextures(1, &tex
);
140 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
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
);