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 // EmulateGLFragColorBroadcast_test.cpp:
7 // Tests for gl_FragColor broadcast behavior emulation.
8 //
9
10 #include "GLSLANG/ShaderLang.h"
11 #include "angle_gl.h"
12 #include "gtest/gtest.h"
13 #include "tests/test_utils/compiler_test.h"
14
15 using namespace sh;
16
17 namespace
18 {
19
20 const int kMaxDrawBuffers = 2;
21
22 class EmulateGLFragColorBroadcastTest : public MatchOutputCodeTest
23 {
24 public:
EmulateGLFragColorBroadcastTest()25 EmulateGLFragColorBroadcastTest()
26 : MatchOutputCodeTest(GL_FRAGMENT_SHADER,
27 0, // compile options
28 SH_GLSL_COMPATIBILITY_OUTPUT)
29 {
30 getResources()->MaxDrawBuffers = kMaxDrawBuffers;
31 getResources()->EXT_draw_buffers = 1;
32 }
33 };
34
35 // Verifies that without explicitly enabling GL_EXT_draw_buffers extension
36 // in the shader, no broadcast emulation.
TEST_F(EmulateGLFragColorBroadcastTest,FragColorNoBroadcast)37 TEST_F(EmulateGLFragColorBroadcastTest, FragColorNoBroadcast)
38 {
39 const std::string shaderString =
40 "void main()\n"
41 "{\n"
42 " gl_FragColor = vec4(1, 0, 0, 0);\n"
43 "}\n";
44 compile(shaderString);
45 EXPECT_TRUE(foundInCode("gl_FragColor"));
46 EXPECT_FALSE(foundInCode("gl_FragData[0]"));
47 EXPECT_FALSE(foundInCode("gl_FragData[1]"));
48 }
49
50 // Verifies that with explicitly enabling GL_EXT_draw_buffers extension
51 // in the shader, broadcast is emualted by replacing gl_FragColor with gl_FragData.
TEST_F(EmulateGLFragColorBroadcastTest,FragColorBroadcast)52 TEST_F(EmulateGLFragColorBroadcastTest, FragColorBroadcast)
53 {
54 const std::string shaderString =
55 "#extension GL_EXT_draw_buffers : require\n"
56 "void main()\n"
57 "{\n"
58 " gl_FragColor = vec4(1, 0, 0, 0);\n"
59 "}\n";
60 compile(shaderString);
61 EXPECT_FALSE(foundInCode("gl_FragColor"));
62 EXPECT_TRUE(foundInCode("gl_FragData[0]"));
63 EXPECT_TRUE(foundInCode("gl_FragData[1]"));
64 }
65
66 // Verifies that with explicitly enabling GL_EXT_draw_buffers extension
67 // in the shader with an empty main(), anothing happens.
TEST_F(EmulateGLFragColorBroadcastTest,EmptyMain)68 TEST_F(EmulateGLFragColorBroadcastTest, EmptyMain)
69 {
70 const std::string shaderString =
71 "#extension GL_EXT_draw_buffers : require\n"
72 "void main()\n"
73 "{\n"
74 "}\n";
75 compile(shaderString);
76 EXPECT_FALSE(foundInCode("gl_FragColor"));
77 EXPECT_FALSE(foundInCode("gl_FragData[0]"));
78 EXPECT_FALSE(foundInCode("gl_FragData[1]"));
79 }
80
81 } // namespace
82