Clean up specifying colors and texture scale in MipmapTest

Remove unnecessary scale parameter from MipmapTestES3, and use the
GLColor class and EXPECT_PIXEL_COLOR_EQ instead of EXPECT_PIXEL_EQ for
greater readability.

BUG=angleproject:596
TEST=angle_end2end_tests

Change-Id: I79c30ce85be5d554d89197f8f1ce7ab0c51c11b6
Reviewed-on: https://chromium-review.googlesource.com/344513
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
This commit is contained in:
Olli Etuaho 2016-05-13 12:11:29 +03:00 коммит произвёл Commit Bot
Родитель de44d3a43a
Коммит 190028d3b2
3 изменённых файлов: 71 добавлений и 95 удалений

Просмотреть файл

@ -209,10 +209,8 @@ class MipmapTestES3 : public ANGLETest
: mTextureArray(0),
mTexture3D(0),
mArrayProgram(0),
mTextureArrayScaleUniformLocation(-1),
mTextureArraySliceUniformLocation(-1),
m3DProgram(0),
mTexture3DScaleUniformLocation(-1),
mTexture3DSliceUniformLocation(-1),
mTexture3DLODUniformLocation(-1)
@ -230,20 +228,20 @@ class MipmapTestES3 : public ANGLETest
// Don't put "#version ..." on its own line. See [cpp]p1:
// "If there are sequences of preprocessing tokens within the list of arguments that
// would otherwise act as preprocessing directives, the behavior is undefined"
// clang-format off
return SHADER_SOURCE
( #version 300 es\n
precision highp float;
in vec4 position;
out vec2 texcoord;
uniform vec2 textureScale;
void main()
{
gl_Position = vec4(position.xy * textureScale, 0.0, 1.0);
gl_Position = vec4(position.xy, 0.0, 1.0);
texcoord = (position.xy * 0.5) + 0.5;
}
);
// clang-format on
}
void setUpArrayProgram()
@ -268,14 +266,10 @@ class MipmapTestES3 : public ANGLETest
FAIL() << "shader compilation failed.";
}
mTextureArrayScaleUniformLocation = glGetUniformLocation(mArrayProgram, "textureScale");
ASSERT_NE(-1, mTextureArrayScaleUniformLocation);
mTextureArraySliceUniformLocation = glGetUniformLocation(mArrayProgram, "slice");
ASSERT_NE(-1, mTextureArraySliceUniformLocation);
glUseProgram(mArrayProgram);
glUniform2f(mTextureArrayScaleUniformLocation, 1.0f, 1.0f);
glUseProgram(0);
ASSERT_GL_NO_ERROR();
}
@ -303,9 +297,6 @@ class MipmapTestES3 : public ANGLETest
FAIL() << "shader compilation failed.";
}
mTexture3DScaleUniformLocation = glGetUniformLocation(m3DProgram, "textureScale");
ASSERT_NE(-1, mTexture3DScaleUniformLocation);
mTexture3DSliceUniformLocation = glGetUniformLocation(m3DProgram, "slice");
ASSERT_NE(-1, mTexture3DSliceUniformLocation);
@ -313,7 +304,6 @@ class MipmapTestES3 : public ANGLETest
ASSERT_NE(-1, mTexture3DLODUniformLocation);
glUseProgram(m3DProgram);
glUniform2f(mTexture3DScaleUniformLocation, 1.0f, 1.0f);
glUniform1f(mTexture3DLODUniformLocation, 0);
glUseProgram(0);
ASSERT_GL_NO_ERROR();
@ -346,11 +336,9 @@ class MipmapTestES3 : public ANGLETest
GLuint mTexture3D;
GLuint mArrayProgram;
GLint mTextureArrayScaleUniformLocation;
GLint mTextureArraySliceUniformLocation;
GLuint m3DProgram;
GLint mTexture3DScaleUniformLocation;
GLint mTexture3DSliceUniformLocation;
GLint mTexture3DLODUniformLocation;
};
@ -370,15 +358,15 @@ TEST_P(MipmapTest, DISABLED_ThreeLevelsInitData)
// Draw a full-sized quad, and check it's blue.
clearAndDrawQuad(m2DProgram, getWindowWidth(), getWindowHeight());
EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 255, 255);
EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::blue);
// Draw a half-sized quad, and check it's blue.
clearAndDrawQuad(m2DProgram, getWindowWidth() / 2, getWindowHeight() / 2);
EXPECT_PIXEL_EQ(getWindowWidth() / 4, getWindowHeight() / 4, 0, 0, 255, 255);
EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 4, getWindowHeight() / 4, GLColor::blue);
// Draw a quarter-sized quad, and check it's blue.
clearAndDrawQuad(m2DProgram, getWindowWidth() / 4, getWindowHeight() / 4);
EXPECT_PIXEL_EQ(getWindowWidth() / 8, getWindowHeight() / 8, 0, 0, 255, 255);
EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 8, getWindowHeight() / 8, GLColor::blue);
// Complete the texture by initializing the remaining levels.
int n = 1;
@ -395,22 +383,22 @@ TEST_P(MipmapTest, DISABLED_ThreeLevelsInitData)
// Draw a full-sized quad, and check it's blue.
clearAndDrawQuad(m2DProgram, getWindowWidth(), getWindowHeight());
EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 255, 255);
EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::blue);
// Draw a half-sized quad, and check it's blue. We've not enabled mipmaps yet, so our init data for level one shouldn't be used.
clearAndDrawQuad(m2DProgram, getWindowWidth() / 2, getWindowHeight() / 2);
EXPECT_PIXEL_EQ(getWindowWidth() / 4, getWindowHeight() / 4, 0, 0, 255, 255);
EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 4, getWindowHeight() / 4, GLColor::blue);
// Enable mipmaps.
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
// Draw a half-sized quad, and check it's green.
clearAndDrawQuad(m2DProgram, getWindowWidth() / 2, getWindowHeight() / 2);
EXPECT_PIXEL_EQ(getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255);
EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 4, getWindowHeight() / 4, GLColor::green);
// Draw a quarter-sized quad, and check it's black, since we've not passed any init data for level two.
clearAndDrawQuad(m2DProgram, getWindowWidth() / 4, getWindowHeight() / 4);
EXPECT_PIXEL_EQ(getWindowWidth() / 8, getWindowHeight() / 8, 0, 0, 0, 255);
EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 8, getWindowHeight() / 8, GLColor::black);
// Pass in level two init data.
glTexImage2D(GL_TEXTURE_2D, 2, GL_RGB, getWindowWidth() / 4, getWindowHeight() / 4, 0, GL_RGB, GL_UNSIGNED_BYTE, mLevelTwoInitData);
@ -418,45 +406,45 @@ TEST_P(MipmapTest, DISABLED_ThreeLevelsInitData)
// Draw a full-sized quad, and check it's blue.
clearAndDrawQuad(m2DProgram, getWindowWidth(), getWindowHeight());
EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 255, 255);
EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::blue);
// Draw a half-sized quad, and check it's green.
clearAndDrawQuad(m2DProgram, getWindowWidth() / 2, getWindowHeight() / 2);
EXPECT_PIXEL_EQ(getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255);
EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 4, getWindowHeight() / 4, GLColor::green);
// Draw a quarter-sized quad, and check it's red.
clearAndDrawQuad(m2DProgram, getWindowWidth() / 4, getWindowHeight() / 4);
EXPECT_PIXEL_EQ(getWindowWidth() / 8, getWindowHeight() / 8, 255, 0, 0, 255);
EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 8, getWindowHeight() / 8, GLColor::red);
// Now disable mipmaps again, and render multiple sized quads. They should all be blue, since level 0 is blue.
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
clearAndDrawQuad(m2DProgram, getWindowWidth(), getWindowHeight());
EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 255, 255);
EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::blue);
clearAndDrawQuad(m2DProgram, getWindowWidth() / 2, getWindowHeight() / 2);
EXPECT_PIXEL_EQ(getWindowWidth() / 4, getWindowHeight() / 4, 0, 0, 255, 255);
EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 4, getWindowHeight() / 4, GLColor::blue);
clearAndDrawQuad(m2DProgram, getWindowWidth() / 4, getWindowHeight() / 4);
EXPECT_PIXEL_EQ(getWindowWidth() / 8, getWindowHeight() / 8, 0, 0, 255, 255);
EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 8, getWindowHeight() / 8, GLColor::blue);
// Now reset level 0 to white, keeping mipmaps disabled. Then, render various sized quads. They should be white.
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, getWindowWidth(), getWindowHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, mLevelZeroWhiteInitData);
ASSERT_GL_NO_ERROR();
clearAndDrawQuad(m2DProgram, getWindowWidth(), getWindowHeight());
EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 255, 255, 255, 255);
EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::white);
clearAndDrawQuad(m2DProgram, getWindowWidth() / 2, getWindowHeight() / 2);
EXPECT_PIXEL_EQ(getWindowWidth() / 4, getWindowHeight() / 4, 255, 255, 255, 255);
EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 4, getWindowHeight() / 4, GLColor::white);
clearAndDrawQuad(m2DProgram, getWindowWidth() / 4, getWindowHeight() / 4);
EXPECT_PIXEL_EQ(getWindowWidth() / 8, getWindowHeight() / 8, 255, 255, 255, 255);
EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 8, getWindowHeight() / 8, GLColor::white);
// Then enable mipmaps again. The quads should be white, green, red respectively.
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
clearAndDrawQuad(m2DProgram, getWindowWidth(), getWindowHeight());
EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 255, 255, 255, 255);
EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::white);
clearAndDrawQuad(m2DProgram, getWindowWidth() / 2, getWindowHeight() / 2);
EXPECT_PIXEL_EQ(getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255);
EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 4, getWindowHeight() / 4, GLColor::green);
clearAndDrawQuad(m2DProgram, getWindowWidth() / 4, getWindowHeight() / 4);
EXPECT_PIXEL_EQ(getWindowWidth() / 8, getWindowHeight() / 8, 255, 0, 0, 255);
EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 8, getWindowHeight() / 8, GLColor::red);
}
// This test generates (and uses) mipmaps on a texture using init data. D3D11 will use a non-renderable TextureStorage for this.
@ -479,22 +467,22 @@ TEST_P(MipmapTest, GenerateMipmapFromInitDataThenRender)
// Now draw the texture to various different sized areas.
clearAndDrawQuad(m2DProgram, getWindowWidth(), getWindowHeight());
EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 255, 255);
EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::blue);
// Use mip level 1
clearAndDrawQuad(m2DProgram, getWindowWidth() / 2, getWindowHeight() / 2);
EXPECT_PIXEL_EQ(getWindowWidth() / 4, getWindowHeight() / 4, 0, 0, 255, 255);
EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 4, getWindowHeight() / 4, GLColor::blue);
// Use mip level 2
clearAndDrawQuad(m2DProgram, getWindowWidth() / 4, getWindowHeight() / 4);
EXPECT_PIXEL_EQ(getWindowWidth() / 8, getWindowHeight() / 8, 0, 0, 255, 255);
EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 8, getWindowHeight() / 8, GLColor::blue);
ASSERT_GL_NO_ERROR();
// Disable mips. Render a quad using the texture and ensure it's blue.
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
clearAndDrawQuad(m2DProgram, getWindowWidth(), getWindowHeight());
EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 255, 255);
EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::blue);
// Clear level 0 of the texture to red.
clearTextureLevel0(GL_TEXTURE_2D, mTexture2D, 1.0f, 0.0f, 0.0f, 1.0f);
@ -504,15 +492,15 @@ TEST_P(MipmapTest, GenerateMipmapFromInitDataThenRender)
// Level 0 is now red, so this should render red.
clearAndDrawQuad(m2DProgram, getWindowWidth(), getWindowHeight());
EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 255, 0, 0, 255);
EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
// Use mip level 1, blue.
clearAndDrawQuad(m2DProgram, getWindowWidth() / 2, getWindowHeight() / 2);
EXPECT_PIXEL_EQ(getWindowWidth() / 4, getWindowHeight() / 4, 0, 0, 255, 255);
EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 4, getWindowHeight() / 4, GLColor::blue);
// Use mip level 2, blue.
clearAndDrawQuad(m2DProgram, getWindowWidth() / 4, getWindowHeight() / 4);
EXPECT_PIXEL_EQ(getWindowWidth() / 8, getWindowHeight() / 8, 0, 0, 255, 255);
EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 8, getWindowHeight() / 8, GLColor::blue);
}
// This test ensures that mips are correctly generated from a rendered image.
@ -533,15 +521,15 @@ TEST_P(MipmapTest, GenerateMipmapFromRenderedImage)
// Now draw the texture to various different sized areas.
clearAndDrawQuad(m2DProgram, getWindowWidth(), getWindowHeight());
EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 255, 255);
EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::blue);
// Use mip level 1
clearAndDrawQuad(m2DProgram, getWindowWidth() / 2, getWindowHeight() / 2);
EXPECT_PIXEL_EQ(getWindowWidth() / 4, getWindowHeight() / 4, 0, 0, 255, 255);
EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 4, getWindowHeight() / 4, GLColor::blue);
// Use mip level 2
clearAndDrawQuad(m2DProgram, getWindowWidth() / 4, getWindowHeight() / 4);
EXPECT_PIXEL_EQ(getWindowWidth() / 8, getWindowHeight() / 8, 0, 0, 255, 255);
EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 8, getWindowHeight() / 8, GLColor::blue);
}
// Test to ensure that rendering to a mipmapped texture works, regardless of whether mipmaps are enabled or not.
@ -563,7 +551,7 @@ TEST_P(MipmapTest, RenderOntoLevelZeroAfterGenerateMipmap)
// Now, draw the texture to a quad that's the same size as the texture. This draws to the default framebuffer.
// The quad should be blue.
clearAndDrawQuad(m2DProgram, getWindowWidth(), getWindowHeight());
EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 255, 255);
EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::blue);
// Now go back to the texture, and generate mips on it.
glGenerateMipmap(GL_TEXTURE_2D);
@ -572,7 +560,7 @@ TEST_P(MipmapTest, RenderOntoLevelZeroAfterGenerateMipmap)
// Now try rendering the textured quad again. Note: we've not told GL to use the generated mips.
// The quad should be blue.
clearAndDrawQuad(m2DProgram, getWindowWidth(), getWindowHeight());
EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 255, 255);
EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::blue);
// Now tell GL to use the generated mips.
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
@ -580,22 +568,22 @@ TEST_P(MipmapTest, RenderOntoLevelZeroAfterGenerateMipmap)
// Now render the textured quad again. It should be still be blue.
clearAndDrawQuad(m2DProgram, getWindowWidth(), getWindowHeight());
EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 255, 255);
EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::blue);
// Now render the textured quad to an area smaller than the texture (i.e. to force minification). This should be blue.
clearAndDrawQuad(m2DProgram, getWindowWidth() / 4, getWindowHeight() / 4);
EXPECT_PIXEL_EQ(getWindowWidth() / 8, getWindowHeight() / 8, 0, 0, 255, 255);
EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 8, getWindowHeight() / 8, GLColor::blue);
// Now clear the texture to green. This just clears the top level. The lower mips should remain blue.
clearTextureLevel0(GL_TEXTURE_2D, mTexture2D, 0.0f, 1.0f, 0.0f, 1.0f);
// Render a textured quad equal in size to the texture. This should be green, since we just cleared level 0.
clearAndDrawQuad(m2DProgram, getWindowWidth(), getWindowHeight());
EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 255, 0, 255);
EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::green);
// Render a small textured quad. This forces minification, so should render blue (the color of levels 1+).
clearAndDrawQuad(m2DProgram, getWindowWidth() / 4, getWindowHeight() / 4);
EXPECT_PIXEL_EQ(getWindowWidth() / 8, getWindowHeight() / 8, 0, 0, 255, 255);
EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 8, getWindowHeight() / 8, GLColor::blue);
// Disable mipmaps again
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
@ -603,11 +591,11 @@ TEST_P(MipmapTest, RenderOntoLevelZeroAfterGenerateMipmap)
// Render a textured quad equal in size to the texture. This should be green, the color of level 0 in the texture.
clearAndDrawQuad(m2DProgram, getWindowWidth(), getWindowHeight());
EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 255, 0, 255);
EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::green);
// Render a small textured quad. This would force minification if mips were enabled, but they're not. Therefore, this should be green.
clearAndDrawQuad(m2DProgram, getWindowWidth() / 4, getWindowHeight() / 4);
EXPECT_PIXEL_EQ(getWindowWidth() / 8, getWindowHeight() / 8, 0, 255, 0, 255);
EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 8, getWindowHeight() / 8, GLColor::green);
}
// This test ensures that the level-zero workaround for TextureCubes (on D3D11 Feature Level 9_3)
@ -618,35 +606,35 @@ TEST_P(MipmapTest, TextureCubeGeneralLevelZero)
// Draw. Since the negative-Y face's is blue, this should be blue.
clearAndDrawQuad(mCubeProgram, getWindowWidth(), getWindowHeight());
EXPECT_PIXEL_EQ(0, 0, 0, 0, 255, 255);
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
// Generate mipmaps, and render. This should be blue.
glGenerateMipmap(GL_TEXTURE_CUBE_MAP);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
clearAndDrawQuad(mCubeProgram, getWindowWidth(), getWindowHeight());
EXPECT_PIXEL_EQ(0, 0, 0, 0, 255, 255);
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
// Draw using a smaller viewport (to force a lower LOD of the texture). This should still be blue.
clearAndDrawQuad(mCubeProgram, getWindowWidth() / 4, getWindowHeight() / 4);
EXPECT_PIXEL_EQ(0, 0, 0, 0, 255, 255);
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
// Now clear the negative-Y face of the cube to red.
clearTextureLevel0(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, mTextureCube, 1.0f, 0.0f, 0.0f, 1.0f);
// Draw using a full-size viewport. This should be red.
clearAndDrawQuad(mCubeProgram, getWindowWidth(), getWindowHeight());
EXPECT_PIXEL_EQ(0, 0, 255, 0, 0, 255);
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
// Draw using a quarter-size viewport, to force a lower LOD. This should be *BLUE*, since we only cleared level zero
// of the negative-Y face to red, and left its mipmaps blue.
clearAndDrawQuad(mCubeProgram, getWindowWidth() / 4, getWindowHeight() / 4);
EXPECT_PIXEL_EQ(0, 0, 0, 0, 255, 255);
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
// Disable mipmaps again, and draw a to a quarter-size viewport.
// Since this should use level zero of the texture, this should be *RED*.
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
clearAndDrawQuad(mCubeProgram, getWindowWidth() / 4, getWindowHeight() / 4);
EXPECT_PIXEL_EQ(0, 0, 255, 0, 0, 255);
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
}
// This test ensures that rendering to level-zero of a TextureCube works as expected.
@ -656,18 +644,18 @@ TEST_P(MipmapTest, TextureCubeRenderToLevelZero)
// Draw. Since the negative-Y face's is blue, this should be blue.
clearAndDrawQuad(mCubeProgram, getWindowWidth(), getWindowHeight());
EXPECT_PIXEL_EQ(0, 0, 0, 0, 255, 255);
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
// Now clear the negative-Y face of the cube to red.
clearTextureLevel0(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, mTextureCube, 1.0f, 0.0f, 0.0f, 1.0f);
// Draw using a full-size viewport. This should be red.
clearAndDrawQuad(mCubeProgram, getWindowWidth(), getWindowHeight());
EXPECT_PIXEL_EQ(0, 0, 255, 0, 0, 255);
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
// Draw a to a quarter-size viewport. This should also be red.
clearAndDrawQuad(mCubeProgram, getWindowWidth() / 4, getWindowHeight() / 4);
EXPECT_PIXEL_EQ(0, 0, 255, 0, 0, 255);
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
}
// Creates a mipmapped 2D array texture with three layers, and calls ANGLE's GenerateMipmap.
@ -682,20 +670,19 @@ TEST_P(MipmapTestES3, MipmapsForTextureArray)
glTexStorage3D(GL_TEXTURE_2D_ARRAY, 5, GL_RGBA8, 16, 16, 3);
// Fill the first layer with red
std::vector<GLubyte> pixels(4 * 16 * 16);
FillWithRGBA<GLubyte>(16u * 16u, 255u, 0u, 0u, 255u, pixels.data());
glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 0, 16, 16, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data());
std::vector<GLColor> pixelsRed(16 * 16, GLColor::red);
glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 0, 16, 16, 1, GL_RGBA, GL_UNSIGNED_BYTE,
pixelsRed.data());
// Fill the second layer with green
FillWithRGBA<GLubyte>(16u * 16u, 0u, 255u, 0u, 255u, pixels.data());
glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 1, 16, 16, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data());
std::vector<GLColor> pixelsGreen(16 * 16, GLColor::green);
glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 1, 16, 16, 1, GL_RGBA, GL_UNSIGNED_BYTE,
pixelsGreen.data());
// Fill the third layer with blue
FillWithRGBA<GLubyte>(16u * 16u, 0u, 0u, 255u, 255u, pixels.data());
glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 2, 16, 16, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data());
std::vector<GLColor> pixelsBlue(16 * 16, GLColor::blue);
glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 2, 16, 16, 1, GL_RGBA, GL_UNSIGNED_BYTE,
pixelsBlue.data());
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
@ -714,19 +701,19 @@ TEST_P(MipmapTestES3, MipmapsForTextureArray)
glUniform1i(mTextureArraySliceUniformLocation, 0);
drawQuad(mArrayProgram, "position", 0.5f);
EXPECT_GL_NO_ERROR();
EXPECT_PIXEL_EQ(px, py, 255, 0, 0, 255);
EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::red);
// Draw the second slice
glUniform1i(mTextureArraySliceUniformLocation, 1);
drawQuad(mArrayProgram, "position", 0.5f);
EXPECT_GL_NO_ERROR();
EXPECT_PIXEL_EQ(px, py, 0, 255, 0, 255);
EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::green);
// Draw the third slice
glUniform1i(mTextureArraySliceUniformLocation, 2);
drawQuad(mArrayProgram, "position", 0.5f);
EXPECT_GL_NO_ERROR();
EXPECT_PIXEL_EQ(px, py, 0, 0, 255, 255);
EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::blue);
}
// Creates a mipmapped 3D texture with two layers, and calls ANGLE's GenerateMipmap.
@ -741,15 +728,14 @@ TEST_P(MipmapTestES3, MipmapsForTexture3D)
glTexStorage3D(GL_TEXTURE_3D, 5, GL_RGBA8, 16, 16, 2);
// Fill the first layer with red
std::vector<GLubyte> pixels(4 * 16 * 16);
FillWithRGBA<GLubyte>(16u * 16u, 255u, 0u, 0u, 255u, pixels.data());
glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 16, 16, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data());
std::vector<GLColor> pixelsRed(16 * 16, GLColor::red);
glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 16, 16, 1, GL_RGBA, GL_UNSIGNED_BYTE,
pixelsRed.data());
// Fill the second layer with green
FillWithRGBA<GLubyte>(16u * 16u, 0u, 255u, 0u, 255u, pixels.data());
glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 1, 16, 16, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data());
std::vector<GLColor> pixelsGreen(16 * 16, GLColor::green);
glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 1, 16, 16, 1, GL_RGBA, GL_UNSIGNED_BYTE,
pixelsGreen.data());
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
@ -770,13 +756,13 @@ TEST_P(MipmapTestES3, MipmapsForTexture3D)
glUniform1f(mTexture3DSliceUniformLocation, 0.25f);
drawQuad(m3DProgram, "position", 0.5f);
EXPECT_GL_NO_ERROR();
EXPECT_PIXEL_EQ(px, py, 255, 0, 0, 255);
EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::red);
// Draw the second slice
glUniform1f(mTexture3DSliceUniformLocation, 0.75f);
drawQuad(m3DProgram, "position", 0.5f);
EXPECT_GL_NO_ERROR();
EXPECT_PIXEL_EQ(px, py, 0, 255, 0, 255);
EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::green);
// Mipmap level 1
// The second mipmap should only have one slice.

