summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2016-02-29 01:01:50 +0100
committerSean Harmer <sean.harmer@kdab.com>2016-05-05 13:21:20 +0000
commit8176659e1f07baafab77471e3eac75cd9ae4b704 (patch)
treec1d9c936fc1196eeb3a1187d5adfc2606bfb162c
parenta72629194293dd29ee9c9f6964ac798f985b5e61 (diff)
render: eradicate Q_FOREACH loops [remaining low-risk]
... by replacing them with C++11 range-for loops. To avoid detaches of these mutable Qt containers, wrap the container in qAsConst(), where needed. This is the batch with low-risk changes. They operate on local containers or the loop body clearly does not cause the container to change. Saves ~3.8KiB in text size on optimized GCC 6.0 Linux AMD64 builds. Change-Id: I9c9669dd89f44d371d7a9cd4fc83a7930a06ce17 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
-rw-r--r--src/render/graphicshelpers/graphicscontext.cpp16
-rw-r--r--src/render/io/objloader.cpp2
-rw-r--r--src/render/picking/qobjectpicker.cpp6
-rw-r--r--src/render/raycasting/qcollisionqueryresult.cpp2
-rw-r--r--src/render/raycasting/qraycastingservice.cpp2
-rw-r--r--src/render/renderstates/renderstatecollection.cpp2
-rw-r--r--src/render/renderstates/renderstateset.cpp4
-rw-r--r--src/render/texture/texture.cpp2
8 files changed, 20 insertions, 16 deletions
diff --git a/src/render/graphicshelpers/graphicscontext.cpp b/src/render/graphicshelpers/graphicscontext.cpp
index 783ab2348..5a099c371 100644
--- a/src/render/graphicshelpers/graphicscontext.cpp
+++ b/src/render/graphicshelpers/graphicscontext.cpp
@@ -469,7 +469,8 @@ void GraphicsContext::activateRenderTarget(RenderTarget *renderTarget, const Att
// We need to check if one of the attachment was resized
TextureManager *textureManager = m_renderer->nodeManagers()->textureManager();
bool needsResize = false;
- Q_FOREACH (const Attachment &attachment, attachments.attachments()) {
+ const auto attachments_ = attachments.attachments();
+ for (const Attachment &attachment : attachments_) {
Texture *rTex = textureManager->lookupResource(attachment.m_textureUuid);
if (rTex != nullptr)
needsResize |= rTex->isTextureReset();
@@ -492,7 +493,8 @@ void GraphicsContext::bindFrameBufferAttachmentHelper(GLuint fboId, const Attach
QSize fboSize;
TextureManager *textureManager = m_renderer->nodeManagers()->textureManager();
- Q_FOREACH (const Attachment &attachment, attachments.attachments()) {
+ const auto attachments_ = attachments.attachments();
+ for (const Attachment &attachment : attachments_) {
Texture *rTex =textureManager->lookupResource(attachment.m_textureUuid);
if (rTex != nullptr) {
QOpenGLTexture *glTex = rTex->getOrCreateGLTexture();
@@ -630,7 +632,8 @@ GraphicsHelperInterface *GraphicsContext::resolveHighestOpenGLFunctions()
? QOpenGLDebugLogger::SynchronousLogging
: QOpenGLDebugLogger::AsynchronousLogging);
- Q_FOREACH (const QOpenGLDebugMessage &msg, m_debugLogger->loggedMessages())
+ const auto msgs = m_debugLogger->loggedMessages();
+ for (const QOpenGLDebugMessage &msg : msgs)
logOpenGLDebugMessage(msg);
}
} else {
@@ -643,7 +646,8 @@ GraphicsHelperInterface *GraphicsContext::resolveHighestOpenGLFunctions()
// TO DO: would that vary like the glHelper ?
QStringList extensions;
- Q_FOREACH (const QByteArray &ext, m_gl->extensions().values())
+ const auto exts = m_gl->extensions();
+ for (const QByteArray &ext : exts)
extensions << QString::fromUtf8(ext);
m_contextInfo.m_major = m_gl->format().version().first;
m_contextInfo.m_minor = m_gl->format().version().second;
@@ -1035,7 +1039,7 @@ void GraphicsContext::setParameters(ShaderParameterPack &parameterPack)
// Bind Shader Storage block to SSBO and update SSBO
const QVector<BlockToSSBO> blockToSSBOs = parameterPack.shaderStorageBuffers();
int ssboIndex = 0;
- Q_FOREACH (const BlockToSSBO b, blockToSSBOs) {
+ for (const BlockToSSBO b : blockToSSBOs) {
Buffer *cpuBuffer = m_renderer->nodeManagers()->bufferManager()->lookupResource(b.m_bufferID);
GLBuffer *ssbo = glBufferForRenderBuffer(cpuBuffer);
bindShaderStorageBlock(shader->programId(), b.m_blockIndex, ssboIndex);
@@ -1055,7 +1059,7 @@ void GraphicsContext::setParameters(ShaderParameterPack &parameterPack)
// TO DO: Convert ShaderData to Buffer so that we can use that generic process
const QVector<BlockToUBO> blockToUBOs = parameterPack.uniformBuffers();
int uboIndex = 0;
- Q_FOREACH (const BlockToUBO &b, blockToUBOs) {
+ for (const BlockToUBO &b : blockToUBOs) {
Buffer *cpuBuffer = m_renderer->nodeManagers()->bufferManager()->lookupResource(b.m_bufferID);
GLBuffer *ubo = glBufferForRenderBuffer(cpuBuffer);
bindUniformBlock(shader->programId(), b.m_blockIndex, uboIndex);
diff --git a/src/render/io/objloader.cpp b/src/render/io/objloader.cpp
index 27aa1061a..a5fe930db 100644
--- a/src/render/io/objloader.cpp
+++ b/src/render/io/objloader.cpp
@@ -462,7 +462,7 @@ void ObjLoader::updateIndices(const QVector<QVector3D> &positions,
const int indexCount = faceIndexVector.size();
m_indices.clear();
m_indices.reserve(indexCount);
- foreach (const FaceIndices &faceIndices, faceIndexVector) {
+ for (const FaceIndices faceIndices : faceIndexVector) {
const unsigned int i = faceIndexMap.value(faceIndices);
m_indices.append(i);
}
diff --git a/src/render/picking/qobjectpicker.cpp b/src/render/picking/qobjectpicker.cpp
index b46fef63b..8bb734d9c 100644
--- a/src/render/picking/qobjectpicker.cpp
+++ b/src/render/picking/qobjectpicker.cpp
@@ -211,11 +211,11 @@ void QObjectPickerPrivate::propagateEvent(QPickEvent *event, EventType type)
if (!m_entities.isEmpty()) {
Qt3DCore::QEntity *entity = m_entities.first();
Qt3DCore::QEntity *parentEntity = nullptr;
- Qt3DRender::QObjectPicker *objectPicker = nullptr;
while (entity != nullptr && entity->parent() != nullptr && !event->isAccepted()) {
parentEntity = entity->parentEntity();
- Q_FOREACH (Qt3DCore::QComponent *c, parentEntity->components()) {
- if ((objectPicker = qobject_cast<Qt3DRender::QObjectPicker *>(c)) != nullptr) {
+ const auto components = parentEntity->components();
+ for (Qt3DCore::QComponent *c : components) {
+ if (auto objectPicker = qobject_cast<Qt3DRender::QObjectPicker *>(c)) {
QObjectPickerPrivate *objectPickerPrivate = static_cast<QObjectPickerPrivate *>(QObjectPickerPrivate::get(objectPicker));
switch (type) {
case Pressed:
diff --git a/src/render/raycasting/qcollisionqueryresult.cpp b/src/render/raycasting/qcollisionqueryresult.cpp
index e1416dc29..e4a6afa69 100644
--- a/src/render/raycasting/qcollisionqueryresult.cpp
+++ b/src/render/raycasting/qcollisionqueryresult.cpp
@@ -95,7 +95,7 @@ QVector<Qt3DCore::QNodeId> QCollisionQueryResult::entitiesHit() const
{
Q_D(const QCollisionQueryResult);
QVector<Qt3DCore::QNodeId> result;
- Q_FOREACH (const Hit& hit, d->m_hits)
+ for (const Hit& hit : d->m_hits)
result << hit.m_entityId;
return result;
}
diff --git a/src/render/raycasting/qraycastingservice.cpp b/src/render/raycasting/qraycastingservice.cpp
index 31df3df47..6dfb1c57a 100644
--- a/src/render/raycasting/qraycastingservice.cpp
+++ b/src/render/raycasting/qraycastingservice.cpp
@@ -137,7 +137,7 @@ QCollisionQueryResult QRayCastingServicePrivate::collides(const QRay3D &ray, QBo
} else {
QVector<Hit> hits = QtConcurrent::blockingMappedReduced<QVector<Hit> >(volumes, gathererFunctor, reduceToAllHits);
std::sort(hits.begin(), hits.end(), compareHitsDistance);
- Q_FOREACH (const Hit &hit, hits)
+ for (const Hit &hit : qAsConst(hits))
q->addEntityHit(result, hit.id, hit.intersection, hit.distance);
}
diff --git a/src/render/renderstates/renderstatecollection.cpp b/src/render/renderstates/renderstatecollection.cpp
index d7659285b..beba83df4 100644
--- a/src/render/renderstates/renderstatecollection.cpp
+++ b/src/render/renderstates/renderstatecollection.cpp
@@ -58,7 +58,7 @@ QVector<RenderStateNode*> RenderStateCollection::renderStates(RenderStateManager
if (m_dirty) {
m_renderStateNodes.clear();
- Q_FOREACH (Qt3DCore::QNodeId id, m_renderStateIds) {
+ for (const Qt3DCore::QNodeId id : m_renderStateIds) {
RenderStateNode *node = manager->lookupResource(id);
m_renderStateNodes.append(node);
}
diff --git a/src/render/renderstates/renderstateset.cpp b/src/render/renderstates/renderstateset.cpp
index 8e850c688..f2715a3cd 100644
--- a/src/render/renderstates/renderstateset.cpp
+++ b/src/render/renderstates/renderstateset.cpp
@@ -124,7 +124,7 @@ int RenderStateSet::changeCost(RenderStateSet *previousState)
cost += int(bs.count());
// now, find out how many states we're changing
- Q_FOREACH (RenderStateImpl *ds, m_states) {
+ for (RenderStateImpl *ds : qAsConst(m_states)) {
// if the other state contains matching, then doesn't
// contribute to cost at all
if (previousState->contains(ds)) {
@@ -266,7 +266,7 @@ bool RenderStateSet::contains(RenderStateImpl *ds) const
if (!(ds->mask() & stateMask()))
return false;
- Q_FOREACH (RenderStateImpl* rs, m_states) {
+ for (RenderStateImpl* rs : m_states) {
if (ds->equalTo(*rs))
return true;
}
diff --git a/src/render/texture/texture.cpp b/src/render/texture/texture.cpp
index d83008776..fb3f6f733 100644
--- a/src/render/texture/texture.cpp
+++ b/src/render/texture/texture.cpp
@@ -444,7 +444,7 @@ void Texture::updateDNA()
m_textureDNA = ::qHash(key) + ::qHash(m_maximumAnisotropy);
// apply non-unique hashes from texture images or texture data
- Q_FOREACH (HTextureImage imgHandle, m_textureImages) {
+ for (HTextureImage imgHandle : qAsConst(m_textureImages)) {
TextureImage *img = m_textureImageManager->data(imgHandle);
if (img)
m_textureDNA += img->dna();