Skip to content

Commit 8d3d896

Browse files
jsfdezediosyncratic
authored andcommitted
Do not send images filled with zeros
Detect if the image data is all zero: if so, send an empty buffer. This happens for a texture atlas, which is later filled with texSubImage2D, discarding the data originally sent, so not sending the data improves performance, notably reducing the loading time. Change-Id: Ife298bb5e8d7ee96b800f06fcb8371a6d08d2101 Reviewed-by: Mårten Nordheim <[email protected]> Reviewed-by: Edward Welbourne <[email protected]>
1 parent 9eb58fa commit 8d3d896

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/plugins/platforms/webgl/qwebglcontext.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,11 +1220,22 @@ QWEBGL_FUNCTION(texImage2D, void, glTexImage2D,
12201220
(GLsizei) width, (GLsizei) height, (GLint) border, (GLenum) format, (GLenum) type,
12211221
(const void *) pixels)
12221222
{
1223+
const auto data = reinterpret_cast<const char *>(pixels);
1224+
const auto dataSize = imageSize(width, height, format, type,
1225+
currentContextData()->pixelStorage);
1226+
const bool isNull = data == nullptr || [](const char *pointer, int size) {
1227+
const char *const end = pointer + size;
1228+
const unsigned int zero = 0u;
1229+
const char *const late = end + 1 - sizeof(zero);
1230+
while (pointer < late) { // we have at least sizeof(zero) more bytes to check:
1231+
if (*reinterpret_cast<const unsigned int *>(pointer) != zero)
1232+
return false;
1233+
pointer += sizeof(zero);
1234+
}
1235+
return pointer >= end || std::memcmp(pointer, &zero, end - pointer) == 0;
1236+
}(data, dataSize);
12231237
postEvent<&texImage2D>(target, level, internalformat, width, height, border, format, type,
1224-
pixels ? QByteArray((const char*)pixels,
1225-
imageSize(width, height, format, type,
1226-
currentContextData()->pixelStorage))
1227-
: nullptr);
1238+
isNull ? nullptr : QByteArray(data, dataSize));
12281239
}
12291240

12301241
QWEBGL_FUNCTION_POSTEVENT(texParameterf, glTexParameterf,

0 commit comments

Comments
 (0)