From 0e9b783ca378ed455a4cde15ca88bda6b424c299 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Fri, 1 Apr 2016 13:14:04 -0700 Subject: [PATCH 01/11] Release skybox texs when not rendering --- .../src/EntityTreeRenderer.cpp | 19 +++++++++++++++---- libraries/model/src/model/Skybox.h | 2 ++ .../src/procedural/ProceduralSkybox.cpp | 8 ++++++++ .../src/procedural/ProceduralSkybox.h | 2 ++ 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index edc7f7d754..b87329d5b6 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -297,7 +297,14 @@ void EntityTreeRenderer::applyZonePropertiesToScene(std::shared_ptrgetLocation(); auto sceneTime = sceneStage->getTime(); + // Skybox and procedural skybox data + auto skybox = std::dynamic_pointer_cast(skyStage->getSkybox()); + static QString userData; + if (!zone) { + userData = QString(); + skybox->clear(); + _pendingSkyboxTexture = false; _skyboxTexture.clear(); @@ -373,9 +380,7 @@ void EntityTreeRenderer::applyZonePropertiesToScene(std::shared_ptrgetBackgroundMode()) { case BACKGROUND_MODE_SKYBOX: { - auto skybox = std::dynamic_pointer_cast(skyStage->getSkybox()); skybox->setColor(zone->getSkyboxProperties().getColorVec3()); - static QString userData; if (userData != zone->getUserData()) { userData = zone->getUserData(); skybox->parse(userData); @@ -414,9 +419,15 @@ void EntityTreeRenderer::applyZonePropertiesToScene(std::shared_ptrsetBackgroundMode(model::SunSkyStage::SKY_DOME); // let the application background through - _pendingSkyboxTexture = false; + // Clear the skybox to release its textures + userData = QString(); + skybox->clear(); + _skyboxTexture.clear(); + _pendingSkyboxTexture = false; + + // Let the application background through + skyStage->setBackgroundMode(model::SunSkyStage::SKY_DOME); break; } diff --git a/libraries/model/src/model/Skybox.h b/libraries/model/src/model/Skybox.h index e9e7ee8b26..8c9e7bb1d6 100755 --- a/libraries/model/src/model/Skybox.h +++ b/libraries/model/src/model/Skybox.h @@ -35,6 +35,8 @@ public: void setCubemap(const gpu::TexturePointer& cubemap); const gpu::TexturePointer& getCubemap() const { return _cubemap; } + virtual void clear() { setCubemap(nullptr); } + void prepare(gpu::Batch& batch, int textureSlot = SKYBOX_SKYMAP_SLOT, int bufferSlot = SKYBOX_CONSTANTS_SLOT) const; virtual void render(gpu::Batch& batch, const ViewFrustum& frustum) const; diff --git a/libraries/procedural/src/procedural/ProceduralSkybox.cpp b/libraries/procedural/src/procedural/ProceduralSkybox.cpp index 4ff38eac74..1aa59c90d7 100644 --- a/libraries/procedural/src/procedural/ProceduralSkybox.cpp +++ b/libraries/procedural/src/procedural/ProceduralSkybox.cpp @@ -25,6 +25,14 @@ ProceduralSkybox::ProceduralSkybox() : model::Skybox() { _procedural._state->setStencilTest(true, 0xFF, gpu::State::StencilTest(0, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); } +void ProceduralSkybox::clear() { + // Parse and prepare a procedural with no shaders to release textures + parse(QString()); + _procedural.ready(); + + Skybox::clear(); +} + void ProceduralSkybox::render(gpu::Batch& batch, const ViewFrustum& frustum) const { if (_procedural.ready()) { ProceduralSkybox::render(batch, frustum, (*this)); diff --git a/libraries/procedural/src/procedural/ProceduralSkybox.h b/libraries/procedural/src/procedural/ProceduralSkybox.h index e817ce271d..2b8f2327a0 100644 --- a/libraries/procedural/src/procedural/ProceduralSkybox.h +++ b/libraries/procedural/src/procedural/ProceduralSkybox.h @@ -24,6 +24,8 @@ public: void parse(const QString& userData) { _procedural.parse(userData); } + virtual void clear() override; + virtual void render(gpu::Batch& batch, const ViewFrustum& frustum) const; static void render(gpu::Batch& batch, const ViewFrustum& frustum, const ProceduralSkybox& skybox); From eb2e254aa6372e99a4c0d370a850eb35271e388f Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Fri, 1 Apr 2016 14:20:28 -0700 Subject: [PATCH 02/11] Release px resources when unused --- .../procedural/src/procedural/Procedural.cpp | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/libraries/procedural/src/procedural/Procedural.cpp b/libraries/procedural/src/procedural/Procedural.cpp index d3aed38198..cedf76b37a 100644 --- a/libraries/procedural/src/procedural/Procedural.cpp +++ b/libraries/procedural/src/procedural/Procedural.cpp @@ -96,6 +96,7 @@ bool Procedural::parseVersion(const QJsonValue& version) { bool Procedural::parseUrl(const QUrl& shaderUrl) { if (!shaderUrl.isValid()) { qWarning() << "Invalid shader URL: " << shaderUrl; + _networkShader.reset(); return false; } @@ -110,6 +111,7 @@ bool Procedural::parseUrl(const QUrl& shaderUrl) { _shaderPath = _shaderUrl.toLocalFile(); qDebug() << "Shader path: " << _shaderPath; if (!QFile(_shaderPath).exists()) { + _networkShader.reset(); return false;; } } else { @@ -135,9 +137,14 @@ bool Procedural::parseTextures(const QJsonArray& channels) { auto textureCache = DependencyManager::get(); size_t channelCount = std::min(MAX_PROCEDURAL_TEXTURE_CHANNELS, (size_t)_parsedChannels.size()); - for (size_t i = 0; i < channelCount; ++i) { - QString url = _parsedChannels.at((int)i).toString(); - _channels[i] = textureCache->getTexture(QUrl(url)); + size_t channel = 0; + for (; channel < channelCount; ++channel) { + QString url = _parsedChannels.at((int)channel).toString(); + _channels[channel] = textureCache->getTexture(QUrl(url)); + } + for (; channel < MAX_PROCEDURAL_TEXTURE_CHANNELS; ++channel) { + // Release those textures no longer in use + _channels[channel] = textureCache->getTexture(QUrl()); } _channelsDirty = true; @@ -149,20 +156,21 @@ bool Procedural::parseTextures(const QJsonArray& channels) { void Procedural::parse(const QJsonObject& proceduralData) { _enabled = false; - if (proceduralData.isEmpty()) { - return; - } - auto version = proceduralData[VERSION_KEY]; auto shaderUrl = proceduralData[URL_KEY].toString(); shaderUrl = ResourceManager::normalizeURL(shaderUrl); auto uniforms = proceduralData[UNIFORMS_KEY].toObject(); auto channels = proceduralData[CHANNELS_KEY].toArray(); - if (parseVersion(version) && - parseUrl(shaderUrl) && - parseUniforms(uniforms) && - parseTextures(channels)) { + bool isValid = true; + + // Run through parsing regardless of validity to clear old cached resources + isValid = parseVersion(version) && isValid; + isValid = parseUrl(shaderUrl) && isValid; + isValid = parseUniforms(uniforms) && isValid; + isValid = parseTextures(channels) && isValid; + + if (!proceduralData.isEmpty() && isValid) { _enabled = true; } } From 4f373937f9dc94d54cf4da57fa612de801f9539d Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Sat, 2 Apr 2016 20:37:11 -0700 Subject: [PATCH 03/11] Additional performance markers --- libraries/fbx/src/FBXReader_Node.cpp | 22 +++++++++++-------- libraries/fbx/src/OBJReader.cpp | 17 ++++++++------ .../src/model-networking/TextureCache.cpp | 4 ++++ libraries/shared/src/shared/NsightHelpers.h | 2 +- 4 files changed, 28 insertions(+), 17 deletions(-) diff --git a/libraries/fbx/src/FBXReader_Node.cpp b/libraries/fbx/src/FBXReader_Node.cpp index a6fba5a4d5..68e9d6abac 100644 --- a/libraries/fbx/src/FBXReader_Node.cpp +++ b/libraries/fbx/src/FBXReader_Node.cpp @@ -9,17 +9,20 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include -#include -#include -#include -#include -#include -#include -#include -#include #include "FBXReader.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + template int streamSize() { return sizeof(T); } @@ -299,6 +302,7 @@ FBXNode parseTextFBXNode(Tokenizer& tokenizer) { } FBXNode FBXReader::parseFBX(QIODevice* device) { + PROFILE_RANGE_EX(__FUNCTION__, 0xff0000ff, device); // verify the prolog const QByteArray BINARY_PROLOG = "Kaydara FBX Binary "; if (device->peek(BINARY_PROLOG.size()) != BINARY_PROLOG) { diff --git a/libraries/fbx/src/OBJReader.cpp b/libraries/fbx/src/OBJReader.cpp index c28d680fb0..84c6c7aaa4 100644 --- a/libraries/fbx/src/OBJReader.cpp +++ b/libraries/fbx/src/OBJReader.cpp @@ -12,17 +12,20 @@ // http://www.scratchapixel.com/old/lessons/3d-advanced-lessons/obj-file-format/obj-file-format/ // http://paulbourke.net/dataformats/obj/ +#include "OBJReader.h" -#include -#include -#include -#include -#include #include // .obj files are not locale-specific. The C/ASCII charset applies. +#include +#include +#include +#include +#include + +#include #include + #include "FBXReader.h" -#include "OBJReader.h" #include "ModelFormatLogging.h" QHash COMMENT_SCALE_HINTS = {{"This file uses centimeters as units", 1.0f / 100.0f}, @@ -404,7 +407,7 @@ done: FBXGeometry* OBJReader::readOBJ(QByteArray& model, const QVariantHash& mapping, const QUrl& url) { - + PROFILE_RANGE_EX(__FUNCTION__, 0xffff0000, nullptr); QBuffer buffer { &model }; buffer.open(QIODevice::ReadOnly); diff --git a/libraries/model-networking/src/model-networking/TextureCache.cpp b/libraries/model-networking/src/model-networking/TextureCache.cpp index 3ba36dc2da..6870fa9b72 100644 --- a/libraries/model-networking/src/model-networking/TextureCache.cpp +++ b/libraries/model-networking/src/model-networking/TextureCache.cpp @@ -21,6 +21,8 @@ #include #include #include + +#include #include #include @@ -278,6 +280,7 @@ void ImageReader::listSupportedImageFormats() { } void ImageReader::run() { + PROFILE_RANGE_EX(__FUNCTION__, 0xffff0000, nullptr); auto originalPriority = QThread::currentThread()->priority(); if (originalPriority == QThread::InheritPriority) { originalPriority = QThread::NormalPriority; @@ -315,6 +318,7 @@ void ImageReader::run() { gpu::Texture* theTexture = nullptr; auto ntex = texture.dynamicCast(); if (ntex) { + PROFILE_RANGE_EX(__FUNCTION__"::textureLoader", 0xffffff00, nullptr); theTexture = ntex->getTextureLoader()(image, _url.toString().toStdString()); } diff --git a/libraries/shared/src/shared/NsightHelpers.h b/libraries/shared/src/shared/NsightHelpers.h index 9853171b34..c637c78162 100644 --- a/libraries/shared/src/shared/NsightHelpers.h +++ b/libraries/shared/src/shared/NsightHelpers.h @@ -20,7 +20,7 @@ public: }; #define PROFILE_RANGE(name) ProfileRange profileRangeThis(name); -#define PROFILE_RANGE_EX(name, argbColor, payload) ProfileRange profileRangeThis(name, argbColor, payload); +#define PROFILE_RANGE_EX(name, argbColor, payload) ProfileRange profileRangeThis(name, argbColor, (uint64_t)payload); #else #define PROFILE_RANGE(name) #define PROFILE_RANGE_EX(name, argbColor, payload) From 667c27866ed152019f2a5e0762aacc592d4fa747 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Sun, 3 Apr 2016 20:15:42 -0700 Subject: [PATCH 04/11] Pushing texel format translation into header --- libraries/gpu/src/gpu/GLBackendTexture.cpp | 364 +------------------- libraries/gpu/src/gpu/GLTexelFormat.h | 372 +++++++++++++++++++++ 2 files changed, 373 insertions(+), 363 deletions(-) create mode 100644 libraries/gpu/src/gpu/GLTexelFormat.h diff --git a/libraries/gpu/src/gpu/GLBackendTexture.cpp b/libraries/gpu/src/gpu/GLBackendTexture.cpp index 3fc7906285..242b9100e1 100755 --- a/libraries/gpu/src/gpu/GLBackendTexture.cpp +++ b/libraries/gpu/src/gpu/GLBackendTexture.cpp @@ -10,6 +10,7 @@ // #include "GPULogging.h" #include "GLBackendShared.h" +#include "GLTexelFormat.h" using namespace gpu; @@ -36,369 +37,6 @@ void GLBackend::GLTexture::setSize(GLuint size) { _size = size; } -class GLTexelFormat { -public: - GLenum internalFormat; - GLenum format; - GLenum type; - - static GLTexelFormat evalGLTexelFormat(const Element& dstFormat, const Element& srcFormat) { - if (dstFormat != srcFormat) { - GLTexelFormat texel = {GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE}; - - switch(dstFormat.getDimension()) { - case gpu::SCALAR: { - texel.format = GL_RED; - texel.type = _elementTypeToGLType[dstFormat.getType()]; - - switch(dstFormat.getSemantic()) { - case gpu::RGB: - case gpu::RGBA: - texel.internalFormat = GL_RED; - break; - case gpu::DEPTH: - texel.internalFormat = GL_DEPTH_COMPONENT; - break; - case gpu::DEPTH_STENCIL: - texel.type = GL_UNSIGNED_INT_24_8; - texel.format = GL_DEPTH_STENCIL; - texel.internalFormat = GL_DEPTH24_STENCIL8; - break; - default: - qCDebug(gpulogging) << "Unknown combination of texel format"; - } - break; - } - - case gpu::VEC2: { - texel.format = GL_RG; - texel.type = _elementTypeToGLType[dstFormat.getType()]; - - switch(dstFormat.getSemantic()) { - case gpu::RGB: - case gpu::RGBA: - texel.internalFormat = GL_RG; - break; - default: - qCDebug(gpulogging) << "Unknown combination of texel format"; - } - - break; - } - - case gpu::VEC3: { - texel.format = GL_RGB; - - texel.type = _elementTypeToGLType[dstFormat.getType()]; - - switch(dstFormat.getSemantic()) { - case gpu::RGB: - case gpu::RGBA: - texel.internalFormat = GL_RGB; - break; - default: - qCDebug(gpulogging) << "Unknown combination of texel format"; - } - - break; - } - - case gpu::VEC4: { - texel.format = GL_RGBA; - texel.type = _elementTypeToGLType[dstFormat.getType()]; - - switch(srcFormat.getSemantic()) { - case gpu::BGRA: - case gpu::SBGRA: - texel.format = GL_BGRA; - break; - case gpu::RGB: - case gpu::RGBA: - case gpu::SRGB: - case gpu::SRGBA: - default: - break; - }; - - switch(dstFormat.getSemantic()) { - case gpu::RGB: - texel.internalFormat = GL_RGB; - break; - case gpu::RGBA: - texel.internalFormat = GL_RGBA; - break; - case gpu::SRGB: - texel.internalFormat = GL_SRGB; - break; - case gpu::SRGBA: - texel.internalFormat = GL_SRGB_ALPHA; - break; - default: - qCDebug(gpulogging) << "Unknown combination of texel format"; - } - break; - } - - default: - qCDebug(gpulogging) << "Unknown combination of texel format"; - } - return texel; - } else { - GLTexelFormat texel = {GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE}; - - switch(dstFormat.getDimension()) { - case gpu::SCALAR: { - texel.format = GL_RED; - texel.type = _elementTypeToGLType[dstFormat.getType()]; - - switch(dstFormat.getSemantic()) { - case gpu::RGB: - case gpu::RGBA: - case gpu::SRGB: - case gpu::SRGBA: - texel.internalFormat = GL_RED; - switch (dstFormat.getType()) { - case gpu::UINT32: { - texel.internalFormat = GL_R32UI; - break; - } - case gpu::INT32: { - texel.internalFormat = GL_R32I; - break; - } - case gpu::NUINT32: { - texel.internalFormat = GL_RED; - break; - } - case gpu::NINT32: { - texel.internalFormat = GL_RED_SNORM; - break; - } - case gpu::FLOAT: { - texel.internalFormat = GL_R32F; - break; - } - case gpu::UINT16: { - texel.internalFormat = GL_R16UI; - break; - } - case gpu::INT16: { - texel.internalFormat = GL_R16I; - break; - } - case gpu::NUINT16: { - texel.internalFormat = GL_R16; - break; - } - case gpu::NINT16: { - texel.internalFormat = GL_R16_SNORM; - break; - } - case gpu::HALF: { - texel.internalFormat = GL_R16F; - break; - } - case gpu::UINT8: { - texel.internalFormat = GL_R8UI; - break; - } - case gpu::INT8: { - texel.internalFormat = GL_R8I; - break; - } - case gpu::NUINT8: { - if ((dstFormat.getSemantic() == gpu::SRGB || dstFormat.getSemantic() == gpu::SRGBA)) { - texel.internalFormat = GL_SLUMINANCE; - } else { - texel.internalFormat = GL_R8; - } - break; - } - case gpu::NINT8: { - texel.internalFormat = GL_R8_SNORM; - break; - } - case gpu::NUM_TYPES: { // quiet compiler - Q_UNREACHABLE(); - } - - } - break; - - case gpu::R11G11B10: - texel.format = GL_RGB; - // the type should be float - texel.internalFormat = GL_R11F_G11F_B10F; - break; - - case gpu::DEPTH: - texel.format = GL_DEPTH_COMPONENT; // It's depth component to load it - texel.internalFormat = GL_DEPTH_COMPONENT; - switch (dstFormat.getType()) { - case gpu::UINT32: - case gpu::INT32: - case gpu::NUINT32: - case gpu::NINT32: { - texel.internalFormat = GL_DEPTH_COMPONENT32; - break; - } - case gpu::FLOAT: { - texel.internalFormat = GL_DEPTH_COMPONENT32F; - break; - } - case gpu::UINT16: - case gpu::INT16: - case gpu::NUINT16: - case gpu::NINT16: - case gpu::HALF: { - texel.internalFormat = GL_DEPTH_COMPONENT16; - break; - } - case gpu::UINT8: - case gpu::INT8: - case gpu::NUINT8: - case gpu::NINT8: { - texel.internalFormat = GL_DEPTH_COMPONENT24; - break; - } - case gpu::NUM_TYPES: { // quiet compiler - Q_UNREACHABLE(); - } - } - break; - case gpu::DEPTH_STENCIL: - texel.type = GL_UNSIGNED_INT_24_8; - texel.format = GL_DEPTH_STENCIL; - texel.internalFormat = GL_DEPTH24_STENCIL8; - break; - default: - qCDebug(gpulogging) << "Unknown combination of texel format"; - } - - break; - } - - case gpu::VEC2: { - texel.format = GL_RG; - texel.type = _elementTypeToGLType[dstFormat.getType()]; - - switch(dstFormat.getSemantic()) { - case gpu::RGB: - case gpu::RGBA: - texel.internalFormat = GL_RG; - break; - default: - qCDebug(gpulogging) << "Unknown combination of texel format"; - } - - break; - } - - case gpu::VEC3: { - texel.format = GL_RGB; - - texel.type = _elementTypeToGLType[dstFormat.getType()]; - - switch(dstFormat.getSemantic()) { - case gpu::RGB: - case gpu::RGBA: - texel.internalFormat = GL_RGB; - break; - case gpu::SRGB: - case gpu::SRGBA: - texel.internalFormat = GL_SRGB; // standard 2.2 gamma correction color - break; - default: - qCDebug(gpulogging) << "Unknown combination of texel format"; - } - break; - } - - case gpu::VEC4: { - texel.format = GL_RGBA; - texel.type = _elementTypeToGLType[dstFormat.getType()]; - - switch(dstFormat.getSemantic()) { - case gpu::RGB: - texel.internalFormat = GL_RGB; - break; - case gpu::RGBA: - texel.internalFormat = GL_RGBA; - switch (dstFormat.getType()) { - case gpu::UINT32: - texel.format = GL_RGBA_INTEGER; - texel.internalFormat = GL_RGBA32UI; - break; - case gpu::INT32: - texel.format = GL_RGBA_INTEGER; - texel.internalFormat = GL_RGBA32I; - break; - case gpu::FLOAT: - texel.internalFormat = GL_RGBA32F; - break; - case gpu::UINT16: - texel.format = GL_RGBA_INTEGER; - texel.internalFormat = GL_RGBA16UI; - break; - case gpu::INT16: - texel.format = GL_RGBA_INTEGER; - texel.internalFormat = GL_RGBA16I; - break; - case gpu::NUINT16: - texel.format = GL_RGBA; - texel.internalFormat = GL_RGBA16; - break; - case gpu::NINT16: - texel.format = GL_RGBA; - texel.internalFormat = GL_RGBA16_SNORM; - break; - case gpu::HALF: - texel.format = GL_RGBA; - texel.internalFormat = GL_RGBA16F; - break; - case gpu::UINT8: - texel.format = GL_RGBA_INTEGER; - texel.internalFormat = GL_RGBA8UI; - break; - case gpu::INT8: - texel.format = GL_RGBA_INTEGER; - texel.internalFormat = GL_RGBA8I; - break; - case gpu::NUINT8: - texel.format = GL_RGBA; - texel.internalFormat = GL_RGBA8; - break; - case gpu::NINT8: - texel.format = GL_RGBA; - texel.internalFormat = GL_RGBA8_SNORM; - break; - case gpu::NUINT32: - case gpu::NINT32: - case gpu::NUM_TYPES: // quiet compiler - Q_UNREACHABLE(); - } - break; - case gpu::SRGB: - texel.internalFormat = GL_SRGB; - break; - case gpu::SRGBA: - texel.internalFormat = GL_SRGB_ALPHA; // standard 2.2 gamma correction color - break; - default: - qCDebug(gpulogging) << "Unknown combination of texel format"; - } - break; - } - - default: - qCDebug(gpulogging) << "Unknown combination of texel format"; - } - return texel; - } - } -}; - - GLBackend::GLTexture* GLBackend::syncGPUObject(const Texture& texture) { GLTexture* object = Backend::getGPUObject(texture); diff --git a/libraries/gpu/src/gpu/GLTexelFormat.h b/libraries/gpu/src/gpu/GLTexelFormat.h new file mode 100644 index 0000000000..274b5eeba3 --- /dev/null +++ b/libraries/gpu/src/gpu/GLTexelFormat.h @@ -0,0 +1,372 @@ +// +// Created by Bradley Austin Davis on 2016/04/03 +// Copyright 2013-2016 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include "GLBackendShared.h" + +class GLTexelFormat { +public: + GLenum internalFormat; + GLenum format; + GLenum type; + + static GLTexelFormat evalGLTexelFormat(const gpu::Element& dstFormat, const gpu::Element& srcFormat) { + using namespace gpu; + if (dstFormat != srcFormat) { + GLTexelFormat texel = { GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE }; + + switch (dstFormat.getDimension()) { + case gpu::SCALAR: { + texel.format = GL_RED; + texel.type = _elementTypeToGLType[dstFormat.getType()]; + + switch (dstFormat.getSemantic()) { + case gpu::RGB: + case gpu::RGBA: + texel.internalFormat = GL_R8; + break; + case gpu::DEPTH: + texel.internalFormat = GL_DEPTH_COMPONENT32; + break; + case gpu::DEPTH_STENCIL: + texel.type = GL_UNSIGNED_INT_24_8; + texel.format = GL_DEPTH_STENCIL; + texel.internalFormat = GL_DEPTH24_STENCIL8; + break; + default: + qCDebug(gpulogging) << "Unknown combination of texel format"; + } + break; + } + + case gpu::VEC2: { + texel.format = GL_RG; + texel.type = _elementTypeToGLType[dstFormat.getType()]; + + switch (dstFormat.getSemantic()) { + case gpu::RGB: + case gpu::RGBA: + texel.internalFormat = GL_RG8; + break; + default: + qCDebug(gpulogging) << "Unknown combination of texel format"; + } + + break; + } + + case gpu::VEC3: { + texel.format = GL_RGB; + + texel.type = _elementTypeToGLType[dstFormat.getType()]; + + switch (dstFormat.getSemantic()) { + case gpu::RGB: + case gpu::RGBA: + texel.internalFormat = GL_RGB8; + break; + default: + qCDebug(gpulogging) << "Unknown combination of texel format"; + } + + break; + } + + case gpu::VEC4: { + texel.format = GL_RGBA; + texel.type = _elementTypeToGLType[dstFormat.getType()]; + + switch (srcFormat.getSemantic()) { + case gpu::BGRA: + case gpu::SBGRA: + texel.format = GL_BGRA; + break; + case gpu::RGB: + case gpu::RGBA: + case gpu::SRGB: + case gpu::SRGBA: + default: + break; + }; + + switch (dstFormat.getSemantic()) { + case gpu::RGB: + texel.internalFormat = GL_RGB8; + break; + case gpu::RGBA: + texel.internalFormat = GL_RGBA8; + break; + case gpu::SRGB: + texel.internalFormat = GL_SRGB8; + break; + case gpu::SRGBA: + texel.internalFormat = GL_SRGB8_ALPHA8; + break; + default: + qCDebug(gpulogging) << "Unknown combination of texel format"; + } + break; + } + + default: + qCDebug(gpulogging) << "Unknown combination of texel format"; + } + return texel; + } else { + GLTexelFormat texel = { GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE }; + + switch (dstFormat.getDimension()) { + case gpu::SCALAR: { + texel.format = GL_RED; + texel.type = _elementTypeToGLType[dstFormat.getType()]; + + switch (dstFormat.getSemantic()) { + case gpu::RGB: + case gpu::RGBA: + case gpu::SRGB: + case gpu::SRGBA: + texel.internalFormat = GL_R8; + switch (dstFormat.getType()) { + case gpu::UINT32: { + texel.internalFormat = GL_R32UI; + break; + } + case gpu::INT32: { + texel.internalFormat = GL_R32I; + break; + } + case gpu::NUINT32: { + texel.internalFormat = GL_R8; + break; + } + case gpu::NINT32: { + texel.internalFormat = GL_R8_SNORM; + break; + } + case gpu::FLOAT: { + texel.internalFormat = GL_R32F; + break; + } + case gpu::UINT16: { + texel.internalFormat = GL_R16UI; + break; + } + case gpu::INT16: { + texel.internalFormat = GL_R16I; + break; + } + case gpu::NUINT16: { + texel.internalFormat = GL_R16; + break; + } + case gpu::NINT16: { + texel.internalFormat = GL_R16_SNORM; + break; + } + case gpu::HALF: { + texel.internalFormat = GL_R16F; + break; + } + case gpu::UINT8: { + texel.internalFormat = GL_R8UI; + break; + } + case gpu::INT8: { + texel.internalFormat = GL_R8I; + break; + } + case gpu::NUINT8: { + if ((dstFormat.getSemantic() == gpu::SRGB || dstFormat.getSemantic() == gpu::SRGBA)) { + texel.internalFormat = GL_SLUMINANCE8; + } else { + texel.internalFormat = GL_R8; + } + break; + } + case gpu::NINT8: { + texel.internalFormat = GL_R8_SNORM; + break; + } + case gpu::NUM_TYPES: { // quiet compiler + Q_UNREACHABLE(); + } + + } + break; + + case gpu::R11G11B10: + texel.format = GL_RGB; + // the type should be float + texel.internalFormat = GL_R11F_G11F_B10F; + break; + + case gpu::DEPTH: + texel.format = GL_DEPTH_COMPONENT; // It's depth component to load it + texel.internalFormat = GL_DEPTH_COMPONENT32; + switch (dstFormat.getType()) { + case gpu::UINT32: + case gpu::INT32: + case gpu::NUINT32: + case gpu::NINT32: { + texel.internalFormat = GL_DEPTH_COMPONENT32; + break; + } + case gpu::FLOAT: { + texel.internalFormat = GL_DEPTH_COMPONENT32F; + break; + } + case gpu::UINT16: + case gpu::INT16: + case gpu::NUINT16: + case gpu::NINT16: + case gpu::HALF: { + texel.internalFormat = GL_DEPTH_COMPONENT16; + break; + } + case gpu::UINT8: + case gpu::INT8: + case gpu::NUINT8: + case gpu::NINT8: { + texel.internalFormat = GL_DEPTH_COMPONENT24; + break; + } + case gpu::NUM_TYPES: { // quiet compiler + Q_UNREACHABLE(); + } + } + break; + case gpu::DEPTH_STENCIL: + texel.type = GL_UNSIGNED_INT_24_8; + texel.format = GL_DEPTH_STENCIL; + texel.internalFormat = GL_DEPTH24_STENCIL8; + break; + default: + qCDebug(gpulogging) << "Unknown combination of texel format"; + } + + break; + } + + case gpu::VEC2: { + texel.format = GL_RG; + texel.type = _elementTypeToGLType[dstFormat.getType()]; + + switch (dstFormat.getSemantic()) { + case gpu::RGB: + case gpu::RGBA: + texel.internalFormat = GL_RG8; + break; + default: + qCDebug(gpulogging) << "Unknown combination of texel format"; + } + + break; + } + + case gpu::VEC3: { + texel.format = GL_RGB; + + texel.type = _elementTypeToGLType[dstFormat.getType()]; + + switch (dstFormat.getSemantic()) { + case gpu::RGB: + case gpu::RGBA: + texel.internalFormat = GL_RGB8; + break; + case gpu::SRGB: + case gpu::SRGBA: + texel.internalFormat = GL_SRGB8; // standard 2.2 gamma correction color + break; + default: + qCDebug(gpulogging) << "Unknown combination of texel format"; + } + break; + } + + case gpu::VEC4: { + texel.format = GL_RGBA; + texel.type = _elementTypeToGLType[dstFormat.getType()]; + + switch (dstFormat.getSemantic()) { + case gpu::RGB: + texel.internalFormat = GL_RGB8; + break; + case gpu::RGBA: + texel.internalFormat = GL_RGBA8; + switch (dstFormat.getType()) { + case gpu::UINT32: + texel.format = GL_RGBA_INTEGER; + texel.internalFormat = GL_RGBA32UI; + break; + case gpu::INT32: + texel.format = GL_RGBA_INTEGER; + texel.internalFormat = GL_RGBA32I; + break; + case gpu::FLOAT: + texel.internalFormat = GL_RGBA32F; + break; + case gpu::UINT16: + texel.format = GL_RGBA_INTEGER; + texel.internalFormat = GL_RGBA16UI; + break; + case gpu::INT16: + texel.format = GL_RGBA_INTEGER; + texel.internalFormat = GL_RGBA16I; + break; + case gpu::NUINT16: + texel.format = GL_RGBA; + texel.internalFormat = GL_RGBA16; + break; + case gpu::NINT16: + texel.format = GL_RGBA; + texel.internalFormat = GL_RGBA16_SNORM; + break; + case gpu::HALF: + texel.format = GL_RGBA; + texel.internalFormat = GL_RGBA16F; + break; + case gpu::UINT8: + texel.format = GL_RGBA_INTEGER; + texel.internalFormat = GL_RGBA8UI; + break; + case gpu::INT8: + texel.format = GL_RGBA_INTEGER; + texel.internalFormat = GL_RGBA8I; + break; + case gpu::NUINT8: + texel.format = GL_RGBA; + texel.internalFormat = GL_RGBA8; + break; + case gpu::NINT8: + texel.format = GL_RGBA; + texel.internalFormat = GL_RGBA8_SNORM; + break; + case gpu::NUINT32: + case gpu::NINT32: + case gpu::NUM_TYPES: // quiet compiler + Q_UNREACHABLE(); + } + break; + case gpu::SRGB: + texel.internalFormat = GL_SRGB8; + break; + case gpu::SRGBA: + texel.internalFormat = GL_SRGB8_ALPHA8; // standard 2.2 gamma correction color + break; + default: + qCDebug(gpulogging) << "Unknown combination of texel format"; + } + break; + } + + default: + qCDebug(gpulogging) << "Unknown combination of texel format"; + } + return texel; + } + } +}; From b2058376ba38c4df8418197a5013386a6555dad2 Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Mon, 4 Apr 2016 17:03:05 +0200 Subject: [PATCH 05/11] used "ReSharper C++" to fix some style and spelling in Application.(h|cpp) --- interface/src/Application.cpp | 182 +++++++++++++++------------------- interface/src/Application.h | 85 ++++++++-------- 2 files changed, 123 insertions(+), 144 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 61d0f4f995..0130df4a73 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -18,23 +18,12 @@ #include #include -#include -#include -#include -#include -#include -#include -#include #include #include #include #include -#include -#include #include -#include -#include #include #include @@ -44,28 +33,18 @@ #include #include -#include #include -#include -#include -#include #include #include -#include - -#include #include -#include - #include #include #include #include #include -#include #include #include #include @@ -110,12 +89,9 @@ #include #include #include -#include #include #include #include -#include -#include #include #include #include @@ -137,7 +113,6 @@ #include "InterfaceActionFactory.h" #include "InterfaceLogging.h" #include "LODManager.h" -#include "Menu.h" #include "ModelPackager.h" #include "PluginContainerProxy.h" #include "scripting/AccountScriptingInterface.h" @@ -171,7 +146,7 @@ -// ON WIndows PC, NVidia Optimus laptop, we want to enable NVIDIA GPU +// ON Windows PC, Nvidia Optimus laptop, we want to enable NVIDIA GPU // FIXME seems to be broken. #if defined(Q_OS_WIN) extern "C" { @@ -254,14 +229,14 @@ public: }); } - void updateHeartbeat() { + static void updateHeartbeat() { auto now = usecTimestampNow(); auto elapsed = now - _heartbeat; _movingAverage.addSample(elapsed); _heartbeat = now; } - void deadlockDetectionCrash() { + static void deadlockDetectionCrash() { uint32_t* crashTrigger = nullptr; *crashTrigger = 0xDEAD10CC; } @@ -390,11 +365,11 @@ public: LambdaEvent(std::function && fun) : QEvent(static_cast(Lambda)), _fun(fun) { } - void call() { _fun(); } + void call() const { _fun(); } }; void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString& message) { - QString logMessage = LogHandler::getInstance().printMessage((LogMsgType) type, context, message); + QString logMessage = LogHandler::getInstance().printMessage(static_cast(type), context, message); if (!logMessage.isEmpty()) { #ifdef Q_OS_WIN @@ -528,7 +503,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : _maxOctreePPS(maxOctreePacketsPerSecond.get()), _lastFaceTrackerUpdate(0) { - // FIXME this may be excessivly conservative. On the other hand + // FIXME this may be excessively conservative. On the other hand // maybe I'm used to having an 8-core machine // Perhaps find the ideal thread count and subtract 2 or 3 // (main thread, present thread, random OS load) @@ -940,13 +915,13 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : _applicationStateDevice = std::make_shared(); _applicationStateDevice->addInputVariant(QString("InHMD"), controller::StateController::ReadLambda([]() -> float { - return (float)qApp->isHMDMode(); + return static_cast(qApp->isHMDMode()); })); _applicationStateDevice->addInputVariant(QString("SnapTurn"), controller::StateController::ReadLambda([]() -> float { - return (float)qApp->getMyAvatar()->getSnapTurn(); + return static_cast(qApp->getMyAvatar()->getSnapTurn()); })); _applicationStateDevice->addInputVariant(QString("Grounded"), controller::StateController::ReadLambda([]() -> float { - return (float)qApp->getMyAvatar()->getCharacterController()->onGround(); + return static_cast(qApp->getMyAvatar()->getCharacterController()->onGround()); })); _applicationStateDevice->addInputVariant(QString("NavigationFocused"), controller::StateController::ReadLambda([]() -> float { auto offscreenUi = DependencyManager::get(); @@ -1014,12 +989,12 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : connect(applicationUpdater.data(), &AutoUpdater::newVersionIsAvailable, dialogsManager.data(), &DialogsManager::showUpdateDialog); applicationUpdater->checkForUpdate(); - // Now that menu is initalized we can sync myAvatar with it's state. + // Now that menu is initialized we can sync myAvatar with it's state. getMyAvatar()->updateMotionBehaviorFromMenu(); // FIXME spacemouse code still needs cleanup #if 0 - // the 3Dconnexion device wants to be initiliazed after a window is displayed. + // the 3Dconnexion device wants to be initialized after a window is displayed. SpacemouseManager::getInstance().init(); #endif @@ -1124,7 +1099,7 @@ void Application::showCursor(const QCursor& cursor) { _cursorNeedsChanging = true; } -void Application::updateHeartbeat() { +void Application::updateHeartbeat() const { static_cast(_deadlockWatchdogThread)->updateHeartbeat(); } @@ -1218,12 +1193,12 @@ void Application::cleanupBeforeQuit() { Application::~Application() { EntityTreePointer tree = getEntities()->getTree(); - tree->setSimulation(NULL); + tree->setSimulation(nullptr); _octreeProcessor.terminate(); _entityEditSender.terminate(); - _physicsEngine->setCharacterController(NULL); + _physicsEngine->setCharacterController(nullptr); ModelEntityItem::cleanupLoadedAnimations(); @@ -1264,7 +1239,7 @@ Application::~Application() { _window->deleteLater(); - qInstallMessageHandler(NULL); // NOTE: Do this as late as possible so we continue to get our log messages + qInstallMessageHandler(nullptr); // NOTE: Do this as late as possible so we continue to get our log messages } void Application::initializeGL() { @@ -1467,7 +1442,7 @@ void Application::paintGL() { uint64_t diff = now - lastPaintBegin; float instantaneousFps = 0.0f; if (diff != 0) { - instantaneousFps = (float)USECS_PER_SECOND / (float)diff; + instantaneousFps = static_cast(USECS_PER_SECOND) / static_cast(diff); _framesPerSecond.updateAverage(_lastInstantaneousFps); } @@ -1479,7 +1454,7 @@ void Application::paintGL() { _lastFramesPerSecondUpdate = now; } - PROFILE_RANGE_EX(__FUNCTION__, 0xff0000ff, (uint64_t)_frameCount); + PROFILE_RANGE_EX(__FUNCTION__, 0xff0000ff, static_cast(_frameCount)); PerformanceTimer perfTimer("paintGL"); if (nullptr == _displayPlugin) { @@ -1744,7 +1719,7 @@ void Application::runTests() { runUnitTests(); } -void Application::audioMuteToggled() { +void Application::audioMuteToggled() const { QAction* muteAction = Menu::getInstance()->getActionForOption(MenuOption::MuteAudio); Q_CHECK_PTR(muteAction); muteAction->setChecked(DependencyManager::get()->isMuted()); @@ -1825,12 +1800,12 @@ bool Application::event(QEvent* event) { return false; } - if ((int)event->type() == (int)Lambda) { - ((LambdaEvent*)event)->call(); + if (static_cast(event->type()) == static_cast(Lambda)) { + static_cast(event)->call(); return true; } - if ((int)event->type() == (int)Paint) { + if (static_cast(event->type()) == static_cast(Paint)) { paintGL(); return true; } @@ -1860,25 +1835,25 @@ bool Application::event(QEvent* event) { switch (event->type()) { case QEvent::MouseMove: - mouseMoveEvent((QMouseEvent*)event); + mouseMoveEvent(static_cast(event)); return true; case QEvent::MouseButtonPress: - mousePressEvent((QMouseEvent*)event); + mousePressEvent(static_cast(event)); return true; case QEvent::MouseButtonDblClick: - mouseDoublePressEvent((QMouseEvent*)event); + mouseDoublePressEvent(static_cast(event)); return true; case QEvent::MouseButtonRelease: - mouseReleaseEvent((QMouseEvent*)event); + mouseReleaseEvent(static_cast(event)); return true; case QEvent::KeyPress: - keyPressEvent((QKeyEvent*)event); + keyPressEvent(static_cast(event)); return true; case QEvent::KeyRelease: - keyReleaseEvent((QKeyEvent*)event); + keyReleaseEvent(static_cast(event)); return true; case QEvent::FocusOut: - focusOutEvent((QFocusEvent*)event); + focusOutEvent(static_cast(event)); return true; case QEvent::TouchBegin: touchBeginEvent(static_cast(event)); @@ -2306,13 +2281,13 @@ void Application::focusOutEvent(QFocusEvent* event) { // synthesize events for keys currently pressed, since we may not get their release events foreach (int key, _keysPressed) { - QKeyEvent event(QEvent::KeyRelease, key, Qt::NoModifier); - keyReleaseEvent(&event); + QKeyEvent keyEvent(QEvent::KeyRelease, key, Qt::NoModifier); + keyReleaseEvent(&keyEvent); } _keysPressed.clear(); } -void Application::maybeToggleMenuVisible(QMouseEvent* event) { +void Application::maybeToggleMenuVisible(QMouseEvent* event) const { #ifndef Q_OS_MAC // If in full screen, and our main windows menu bar is hidden, and we're close to the top of the QMainWindow // then show the menubar. @@ -2428,7 +2403,7 @@ void Application::mousePressEvent(QMouseEvent* event) { } } -void Application::mouseDoublePressEvent(QMouseEvent* event) { +void Application::mouseDoublePressEvent(QMouseEvent* event) const { // if one of our scripts have asked to capture this event, then stop processing it if (_controllerScriptingInterface->isMouseCaptured()) { return; @@ -2528,7 +2503,7 @@ void Application::touchEndEvent(QTouchEvent* event) { // put any application specific touch behavior below here.. } -void Application::wheelEvent(QWheelEvent* event) { +void Application::wheelEvent(QWheelEvent* event) const { _altPressed = false; _controllerScriptingInterface->emitWheelEvent(event); // send events to any registered scripts @@ -2599,7 +2574,7 @@ void Application::idle(uint64_t now) { bool isThrottled = displayPlugin->isThrottled(); // Only run simulation code if more than the targetFramePeriod have passed since last time we ran // This attempts to lock the simulation at 60 updates per second, regardless of framerate - float timeSinceLastUpdateUs = (float)_lastTimeUpdated.nsecsElapsed() / NSECS_PER_USEC; + float timeSinceLastUpdateUs = static_cast(_lastTimeUpdated.nsecsElapsed()) / NSECS_PER_USEC; float secondsSinceLastUpdate = timeSinceLastUpdateUs / USECS_PER_SECOND; if (isThrottled && (timeSinceLastUpdateUs / USECS_PER_MSEC) < THROTTLED_SIM_FRAME_PERIOD_MS) { @@ -2639,7 +2614,7 @@ void Application::idle(uint64_t now) { static uint64_t lastIdleStart{ now }; uint64_t idleStartToStartDuration = now - lastIdleStart; if (idleStartToStartDuration != 0) { - _simsPerSecond.updateAverage((float)USECS_PER_SECOND / (float)idleStartToStartDuration); + _simsPerSecond.updateAverage(static_cast(USECS_PER_SECOND) / static_cast(idleStartToStartDuration)); } lastIdleStart = now; } @@ -2707,9 +2682,11 @@ float Application::getAverageSimsPerSecond() { } return _simsPerSecondReport; } + void Application::setAvatarSimrateSample(float sample) { _avatarSimsPerSecond.updateAverage(sample); } + float Application::getAvatarSimrate() { uint64_t now = usecTimestampNow(); @@ -2724,7 +2701,7 @@ void Application::setLowVelocityFilter(bool lowVelocityFilter) { controller::InputDevice::setLowVelocityFilter(lowVelocityFilter); } -ivec2 Application::getMouse() { +ivec2 Application::getMouse() const { auto reticlePosition = getApplicationCompositor().getReticlePosition(); // in the HMD, the reticlePosition is the mouse position @@ -2741,11 +2718,11 @@ FaceTracker* Application::getActiveFaceTracker() { auto dde = DependencyManager::get(); return (dde->isActive() ? static_cast(dde.data()) : - (faceshift->isActive() ? static_cast(faceshift.data()) : NULL)); + (faceshift->isActive() ? static_cast(faceshift.data()) : nullptr)); } FaceTracker* Application::getSelectedFaceTracker() { - FaceTracker* faceTracker = NULL; + FaceTracker* faceTracker = nullptr; #ifdef HAVE_FACESHIFT if (Menu::getInstance()->isOptionChecked(MenuOption::Faceshift)) { faceTracker = DependencyManager::get().data(); @@ -2759,7 +2736,7 @@ FaceTracker* Application::getSelectedFaceTracker() { return faceTracker; } -void Application::setActiveFaceTracker() { +void Application::setActiveFaceTracker() const { #if defined(HAVE_FACESHIFT) || defined(HAVE_DDE) bool isMuted = Menu::getInstance()->isOptionChecked(MenuOption::MuteFaceTracking); #endif @@ -2896,7 +2873,7 @@ void Application::loadSettings() { _settingsLoaded = true; } -void Application::saveSettings() { +void Application::saveSettings() const { sessionRunTime.set(_sessionRunTimer.elapsed() / MSECS_PER_SEC); DependencyManager::get()->saveSettings(); DependencyManager::get()->saveSettings(); @@ -2986,7 +2963,7 @@ void Application::init() { connect(getMyAvatar(), &MyAvatar::newCollisionSoundURL, DependencyManager::get().data(), &SoundCache::getSound); } -void Application::updateLOD() { +void Application::updateLOD() const { PerformanceTimer perfTimer("LOD"); // adjust it unless we were asked to disable this feature, or if we're currently in throttleRendering mode if (!isThrottleRendering()) { @@ -3188,13 +3165,13 @@ void Application::reloadResourceCaches() { getMyAvatar()->resetFullAvatarURL(); } -void Application::rotationModeChanged() { +void Application::rotationModeChanged() const { if (!Menu::getInstance()->isOptionChecked(MenuOption::CenterPlayerInView)) { getMyAvatar()->setHeadPitch(0); } } -void Application::updateDialogs(float deltaTime) { +void Application::updateDialogs(float deltaTime) const { PerformanceTimer perfTimer("updateDialogs"); bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); PerformanceWarning warn(showWarnings, "Application::updateDialogs()"); @@ -3220,7 +3197,7 @@ void Application::updateDialogs(float deltaTime) { void Application::update(float deltaTime) { - PROFILE_RANGE_EX(__FUNCTION__, 0xffff0000, (uint64_t)_frameCount + 1); + PROFILE_RANGE_EX(__FUNCTION__, 0xffff0000, static_cast(_frameCount) + 1); bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); PerformanceWarning warn(showWarnings, "Application::update()"); @@ -3230,7 +3207,7 @@ void Application::update(float deltaTime) { if (!_physicsEnabled && _processOctreeStatsCounter > 0) { // process octree stats packets are sent in between full sends of a scene. - // We keep physics disabled until we've recieved a full scene and everything near the avatar in that + // We keep physics disabled until we've received a full scene and everything near the avatar in that // scene is ready to compute its collision shape. if (nearbyEntitiesAreReadyForPhysics()) { @@ -3380,14 +3357,14 @@ void Application::update(float deltaTime) { }); } { - PROFILE_RANGE_EX("StepSimulation", 0xffff8000, (uint64_t)getActiveDisplayPlugin()->presentCount()); + PROFILE_RANGE_EX("StepSimulation", 0xffff8000, static_cast(getActiveDisplayPlugin()->presentCount())); PerformanceTimer perfTimer("stepSimulation"); getEntities()->getTree()->withWriteLock([&] { _physicsEngine->stepSimulation(); }); } { - PROFILE_RANGE_EX("HarvestChanges", 0xffffff00, (uint64_t)getActiveDisplayPlugin()->presentCount()); + PROFILE_RANGE_EX("HarvestChanges", 0xffffff00, static_cast(getActiveDisplayPlugin()->presentCount())); PerformanceTimer perfTimer("harvestChanges"); if (_physicsEngine->hasOutgoingChanges()) { getEntities()->getTree()->withWriteLock([&] { @@ -3425,20 +3402,20 @@ void Application::update(float deltaTime) { qApp->setAvatarSimrateSample(1.0f / deltaTime); { - PROFILE_RANGE_EX("OtherAvatars", 0xffff00ff, (uint64_t)getActiveDisplayPlugin()->presentCount()); + PROFILE_RANGE_EX("OtherAvatars", 0xffff00ff, static_cast(getActiveDisplayPlugin()->presentCount())); avatarManager->updateOtherAvatars(deltaTime); } qApp->updateMyAvatarLookAtPosition(); { - PROFILE_RANGE_EX("MyAvatar", 0xffff00ff, (uint64_t)getActiveDisplayPlugin()->presentCount()); + PROFILE_RANGE_EX("MyAvatar", 0xffff00ff, static_cast(getActiveDisplayPlugin()->presentCount())); avatarManager->updateMyAvatar(deltaTime); } } { - PROFILE_RANGE_EX("Overlays", 0xffff0000, (uint64_t)getActiveDisplayPlugin()->presentCount()); + PROFILE_RANGE_EX("Overlays", 0xffff0000, static_cast(getActiveDisplayPlugin()->presentCount())); PerformanceTimer perfTimer("overlays"); _overlays.update(deltaTime); } @@ -3458,7 +3435,7 @@ void Application::update(float deltaTime) { // Update my voxel servers with my current voxel query... { - PROFILE_RANGE_EX("QueryOctree", 0xffff0000, (uint64_t)getActiveDisplayPlugin()->presentCount()); + PROFILE_RANGE_EX("QueryOctree", 0xffff0000, static_cast(getActiveDisplayPlugin()->presentCount())); PerformanceTimer perfTimer("queryOctree"); quint64 sinceLastQuery = now - _lastQueriedTime; const quint64 TOO_LONG_SINCE_LAST_QUERY = 3 * USECS_PER_SECOND; @@ -3497,7 +3474,7 @@ void Application::update(float deltaTime) { } { - PROFILE_RANGE_EX("PreRenderLambdas", 0xffff0000, (uint64_t)0); + PROFILE_RANGE_EX("PreRenderLambdas", 0xffff0000, static_cast(0)); std::unique_lock guard(_preRenderLambdasLock); for (auto& iter : _preRenderLambdas) { @@ -3535,7 +3512,7 @@ int Application::sendNackPackets() { QSet missingSequenceNumbers; _octreeServerSceneStats.withReadLock([&] { - // retreive octree scene stats of this node + // retrieve octree scene stats of this node if (_octreeServerSceneStats.find(nodeUUID) == _octreeServerSceneStats.end()) { return; } @@ -3551,7 +3528,7 @@ int Application::sendNackPackets() { } if (nackPacketList->getNumPackets()) { - packetsSent += (int)nackPacketList->getNumPackets(); + packetsSent += static_cast(nackPacketList->getNumPackets()); // send the packet list nodeList->sendPacketList(std::move(nackPacketList), *node); @@ -3735,7 +3712,7 @@ bool Application::isHMDMode() const { } float Application::getTargetFrameRate() { return getActiveDisplayPlugin()->getTargetFrameRate(); } -QRect Application::getDesirableApplicationGeometry() { +QRect Application::getDesirableApplicationGeometry() const { QRect applicationGeometry = getWindow()->geometry(); // If our parent window is on the HMD, then don't use its geometry, instead use @@ -3748,7 +3725,7 @@ QRect Application::getDesirableApplicationGeometry() { // if our app's screen is the hmd screen, we don't want to place the // running scripts widget on it. So we need to pick a better screen. - // we will use the screen for the HMDTools since it's a guarenteed + // we will use the screen for the HMDTools since it's a guaranteed // better screen. if (appScreen == hmdScreen) { QScreen* betterScreen = hmdTools->windowHandle()->screen(); @@ -3777,7 +3754,7 @@ void Application::loadViewFrustum(Camera& camera, ViewFrustum& viewFrustum) { viewFrustum.calculate(); } -glm::vec3 Application::getSunDirection() { +glm::vec3 Application::getSunDirection() const { // Sun direction is in fact just the location of the sun relative to the origin auto skyStage = DependencyManager::get()->getSkyStage(); return skyStage->getSunLight()->getDirection(); @@ -3979,7 +3956,8 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se RenderArgs::DebugFlags renderDebugFlags = RenderArgs::RENDER_DEBUG_NONE; if (Menu::getInstance()->isOptionChecked(MenuOption::PhysicsShowHulls)) { - renderDebugFlags = (RenderArgs::DebugFlags) (renderDebugFlags | (int)RenderArgs::RENDER_DEBUG_HULLS); + renderDebugFlags = static_cast(renderDebugFlags | + static_cast(RenderArgs::RENDER_DEBUG_HULLS)); } renderArgs->_debugFlags = renderDebugFlags; //ViveControllerManager::getInstance().updateRendering(renderArgs, _main3DScene, pendingChanges); @@ -4033,7 +4011,7 @@ void Application::renderRearViewMirror(RenderArgs* renderArgs, const QRect& regi auto originalViewport = renderArgs->_viewport; // Grab current viewport to reset it at the end - float aspect = (float)region.width() / region.height(); + float aspect = static_cast(region.width()) / region.height(); float fov = MIRROR_FIELD_OF_VIEW; auto myAvatar = getMyAvatar(); @@ -4044,7 +4022,7 @@ void Application::renderRearViewMirror(RenderArgs* renderArgs, const QRect& regi myAvatar->getOrientation() * glm::vec3(0.0f, 0.0f, -1.0f) * MIRROR_REARVIEW_BODY_DISTANCE * myAvatar->getScale()); } else { // HEAD zoom level - // FIXME note that the positioing of the camera relative to the avatar can suffer limited + // FIXME note that the positioning of the camera relative to the avatar can suffer limited // precision as the user's position moves further away from the origin. Thus at // /1e7,1e7,1e7 (well outside the buildable volume) the mirror camera veers and sways // wildly as you rotate your avatar because the floating point values are becoming @@ -4069,7 +4047,7 @@ void Application::renderRearViewMirror(RenderArgs* renderArgs, const QRect& regi // set the bounds of rear mirror view // the region is in device independent coordinates; must convert to device - float ratio = (float)QApplication::desktop()->windowHandle()->devicePixelRatio() * getRenderResolutionScale(); + float ratio = static_cast(QApplication::desktop()->windowHandle()->devicePixelRatio()) * getRenderResolutionScale(); int width = region.width() * ratio; int height = region.height() * ratio; gpu::Vec4i viewport = gpu::Vec4i(0, 0, width, height); @@ -4090,7 +4068,7 @@ void Application::resetSensors(bool andReload) { QMetaObject::invokeMethod(DependencyManager::get().data(), "reset", Qt::QueuedConnection); } -void Application::updateWindowTitle(){ +void Application::updateWindowTitle() const { QString buildVersion = " (build " + applicationVersion() + ")"; auto nodeList = DependencyManager::get(); @@ -4148,14 +4126,14 @@ void Application::resettingDomain() { _notifiedPacketVersionMismatchThisDomain = false; } -void Application::nodeAdded(SharedNodePointer node) { +void Application::nodeAdded(SharedNodePointer node) const { if (node->getType() == NodeType::AvatarMixer) { // new avatar mixer, send off our identity packet right away getMyAvatar()->sendIdentityPacket(); } } -void Application::nodeActivated(SharedNodePointer node) { +void Application::nodeActivated(SharedNodePointer node) const { if (node->getType() == NodeType::AssetServer) { // asset server just connected - check if we have the asset browser showing @@ -4289,7 +4267,7 @@ int Application::processOctreeStats(ReceivedMessage& message, SharedNodePointer statsMessageLength = octreeStats.unpackFromPacket(message); // see if this is the first we've heard of this node... - NodeToJurisdictionMap* jurisdiction = NULL; + NodeToJurisdictionMap* jurisdiction = nullptr; QString serverType; if (sendingNode->getType() == NodeType::EntityServer) { jurisdiction = &_entityServerJurisdictions; @@ -4445,7 +4423,7 @@ bool Application::acceptURL(const QString& urlString, bool defaultUpload) { return defaultUpload; } -void Application::setSessionUUID(const QUuid& sessionUUID) { +void Application::setSessionUUID(const QUuid& sessionUUID) const { // HACK: until we swap the library dependency order between physics and entities // we cache the sessionID in two distinct places for physics. Physics::setSessionUUID(sessionUUID); // TODO: remove this one @@ -4586,7 +4564,7 @@ bool Application::displayAvatarAttachmentConfirmationDialog(const QString& name) } } -void Application::toggleRunningScriptsWidget() { +void Application::toggleRunningScriptsWidget() const { static const QUrl url("hifi/dialogs/RunningScripts.qml"); DependencyManager::get()->show(url, "RunningScripts"); //if (_runningScriptsWidget->isVisible()) { @@ -4623,7 +4601,7 @@ void Application::packageModel() { ModelPackager::package(); } -void Application::openUrl(const QUrl& url) { +void Application::openUrl(const QUrl& url) const { if (!url.isEmpty()) { if (url.scheme() == HIFI_URL_SCHEME) { DependencyManager::get()->handleLookupString(url.toString()); @@ -4653,7 +4631,7 @@ void Application::setPreviousScriptLocation(const QString& location) { _previousScriptLocation.set(location); } -void Application::loadScriptURLDialog() { +void Application::loadScriptURLDialog() const { auto newScript = OffscreenUi::getText(nullptr, "Open and Run Script", "Script URL"); if (!newScript.isEmpty()) { DependencyManager::get()->loadScript(newScript); @@ -4718,7 +4696,7 @@ void Application::notifyPacketVersionMismatch() { } } -void Application::checkSkeleton() { +void Application::checkSkeleton() const { if (getMyAvatar()->getSkeletonModel()->isActive() && !getMyAvatar()->getSkeletonModel()->hasSkeleton()) { qCDebug(interfaceapp) << "MyAvatar model has no skeleton"; @@ -4799,7 +4777,7 @@ void Application::setMaxOctreePacketsPerSecond(int maxOctreePPS) { } } -int Application::getMaxOctreePacketsPerSecond() { +int Application::getMaxOctreePacketsPerSecond() const { return _maxOctreePPS; } @@ -4823,7 +4801,7 @@ DisplayPlugin* Application::getActiveDisplayPlugin() { } const DisplayPlugin* Application::getActiveDisplayPlugin() const { - return ((Application*)this)->getActiveDisplayPlugin(); + return const_cast(this)->getActiveDisplayPlugin(); } static void addDisplayPluginToMenu(DisplayPluginPointer displayPlugin, bool active = false) { @@ -4903,7 +4881,7 @@ void Application::updateDisplayMode() { } } - // concactonate the groupings into a single list in the order: standard, advanced, developer + // concatenate the groupings into a single list in the order: standard, advanced, developer standard.insert(std::end(standard), std::begin(advanced), std::end(advanced)); standard.insert(std::end(standard), std::begin(developer), std::end(developer)); @@ -4915,7 +4893,7 @@ void Application::updateDisplayMode() { first = false; } - // after all plugins have been added to the menu, add a seperator to the menu + // after all plugins have been added to the menu, add a separator to the menu auto menu = Menu::getInstance(); auto parent = menu->getMenu(MenuOption::OutputMenu); parent->addSeparator(); @@ -4986,7 +4964,7 @@ void Application::updateDisplayMode() { emit activeDisplayPluginChanged(); - // reset the avatar, to set head and hand palms back to a resonable default pose. + // reset the avatar, to set head and hand palms back to a reasonable default pose. getMyAvatar()->reset(false); Q_ASSERT_X(_displayPlugin, "Application::updateDisplayMode", "could not find an activated display plugin"); @@ -5115,7 +5093,7 @@ void Application::setActiveDisplayPlugin(const QString& pluginName) { updateDisplayMode(); } -void Application::handleLocalServerConnection() { +void Application::handleLocalServerConnection() const { auto server = qobject_cast(sender()); qDebug() << "Got connection on local server from additional instance - waiting for parameters"; @@ -5128,7 +5106,7 @@ void Application::handleLocalServerConnection() { qApp->getWindow()->activateWindow(); } -void Application::readArgumentsFromLocalSocket() { +void Application::readArgumentsFromLocalSocket() const { auto socket = qobject_cast(sender()); auto message = socket->readAll(); diff --git a/interface/src/Application.h b/interface/src/Application.h index 4f67fbb545..4f6064df20 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -135,14 +135,14 @@ public: const ViewFrustum* getDisplayViewFrustum() const; ViewFrustum* getShadowViewFrustum() override { return &_shadowViewFrustum; } const OctreePacketProcessor& getOctreePacketProcessor() const { return _octreeProcessor; } - EntityTreeRenderer* getEntities() { return DependencyManager::get().data(); } + EntityTreeRenderer* getEntities() const { return DependencyManager::get().data(); } QUndoStack* getUndoStack() { return &_undoStack; } - MainWindow* getWindow() { return _window; } - EntityTreePointer getEntityClipboard() { return _entityClipboard; } + MainWindow* getWindow() const { return _window; } + EntityTreePointer getEntityClipboard() const { return _entityClipboard; } EntityTreeRenderer* getEntityClipboardRenderer() { return &_entityClipboardRenderer; } EntityEditPacketSender* getEntityEditPacketSender() { return &_entityEditSender; } - ivec2 getMouse(); + ivec2 getMouse() const; FaceTracker* getActiveFaceTracker(); FaceTracker* getSelectedFaceTracker(); @@ -155,7 +155,7 @@ public: bool isForeground() const { return _isForeground; } - uint32_t getFrameCount() { return _frameCount; } + uint32_t getFrameCount() const { return _frameCount; } float getFps() const { return _fps; } float getTargetFrameRate(); // frames/second float getLastInstanteousFps() const { return _lastInstantaneousFps; } @@ -179,7 +179,7 @@ public: DisplayPlugin* getActiveDisplayPlugin(); const DisplayPlugin* getActiveDisplayPlugin() const; - FileLogger* getLogger() { return _logger; } + FileLogger* getLogger() const { return _logger; } glm::vec2 getViewportDimensions() const; @@ -189,7 +189,7 @@ public: bool isAboutToQuit() const { return _aboutToQuit; } - // the isHMDmode is true whenever we use the interface from an HMD and not a standard flat display + // the isHMDMode is true whenever we use the interface from an HMD and not a standard flat display // rendering of several elements depend on that // TODO: carry that information on the Camera as a setting bool isHMDMode() const; @@ -197,14 +197,14 @@ public: glm::mat4 getEyeOffset(int eye) const; glm::mat4 getEyeProjection(int eye) const; - QRect getDesirableApplicationGeometry(); + QRect getDesirableApplicationGeometry() const; Bookmarks* getBookmarks() const { return _bookmarks; } virtual bool canAcceptURL(const QString& url) const override; virtual bool acceptURL(const QString& url, bool defaultUpload = false) override; void setMaxOctreePacketsPerSecond(int maxOctreePPS); - int getMaxOctreePacketsPerSecond(); + int getMaxOctreePacketsPerSecond() const; render::ScenePointer getMain3DScene() override { return _main3DScene; } render::ScenePointer getMain3DScene() const { return _main3DScene; } @@ -239,22 +239,22 @@ public slots: bool exportEntities(const QString& filename, float x, float y, float z, float scale); bool importEntities(const QString& url); - void setLowVelocityFilter(bool lowVelocityFilter); + static void setLowVelocityFilter(bool lowVelocityFilter); Q_INVOKABLE void loadDialog(); - Q_INVOKABLE void loadScriptURLDialog(); + Q_INVOKABLE void loadScriptURLDialog() const; void toggleLogDialog(); - void toggleRunningScriptsWidget(); + void toggleRunningScriptsWidget() const; void toggleAssetServerWidget(QString filePath = ""); - void handleLocalServerConnection(); - void readArgumentsFromLocalSocket(); + void handleLocalServerConnection() const; + void readArgumentsFromLocalSocket() const; - void packageModel(); + static void packageModel(); - void openUrl(const QUrl& url); + void openUrl(const QUrl& url) const; void resetSensors(bool andReload = false); - void setActiveFaceTracker(); + void setActiveFaceTracker() const; #ifdef HAVE_IVIEWHMD void setActiveEyeTracker(); @@ -264,7 +264,7 @@ public slots: #endif void aboutApp(); - void showHelp(); + static void showHelp(); void cycleCamera(); void cameraMenuChanged(); @@ -273,14 +273,14 @@ public slots: void reloadResourceCaches(); - void updateHeartbeat(); + void updateHeartbeat() const; - void crashApplication(); - void deadlockApplication(); + static void crashApplication(); + static void deadlockApplication(); - void rotationModeChanged(); + void rotationModeChanged() const; - void runTests(); + static void runTests(); private slots: void showDesktop(); @@ -290,7 +290,7 @@ private slots: void resettingDomain(); - void audioMuteToggled(); + void audioMuteToggled() const; void faceTrackerMuteToggled(); void activeChanged(Qt::ApplicationState state); @@ -298,7 +298,7 @@ private slots: void notifyPacketVersionMismatch(); void loadSettings(); - void saveSettings(); + void saveSettings() const; bool acceptSnapshot(const QString& urlString); bool askToSetAvatarUrl(const QString& url); @@ -308,18 +308,18 @@ private slots: void displayAvatarAttachmentWarning(const QString& message) const; bool displayAvatarAttachmentConfirmationDialog(const QString& name) const; - void setSessionUUID(const QUuid& sessionUUID); + void setSessionUUID(const QUuid& sessionUUID) const; void domainChanged(const QString& domainHostname); - void updateWindowTitle(); - void nodeAdded(SharedNodePointer node); - void nodeActivated(SharedNodePointer node); + void updateWindowTitle() const; + void nodeAdded(SharedNodePointer node) const; + void nodeActivated(SharedNodePointer node) const; void nodeKilled(SharedNodePointer node); - void packetSent(quint64 length); + static void packetSent(quint64 length); void updateDisplayMode(); void updateInputModes(); private: - void initDisplay(); + static void initDisplay(); void init(); void cleanupBeforeQuit(); @@ -327,14 +327,14 @@ private: void update(float deltaTime); // Various helper functions called during update() - void updateLOD(); + void updateLOD() const; void updateThreads(float deltaTime); - void updateDialogs(float deltaTime); + void updateDialogs(float deltaTime) const; void queryOctree(NodeType_t serverType, PacketType packetType, NodeToJurisdictionMap& jurisdictions); - void loadViewFrustum(Camera& camera, ViewFrustum& viewFrustum); + static void loadViewFrustum(Camera& camera, ViewFrustum& viewFrustum); - glm::vec3 getSunDirection(); + glm::vec3 getSunDirection() const; void renderRearViewMirror(RenderArgs* renderArgs, const QRect& region); @@ -344,7 +344,7 @@ private: MyAvatar* getMyAvatar() const; - void checkSkeleton(); + void checkSkeleton() const; void initializeAcceptedFiles(); @@ -366,18 +366,18 @@ private: void mouseMoveEvent(QMouseEvent* event); void mousePressEvent(QMouseEvent* event); - void mouseDoublePressEvent(QMouseEvent* event); + void mouseDoublePressEvent(QMouseEvent* event) const; void mouseReleaseEvent(QMouseEvent* event); void touchBeginEvent(QTouchEvent* event); void touchEndEvent(QTouchEvent* event); void touchUpdateEvent(QTouchEvent* event); - void wheelEvent(QWheelEvent* event); + void wheelEvent(QWheelEvent* event) const; void dropEvent(QDropEvent* event); - void dragEnterEvent(QDragEnterEvent* event); + static void dragEnterEvent(QDragEnterEvent* event); - void maybeToggleMenuVisible(QMouseEvent* event); + void maybeToggleMenuVisible(QMouseEvent* event) const; MainWindow* _window; QElapsedTimer& _sessionRunTimer; @@ -423,7 +423,7 @@ private: int _avatarSimsPerSecondReport {0}; quint64 _lastAvatarSimsPerSecondUpdate {0}; Camera _myCamera; // My view onto the world - Camera _mirrorCamera; // Cammera for mirror view + Camera _mirrorCamera; // Camera for mirror view QRect _mirrorViewRect; Setting::Handle _previousScriptLocation; @@ -475,7 +475,8 @@ private: quint64 _lastFaceTrackerUpdate; - render::ScenePointer _main3DScene{ new render::Scene(glm::vec3(-0.5f * (float)TREE_SCALE), (float)TREE_SCALE) }; + render::ScenePointer _main3DScene{ new render::Scene(glm::vec3(-0.5f * static_cast(TREE_SCALE)), + static_cast(TREE_SCALE)) }; render::EnginePointer _renderEngine{ new render::Engine() }; gpu::ContextPointer _gpuContext; // initialized during window creation From 142f37da1c55c08fe7c6268aa0b261647f16ca22 Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Mon, 4 Apr 2016 17:33:47 +0200 Subject: [PATCH 06/11] fix accidentally violated style rule 3.1.2.1 --- CONTRIBUTING.md | 2 +- interface/src/Application.cpp | 40 +++++++++++++++++------------------ interface/src/Application.h | 3 +-- 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4f1153b4f4..86ea351609 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -16,7 +16,7 @@ Contributing git checkout -b new_branch_name ``` 4. Code - * Follow the [coding standard](http://docs.highfidelity.io/v1.0/docs/coding-standard) + * Follow the [coding standard](https://readme.highfidelity.com/v1.0/docs/coding-standard) 5. Commit * Use [well formed commit messages](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html) 6. Update your branch diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 0130df4a73..17a918c0e8 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -369,7 +369,7 @@ public: }; void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString& message) { - QString logMessage = LogHandler::getInstance().printMessage(static_cast(type), context, message); + QString logMessage = LogHandler::getInstance().printMessage((LogMsgType) type, context, message); if (!logMessage.isEmpty()) { #ifdef Q_OS_WIN @@ -915,13 +915,13 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : _applicationStateDevice = std::make_shared(); _applicationStateDevice->addInputVariant(QString("InHMD"), controller::StateController::ReadLambda([]() -> float { - return static_cast(qApp->isHMDMode()); + return (float)qApp->isHMDMode(); })); _applicationStateDevice->addInputVariant(QString("SnapTurn"), controller::StateController::ReadLambda([]() -> float { - return static_cast(qApp->getMyAvatar()->getSnapTurn()); + return (float)qApp->getMyAvatar()->getSnapTurn(); })); _applicationStateDevice->addInputVariant(QString("Grounded"), controller::StateController::ReadLambda([]() -> float { - return static_cast(qApp->getMyAvatar()->getCharacterController()->onGround()); + return (float)qApp->getMyAvatar()->getCharacterController()->onGround(); })); _applicationStateDevice->addInputVariant(QString("NavigationFocused"), controller::StateController::ReadLambda([]() -> float { auto offscreenUi = DependencyManager::get(); @@ -1442,7 +1442,7 @@ void Application::paintGL() { uint64_t diff = now - lastPaintBegin; float instantaneousFps = 0.0f; if (diff != 0) { - instantaneousFps = static_cast(USECS_PER_SECOND) / static_cast(diff); + instantaneousFps = (float)USECS_PER_SECOND / (float)diff; _framesPerSecond.updateAverage(_lastInstantaneousFps); } @@ -1454,7 +1454,7 @@ void Application::paintGL() { _lastFramesPerSecondUpdate = now; } - PROFILE_RANGE_EX(__FUNCTION__, 0xff0000ff, static_cast(_frameCount)); + PROFILE_RANGE_EX(__FUNCTION__, 0xff0000ff, (uint64_t)_frameCount); PerformanceTimer perfTimer("paintGL"); if (nullptr == _displayPlugin) { @@ -1800,12 +1800,12 @@ bool Application::event(QEvent* event) { return false; } - if (static_cast(event->type()) == static_cast(Lambda)) { + if ((int)event->type() == (int)Lambda) { static_cast(event)->call(); return true; } - if (static_cast(event->type()) == static_cast(Paint)) { + if ((int)event->type() == (int)Paint) { paintGL(); return true; } @@ -2574,7 +2574,7 @@ void Application::idle(uint64_t now) { bool isThrottled = displayPlugin->isThrottled(); // Only run simulation code if more than the targetFramePeriod have passed since last time we ran // This attempts to lock the simulation at 60 updates per second, regardless of framerate - float timeSinceLastUpdateUs = static_cast(_lastTimeUpdated.nsecsElapsed()) / NSECS_PER_USEC; + float timeSinceLastUpdateUs = (float)_lastTimeUpdated.nsecsElapsed() / NSECS_PER_USEC; float secondsSinceLastUpdate = timeSinceLastUpdateUs / USECS_PER_SECOND; if (isThrottled && (timeSinceLastUpdateUs / USECS_PER_MSEC) < THROTTLED_SIM_FRAME_PERIOD_MS) { @@ -3197,7 +3197,7 @@ void Application::updateDialogs(float deltaTime) const { void Application::update(float deltaTime) { - PROFILE_RANGE_EX(__FUNCTION__, 0xffff0000, static_cast(_frameCount) + 1); + PROFILE_RANGE_EX(__FUNCTION__, 0xffff0000, (uint64_t)_frameCount + 1); bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); PerformanceWarning warn(showWarnings, "Application::update()"); @@ -3357,14 +3357,14 @@ void Application::update(float deltaTime) { }); } { - PROFILE_RANGE_EX("StepSimulation", 0xffff8000, static_cast(getActiveDisplayPlugin()->presentCount())); + PROFILE_RANGE_EX("StepSimulation", 0xffff8000, (uint64_t)getActiveDisplayPlugin()->presentCount()); PerformanceTimer perfTimer("stepSimulation"); getEntities()->getTree()->withWriteLock([&] { _physicsEngine->stepSimulation(); }); } { - PROFILE_RANGE_EX("HarvestChanges", 0xffffff00, static_cast(getActiveDisplayPlugin()->presentCount())); + PROFILE_RANGE_EX("HarvestChanges", 0xffffff00, (uint64_t)getActiveDisplayPlugin()->presentCount()); PerformanceTimer perfTimer("harvestChanges"); if (_physicsEngine->hasOutgoingChanges()) { getEntities()->getTree()->withWriteLock([&] { @@ -3402,20 +3402,20 @@ void Application::update(float deltaTime) { qApp->setAvatarSimrateSample(1.0f / deltaTime); { - PROFILE_RANGE_EX("OtherAvatars", 0xffff00ff, static_cast(getActiveDisplayPlugin()->presentCount())); + PROFILE_RANGE_EX("OtherAvatars", 0xffff00ff, (uint64_t)getActiveDisplayPlugin()->presentCount()); avatarManager->updateOtherAvatars(deltaTime); } qApp->updateMyAvatarLookAtPosition(); { - PROFILE_RANGE_EX("MyAvatar", 0xffff00ff, static_cast(getActiveDisplayPlugin()->presentCount())); + PROFILE_RANGE_EX("MyAvatar", 0xffff00ff, (uint64_t)getActiveDisplayPlugin()->presentCount()); avatarManager->updateMyAvatar(deltaTime); } } { - PROFILE_RANGE_EX("Overlays", 0xffff0000, static_cast(getActiveDisplayPlugin()->presentCount())); + PROFILE_RANGE_EX("Overlays", 0xffff0000, (uint64_t)getActiveDisplayPlugin()->presentCount()); PerformanceTimer perfTimer("overlays"); _overlays.update(deltaTime); } @@ -3435,7 +3435,7 @@ void Application::update(float deltaTime) { // Update my voxel servers with my current voxel query... { - PROFILE_RANGE_EX("QueryOctree", 0xffff0000, static_cast(getActiveDisplayPlugin()->presentCount())); + PROFILE_RANGE_EX("QueryOctree", 0xffff0000, (uint64_t)getActiveDisplayPlugin()->presentCount()); PerformanceTimer perfTimer("queryOctree"); quint64 sinceLastQuery = now - _lastQueriedTime; const quint64 TOO_LONG_SINCE_LAST_QUERY = 3 * USECS_PER_SECOND; @@ -3474,7 +3474,7 @@ void Application::update(float deltaTime) { } { - PROFILE_RANGE_EX("PreRenderLambdas", 0xffff0000, static_cast(0)); + PROFILE_RANGE_EX("PreRenderLambdas", 0xffff0000, (uint64_t)0); std::unique_lock guard(_preRenderLambdasLock); for (auto& iter : _preRenderLambdas) { @@ -3528,7 +3528,7 @@ int Application::sendNackPackets() { } if (nackPacketList->getNumPackets()) { - packetsSent += static_cast(nackPacketList->getNumPackets()); + packetsSent += (int)nackPacketList->getNumPackets(); // send the packet list nodeList->sendPacketList(std::move(nackPacketList), *node); @@ -4011,7 +4011,7 @@ void Application::renderRearViewMirror(RenderArgs* renderArgs, const QRect& regi auto originalViewport = renderArgs->_viewport; // Grab current viewport to reset it at the end - float aspect = static_cast(region.width()) / region.height(); + float aspect = (float)region.width() / region.height(); float fov = MIRROR_FIELD_OF_VIEW; auto myAvatar = getMyAvatar(); @@ -4047,7 +4047,7 @@ void Application::renderRearViewMirror(RenderArgs* renderArgs, const QRect& regi // set the bounds of rear mirror view // the region is in device independent coordinates; must convert to device - float ratio = static_cast(QApplication::desktop()->windowHandle()->devicePixelRatio()) * getRenderResolutionScale(); + float ratio = (float)QApplication::desktop()->windowHandle()->devicePixelRatio() * getRenderResolutionScale(); int width = region.width() * ratio; int height = region.height() * ratio; gpu::Vec4i viewport = gpu::Vec4i(0, 0, width, height); diff --git a/interface/src/Application.h b/interface/src/Application.h index 4f6064df20..e3196febd5 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -475,8 +475,7 @@ private: quint64 _lastFaceTrackerUpdate; - render::ScenePointer _main3DScene{ new render::Scene(glm::vec3(-0.5f * static_cast(TREE_SCALE)), - static_cast(TREE_SCALE)) }; + render::ScenePointer _main3DScene{ new render::Scene(glm::vec3(-0.5f * (float)TREE_SCALE), (float)TREE_SCALE) }; render::EnginePointer _renderEngine{ new render::Engine() }; gpu::ContextPointer _gpuContext; // initialized during window creation From 2be4097bc528ddfde0287b3a9a21ef651ec72b54 Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Mon, 4 Apr 2016 17:36:43 +0200 Subject: [PATCH 07/11] another 3.1.2.1 rollback --- interface/src/Application.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 17a918c0e8..0172b3ce3a 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2614,7 +2614,7 @@ void Application::idle(uint64_t now) { static uint64_t lastIdleStart{ now }; uint64_t idleStartToStartDuration = now - lastIdleStart; if (idleStartToStartDuration != 0) { - _simsPerSecond.updateAverage(static_cast(USECS_PER_SECOND) / static_cast(idleStartToStartDuration)); + _simsPerSecond.updateAverage((float)USECS_PER_SECOND / (float)idleStartToStartDuration); } lastIdleStart = now; } From 1da8fe5838df37c9ea2260d5823d19d98c738f45 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 4 Apr 2016 09:46:10 -0700 Subject: [PATCH 08/11] only a single log line per client version mismatch --- ice-server/src/IceServer.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ice-server/src/IceServer.cpp b/ice-server/src/IceServer.cpp index a512d5a049..59c36eae30 100644 --- a/ice-server/src/IceServer.cpp +++ b/ice-server/src/IceServer.cpp @@ -62,7 +62,14 @@ bool IceServer::packetVersionMatch(const udt::Packet& packet) { if (headerVersion == versionForPacketType(headerType)) { return true; } else { - qDebug() << "Packet version mismatch for packet" << headerType << " from" << packet.getSenderSockAddr(); + static QSet mismatchedClients; + + // only output a version mismatch once per ice-server run + if (!mismatchedClients.contains(packet.getSenderSockAddr())) { + mismatchedClients.insert(packet.getSenderSockAddr()); + + qDebug() << "Packet version mismatch for packet" << headerType << " from" << packet.getSenderSockAddr(); + } return false; } From 145b734b98cb557b9e8a5e12868db572bf1bfbbc Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 4 Apr 2016 09:49:04 -0700 Subject: [PATCH 09/11] completely remove version mismatch debug --- ice-server/src/IceServer.cpp | 9 --------- 1 file changed, 9 deletions(-) diff --git a/ice-server/src/IceServer.cpp b/ice-server/src/IceServer.cpp index 59c36eae30..c1e92f276f 100644 --- a/ice-server/src/IceServer.cpp +++ b/ice-server/src/IceServer.cpp @@ -62,15 +62,6 @@ bool IceServer::packetVersionMatch(const udt::Packet& packet) { if (headerVersion == versionForPacketType(headerType)) { return true; } else { - static QSet mismatchedClients; - - // only output a version mismatch once per ice-server run - if (!mismatchedClients.contains(packet.getSenderSockAddr())) { - mismatchedClients.insert(packet.getSenderSockAddr()); - - qDebug() << "Packet version mismatch for packet" << headerType << " from" << packet.getSenderSockAddr(); - } - return false; } } From d1898eeac6f27fb9fb214e3795eb9b6412fe8f6d Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Mon, 4 Apr 2016 10:31:36 -0700 Subject: [PATCH 10/11] ModelCache: reset thread priority back to normal Based on PR feedback on https://github.com/highfidelity/hifi/pull/7550 --- .../model-networking/src/model-networking/ModelCache.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libraries/model-networking/src/model-networking/ModelCache.cpp b/libraries/model-networking/src/model-networking/ModelCache.cpp index 4985859c40..852e3d9e81 100644 --- a/libraries/model-networking/src/model-networking/ModelCache.cpp +++ b/libraries/model-networking/src/model-networking/ModelCache.cpp @@ -10,6 +10,7 @@ // #include "ModelCache.h" +#include #include #include "FBXReader.h" #include "OBJReader.h" @@ -117,6 +118,9 @@ void GeometryReader::run() { originalPriority = QThread::NormalPriority; } QThread::currentThread()->setPriority(QThread::LowPriority); + Finally setPriorityBackToNormal([originalPriority]() { + QThread::currentThread()->setPriority(originalPriority); + }); if (!_resource.data()) { qCWarning(modelnetworking) << "Abandoning load of" << _url << "; resource was deleted"; @@ -167,8 +171,6 @@ void GeometryReader::run() { QMetaObject::invokeMethod(resource.data(), "finishedLoading", Qt::BlockingQueuedConnection, Q_ARG(bool, false)); } } - - QThread::currentThread()->setPriority(originalPriority); } class GeometryDefinitionResource : public GeometryResource { From e70319d83dce7a0ed7b93018b7f54cdd56908630 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 4 Apr 2016 10:53:16 -0700 Subject: [PATCH 11/11] don't re-connect multiple times to QNetworkAccessManager signal --- ice-server/src/IceServer.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ice-server/src/IceServer.cpp b/ice-server/src/IceServer.cpp index c1e92f276f..b66ccaa057 100644 --- a/ice-server/src/IceServer.cpp +++ b/ice-server/src/IceServer.cpp @@ -53,6 +53,10 @@ IceServer::IceServer(int argc, char* argv[]) : QTimer* inactivePeerTimer = new QTimer(this); connect(inactivePeerTimer, &QTimer::timeout, this, &IceServer::clearInactivePeers); inactivePeerTimer->start(CLEAR_INACTIVE_PEERS_INTERVAL_MSECS); + + // handle public keys when they arrive from the QNetworkAccessManager + auto& networkAccessManager = NetworkAccessManager::getInstance(); + connect(&networkAccessManager, &QNetworkAccessManager::finished, this, &IceServer::publicKeyReplyFinished); } bool IceServer::packetVersionMatch(const udt::Packet& packet) { @@ -200,7 +204,6 @@ bool IceServer::isVerifiedHeartbeat(const QUuid& domainID, const QByteArray& pla void IceServer::requestDomainPublicKey(const QUuid& domainID) { // send a request to the metaverse API for the public key for this domain auto& networkAccessManager = NetworkAccessManager::getInstance(); - connect(&networkAccessManager, &QNetworkAccessManager::finished, this, &IceServer::publicKeyReplyFinished); QUrl publicKeyURL { NetworkingConstants::METAVERSE_SERVER_URL }; QString publicKeyPath = QString("/api/v1/domains/%1/public_key").arg(uuidStringWithoutCurlyBraces(domainID));