Add a test for sampler as a function parameter
This adds some coverage for samplers that's missing from dEQP.
The test shader passes a sampler to an user-defined function, samples
the texture there and sets the returned sample to gl_FragColor. The
test then checks that the shader result is correct.
BUG=angleproject:1261
TEST=angle_end2end_tests
Change-Id: I2cc511e591a4af01515c6fb38fd43c5f15337bcb
Reviewed-on: https://chromium-review.googlesource.com/321622
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Zhenyao Mo <zmo@chromium.org>
Tested-by: Olli Etuaho <oetuaho@nvidia.com>
diff --git a/src/tests/gl_tests/TextureTest.cpp b/src/tests/gl_tests/TextureTest.cpp
index cddb415..7aff3f4 100644
--- a/src/tests/gl_tests/TextureTest.cpp
+++ b/src/tests/gl_tests/TextureTest.cpp
@@ -284,6 +284,33 @@
GLint mDrawScaleUniformLocation;
};
+class Sampler2DAsFunctionParameterTest : public Texture2DTest
+{
+ protected:
+ Sampler2DAsFunctionParameterTest() : Texture2DTest() {}
+
+ std::string getFragmentShaderSource() override
+ {
+ return std::string(SHADER_SOURCE
+ (
+ precision highp float;
+ uniform sampler2D tex;
+ varying vec2 texcoord;
+
+ vec4 computeFragColor(sampler2D aTex)
+ {
+ return texture2D(aTex, texcoord);
+ }
+
+ void main()
+ {
+ gl_FragColor = computeFragColor(tex);
+ }
+ )
+ );
+ }
+};
+
class TextureCubeTest : public TexCoordDrawTest
{
protected:
@@ -476,6 +503,24 @@
EXPECT_PIXEL_NEAR(px, py, 0, 180, 0, 255, 2);
}
+TEST_P(Sampler2DAsFunctionParameterTest, Sampler2DAsFunctionParameter)
+{
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, mTexture2D);
+ GLubyte texData[4];
+ texData[0] = 0;
+ texData[1] = 128;
+ texData[2] = 0;
+ texData[3] = 255;
+ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
+ glUseProgram(mProgram);
+ glUniform1i(mTexture2DUniformLocation, 0);
+ drawQuad(mProgram, "position", 0.5f);
+ EXPECT_GL_NO_ERROR();
+
+ EXPECT_PIXEL_NEAR(0, 0, 0, 128, 0, 255, 2);
+}
+
// Copy of a test in conformance/textures/texture-mips, to test generate mipmaps
TEST_P(Texture2DTestWithDrawScale, MipmapsTwice)
{
@@ -1238,6 +1283,7 @@
ANGLE_INSTANTIATE_TEST(Texture2DTest, ES2_D3D9(), ES2_D3D11(), ES2_D3D11_FL9_3());
ANGLE_INSTANTIATE_TEST(TextureCubeTest, ES2_D3D9(), ES2_D3D11(), ES2_D3D11_FL9_3());
ANGLE_INSTANTIATE_TEST(Texture2DTestWithDrawScale, ES2_D3D9(), ES2_D3D11(), ES2_D3D11_FL9_3());
+ANGLE_INSTANTIATE_TEST(Sampler2DAsFunctionParameterTest, ES2_D3D9(), ES2_D3D11(), ES2_D3D11_FL9_3());
ANGLE_INSTANTIATE_TEST(Texture2DArrayTestES3, ES3_D3D11(), ES3_OPENGL());
ANGLE_INSTANTIATE_TEST(TextureLimitsTest, ES2_D3D11(), ES2_OPENGL());