xref: /aosp_15_r20/external/angle/src/tests/gl_tests/FloatingPointSurfaceTest.cpp (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1 //
2 // Copyright 2017 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 // FloatingPointSurfaceTest.cpp : Test functionality of the EGL_EXT_pixel_format_float extension.
8 
9 #include "test_utils/ANGLETest.h"
10 
11 using namespace angle;
12 
13 class FloatingPointSurfaceTest : public ANGLETest<>
14 {
15   protected:
FloatingPointSurfaceTest()16     FloatingPointSurfaceTest()
17     {
18         setWindowWidth(512);
19         setWindowHeight(512);
20         setConfigRedBits(16);
21         setConfigGreenBits(16);
22         setConfigBlueBits(16);
23         setConfigAlphaBits(16);
24         setConfigComponentType(EGL_COLOR_COMPONENT_TYPE_FLOAT_EXT);
25     }
26 
testSetUp()27     void testSetUp() override
28     {
29         constexpr char kFS[] =
30             "precision highp float;\n"
31             "void main()\n"
32             "{\n"
33             "   gl_FragColor = vec4(1.0, 2.0, 3.0, 4.0);\n"
34             "}\n";
35 
36         mProgram = CompileProgram(essl1_shaders::vs::Simple(), kFS);
37         ASSERT_NE(0u, mProgram) << "shader compilation failed.";
38 
39         ASSERT_GL_NO_ERROR();
40     }
41 
testTearDown()42     void testTearDown() override { glDeleteProgram(mProgram); }
43 
44     GLuint mProgram;
45 };
46 
47 // Test clearing and checking the color is correct
TEST_P(FloatingPointSurfaceTest,Clearing)48 TEST_P(FloatingPointSurfaceTest, Clearing)
49 {
50     GLColor32F clearColor(0.0f, 1.0f, 2.0f, 3.0f);
51     glClearColor(clearColor.R, clearColor.G, clearColor.B, clearColor.A);
52     glClear(GL_COLOR_BUFFER_BIT);
53     ASSERT_GL_NO_ERROR();
54 
55     EXPECT_PIXEL_COLOR32F_EQ(0, 0, clearColor);
56 }
57 
58 // Test drawing and checking the color is correct
TEST_P(FloatingPointSurfaceTest,Drawing)59 TEST_P(FloatingPointSurfaceTest, Drawing)
60 {
61     glUseProgram(mProgram);
62     drawQuad(mProgram, essl1_shaders::PositionAttrib(), 0.5f);
63 
64     EXPECT_PIXEL_32F_EQ(0, 0, 1.0f, 2.0f, 3.0f, 4.0f);
65 }
66 
67 // Use this to select which configurations (e.g. which renderer, which GLES major version) these
68 // tests should be run against.
69 ANGLE_INSTANTIATE_TEST(FloatingPointSurfaceTest,
70                        ES2_D3D11(),
71                        ES3_D3D11(),
72                        ES2_D3D11_PRESENT_PATH_FAST());
73 
74 // This test suite is not instantiated on some OSes.
75 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(FloatingPointSurfaceTest);
76