1 // 2 // Copyright 2018 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 // GlFragDataNotModified_test.cpp: 7 // Test that the properties of built-in gl_FragData are not modified when a shader is compiled 8 // multiple times. 9 // 10 11 #include "tests/test_utils/ShaderCompileTreeTest.h" 12 13 namespace 14 { 15 16 class GlFragDataNotModifiedTest : public sh::ShaderCompileTreeTest 17 { 18 public: GlFragDataNotModifiedTest()19 GlFragDataNotModifiedTest() {} 20 21 protected: initResources(ShBuiltInResources * resources)22 void initResources(ShBuiltInResources *resources) override 23 { 24 resources->MaxDrawBuffers = 4; 25 resources->EXT_draw_buffers = 1; 26 } 27 getShaderType() const28 ::GLenum getShaderType() const override { return GL_FRAGMENT_SHADER; } getShaderSpec() const29 ShShaderSpec getShaderSpec() const override { return SH_GLES2_SPEC; } 30 }; 31 32 // Test a bug where we could modify the value of a builtin variable. TEST_F(GlFragDataNotModifiedTest,BuiltinRewritingBug)33TEST_F(GlFragDataNotModifiedTest, BuiltinRewritingBug) 34 { 35 const std::string &shaderString = 36 "#extension GL_EXT_draw_buffers : require\n" 37 "precision mediump float;\n" 38 "void main() {\n" 39 " gl_FragData[gl_MaxDrawBuffers] = vec4(0.0);\n" 40 "}"; 41 42 if (compile(shaderString)) 43 { 44 FAIL() << "Shader compilation succeeded, expecting failure\n"; 45 } 46 if (compile(shaderString)) 47 { 48 FAIL() << "Shader compilation succeeded, expecting failure\n"; 49 } 50 } 51 52 } // anonymous namespace 53