summaryrefslogtreecommitdiff
path: root/src/gui/opengl/qopenglfunctions.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@theqtcompany.com>2016-01-29 10:43:35 +0100
committerLaszlo Agocs <laszlo.agocs@theqtcompany.com>2016-03-01 14:46:14 +0000
commit29d8159c4478a5275d2ea102daf270a91ed7e92e (patch)
tree709a145107cdfc58e67b4fabe6a76534d5cc7801 /src/gui/opengl/qopenglfunctions.cpp
parent7ee585bbffb4350ec327116d30cd63e3d1142581 (diff)
downloadqtbase-29d8159c4478a5275d2ea102daf270a91ed7e92e.tar.gz
Avoid repeated QByteArray creation when resolving opengl functions
Add an getProcAddress(const char *) overload to QOpenGLContext, and refactor the QPA interface to take a const char *. Like this we can avoid lots of mallocs when resoving GL methods. Change-Id: Ic45b985fbaa0da8d32ba3e3b485351173352ca6f Reviewed-by: Laszlo Agocs <laszlo.agocs@theqtcompany.com> Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/gui/opengl/qopenglfunctions.cpp')
-rw-r--r--src/gui/opengl/qopenglfunctions.cpp55
1 files changed, 29 insertions, 26 deletions
diff --git a/src/gui/opengl/qopenglfunctions.cpp b/src/gui/opengl/qopenglfunctions.cpp
index b7a82a5def..b77f2c4f0f 100644
--- a/src/gui/opengl/qopenglfunctions.cpp
+++ b/src/gui/opengl/qopenglfunctions.cpp
@@ -2199,36 +2199,39 @@ private:
static QFunctionPointer getProcAddress(QOpenGLContext *context, const char *funcName, int policy)
{
- QByteArray fn = funcName;
- int size = fn.size();
- QFunctionPointer function = context->getProcAddress(fn);
-
- // create room for the extension names
- fn.resize(size + 5);
- char *ext = fn.data() + size;
- if (!function && (policy & ResolveOES)) {
- memcpy(ext, "OES\0\0", 5);
- function = context->getProcAddress(fn);
- }
+ QFunctionPointer function = context->getProcAddress(funcName);
+
+ if (!function && policy) {
+ char fn[512];
+ size_t size = strlen(funcName);
+ Q_ASSERT(size < 500);
+ memcpy(fn, funcName, size);
+
+ char *ext = fn + size;
+ if (!function && (policy & ResolveOES)) {
+ memcpy(ext, "OES", 4);
+ function = context->getProcAddress(fn);
+ }
- if (!function) {
- memcpy(ext, "ARB\0\0", 5);
- function = context->getProcAddress(fn);
- }
+ if (!function) {
+ memcpy(ext, "ARB", 4);
+ function = context->getProcAddress(fn);
+ }
- if (!function && (policy & ResolveEXT)) {
- memcpy(ext, "EXT\0\0", 5);
- function = context->getProcAddress(fn);
- }
+ if (!function && (policy & ResolveEXT)) {
+ memcpy(ext, "EXT", 4);
+ function = context->getProcAddress(fn);
+ }
- if (!function && (policy & ResolveANGLE)) {
- memcpy(ext, "ANGLE", 5);
- function = context->getProcAddress(fn);
- }
+ if (!function && (policy & ResolveANGLE)) {
+ memcpy(ext, "ANGLE", 6);
+ function = context->getProcAddress(fn);
+ }
- if (!function && (policy & ResolveNV)) {
- memcpy(ext, "NV\0\0\0", 5);
- function = context->getProcAddress(fn);
+ if (!function && (policy & ResolveNV)) {
+ memcpy(ext, "NV", 3);
+ function = context->getProcAddress(fn);
+ }
}
return function;