Bug 1249483 - Stop filling A with 1.0 on readback from no-alpha. - r=jrmuizel

This commit is contained in:
Jeff Gilbert 2016-02-25 17:47:50 -08:00
parent b5e71837e2
commit be87f2d8a8

View File

@ -1207,57 +1207,6 @@ WebGLContext::PixelStorei(GLenum pname, GLint param)
ErrorInvalidEnumInfo("pixelStorei: parameter", pname);
}
// `width` in pixels.
// `stride` in bytes.
static void
SetFullAlpha(void* data, GLenum format, GLenum type, size_t width, size_t height,
size_t stride)
{
if (format == LOCAL_GL_ALPHA && type == LOCAL_GL_UNSIGNED_BYTE) {
// Just memset the rows.
uint8_t* row = static_cast<uint8_t*>(data);
for (size_t j = 0; j < height; ++j) {
memset(row, 0xff, width);
row += stride;
}
return;
}
if (format == LOCAL_GL_RGBA && type == LOCAL_GL_UNSIGNED_BYTE) {
for (size_t j = 0; j < height; ++j) {
uint8_t* row = static_cast<uint8_t*>(data) + j*stride;
uint8_t* pAlpha = row + 3;
uint8_t* pAlphaEnd = pAlpha + 4*width;
while (pAlpha != pAlphaEnd) {
*pAlpha = 0xff;
pAlpha += 4;
}
}
return;
}
if (format == LOCAL_GL_RGBA && type == LOCAL_GL_FLOAT) {
for (size_t j = 0; j < height; ++j) {
uint8_t* rowBytes = static_cast<uint8_t*>(data) + j*stride;
float* row = reinterpret_cast<float*>(rowBytes);
float* pAlpha = row + 3;
float* pAlphaEnd = pAlpha + 4*width;
while (pAlpha != pAlphaEnd) {
*pAlpha = 1.0f;
pAlpha += 4;
}
}
return;
}
MOZ_CRASH("Unhandled case, how'd we get here?");
}
bool
WebGLContext::DoReadPixelsAndConvert(GLint x, GLint y, GLsizei width, GLsizei height,
GLenum destFormat, GLenum destType, void* destBytes,
@ -1763,25 +1712,6 @@ WebGLContext::ReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum
row += rowStride.value();
}
}
// if we're reading alpha, we may need to do fixup. Note that we don't allow
// GL_ALPHA to readpixels currently, but we had the code written for it already.
const bool formatHasAlpha = format == LOCAL_GL_ALPHA ||
format == LOCAL_GL_RGBA;
if (!formatHasAlpha)
return;
bool needAlphaFilled;
if (mBoundReadFramebuffer) {
needAlphaFilled = !mBoundReadFramebuffer->ColorAttachment(0).HasAlpha();
} else {
needAlphaFilled = !mOptions.alpha;
}
if (!needAlphaFilled)
return;
SetFullAlpha(data, format, type, width, height, rowStride.value());
}
void