1 //
2 // Copyright 2019 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 // samplerVideoWEBGL_test.cpp:
7 // Tests compiling shaders that use samplerVideoWEBGL types
8 //
9
10 #include "GLSLANG/ShaderLang.h"
11 #include "angle_gl.h"
12 #include "gtest/gtest.h"
13 #include "tests/test_utils/ShaderCompileTreeTest.h"
14
15 using namespace sh;
16
17 class SamplerVideoWEBGLTest : public ShaderCompileTreeTest
18 {
19 public:
SamplerVideoWEBGLTest()20 SamplerVideoWEBGLTest() {}
21
initResources(ShBuiltInResources * resources)22 void initResources(ShBuiltInResources *resources) override
23 {
24 resources->WEBGL_video_texture = 1;
25 }
26
27 protected:
getShaderType() const28 ::GLenum getShaderType() const override { return GL_FRAGMENT_SHADER; }
getShaderSpec() const29 ShShaderSpec getShaderSpec() const override { return SH_GLES3_1_SPEC; }
30 };
31
32 // Checks whether compiler returns error when extension isn't enabled but samplerVideoWEBGL is
33 // used in shader.
TEST_F(SamplerVideoWEBGLTest,UsingSamplerVideoWEBGLWithoutWEBGLVideoTextureExtensionRequired)34 TEST_F(SamplerVideoWEBGLTest, UsingSamplerVideoWEBGLWithoutWEBGLVideoTextureExtensionRequired)
35 {
36 const std::string &shaderString =
37 "precision mediump float;\n"
38 "uniform mediump samplerVideoWEBGL s;\n"
39 "void main()\n"
40 "{\n"
41 " gl_FragColor = textureVideoWEBGL(s, vec2(0.0, 0.0));\n"
42 "}\n";
43
44 if (compile(shaderString))
45 {
46 FAIL() << "Shader compilation passed, expecting fail:\n" << mInfoLog;
47 }
48 }
49
50 // Checks whether compiler returns error when extension isn't enabled but use samplerVideoWEBGL is
51 // used in ES300 shader.
TEST_F(SamplerVideoWEBGLTest,UsingSamplerVideoWEBGLWithoutWEBGLVideoTextureExtensionRequiredInES300)52 TEST_F(SamplerVideoWEBGLTest,
53 UsingSamplerVideoWEBGLWithoutWEBGLVideoTextureExtensionRequiredInES300)
54 {
55 const std::string &shaderString =
56 "#version 300 es"
57 "precision mediump float;\n"
58 "uniform mediump samplerVideoWEBGL s;\n"
59 "out vec4 my_FragColor;\n"
60 "void main()\n"
61 "{\n"
62 " my_FragColor = texture(s, vec2(0.0, 0.0));\n"
63 "}\n";
64
65 if (compile(shaderString))
66 {
67 FAIL() << "Shader compilation passed, expecting fail:\n" << mInfoLog;
68 }
69 }
70
71 // Checks whether compiler can support samplerVideoWEBGL as texture2D parameter.
TEST_F(SamplerVideoWEBGLTest,SamplerVideoWEBGLCanBeSupportedInTexture2D)72 TEST_F(SamplerVideoWEBGLTest, SamplerVideoWEBGLCanBeSupportedInTexture2D)
73 {
74 const std::string &shaderString =
75 "#extension GL_WEBGL_video_texture : require\n"
76 "precision mediump float;\n"
77 "uniform mediump samplerVideoWEBGL s;\n"
78 "void main()\n"
79 "{\n"
80 " gl_FragColor = textureVideoWEBGL(s, vec2(0.0, 0.0));\n"
81 "}\n";
82
83 if (!compile(shaderString))
84 {
85 FAIL() << "Shader compilation failed, expecting success:\n" << mInfoLog;
86 }
87 }
88
89 // Checks whether compiler can support samplerVideoWEBGL as texture parameter in ES300.
TEST_F(SamplerVideoWEBGLTest,SamplerVideoWEBGLCanBeSupportedInTextureInES300)90 TEST_F(SamplerVideoWEBGLTest, SamplerVideoWEBGLCanBeSupportedInTextureInES300)
91 {
92 const std::string &shaderString =
93 "#version 300 es\n"
94 "#extension GL_WEBGL_video_texture : require\n"
95 "precision mediump float;\n"
96 "uniform mediump samplerVideoWEBGL s;\n"
97 "out vec4 my_FragColor;\n"
98 "void main()\n"
99 "{\n"
100 " my_FragColor = texture(s, vec2(0.0, 0.0));\n"
101 "}\n";
102
103 if (!compile(shaderString))
104 {
105 FAIL() << "Shader compilation failed, expecting success:\n" << mInfoLog;
106 }
107 }