summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesus Fernandez <jesus.fernandez@qt.io>2017-09-23 13:01:28 +0200
committerEdward Welbourne <edward.welbourne@qt.io>2017-11-24 13:31:24 +0000
commit8d3d896cc2d47f2d4e1bffee60a159e8a60b6b43 (patch)
tree3553d734cf280dd7b3744ce0404d69d96f7463e3
parent9eb58fabd550b59e3c89834624b077a92a2a4475 (diff)
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 <marten.nordheim@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
-rw-r--r--src/plugins/platforms/webgl/qwebglcontext.cpp19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/plugins/platforms/webgl/qwebglcontext.cpp b/src/plugins/platforms/webgl/qwebglcontext.cpp
index 6dfdc9b..b77aa7f 100644
--- a/src/plugins/platforms/webgl/qwebglcontext.cpp
+++ b/src/plugins/platforms/webgl/qwebglcontext.cpp
@@ -1220,11 +1220,22 @@ QWEBGL_FUNCTION(texImage2D, void, glTexImage2D,
(GLsizei) width, (GLsizei) height, (GLint) border, (GLenum) format, (GLenum) type,
(const void *) pixels)
{
+ const auto data = reinterpret_cast<const char *>(pixels);
+ const auto dataSize = imageSize(width, height, format, type,
+ currentContextData()->pixelStorage);
+ const bool isNull = data == nullptr || [](const char *pointer, int size) {
+ const char *const end = pointer + size;
+ const unsigned int zero = 0u;
+ const char *const late = end + 1 - sizeof(zero);
+ while (pointer < late) { // we have at least sizeof(zero) more bytes to check:
+ if (*reinterpret_cast<const unsigned int *>(pointer) != zero)
+ return false;
+ pointer += sizeof(zero);
+ }
+ return pointer >= end || std::memcmp(pointer, &zero, end - pointer) == 0;
+ }(data, dataSize);
postEvent<&texImage2D>(target, level, internalformat, width, height, border, format, type,
- pixels ? QByteArray((const char*)pixels,
- imageSize(width, height, format, type,
- currentContextData()->pixelStorage))
- : nullptr);
+ isNull ? nullptr : QByteArray(data, dataSize));
}
QWEBGL_FUNCTION_POSTEVENT(texParameterf, glTexParameterf,