Просмотреть файл

@ -20,6 +20,7 @@ const GLColor GLColor::green = GLColor(0u, 255u, 0u, 255u);
const GLColor GLColor::blue = GLColor(0u, 0u, 255u, 255u);
const GLColor GLColor::cyan = GLColor(0u, 255u, 255u, 255u);
const GLColor GLColor::black = GLColor(0u, 0u, 0u, 255u);
const GLColor GLColor::white = GLColor(255u, 255u, 255u, 255u);
namespace
{

Просмотреть файл

@ -58,6 +58,7 @@ struct GLColor
static const GLColor blue;
static const GLColor cyan;
static const GLColor black;
static const GLColor white;
};
// Useful to cast any type to GLubyte.
@ -72,18 +73,6 @@ bool operator==(const GLColor &a, const GLColor &b);
std::ostream &operator<<(std::ostream &ostream, const GLColor &color);
GLColor ReadColor(GLint x, GLint y);
template <typename T>
void FillWithRGBA(size_t pixelCount, T red, T green, T blue, T alpha, T *outArray)
{
for (size_t i = 0u; i < pixelCount; ++i)
{
outArray[i * 4u] = red;
outArray[i * 4u + 1u] = green;
outArray[i * 4u + 2u] = blue;
outArray[i * 4u + 3u] = alpha;
}
}
} // namespace angle
#define EXPECT_PIXEL_EQ(x, y, r, g, b, a) \