Commit 15cff312 by Shahbaz Youssefi Committed by Commit Bot

Move lod-sampling shaders to shader utils

Will be reused in a test in a following change. Bug: angleproject:2914 Change-Id: I4e255d5c762f2a6c064b06c558519d82ec6ead5f Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2239085 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: 's avatarTim Van Patten <timvp@google.com>
parent 000a79f1
...@@ -483,35 +483,15 @@ class Texture2DBaseMaxTestES3 : public ANGLETest ...@@ -483,35 +483,15 @@ class Texture2DBaseMaxTestES3 : public ANGLETest
void initTest() void initTest()
{ {
// Set up program to sample from specific lod level. // Set up program to sample from specific lod level.
constexpr char kVS[] = R"(#version 300 es mProgram.makeRaster(essl3_shaders::vs::Texture2DLod(), essl3_shaders::fs::Texture2DLod());
out vec2 texCoord;
in vec4 position;
void main()
{
gl_Position = vec4(position.xy, 0.0, 1.0);
texCoord = position.xy * 0.5 + 0.5;
})";
constexpr char kFS[] = R"(#version 300 es
precision mediump float;
out vec4 fragColor;
in vec2 texCoord;
uniform float lod;
uniform sampler2D s;
void main()
{
fragColor = textureLod(s, texCoord, lod);
})";
mProgram.makeRaster(kVS, kFS);
ASSERT(mProgram.valid()); ASSERT(mProgram.valid());
glUseProgram(mProgram); glUseProgram(mProgram);
mTextureLocation = glGetUniformLocation(mProgram, "s"); mTextureLocation = glGetUniformLocation(mProgram, essl3_shaders::Texture2DUniform());
ASSERT_NE(-1, mTextureLocation); ASSERT_NE(-1, mTextureLocation);
mLodLocation = glGetUniformLocation(mProgram, "lod"); mLodLocation = glGetUniformLocation(mProgram, essl3_shaders::LodUniform());
ASSERT_NE(-1, mLodLocation); ASSERT_NE(-1, mLodLocation);
// Set up texture with a handful of lods. // Set up texture with a handful of lods.
...@@ -2646,7 +2626,7 @@ TEST_P(Texture2DBaseMaxTestES3, PingPongBaseLevel) ...@@ -2646,7 +2626,7 @@ TEST_P(Texture2DBaseMaxTestES3, PingPongBaseLevel)
for (uint32_t lod = 0; lod < kMipCount - base; ++lod) for (uint32_t lod = 0; lod < kMipCount - base; ++lod)
{ {
setLodUniform(lod); setLodUniform(lod);
drawQuad(mProgram, "position", 0.5f); drawQuad(mProgram, essl3_shaders::PositionAttrib(), 0.5f);
EXPECT_PIXEL_COLOR_EQ(0, 0, kMipColors[base + lod]); EXPECT_PIXEL_COLOR_EQ(0, 0, kMipColors[base + lod]);
} }
} }
...@@ -2658,7 +2638,7 @@ TEST_P(Texture2DBaseMaxTestES3, PingPongBaseLevel) ...@@ -2658,7 +2638,7 @@ TEST_P(Texture2DBaseMaxTestES3, PingPongBaseLevel)
for (uint32_t lod = 0; lod < kMipCount - base; ++lod) for (uint32_t lod = 0; lod < kMipCount - base; ++lod)
{ {
setLodUniform(lod); setLodUniform(lod);
drawQuad(mProgram, "position", 0.5f); drawQuad(mProgram, essl3_shaders::PositionAttrib(), 0.5f);
EXPECT_PIXEL_COLOR_EQ(0, 0, kMipColors[base + lod]); EXPECT_PIXEL_COLOR_EQ(0, 0, kMipColors[base + lod]);
} }
} }
...@@ -2676,7 +2656,7 @@ TEST_P(Texture2DBaseMaxTestES3, SubImageAfterRedefine) ...@@ -2676,7 +2656,7 @@ TEST_P(Texture2DBaseMaxTestES3, SubImageAfterRedefine)
for (uint32_t lod = 0; lod < kMipCount; ++lod) for (uint32_t lod = 0; lod < kMipCount; ++lod)
{ {
setLodUniform(lod); setLodUniform(lod);
drawQuad(mProgram, "position", 0.5f); drawQuad(mProgram, essl3_shaders::PositionAttrib(), 0.5f);
EXPECT_PIXEL_COLOR_EQ(0, 0, kMipColors[lod]); EXPECT_PIXEL_COLOR_EQ(0, 0, kMipColors[lod]);
} }
...@@ -2719,7 +2699,7 @@ TEST_P(Texture2DBaseMaxTestES3, SubImageAfterRedefine) ...@@ -2719,7 +2699,7 @@ TEST_P(Texture2DBaseMaxTestES3, SubImageAfterRedefine)
for (uint32_t lod = 0; lod < kMipCount; ++lod) for (uint32_t lod = 0; lod < kMipCount; ++lod)
{ {
setLodUniform(lod); setLodUniform(lod);
drawQuad(mProgram, "position", 0.5f); drawQuad(mProgram, essl3_shaders::PositionAttrib(), 0.5f);
EXPECT_PIXEL_COLOR_EQ(0, 0, kSubImageMipColors[lod]); EXPECT_PIXEL_COLOR_EQ(0, 0, kSubImageMipColors[lod]);
EXPECT_PIXEL_COLOR_EQ(w, 0, kNewMipColors[lod]); EXPECT_PIXEL_COLOR_EQ(w, 0, kNewMipColors[lod]);
EXPECT_PIXEL_COLOR_EQ(0, h, kNewMipColors[lod]); EXPECT_PIXEL_COLOR_EQ(0, h, kNewMipColors[lod]);
...@@ -2737,7 +2717,7 @@ TEST_P(Texture2DBaseMaxTestES3, IncompatiblyRedefineLevelThenRevert) ...@@ -2737,7 +2717,7 @@ TEST_P(Texture2DBaseMaxTestES3, IncompatiblyRedefineLevelThenRevert)
for (uint32_t lod = 0; lod < kMipCount; ++lod) for (uint32_t lod = 0; lod < kMipCount; ++lod)
{ {
setLodUniform(lod); setLodUniform(lod);
drawQuad(mProgram, "position", 0.5f); drawQuad(mProgram, essl3_shaders::PositionAttrib(), 0.5f);
EXPECT_PIXEL_COLOR_EQ(0, 0, kMipColors[lod]); EXPECT_PIXEL_COLOR_EQ(0, 0, kMipColors[lod]);
} }
...@@ -2761,7 +2741,7 @@ TEST_P(Texture2DBaseMaxTestES3, IncompatiblyRedefineLevelThenRevert) ...@@ -2761,7 +2741,7 @@ TEST_P(Texture2DBaseMaxTestES3, IncompatiblyRedefineLevelThenRevert)
for (uint32_t lod = 0; lod < kMipCount; ++lod) for (uint32_t lod = 0; lod < kMipCount; ++lod)
{ {
setLodUniform(lod); setLodUniform(lod);
drawQuad(mProgram, "position", 0.5f); drawQuad(mProgram, essl3_shaders::PositionAttrib(), 0.5f);
EXPECT_PIXEL_COLOR_EQ(0, 0, lod == 1 ? GLColor::cyan : kMipColors[lod]); EXPECT_PIXEL_COLOR_EQ(0, 0, lod == 1 ? GLColor::cyan : kMipColors[lod]);
} }
} }
...@@ -2777,7 +2757,7 @@ TEST_P(Texture2DBaseMaxTestES3, RedefineEveryLevelToAnotherFormat) ...@@ -2777,7 +2757,7 @@ TEST_P(Texture2DBaseMaxTestES3, RedefineEveryLevelToAnotherFormat)
for (uint32_t lod = 0; lod < kMipCount; ++lod) for (uint32_t lod = 0; lod < kMipCount; ++lod)
{ {
setLodUniform(lod); setLodUniform(lod);
drawQuad(mProgram, "position", 0.5f); drawQuad(mProgram, essl3_shaders::PositionAttrib(), 0.5f);
EXPECT_PIXEL_COLOR_EQ(0, 0, kMipColors[lod]); EXPECT_PIXEL_COLOR_EQ(0, 0, kMipColors[lod]);
} }
...@@ -2802,7 +2782,7 @@ TEST_P(Texture2DBaseMaxTestES3, RedefineEveryLevelToAnotherFormat) ...@@ -2802,7 +2782,7 @@ TEST_P(Texture2DBaseMaxTestES3, RedefineEveryLevelToAnotherFormat)
for (uint32_t lod = 0; lod < kMipCount; ++lod) for (uint32_t lod = 0; lod < kMipCount; ++lod)
{ {
setLodUniform(lod); setLodUniform(lod);
drawQuad(mProgram, "position", 0.5f); drawQuad(mProgram, essl3_shaders::PositionAttrib(), 0.5f);
GLColor32F mipColor32F = kNewMipColors[lod]; GLColor32F mipColor32F = kNewMipColors[lod];
GLColor mipColor(static_cast<GLubyte>(std::roundf(mipColor32F.R * 255)), GLColor mipColor(static_cast<GLubyte>(std::roundf(mipColor32F.R * 255)),
......
...@@ -447,6 +447,14 @@ const char *PositionAttrib() ...@@ -447,6 +447,14 @@ const char *PositionAttrib()
{ {
return "a_position"; return "a_position";
} }
const char *Texture2DUniform()
{
return "u_tex2D";
}
const char *LodUniform()
{
return "u_lod";
}
namespace vs namespace vs
{ {
...@@ -486,6 +494,21 @@ void main() ...@@ -486,6 +494,21 @@ void main()
})"; })";
} }
// A shader that simply passes through attribute a_position, setting it to gl_Position and varying
// texcoord.
const char *Texture2DLod()
{
return R"(#version 300 es
in vec4 a_position;
out vec2 v_texCoord;
void main()
{
gl_Position = vec4(a_position.xy, 0.0, 1.0);
v_texCoord = a_position.xy * 0.5 + vec2(0.5);
})";
}
} // namespace vs } // namespace vs
namespace fs namespace fs
...@@ -527,6 +550,22 @@ void main() ...@@ -527,6 +550,22 @@ void main()
})"; })";
} }
// A shader that samples the texture at a given lod.
const char *Texture2DLod()
{
return R"(#version 300 es
precision mediump float;
uniform sampler2D u_tex2D;
uniform float u_lod;
in vec2 v_texCoord;
out vec4 my_FragColor;
void main()
{
my_FragColor = textureLod(u_tex2D, v_texCoord, u_lod);
})";
}
} // namespace fs } // namespace fs
} // namespace essl3_shaders } // namespace essl3_shaders
......
...@@ -103,6 +103,8 @@ namespace essl3_shaders ...@@ -103,6 +103,8 @@ namespace essl3_shaders
{ {
ANGLE_UTIL_EXPORT const char *PositionAttrib(); ANGLE_UTIL_EXPORT const char *PositionAttrib();
ANGLE_UTIL_EXPORT const char *Texture2DUniform();
ANGLE_UTIL_EXPORT const char *LodUniform();
namespace vs namespace vs
{ {
...@@ -117,6 +119,10 @@ ANGLE_UTIL_EXPORT const char *Simple(); ...@@ -117,6 +119,10 @@ ANGLE_UTIL_EXPORT const char *Simple();
// v_position. // v_position.
ANGLE_UTIL_EXPORT const char *Passthrough(); ANGLE_UTIL_EXPORT const char *Passthrough();
// A shader that simply passes through attribute a_position, setting it to gl_Position and varying
// texcoord.
ANGLE_UTIL_EXPORT const char *Texture2DLod();
} // namespace vs } // namespace vs
namespace fs namespace fs
...@@ -131,6 +137,9 @@ ANGLE_UTIL_EXPORT const char *Green(); ...@@ -131,6 +137,9 @@ ANGLE_UTIL_EXPORT const char *Green();
// A shader that fills with 100% opaque blue. // A shader that fills with 100% opaque blue.
ANGLE_UTIL_EXPORT const char *Blue(); ANGLE_UTIL_EXPORT const char *Blue();
// A shader that samples the texture at a given lod.
ANGLE_UTIL_EXPORT const char *Texture2DLod();
} // namespace fs } // namespace fs
} // namespace essl3_shaders } // namespace essl3_shaders
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment