From f9fae251ca07401ee1b0039edc6ea6b7a522b5a7 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 22 Oct 2015 12:36:18 +0200 Subject: Quick: Sanitize reading environment variables. Where possible, use qEnvironmentVariableIsSet()/ qEnvironmentVariableIsEmpty() instead of checking on the return value of qgetenv(). Where the value is required, add a check using one of qEnvironmentVariableIsSet()/Empty(). Move QSGAtlasTexture::qsg_envInt() to qsgrenderer.cpp for reuse as qt_sg_envInt() and add qt_sg_envFloat(). Change-Id: I4c93f16c228d4f537154f389a0fa1427654485f7 Reviewed-by: Gunnar Sletta --- src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp | 35 ++++++++--------------- 1 file changed, 12 insertions(+), 23 deletions(-) (limited to 'src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp') diff --git a/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp b/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp index 60ada14c32..66a8f6fbd3 100644 --- a/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp +++ b/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp @@ -61,6 +61,8 @@ QT_BEGIN_NAMESPACE extern QByteArray qsgShaderRewriter_insertZAttributes(const char *input, QSurfaceFormat::OpenGLContextProfile profile); +int qt_sg_envInt(const char *name, int defaultValue); + namespace QSGBatchRenderer { @@ -785,30 +787,17 @@ Renderer::Renderer(QSGRenderContext *ctx) } m_bufferStrategy = GL_STATIC_DRAW; - QByteArray strategy = qgetenv("QSG_RENDERER_BUFFER_STRATEGY"); - if (strategy == "dynamic") { - m_bufferStrategy = GL_DYNAMIC_DRAW; - } else if (strategy == "stream") { - m_bufferStrategy = GL_STREAM_DRAW; - } - - m_batchNodeThreshold = 64; - QByteArray alternateThreshold = qgetenv("QSG_RENDERER_BATCH_NODE_THRESHOLD"); - if (alternateThreshold.length() > 0) { - bool ok = false; - int threshold = alternateThreshold.toInt(&ok); - if (ok) - m_batchNodeThreshold = threshold; - } - - m_batchVertexThreshold = 1024; - alternateThreshold = qgetenv("QSG_RENDERER_BATCH_VERTEX_THRESHOLD"); - if (alternateThreshold.length() > 0) { - bool ok = false; - int threshold = alternateThreshold.toInt(&ok); - if (ok) - m_batchVertexThreshold = threshold; + if (Q_UNLIKELY(qEnvironmentVariableIsSet("QSG_RENDERER_BUFFER_STRATEGY"))) { + const QByteArray strategy = qgetenv("QSG_RENDERER_BUFFER_STRATEGY"); + if (strategy == "dynamic") + m_bufferStrategy = GL_DYNAMIC_DRAW; + else if (strategy == "stream") + m_bufferStrategy = GL_STREAM_DRAW; } + + m_batchNodeThreshold = qt_sg_envInt("QSG_RENDERER_BATCH_NODE_THRESHOLD", 64); + m_batchVertexThreshold = qt_sg_envInt("QSG_RENDERER_BATCH_VERTEX_THRESHOLD", 1024); + if (Q_UNLIKELY(debug_build() || debug_render())) { qDebug() << "Batch thresholds: nodes:" << m_batchNodeThreshold << " vertices:" << m_batchVertexThreshold; qDebug() << "Using buffer strategy:" << (m_bufferStrategy == GL_STATIC_DRAW ? "static" : (m_bufferStrategy == GL_DYNAMIC_DRAW ? "dynamic" : "stream")); -- cgit v1.2.3