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.
7
#include "test_utils/ANGLETest.h"
9
#include "test_utils/gl_raii.h"
11
using namespace angle;
16
class WEBGLVideoTextureTest : public ANGLETest
19
WEBGLVideoTextureTest()
24
setConfigGreenBits(8);
26
setConfigAlphaBits(8);
30
class WEBGLVideoTextureES300Test : public ANGLETest
33
WEBGLVideoTextureES300Test()
38
setConfigGreenBits(8);
40
setConfigAlphaBits(8);
44
// Test to verify samplerVideoWEBGL works fine when extension is enabled.
45
TEST_P(WEBGLVideoTextureTest, VerifySamplerVideoWEBGL)
47
ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_WEBGL_video_texture"));
49
constexpr char kVS[] = R"(
50
attribute vec2 position;
51
varying mediump vec2 texCoord;
54
gl_Position = vec4(position, 0, 1);
55
texCoord = position * 0.5 + vec2(0.5);
58
constexpr char kFS[] = R"(
60
#extension GL_WEBGL_video_texture : require
61
precision mediump float;
62
varying mediump vec2 texCoord;
63
uniform mediump samplerVideoWEBGL s;
66
gl_FragColor = textureVideoWEBGL(s, texCoord);
69
ANGLE_GL_PROGRAM(program, kVS, kFS);
70
// Initialize basic red texture.
71
const std::vector<GLColor> redColors(4, GLColor::red);
73
glBindTexture(GL_TEXTURE_VIDEO_IMAGE_WEBGL, texture);
74
glTexImage2D(GL_TEXTURE_VIDEO_IMAGE_WEBGL, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
76
glTexParameteri(GL_TEXTURE_VIDEO_IMAGE_WEBGL, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
77
glTexParameteri(GL_TEXTURE_VIDEO_IMAGE_WEBGL, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
81
drawQuad(program, "position", 0.0f);
82
EXPECT_PIXEL_RECT_EQ(0, 0, getWindowWidth(), getWindowHeight(), GLColor::red);
83
glBindTexture(GL_TEXTURE_VIDEO_IMAGE_WEBGL, 0);
87
// Test to verify samplerVideoWEBGL works fine as parameter of user defined function
88
// when extension is enabled.
89
TEST_P(WEBGLVideoTextureTest, VerifySamplerVideoWEBGLAsParameter)
91
ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_WEBGL_video_texture"));
93
constexpr char kVS[] = R"(
94
attribute vec2 position;
95
varying mediump vec2 texCoord;
98
gl_Position = vec4(position, 0, 1);
99
texCoord = position * 0.5 + vec2(0.5);
102
constexpr char kFS[] = R"(
104
#extension GL_WEBGL_video_texture : require
105
precision mediump float;
106
varying mediump vec2 texCoord;
107
uniform mediump samplerVideoWEBGL s;
109
vec4 wrapTextureVideoWEBGL(samplerVideoWEBGL sampler, vec2 coord)
111
return textureVideoWEBGL(sampler, coord);
116
gl_FragColor = wrapTextureVideoWEBGL(s, texCoord);
119
ANGLE_GL_PROGRAM(program, kVS, kFS);
120
// Initialize basic red texture.
121
const std::vector<GLColor> redColors(4, GLColor::red);
123
glBindTexture(GL_TEXTURE_VIDEO_IMAGE_WEBGL, texture);
124
glTexImage2D(GL_TEXTURE_VIDEO_IMAGE_WEBGL, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
126
glTexParameteri(GL_TEXTURE_VIDEO_IMAGE_WEBGL, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
127
glTexParameteri(GL_TEXTURE_VIDEO_IMAGE_WEBGL, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
128
ASSERT_GL_NO_ERROR();
130
drawQuad(program, "position", 0.0f);
131
EXPECT_PIXEL_RECT_EQ(0, 0, getWindowWidth(), getWindowHeight(), GLColor::red);
132
glBindTexture(GL_TEXTURE_VIDEO_IMAGE_WEBGL, 0);
133
ASSERT_GL_NO_ERROR();
136
// Test to ensure ANGLE state manager knows the change when binding VideoImage
137
// and can handle it correctly based on the program.
138
TEST_P(WEBGLVideoTextureTest, VerifyStateManagerKnowsBindingVideoImage)
140
ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_WEBGL_video_texture"));
142
constexpr char kVS[] = R"(
143
attribute vec2 position;
144
varying mediump vec2 texCoord;
147
gl_Position = vec4(position, 0, 1);
148
texCoord = position * 0.5 + vec2(0.5);
151
constexpr char kFS2D[] = R"(
153
precision mediump float;
154
varying mediump vec2 texCoord;
155
uniform mediump sampler2D s;
159
gl_FragColor = texture2D(s, texCoord);
162
constexpr char kFSVideoImage[] = R"(
164
#extension GL_WEBGL_video_texture : require
165
precision mediump float;
166
varying mediump vec2 texCoord;
167
uniform mediump samplerVideoWEBGL s;
171
gl_FragColor = textureVideoWEBGL(s, texCoord);
174
ANGLE_GL_PROGRAM(program2D, kVS, kFS2D);
175
ANGLE_GL_PROGRAM(programVideoImage, kVS, kFSVideoImage);
176
// Initialize basic red texture.
177
const std::vector<GLColor> redColors(4, GLColor::red);
178
const std::vector<GLColor> greenColors(4, GLColor::green);
180
GLTexture textureVideoImage;
181
glBindTexture(GL_TEXTURE_2D, texture2D);
182
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, redColors.data());
183
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
184
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
185
ASSERT_GL_NO_ERROR();
187
// This should unbind the native TEXTURE_2D
188
glBindTexture(GL_TEXTURE_VIDEO_IMAGE_WEBGL, textureVideoImage);
189
glTexImage2D(GL_TEXTURE_VIDEO_IMAGE_WEBGL, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
191
glTexParameteri(GL_TEXTURE_VIDEO_IMAGE_WEBGL, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
192
glTexParameteri(GL_TEXTURE_VIDEO_IMAGE_WEBGL, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
193
ASSERT_GL_NO_ERROR();
195
// ANGLE will check state change and apply changes through state manager. If state manager
196
// is aware of the unbind, it will bind the correct texture back in native and the draw should
198
drawQuad(program2D, "position", 0.0f);
199
EXPECT_PIXEL_RECT_EQ(0, 0, getWindowWidth(), getWindowHeight(), GLColor::red);
200
drawQuad(programVideoImage, "position", 0.0f);
201
EXPECT_PIXEL_RECT_EQ(0, 0, getWindowWidth(), getWindowHeight(), GLColor::green);
202
drawQuad(program2D, "position", 0.0f);
203
EXPECT_PIXEL_RECT_EQ(0, 0, getWindowWidth(), getWindowHeight(), GLColor::red);
205
glBindTexture(GL_TEXTURE_VIDEO_IMAGE_WEBGL, 0);
206
glBindTexture(GL_TEXTURE_2D, 0);
207
ASSERT_GL_NO_ERROR();
210
// Test to verify samplerVideoWEBGL works fine in ES300 when extension is enabled.
211
TEST_P(WEBGLVideoTextureES300Test, VerifySamplerVideoWEBGLInES300)
213
ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_WEBGL_video_texture"));
215
constexpr char kVS[] = R"(#version 300 es
217
out mediump vec2 texCoord;
221
gl_Position = vec4(position, 0, 1);
222
texCoord = position * 0.5 + vec2(0.5);
225
constexpr char kFS[] = R"(#version 300 es
226
#extension GL_WEBGL_video_texture : require
227
precision mediump float;
228
in mediump vec2 texCoord;
229
uniform mediump samplerVideoWEBGL s;
230
out vec4 my_FragColor;
233
my_FragColor = texture(s, texCoord);
236
ANGLE_GL_PROGRAM(program, kVS, kFS);
237
// Initialize basic red texture.
238
const std::vector<GLColor> redColors(4, GLColor::red);
240
glBindTexture(GL_TEXTURE_VIDEO_IMAGE_WEBGL, texture);
241
glTexImage2D(GL_TEXTURE_VIDEO_IMAGE_WEBGL, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
243
glTexParameteri(GL_TEXTURE_VIDEO_IMAGE_WEBGL, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
244
glTexParameteri(GL_TEXTURE_VIDEO_IMAGE_WEBGL, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
245
ASSERT_GL_NO_ERROR();
247
drawQuad(program, "position", 0.0f);
248
EXPECT_PIXEL_RECT_EQ(0, 0, getWindowWidth(), getWindowHeight(), GLColor::red);
249
glBindTexture(GL_TEXTURE_VIDEO_IMAGE_WEBGL, 0);
250
ASSERT_GL_NO_ERROR();
253
ANGLE_INSTANTIATE_TEST_ES2_AND_ES3(WEBGLVideoTextureTest);
254
ANGLE_INSTANTIATE_TEST_ES3(WEBGLVideoTextureES300Test);