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