Re-land "D3D11: Fix readback of BGRA-backed formats."
For some BGRA-backed formats (RGBA4, R5G6B5, RGB5A1), our ReadPixels
implementation wasn't aware the BGRA format didn't exactly match the
RGBA format. For these it would do the 'fast path' memcpy method, when
it should stop and do the slow pixel-by-pixel packing method.
Fixes conformance2/reading/read-pixels-from-fbo-test.html.
Reland: fix empty format info that was causing us to only see the
first pixel in the FBO in a ReadPixels call. Also fix bugs in the
unorm 16-bit format readback code, and add ASSERTs to catch bugs in
subsequent new formats.
BUG=angleproject:1407
BUG=chromium:616176
Change-Id: I9fd55b9e1dd6a306eb4db195d775c02a1eb1f93f
Reviewed-on: https://chromium-review.googlesource.com/357132
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Jamie Madill <jmadill@chromium.org>
diff --git a/src/tests/test_utils/ANGLETest.cpp b/src/tests/test_utils/ANGLETest.cpp
index c8236d9..1b13834 100644
--- a/src/tests/test_utils/ANGLETest.cpp
+++ b/src/tests/test_utils/ANGLETest.cpp
@@ -15,6 +15,7 @@
namespace angle
{
+const GLColorRGB GLColorRGB::black(0u, 0u, 0u);
const GLColorRGB GLColorRGB::blue(0u, 0u, 255u);
const GLColorRGB GLColorRGB::green(0u, 255u, 0u);
const GLColorRGB GLColorRGB::red(255u, 0u, 0u);
@@ -37,6 +38,11 @@
return static_cast<float>(channelValue) / 255.0f;
}
+GLubyte ColorDenorm(float colorValue)
+{
+ return static_cast<GLubyte>(colorValue * 255.0f);
+}
+
// Use a custom ANGLE platform class to capture and report internal errors.
class TestPlatform : public angle::Platform
{
@@ -89,6 +95,17 @@
}
TestPlatform g_testPlatformInstance;
+
+std::array<Vector3, 4> GetIndexedQuadVertices()
+{
+ std::array<Vector3, 4> vertices;
+ vertices[0] = Vector3(-1.0f, 1.0f, 0.5f);
+ vertices[1] = Vector3(-1.0f, -1.0f, 0.5f);
+ vertices[2] = Vector3(1.0f, -1.0f, 0.5f);
+ vertices[3] = Vector3(1.0f, 1.0f, 0.5f);
+ return vertices;
+}
+
} // anonymous namespace
GLColorRGB::GLColorRGB() : R(0), G(0), B(0)
@@ -99,6 +116,11 @@
{
}
+GLColorRGB::GLColorRGB(const Vector3 &floatColor)
+ : R(ColorDenorm(floatColor.x)), G(ColorDenorm(floatColor.y)), B(ColorDenorm(floatColor.z))
+{
+}
+
GLColor::GLColor() : R(0), G(0), B(0), A(0)
{
}
@@ -107,6 +129,22 @@
{
}
+GLColor::GLColor(const Vector4 &floatColor)
+ : R(ColorDenorm(floatColor.x)),
+ G(ColorDenorm(floatColor.y)),
+ B(ColorDenorm(floatColor.z)),
+ A(ColorDenorm(floatColor.w))
+{
+}
+
+GLColor::GLColor(const GLColor16 &color16)
+ : R(static_cast<GLubyte>(color16.R)),
+ G(static_cast<GLubyte>(color16.G)),
+ B(static_cast<GLubyte>(color16.B)),
+ A(static_cast<GLubyte>(color16.A))
+{
+}
+
GLColor::GLColor(GLuint colorValue) : R(0), G(0), B(0), A(0)
{
memcpy(&R, &colorValue, sizeof(GLuint));
@@ -169,6 +207,19 @@
} // namespace angle
+// static
+std::array<Vector3, 6> ANGLETest::GetQuadVertices()
+{
+ std::array<Vector3, 6> vertices;
+ vertices[0] = Vector3(-1.0f, 1.0f, 0.5f);
+ vertices[1] = Vector3(-1.0f, -1.0f, 0.5f);
+ vertices[2] = Vector3(1.0f, -1.0f, 0.5f);
+ vertices[3] = Vector3(-1.0f, 1.0f, 0.5f);
+ vertices[4] = Vector3(1.0f, -1.0f, 0.5f);
+ vertices[5] = Vector3(1.0f, 1.0f, 0.5f);
+ return vertices;
+}
+
ANGLETest::ANGLETest()
: mEGLWindow(nullptr),
mWidth(16),
@@ -261,19 +312,6 @@
}
}
-// static
-std::array<Vector3, 6> ANGLETest::GetQuadVertices()
-{
- std::array<Vector3, 6> vertices;
- vertices[0] = Vector3(-1.0f, 1.0f, 0.5f);
- vertices[1] = Vector3(-1.0f, -1.0f, 0.5f);
- vertices[2] = Vector3(1.0f, -1.0f, 0.5f);
- vertices[3] = Vector3(-1.0f, 1.0f, 0.5f);
- vertices[4] = Vector3(1.0f, -1.0f, 0.5f);
- vertices[5] = Vector3(1.0f, 1.0f, 0.5f);
- return vertices;
-}
-
void ANGLETest::setupQuadVertexBuffer(GLfloat positionAttribZ, GLfloat positionAttribXYScale)
{
if (mQuadVertexBuffer == 0)
@@ -293,6 +331,25 @@
glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 3 * 6, quadVertices.data(), GL_STATIC_DRAW);
}
+void ANGLETest::setupIndexedQuadVertexBuffer(GLfloat positionAttribZ, GLfloat positionAttribXYScale)
+{
+ if (mQuadVertexBuffer == 0)
+ {
+ glGenBuffers(1, &mQuadVertexBuffer);
+ }
+
+ auto quadVertices = angle::GetIndexedQuadVertices();
+ for (Vector3 &vertex : quadVertices)
+ {
+ vertex.x *= positionAttribXYScale;
+ vertex.y *= positionAttribXYScale;
+ vertex.z = positionAttribZ;
+ }
+
+ glBindBuffer(GL_ARRAY_BUFFER, mQuadVertexBuffer);
+ glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 3 * 4, quadVertices.data(), GL_STATIC_DRAW);
+}
+
// static
void ANGLETest::drawQuad(GLuint program,
const std::string &positionAttribName,
@@ -380,7 +437,7 @@
GLuint prevBinding = 0;
glGetIntegerv(GL_ARRAY_BUFFER_BINDING, reinterpret_cast<GLint *>(&prevBinding));
- setupQuadVertexBuffer(positionAttribZ, positionAttribXYScale);
+ setupIndexedQuadVertexBuffer(positionAttribZ, positionAttribXYScale);
glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
glEnableVertexAttribArray(positionLocation);