2 * Copyright © 2015 Advanced Micro Devices, 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
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
24 #include "piglit-util-gl.h"
27 static bool test_srgb
;
29 static enum piglit_result
30 draw(struct egl_state
*state
)
32 enum piglit_result result
= PIGLIT_PASS
;
33 float green
[] = {0, 0.3, 0, 0};
34 float expected_green
[4];
35 float expected_blend
[4];
37 eglMakeCurrent(state
->egl_dpy
, state
->surf
, state
->surf
, state
->ctx
);
39 glViewport(0, 0, state
->width
, state
->height
);
40 piglit_ortho_projection(state
->width
, state
->height
, GL_FALSE
);
42 glClearColor(0.5, 0.5, 0.5, 1.0);
43 glClear(GL_COLOR_BUFFER_BIT
);
45 glColor4f(green
[0], green
[1], green
[2], green
[3]);
47 /* Draw first without blending. */
48 piglit_draw_rect(0, 0, 20, 20);
50 /* Draw second with blending. */
51 piglit_draw_rect(20, 0, 20, 20);
53 glBlendFunc(GL_ONE
, GL_ONE
);
54 piglit_draw_rect(20, 0, 20, 20);
58 memcpy(expected_green
, green
, sizeof(float) * 4);
60 expected_green
[1] = piglit_linear_to_srgb(green
[1]);
61 if (!piglit_probe_rect_rgb(0, 0, 20, 20, expected_green
))
65 memcpy(expected_blend
, green
, sizeof(float) * 4);
67 expected_blend
[1] = piglit_linear_to_srgb(green
[1] * 2.0);
69 expected_blend
[1] *= 2;
70 if (!piglit_probe_rect_rgb(20, 0, 20, 20, expected_blend
))
73 eglSwapBuffers(state
->egl_dpy
, state
->surf
);
78 main(int argc
, char *argv
[])
81 const char *extensions
[] = {"EGL_KHR_gl_colorspace", NULL
};
82 const EGLint surface_linear
[] = {
83 EGL_GL_COLORSPACE_KHR
, EGL_GL_COLORSPACE_LINEAR_KHR
,
86 const EGLint surface_srgb
[] = {
87 EGL_GL_COLORSPACE_KHR
, EGL_GL_COLORSPACE_SRGB_KHR
,
90 const EGLint test_attribs
[] = {
91 EGL_RENDERABLE_TYPE
, EGL_OPENGL_ES_BIT
,
95 piglit_strip_arg(&argc
, argv
, "-fbo");
96 test_srgb
= piglit_strip_arg(&argc
, argv
, "srgb");
100 test
.stop_on_failure
= true;
101 test
.config_attribs
= test_attribs
;
102 test
.surface_attribs
= test_srgb
? surface_srgb
: surface_linear
;
103 test
.extensions
= extensions
;
105 return egl_util_run(&test
, argc
, argv
) == PIGLIT_PASS
? EXIT_SUCCESS