From 5ec9c5bb45da21b7cbfa1503300434bf1c94fbea Mon Sep 17 00:00:00 2001 From: Olivier Prat Date: Thu, 21 Sep 2017 09:32:34 +0200 Subject: [PATCH] Fixed some coding standard issues --- libraries/gpu-gl/src/gpu/gl/GLTexelFormat.cpp | 2 - libraries/gpu/src/gpu/Texture.cpp | 26 +++++----- libraries/image/src/image/Image.cpp | 47 ++++++++++--------- libraries/image/src/image/Image.h | 7 +-- 4 files changed, 40 insertions(+), 42 deletions(-) diff --git a/libraries/gpu-gl/src/gpu/gl/GLTexelFormat.cpp b/libraries/gpu-gl/src/gpu/gl/GLTexelFormat.cpp index 8d4259e240..192a82dafc 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLTexelFormat.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLTexelFormat.cpp @@ -508,14 +508,12 @@ GLTexelFormat GLTexelFormat::evalGLTexelFormat(const Element& dstFormat, const E case gpu::R11G11B10: texel.format = GL_RGB; texel.type = GL_UNSIGNED_INT_10F_11F_11F_REV; - // the type should be float texel.internalFormat = GL_R11F_G11F_B10F; break; case gpu::RGB9E5: texel.format = GL_RGB; texel.type = GL_UNSIGNED_INT_5_9_9_9_REV; - // the type should be float texel.internalFormat = GL_RGB9_E5; break; diff --git a/libraries/gpu/src/gpu/Texture.cpp b/libraries/gpu/src/gpu/Texture.cpp index 4c2f4960c7..4a588c3c84 100755 --- a/libraries/gpu/src/gpu/Texture.cpp +++ b/libraries/gpu/src/gpu/Texture.cpp @@ -686,17 +686,17 @@ bool sphericalHarmonicsFromTexture(const gpu::Texture& cubeTexture, std::vector< auto mipFormat = cubeTexture.getStoredMipFormat(); std::function unpackFunc; - switch (mipFormat.getSemantic()) - { - case gpu::R11G11B10: - unpackFunc = glm::unpackF2x11_1x10; - break; - case gpu::RGB9E5: - unpackFunc = glm::unpackF3x9_E1x5; - break; - default: - assert(false); - break; + + switch (mipFormat.getSemantic()) { + case gpu::R11G11B10: + unpackFunc = glm::unpackF2x11_1x10; + break; + case gpu::RGB9E5: + unpackFunc = glm::unpackF3x9_E1x5; + break; + default: + assert(false); + break; } const uint sqOrder = order*order; @@ -732,7 +732,7 @@ bool sphericalHarmonicsFromTexture(const gpu::Texture& cubeTexture, std::vector< for(int face=0; face < gpu::Texture::NUM_CUBE_FACES; face++) { PROFILE_RANGE(render_gpu, "ProcessFace"); - auto data = (const uint32*)cubeTexture.accessStoredMipFace(0, face)->readData(); + auto data = reinterpret_cast( cubeTexture.accessStoredMipFace(0, face)->readData() ); if (data == nullptr) { continue; } @@ -813,7 +813,7 @@ bool sphericalHarmonicsFromTexture(const gpu::Texture& cubeTexture, std::vector< // index of texel in texture // get color from texture - glm::vec3 color{ 0.f, 0.f, 0.f }; + glm::vec3 color{ 0.0f, 0.0f, 0.0f }; for (int i = 0; i < stride; ++i) { for (int j = 0; j < stride; ++j) { int k = (int)(x + i - halfStride + (y + j - halfStride) * width); diff --git a/libraries/image/src/image/Image.cpp b/libraries/image/src/image/Image.cpp index b1b87883bb..2ae62a9ce3 100644 --- a/libraries/image/src/image/Image.cpp +++ b/libraries/image/src/image/Image.cpp @@ -67,6 +67,10 @@ glm::uvec2 rectifyToSparseSize(const glm::uvec2& size) { namespace image { +enum { + QIMAGE_HDR_FORMAT = QImage::Format_RGB30 +}; + TextureUsage::TextureLoader TextureUsage::getTextureLoaderForType(Type type, const QVariantMap& options) { switch (type) { case ALBEDO_TEXTURE: @@ -206,7 +210,7 @@ void setCubeTexturesCompressionEnabled(bool enabled) { } static float denormalize(float value, const float minValue) { - return value < minValue ? 0.f : value; + return value < minValue ? 0.0f : value; } uint32 packR11G11B10F(const glm::vec3& color) { @@ -319,17 +323,18 @@ struct OutputHandler : public nvtt::OutputHandler { _data = static_cast(malloc(size)); _current = _data; } + virtual bool writeData(const void* data, int size) override { assert(_current + size <= _data + _size); memcpy(_current, data, size); _current += size; return true; } + virtual void endImage() override { if (_face >= 0) { _texture->assignStoredMipFace(_miplevel, _face, _size, static_cast(_data)); - } - else { + } else { _texture->assignStoredMip(_miplevel, _size, static_cast(_data)); } free(_data); @@ -433,11 +438,11 @@ void generateHDRMips(gpu::Texture* texture, const QImage& image, int face) { data.resize(width*height); dataIt = data.begin(); for (auto lineNb = 0; lineNb < height; lineNb++) { - const uint32* srcPixelIt = (const uint32*)image.constScanLine(lineNb); + const uint32* srcPixelIt = reinterpret_cast( image.constScanLine(lineNb) ); const uint32* srcPixelEnd = srcPixelIt + width; while (srcPixelIt < srcPixelEnd) { - *dataIt = glm::vec4(unpackFunc(*srcPixelIt), 1.f); + *dataIt = glm::vec4(unpackFunc(*srcPixelIt), 1.0f); ++srcPixelIt; ++dataIt; } @@ -446,7 +451,7 @@ void generateHDRMips(gpu::Texture* texture, const QImage& image, int face) { nvtt::OutputOptions outputOptions; outputOptions.setOutputHeader(false); - std::auto_ptr outputHandler; + std::unique_ptr outputHandler; MyErrorHandler errorHandler; outputOptions.setErrorHandler(&errorHandler); nvtt::Context context; @@ -1086,29 +1091,29 @@ QImage convertToHDRFormat(QImage srcImage, gpu::Element format) { #endif switch (format.getSemantic()) { - case gpu::R11G11B10: - packFunc = packR11G11B10F; + case gpu::R11G11B10: + packFunc = packR11G11B10F; #ifdef DEBUG_COLOR_PACKING - unpackFunc = glm::unpackF2x11_1x10; + unpackFunc = glm::unpackF2x11_1x10; #endif - break; - case gpu::RGB9E5: - packFunc = glm::packF3x9_E1x5; + break; + case gpu::RGB9E5: + packFunc = glm::packF3x9_E1x5; #ifdef DEBUG_COLOR_PACKING - unpackFunc = glm::unpackF3x9_E1x5; + unpackFunc = glm::unpackF3x9_E1x5; #endif - break; - default: - qCWarning(imagelogging) << "Unsupported HDR format"; - Q_UNREACHABLE(); - return srcImage; + break; + default: + qCWarning(imagelogging) << "Unsupported HDR format"; + Q_UNREACHABLE(); + return srcImage; } srcImage = srcImage.convertToFormat(QImage::Format_ARGB32); for (auto y = 0; y < srcImage.height(); y++) { - const QRgb* srcLineIt = (const QRgb*) srcImage.constScanLine(y); + const QRgb* srcLineIt = reinterpret_cast( srcImage.constScanLine(y) ); const QRgb* srcLineEnd = srcLineIt + srcImage.width(); - uint32* hdrLineIt = (uint32*) hdrImage.scanLine(y); + uint32* hdrLineIt = reinterpret_cast( hdrImage.scanLine(y) ); glm::vec3 color; while (srcLineIt < srcLineEnd) { @@ -1116,7 +1121,7 @@ QImage convertToHDRFormat(QImage srcImage, gpu::Element format) { color.g = qGreen(*srcLineIt); color.b = qBlue(*srcLineIt); // Normalize and apply gamma - color /= 255.f; + color /= 255.0f; color.r = powf(color.r, 2.2f); color.g = powf(color.g, 2.2f); color.b = powf(color.b, 2.2f); diff --git a/libraries/image/src/image/Image.h b/libraries/image/src/image/Image.h index c8be097542..3bf45ace98 100644 --- a/libraries/image/src/image/Image.h +++ b/libraries/image/src/image/Image.h @@ -13,11 +13,11 @@ #define hifi_image_Image_h #include -#include #include class QByteArray; +class QImage; namespace image { @@ -74,11 +74,6 @@ void setNormalTexturesCompressionEnabled(bool enabled); void setGrayscaleTexturesCompressionEnabled(bool enabled); void setCubeTexturesCompressionEnabled(bool enabled); -enum -{ - QIMAGE_HDR_FORMAT = QImage::Format_RGB30 -}; - gpu::TexturePointer processImage(const QByteArray& content, const std::string& url, int maxNumPixels, TextureUsage::Type textureType); } // namespace image