summaryrefslogtreecommitdiffstats
path: root/src/opengl
diff options
context:
space:
mode:
authorRhys Weatherley <rhys.weatherley@nokia.com>2009-10-01 07:52:09 (GMT)
committerRhys Weatherley <rhys.weatherley@nokia.com>2009-10-01 07:52:09 (GMT)
commit871bdaff6d7ae05571830ae87d9de6ef4e2cdb9f (patch)
treed9dcf9d8437c7a7777f64ce41f5f55a44269fee7 /src/opengl
parentf23ab31348bb6d3c6b7cb1ccf429ea932824e4e4 (diff)
downloadQt-871bdaff6d7ae05571830ae87d9de6ef4e2cdb9f.zip
Qt-871bdaff6d7ae05571830ae87d9de6ef4e2cdb9f.tar.gz
Qt-871bdaff6d7ae05571830ae87d9de6ef4e2cdb9f.tar.bz2
QGLContext::areSharing() to check for GL share relationships
Reviewed-by: Samuel
Diffstat (limited to 'src/opengl')
-rw-r--r--src/opengl/qgl.cpp21
-rw-r--r--src/opengl/qgl.h2
-rw-r--r--src/opengl/qgl_p.h5
-rw-r--r--src/opengl/qglshaderprogram.cpp8
-rw-r--r--src/opengl/qpaintengine_opengl.cpp10
-rw-r--r--src/opengl/qpixmapdata_gl.cpp2
6 files changed, 29 insertions, 19 deletions
diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp
index 1276443..bfb004e 100644
--- a/src/opengl/qgl.cpp
+++ b/src/opengl/qgl.cpp
@@ -2254,7 +2254,7 @@ QGLTexture *QGLContextPrivate::textureCacheLookup(const qint64 key, GLenum targe
Q_Q(QGLContext);
QGLTexture *texture = QGLTextureCache::instance()->getTexture(key);
if (texture && texture->target == target
- && (texture->context == q || qgl_share_reg()->checkSharing(q, texture->context)))
+ && (texture->context == q || QGLContext::areSharing(q, texture->context)))
{
return texture;
}
@@ -2755,6 +2755,20 @@ void QGLContext::setDevice(QPaintDevice *pDev)
*/
/*!
+ Returns true if \a context1 and \a context2 are sharing their
+ GL resources such as textures, shader programs, etc;
+ otherwise returns false.
+
+ \since 4.6
+*/
+bool QGLContext::areSharing(const QGLContext *context1, const QGLContext *context2)
+{
+ if (!context1 || !context2)
+ return false;
+ return context1->d_ptr->group == context2->d_ptr->group;
+}
+
+/*!
\fn bool QGLContext::deviceIsPixmap() const
Returns true if the paint device of this context is a pixmap;
@@ -4835,11 +4849,6 @@ Q_OPENGL_EXPORT const QString qt_gl_library_name()
}
#endif
-bool QGLShareRegister::checkSharing(const QGLContext *context1, const QGLContext *context2) {
- bool sharing = (context1 && context2 && context1->d_ptr->group == context2->d_ptr->group);
- return sharing;
-}
-
void QGLShareRegister::addShare(const QGLContext *context, const QGLContext *share) {
Q_ASSERT(context && share);
if (context->d_ptr->group == share->d_ptr->group)
diff --git a/src/opengl/qgl.h b/src/opengl/qgl.h
index 1776004..b1c1317 100644
--- a/src/opengl/qgl.h
+++ b/src/opengl/qgl.h
@@ -282,6 +282,8 @@ public:
bool isSharing() const;
void reset();
+ static bool areSharing(const QGLContext *context1, const QGLContext *context2);
+
QGLFormat format() const;
QGLFormat requestedFormat() const;
void setFormat(const QGLFormat& format);
diff --git a/src/opengl/qgl_p.h b/src/opengl/qgl_p.h
index a113b0f..9b09c7c 100644
--- a/src/opengl/qgl_p.h
+++ b/src/opengl/qgl_p.h
@@ -405,7 +405,6 @@ public:
QGLShareRegister() {}
~QGLShareRegister() { reg.clear(); }
- bool checkSharing(const QGLContext *context1, const QGLContext *context2);
void addShare(const QGLContext *context, const QGLContext *share);
QList<const QGLContext *> shares(const QGLContext *context);
void removeShare(const QGLContext *context);
@@ -436,7 +435,7 @@ public:
QGLContext *current = const_cast<QGLContext *>(QGLContext::currentContext());
QGLContext *ctx = const_cast<QGLContext *>(context);
Q_ASSERT(ctx);
- bool switch_context = current != ctx && !qgl_share_reg()->checkSharing(current, ctx);
+ bool switch_context = current != ctx && !QGLContext::areSharing(current, ctx);
if (switch_context)
ctx->makeCurrent();
#if defined(Q_WS_X11)
@@ -547,7 +546,7 @@ public:
: m_oldContext(0)
{
QGLContext *currentContext = const_cast<QGLContext *>(QGLContext::currentContext());
- if (currentContext != ctx && !qgl_share_reg()->checkSharing(ctx, currentContext)) {
+ if (currentContext != ctx && !QGLContext::areSharing(ctx, currentContext)) {
m_oldContext = currentContext;
m_ctx = const_cast<QGLContext *>(ctx);
m_ctx->makeCurrent();
diff --git a/src/opengl/qglshaderprogram.cpp b/src/opengl/qglshaderprogram.cpp
index ebcd723..dfa6c40 100644
--- a/src/opengl/qglshaderprogram.cpp
+++ b/src/opengl/qglshaderprogram.cpp
@@ -349,7 +349,7 @@ QGLShader::QGLShader(QGLShader::ShaderType type, const QGLContext *context, QObj
context = QGLContext::currentContext();
d = new QGLShaderPrivate(context, type);
#ifndef QT_NO_DEBUG
- if (context && !qgl_share_reg()->checkSharing(context, QGLContext::currentContext())) {
+ if (context && !QGLContext::areSharing(context, QGLContext::currentContext())) {
qWarning("QGLShader::QGLShader: \'context\' must be the currect context or sharing with it.");
return;
}
@@ -374,7 +374,7 @@ QGLShader::QGLShader
context = QGLContext::currentContext();
d = new QGLShaderPrivate(context, type);
#ifndef QT_NO_DEBUG
- if (context && !qgl_share_reg()->checkSharing(context, QGLContext::currentContext())) {
+ if (context && !QGLContext::areSharing(context, QGLContext::currentContext())) {
qWarning("QGLShader::QGLShader: \'context\' must be currect context or sharing with it.");
return;
}
@@ -806,8 +806,8 @@ bool QGLShaderProgram::addShader(QGLShader *shader)
if (d->shaders.contains(shader))
return true; // Already added to this shader program.
if (d->programGuard.id() && shader) {
- if (!qgl_share_reg()->checkSharing(shader->d->shaderGuard.context(),
- d->programGuard.context())) {
+ if (!QGLContext::areSharing(shader->d->shaderGuard.context(),
+ d->programGuard.context())) {
qWarning("QGLShaderProgram::addShader: Program and shader are not associated with same context.");
return false;
}
diff --git a/src/opengl/qpaintengine_opengl.cpp b/src/opengl/qpaintengine_opengl.cpp
index a904064..da490c0 100644
--- a/src/opengl/qpaintengine_opengl.cpp
+++ b/src/opengl/qpaintengine_opengl.cpp
@@ -338,7 +338,7 @@ void QGLOffscreen::initialize()
int dim = qMax(2048, static_cast<int>(qt_next_power_of_two(qMax(device->size().width(), device->size().height()))));
- bool shared_context = qgl_share_reg()->checkSharing(device->context(), ctx);
+ bool shared_context = QGLContext::areSharing(device->context(), ctx);
bool would_fail = last_failed_size.isValid() &&
(device->size().width() >= last_failed_size.width() ||
device->size().height() >= last_failed_size.height());
@@ -555,7 +555,7 @@ public:
QList<const QGLContext *> contexts = programs.uniqueKeys();
for (int i=0; i<contexts.size(); ++i) {
const QGLContext *cx = contexts.at(i);
- if (cx != ctx && qgl_share_reg()->checkSharing(cx, ctx)) {
+ if (cx != ctx && QGLContext::areSharing(cx, ctx)) {
QList<GLProgram> progs = programs.values(cx);
for (int k=0; k<progs.size(); ++k) {
const GLProgram &prg = progs.at(k);
@@ -1015,7 +1015,7 @@ public:
}
inline GLuint getBuffer(const QGradient &gradient, qreal opacity, QGLContext *ctx) {
- if (buffer_ctx && !qgl_share_reg()->checkSharing(buffer_ctx, ctx))
+ if (buffer_ctx && !QGLContext::areSharing(buffer_ctx, ctx))
cleanCache();
buffer_ctx = ctx;
@@ -1365,7 +1365,7 @@ bool QOpenGLPaintEngine::begin(QPaintDevice *pdev)
#ifdef QT_OPENGL_ES
d->max_texture_size = ctx->d_func()->maxTextureSize();
#else
- bool shared_ctx = qgl_share_reg()->checkSharing(d->device->context(), d->shader_ctx);
+ bool shared_ctx = QGLContext::areSharing(d->device->context(), d->shader_ctx);
if (shared_ctx) {
d->max_texture_size = d->shader_ctx->d_func()->maxTextureSize();
@@ -4683,7 +4683,7 @@ void QGLGlyphCache::cacheGlyphs(QGLContext *context, const QTextItemInt &ti,
QList<const QGLContext *> contexts = qt_context_cache.keys();
for (int i=0; i<contexts.size(); ++i) {
const QGLContext *ctx = contexts.at(i);
- if (ctx != context && qgl_share_reg()->checkSharing(context, ctx)) {
+ if (ctx != context && QGLContext::areSharing(context, ctx)) {
context_key = ctx;
dev_it = qt_context_cache.constFind(context_key);
break;
diff --git a/src/opengl/qpixmapdata_gl.cpp b/src/opengl/qpixmapdata_gl.cpp
index 2331c6d..1ee3bbf 100644
--- a/src/opengl/qpixmapdata_gl.cpp
+++ b/src/opengl/qpixmapdata_gl.cpp
@@ -248,7 +248,7 @@ bool QGLPixmapData::isValidContext(const QGLContext *ctx) const
return true;
const QGLContext *share_ctx = qt_gl_share_widget()->context();
- return ctx == share_ctx || qgl_share_reg()->checkSharing(ctx, share_ctx);
+ return ctx == share_ctx || QGLContext::areSharing(ctx, share_ctx);
}
void QGLPixmapData::resize(int width, int height)