• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2016 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 
7 // SRGBFramebufferTest.cpp: Tests of sRGB framebuffer functionality.
8 
9 #include "test_utils/ANGLETest.h"
10 #include "test_utils/gl_raii.h"
11 
12 namespace angle
13 {
14 
15 class SRGBFramebufferTest : public ANGLETest
16 {
17   protected:
SRGBFramebufferTest()18     SRGBFramebufferTest()
19     {
20         setWindowWidth(128);
21         setWindowHeight(128);
22         setConfigRedBits(8);
23         setConfigGreenBits(8);
24         setConfigBlueBits(8);
25         setConfigAlphaBits(8);
26     }
27 
testSetUp()28     void testSetUp() override
29     {
30         mProgram = CompileProgram(essl1_shaders::vs::Simple(), essl1_shaders::fs::UniformColor());
31         ASSERT_NE(0u, mProgram);
32 
33         mColorLocation = glGetUniformLocation(mProgram, essl1_shaders::ColorUniform());
34         ASSERT_NE(-1, mColorLocation);
35     }
36 
testTearDown()37     void testTearDown() override { glDeleteProgram(mProgram); }
38 
39     GLuint mProgram      = 0;
40     GLint mColorLocation = -1;
41 };
42 
43 // Test basic validation of GL_EXT_sRGB_write_control
TEST_P(SRGBFramebufferTest,Validation)44 TEST_P(SRGBFramebufferTest, Validation)
45 {
46     GLenum expectedError =
47         IsGLExtensionEnabled("GL_EXT_sRGB_write_control") ? GL_NO_ERROR : GL_INVALID_ENUM;
48 
49     GLboolean value = GL_FALSE;
50     glEnable(GL_FRAMEBUFFER_SRGB_EXT);
51     EXPECT_GL_ERROR(expectedError);
52 
53     glGetBooleanv(GL_FRAMEBUFFER_SRGB_EXT, &value);
54     EXPECT_GL_ERROR(expectedError);
55     if (expectedError == GL_NO_ERROR)
56     {
57         EXPECT_GL_TRUE(value);
58     }
59 
60     glDisable(GL_FRAMEBUFFER_SRGB_EXT);
61     EXPECT_GL_ERROR(expectedError);
62 
63     glGetBooleanv(GL_FRAMEBUFFER_SRGB_EXT, &value);
64     EXPECT_GL_ERROR(expectedError);
65     if (expectedError == GL_NO_ERROR)
66     {
67         EXPECT_GL_FALSE(value);
68     }
69 }
70 
71 // Test basic functionality of GL_EXT_sRGB_write_control
TEST_P(SRGBFramebufferTest,BasicUsage)72 TEST_P(SRGBFramebufferTest, BasicUsage)
73 {
74     if (!IsGLExtensionEnabled("GL_EXT_sRGB_write_control") ||
75         (!IsGLExtensionEnabled("GL_EXT_sRGB") && getClientMajorVersion() < 3))
76     {
77         std::cout
78             << "Test skipped because GL_EXT_sRGB_write_control and GL_EXT_sRGB are not available."
79             << std::endl;
80         return;
81     }
82 
83     GLColor linearColor(64, 127, 191, 255);
84     GLColor srgbColor(13, 54, 133, 255);
85 
86     GLTexture texture;
87     glBindTexture(GL_TEXTURE_2D, texture.get());
88     glTexImage2D(GL_TEXTURE_2D, 0, GL_SRGB_ALPHA_EXT, 1, 1, 0, GL_SRGB_ALPHA_EXT, GL_UNSIGNED_BYTE,
89                  nullptr);
90 
91     GLFramebuffer framebuffer;
92     glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
93     glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
94 
95     glUseProgram(mProgram);
96     glUniform4fv(mColorLocation, 1, srgbColor.toNormalizedVector().data());
97 
98     glEnable(GL_FRAMEBUFFER_SRGB_EXT);
99     drawQuad(mProgram, essl1_shaders::PositionAttrib(), 0.5f);
100     EXPECT_PIXEL_COLOR_NEAR(0, 0, linearColor, 1.0);
101 
102     glDisable(GL_FRAMEBUFFER_SRGB_EXT);
103     drawQuad(mProgram, essl1_shaders::PositionAttrib(), 0.5f);
104     EXPECT_PIXEL_COLOR_NEAR(0, 0, srgbColor, 1.0);
105 }
106 
107 // Use this to select which configurations (e.g. which renderer, which GLES major version) these
108 // tests should be run against.
109 ANGLE_INSTANTIATE_TEST_ES2_AND_ES3(SRGBFramebufferTest);
110 
111 }  // namespace angle
112