Path: blob/main_old/src/tests/compiler_tests/ARB_texture_rectangle_test.cpp
1693 views
//1// Copyright 2014 The ANGLE Project Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4//5// ARB_texture_rectangle_test.cpp:6// Test for the ARB_texture_rectangle extension7//89#include "GLSLANG/ShaderLang.h"10#include "angle_gl.h"11#include "gtest/gtest.h"12#include "tests/test_utils/ShaderCompileTreeTest.h"1314using namespace sh;1516class ARBTextureRectangleTestNoExt : public ShaderCompileTreeTest17{18protected:19::GLenum getShaderType() const override { return GL_FRAGMENT_SHADER; }20ShShaderSpec getShaderSpec() const override { return SH_GLES3_SPEC; }21};2223class ARBTextureRectangleTest : public ARBTextureRectangleTestNoExt24{25protected:26void initResources(ShBuiltInResources *resources) override27{28resources->ARB_texture_rectangle = 1;29}30};3132// Check that if the extension is not supported, trying to use the features without having an33// extension directive fails.34TEST_F(ARBTextureRectangleTestNoExt, NewTypeAndBuiltinsWithoutExtensionDirective)35{36const std::string &shaderString =37R"(38precision mediump float;39uniform sampler2DRect tex;40void main()41{42vec4 color = texture2DRect(tex, vec2(1.0));43color = texture2DRectProj(tex, vec3(1.0));44color = texture2DRectProj(tex, vec4(1.0));45})";46if (compile(shaderString))47{48FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;49}50}5152// Check that if the extension is not supported, trying to use the features fails.53TEST_F(ARBTextureRectangleTestNoExt, NewTypeAndBuiltinsWithExtensionDirective)54{55const std::string &shaderString =56R"(57#extension GL_ARB_texture_rectangle : enable58precision mediump float;59uniform sampler2DRect tex;60void main()61{62vec4 color = texture2DRect(tex, vec2(1.0));63color = texture2DRectProj(tex, vec3(1.0));64color = texture2DRectProj(tex, vec4(1.0));65})";66if (compile(shaderString))67{68FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;69}70}7172// Check that new types and builtins are usable even with the #extension directive73// Issue #15 of ARB_texture_rectangle explains that the extension was specified before the74// #extension mechanism was in place so it doesn't require explicit enabling.75TEST_F(ARBTextureRectangleTest, NewTypeAndBuiltinsWithoutExtensionDirective)76{77const std::string &shaderString =78"precision mediump float;\n"79"uniform sampler2DRect tex;\n"80"void main() {\n"81" vec4 color = texture2DRect(tex, vec2(1.0));"82" color = texture2DRectProj(tex, vec3(1.0));"83" color = texture2DRectProj(tex, vec4(1.0));"84"}\n";85if (!compile(shaderString))86{87FAIL() << "Shader compilation failed, expecting success:\n" << mInfoLog;88}89}9091// Test valid usage of the new types and builtins92TEST_F(ARBTextureRectangleTest, NewTypeAndBuiltingsWithExtensionDirective)93{94const std::string &shaderString =95"#extension GL_ARB_texture_rectangle : require\n"96"precision mediump float;\n"97"uniform sampler2DRect tex;\n"98"void main() {\n"99" vec4 color = texture2DRect(tex, vec2(1.0));"100" color = texture2DRectProj(tex, vec3(1.0));"101" color = texture2DRectProj(tex, vec4(1.0));"102"}\n";103if (!compile(shaderString))104{105FAIL() << "Shader compilation failed, expecting success:\n" << mInfoLog;106}107}108109// Check that it is not possible to pass a sampler2DRect where sampler2D is expected, and vice versa110TEST_F(ARBTextureRectangleTest, Rect2DVs2DMismatch)111{112const std::string &shaderString1 =113"#extension GL_ARB_texture_rectangle : require\n"114"precision mediump float;\n"115"uniform sampler2DRect tex;\n"116"void main() {\n"117" vec4 color = texture2D(tex, vec2(1.0));"118"}\n";119if (compile(shaderString1))120{121FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;122}123124const std::string &shaderString2 =125"#extension GL_ARB_texture_rectangle : require\n"126"precision mediump float;\n"127"uniform sampler2D tex;\n"128"void main() {\n"129" vec4 color = texture2DRect(tex, vec2(1.0));"130"}\n";131if (compile(shaderString2))132{133FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;134}135}136137// Disabling ARB_texture_rectangle in GLSL should work, even if it is enabled by default.138// See ARB_texture_rectangle spec: "a shader can still include all variations of #extension139// GL_ARB_texture_rectangle in its source code"140TEST_F(ARBTextureRectangleTest, DisableARBTextureRectangle)141{142const std::string &shaderString =143R"(144#extension GL_ARB_texture_rectangle : disable145146precision mediump float;147148uniform sampler2DRect s;149void main()150{})";151if (compile(shaderString))152{153FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;154}155}156157// The compiler option to disable ARB_texture_rectangle should prevent shaders from158// enabling it.159TEST_F(ARBTextureRectangleTest, CompilerOption)160{161const std::string &shaderString =162R"(163#extension GL_ARB_texture_rectangle : enable164precision mediump float;165uniform sampler2DRect s;166void main() {})";167mExtraCompileOptions |= SH_DISABLE_ARB_TEXTURE_RECTANGLE;168if (compile(shaderString))169{170FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;171}172}173174// The compiler option to disable ARB_texture_rectangle should be toggleable.175TEST_F(ARBTextureRectangleTest, ToggleCompilerOption)176{177const std::string &shaderString =178R"(179precision mediump float;180uniform sampler2DRect s;181void main() {})";182if (!compile(shaderString))183{184FAIL() << "Shader compilation failed, expecting success:\n" << mInfoLog;185}186mExtraCompileOptions |= SH_DISABLE_ARB_TEXTURE_RECTANGLE;187if (compile(shaderString))188{189FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;190}191mExtraCompileOptions &= ~SH_DISABLE_ARB_TEXTURE_RECTANGLE;192if (!compile(shaderString))193{194FAIL() << "Shader compilation failed, expecting success:\n" << mInfoLog;195}196}197198199