From ecfe56085db9314c3b7f65d7ddd8f414e8b88b9d Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Sat, 3 Sep 2016 15:02:49 -0700 Subject: [PATCH] GLM update and GLI integration --- CMakeLists.txt | 7 ++ cmake/externals/gli/CMakeLists.txt | 21 ++++++ cmake/externals/glm/CMakeLists.txt | 4 +- cmake/macros/TargetGli.cmake | 12 ++++ cmake/modules/FindGLI.cmake | 26 +++++++ interface/src/Application.cpp | 2 +- interface/src/avatar/SoftAttachmentModel.cpp | 2 +- libraries/animation/src/Rig.cpp | 4 +- libraries/audio/src/AudioInjector.cpp | 2 +- .../src/RenderableLightEntityItem.cpp | 2 +- .../src/RenderableModelEntityItem.cpp | 2 +- .../src/RenderablePolyVoxEntityItem.cpp | 2 +- libraries/entities/src/EntityItemProperties.h | 3 +- libraries/entities/src/LightEntityItem.cpp | 4 +- .../src/model-networking/TextureCache.cpp | 21 ++++++ libraries/physics/src/BulletUtil.h | 2 +- libraries/shared/CMakeLists.txt | 2 +- libraries/shared/src/AACube.cpp | 8 +-- libraries/shared/src/Extents.h | 4 +- libraries/shared/src/GLMHelpers.h | 6 +- libraries/shared/src/SpatiallyNestable.cpp | 4 +- tests/render-texture-load/CMakeLists.txt | 3 + tests/render-texture-load/src/GLIHelpers.cpp | 70 ++++++++++++++++++ tests/render-texture-load/src/GLIHelpers.h | 47 ++++++++++++ tests/render-texture-load/src/main.cpp | 71 ++++++++----------- 25 files changed, 262 insertions(+), 69 deletions(-) create mode 100644 cmake/externals/gli/CMakeLists.txt create mode 100644 cmake/macros/TargetGli.cmake create mode 100644 cmake/modules/FindGLI.cmake create mode 100644 tests/render-texture-load/src/GLIHelpers.cpp create mode 100644 tests/render-texture-load/src/GLIHelpers.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 93ad411229..1ab7e55343 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,6 +74,13 @@ else () endif () endif(WIN32) +if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "5.3") + # GLM 0.9.8 on Ubuntu 14 (gcc 4.4) has issues with the simd declarations + add_definitions(-DGLM_FORCE_PURE) + endif() +endif() + if (NOT ANDROID) if ((NOT MSVC12) AND (NOT MSVC14)) include(CheckCXXCompilerFlag) diff --git a/cmake/externals/gli/CMakeLists.txt b/cmake/externals/gli/CMakeLists.txt new file mode 100644 index 0000000000..2ef4d2b3af --- /dev/null +++ b/cmake/externals/gli/CMakeLists.txt @@ -0,0 +1,21 @@ +set(EXTERNAL_NAME gli) + +include(ExternalProject) +ExternalProject_Add( + ${EXTERNAL_NAME} + URL https://hifi-public.s3.amazonaws.com/dependencies/gli-0.8.1.0.zip + URL_MD5 00c990f59c12bbf367956ef399d6f798 + BINARY_DIR ${EXTERNAL_PROJECT_PREFIX}/build + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + LOG_DOWNLOAD 1 +) + +# Hide this external target (for ide users) +set_target_properties(${EXTERNAL_NAME} PROPERTIES FOLDER "hidden/externals") + +ExternalProject_Get_Property(${EXTERNAL_NAME} SOURCE_DIR) + +string(TOUPPER ${EXTERNAL_NAME} EXTERNAL_NAME_UPPER) +set(${EXTERNAL_NAME_UPPER}_INCLUDE_DIRS ${SOURCE_DIR} CACHE PATH "List of gli include directories") \ No newline at end of file diff --git a/cmake/externals/glm/CMakeLists.txt b/cmake/externals/glm/CMakeLists.txt index 74e98ad19e..79a44fa48e 100644 --- a/cmake/externals/glm/CMakeLists.txt +++ b/cmake/externals/glm/CMakeLists.txt @@ -3,8 +3,8 @@ set(EXTERNAL_NAME glm) include(ExternalProject) ExternalProject_Add( ${EXTERNAL_NAME} - URL http://hifi-public.s3.amazonaws.com/dependencies/glm-0.9.5.4.zip - URL_MD5 fab76fc982b256b46208e5c750ed456a + URL https://hifi-public.s3.amazonaws.com/dependencies/glm-0.9.8.zip + URL_MD5 579ac77a3110befa3244d68c0ceb7281 BINARY_DIR ${EXTERNAL_PROJECT_PREFIX}/build CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH= LOG_DOWNLOAD 1 diff --git a/cmake/macros/TargetGli.cmake b/cmake/macros/TargetGli.cmake new file mode 100644 index 0000000000..664fcc00c5 --- /dev/null +++ b/cmake/macros/TargetGli.cmake @@ -0,0 +1,12 @@ +# +# Copyright 2015 High Fidelity, Inc. +# Created by Bradley Austin Davis on 2015/10/10 +# +# Distributed under the Apache License, Version 2.0. +# See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +# +macro(TARGET_GLI) + add_dependency_external_projects(gli) + find_package(GLI REQUIRED) + target_include_directories(${TARGET_NAME} PUBLIC ${GLI_INCLUDE_DIRS}) +endmacro() \ No newline at end of file diff --git a/cmake/modules/FindGLI.cmake b/cmake/modules/FindGLI.cmake new file mode 100644 index 0000000000..0f42a9b052 --- /dev/null +++ b/cmake/modules/FindGLI.cmake @@ -0,0 +1,26 @@ +# +# FindGLI.cmake +# +# Try to find GLI include path. +# Once done this will define +# +# GLI_INCLUDE_DIRS +# +# Created on 2016/09/03 by Bradley Austin Davis +# 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 +# + +# setup hints for GLI search +include("${MACRO_DIR}/HifiLibrarySearchHints.cmake") +hifi_library_search_hints("gli") + +# locate header +find_path(GLI_INCLUDE_DIRS "gli/gli.hpp" HINTS ${GLI_SEARCH_DIRS}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(GLI DEFAULT_MSG GLI_INCLUDE_DIRS) + +mark_as_advanced(GLI_INCLUDE_DIRS GLI_SEARCH_DIRS) \ No newline at end of file diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 904a6c5b65..7b07df414f 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3288,7 +3288,7 @@ void Application::init() { getEntities()->setEntityLoadingPriorityFunction([this](const EntityItem& item) { auto dims = item.getDimensions(); - auto maxSize = glm::max(dims.x, dims.y, dims.z); + auto maxSize = glm::compMax(dims); if (maxSize <= 0.0f) { return 0.0f; diff --git a/interface/src/avatar/SoftAttachmentModel.cpp b/interface/src/avatar/SoftAttachmentModel.cpp index b90fd9470c..c2e8dab2a1 100644 --- a/interface/src/avatar/SoftAttachmentModel.cpp +++ b/interface/src/avatar/SoftAttachmentModel.cpp @@ -55,7 +55,7 @@ void SoftAttachmentModel::updateClusterMatrices(glm::vec3 modelPosition, glm::qu // TODO: cache these look ups as an optimization int jointIndexOverride = getJointIndexOverride(cluster.jointIndex); - glm::mat4 jointMatrix(glm::mat4::_null); + glm::mat4 jointMatrix; if (jointIndexOverride >= 0 && jointIndexOverride < _rigOverride->getJointStateCount()) { jointMatrix = _rigOverride->getJointTransform(jointIndexOverride); } else { diff --git a/libraries/animation/src/Rig.cpp b/libraries/animation/src/Rig.cpp index d6ec0487f0..877c6c3e91 100644 --- a/libraries/animation/src/Rig.cpp +++ b/libraries/animation/src/Rig.cpp @@ -1093,7 +1093,7 @@ void Rig::updateFromHandParameters(const HandParameters& params, float dt) { // prevent the hand IK targets from intersecting the body capsule glm::vec3 handPosition = params.leftPosition; - glm::vec3 displacement(glm::vec3::_null); + glm::vec3 displacement; if (findSphereCapsulePenetration(handPosition, HAND_RADIUS, bodyCapsuleStart, bodyCapsuleEnd, bodyCapsuleRadius, displacement)) { handPosition -= displacement; } @@ -1111,7 +1111,7 @@ void Rig::updateFromHandParameters(const HandParameters& params, float dt) { // prevent the hand IK targets from intersecting the body capsule glm::vec3 handPosition = params.rightPosition; - glm::vec3 displacement(glm::vec3::_null); + glm::vec3 displacement; if (findSphereCapsulePenetration(handPosition, HAND_RADIUS, bodyCapsuleStart, bodyCapsuleEnd, bodyCapsuleRadius, displacement)) { handPosition -= displacement; } diff --git a/libraries/audio/src/AudioInjector.cpp b/libraries/audio/src/AudioInjector.cpp index c6368259c0..5fc07adb8d 100644 --- a/libraries/audio/src/AudioInjector.cpp +++ b/libraries/audio/src/AudioInjector.cpp @@ -26,7 +26,7 @@ #include "SoundCache.h" #include "AudioSRC.h" -int audioInjectorPtrMetaTypeId = qRegisterMetaType(); +//int audioInjectorPtrMetaTypeId = qRegisterMetaType(); AudioInjectorState operator& (AudioInjectorState lhs, AudioInjectorState rhs) { return static_cast(static_cast(lhs) & static_cast(rhs)); diff --git a/libraries/entities-renderer/src/RenderableLightEntityItem.cpp b/libraries/entities-renderer/src/RenderableLightEntityItem.cpp index b7f32cca65..3ed26456b4 100644 --- a/libraries/entities-renderer/src/RenderableLightEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableLightEntityItem.cpp @@ -33,7 +33,7 @@ void RenderableLightEntityItem::render(RenderArgs* args) { glm::vec3 position = getPosition(); glm::vec3 dimensions = getDimensions(); glm::quat rotation = getRotation(); - float largestDiameter = glm::max(dimensions.x, dimensions.y, dimensions.z); + float largestDiameter = glm::compMax(dimensions); glm::vec3 color = toGlm(getXColor()); diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index abc4e1c767..f2e938ece3 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -299,7 +299,7 @@ bool RenderableModelEntityItem::getAnimationFrame() { if (index < translations.size()) { translationMat = glm::translate(translations[index]); } - glm::mat4 rotationMat(glm::mat4::_null); + glm::mat4 rotationMat; if (index < rotations.size()) { rotationMat = glm::mat4_cast(fbxJoints[index].preRotation * rotations[index] * fbxJoints[index].postRotation); } else { diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index eb6db2874f..a2ca2a7cfe 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -447,7 +447,7 @@ bool RenderablePolyVoxEntityItem::findDetailedRayIntersection(const glm::vec3& o // set ray cast length to long enough to cover all of the voxel space float distanceToEntity = glm::distance(origin, getPosition()); glm::vec3 dimensions = getDimensions(); - float largestDimension = glm::max(dimensions.x, dimensions.y, dimensions.z) * 2.0f; + float largestDimension = glm::compMax(dimensions) * 2.0f; glm::vec3 farPoint = origin + normDirection * (distanceToEntity + largestDimension); glm::vec4 originInVoxel = wtvMatrix * glm::vec4(origin, 1.0f); diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index 473966dd60..3468b7dcde 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -15,7 +15,6 @@ #include #include -#include #include #include @@ -221,7 +220,7 @@ public: public: - float getMaxDimension() const { return glm::max(_dimensions.x, _dimensions.y, _dimensions.z); } + float getMaxDimension() const { return glm::compMax(_dimensions); } float getAge() const { return (float)(usecTimestampNow() - _created) / (float)USECS_PER_SECOND; } bool hasCreatedTime() const { return (_created != UNKNOWN_CREATED_TIME); } diff --git a/libraries/entities/src/LightEntityItem.cpp b/libraries/entities/src/LightEntityItem.cpp index 1be133463c..9a143beb8d 100644 --- a/libraries/entities/src/LightEntityItem.cpp +++ b/libraries/entities/src/LightEntityItem.cpp @@ -49,7 +49,7 @@ void LightEntityItem::setDimensions(const glm::vec3& value) { const float width = length * glm::sin(glm::radians(_cutoff)); EntityItem::setDimensions(glm::vec3(width, width, length)); } else { - float maxDimension = glm::max(value.x, value.y, value.z); + float maxDimension = glm::compMax(value); EntityItem::setDimensions(glm::vec3(maxDimension, maxDimension, maxDimension)); } } @@ -82,7 +82,7 @@ void LightEntityItem::setIsSpotlight(bool value) { const float width = length * glm::sin(glm::radians(_cutoff)); setDimensions(glm::vec3(width, width, length)); } else { - float maxDimension = glm::max(dimensions.x, dimensions.y, dimensions.z); + float maxDimension = glm::compMax(dimensions); setDimensions(glm::vec3(maxDimension, maxDimension, maxDimension)); } } diff --git a/libraries/model-networking/src/model-networking/TextureCache.cpp b/libraries/model-networking/src/model-networking/TextureCache.cpp index 1cc00bb850..32a6f4c323 100644 --- a/libraries/model-networking/src/model-networking/TextureCache.cpp +++ b/libraries/model-networking/src/model-networking/TextureCache.cpp @@ -18,12 +18,15 @@ #include #include #include +#include +#include #include #include #include +#include #include #include @@ -307,6 +310,24 @@ ImageReader::ImageReader(const QWeakPointer& resource, const QByteArra _url(url), _content(data) { +#if DEBUG_DUMP_TEXTURE_LOADS + static auto start = usecTimestampNow() / USECS_PER_MSEC; + auto now = usecTimestampNow() / USECS_PER_MSEC - start; + QString urlStr = _url.toString(); + auto dot = urlStr.lastIndexOf("."); + QString outFileName = QString(QCryptographicHash::hash(urlStr.toLocal8Bit(), QCryptographicHash::Md5).toHex()) + urlStr.right(urlStr.length() - dot); + QFile loadRecord("h:/textures/loads.txt"); + loadRecord.open(QFile::Text | QFile::Append | QFile::ReadWrite); + loadRecord.write(QString("%1 %2\n").arg(now).arg(outFileName).toLocal8Bit()); + outFileName = "h:/textures/" + outFileName; + QFileInfo outInfo(outFileName); + if (!outInfo.exists()) { + QFile outFile(outFileName); + outFile.open(QFile::WriteOnly | QFile::Truncate); + outFile.write(data); + outFile.close(); + } +#endif } void ImageReader::listSupportedImageFormats() { diff --git a/libraries/physics/src/BulletUtil.h b/libraries/physics/src/BulletUtil.h index 0122e86288..b6fac74617 100644 --- a/libraries/physics/src/BulletUtil.h +++ b/libraries/physics/src/BulletUtil.h @@ -46,7 +46,7 @@ inline btTransform glmToBullet(const glm::mat4& m) { } inline glm::mat4 bulletToGLM(const btTransform& t) { - glm::mat4 m(glm::mat4::_null); + glm::mat4 m; const btMatrix3x3& basis = t.getBasis(); // copy over 3x3 part diff --git a/libraries/shared/CMakeLists.txt b/libraries/shared/CMakeLists.txt index da345d1970..f9b835df5c 100644 --- a/libraries/shared/CMakeLists.txt +++ b/libraries/shared/CMakeLists.txt @@ -8,4 +8,4 @@ if (WIN32) endif() target_zlib() -target_nsight() +target_nsight() \ No newline at end of file diff --git a/libraries/shared/src/AACube.cpp b/libraries/shared/src/AACube.cpp index f8122ea4dc..8cff3255b3 100644 --- a/libraries/shared/src/AACube.cpp +++ b/libraries/shared/src/AACube.cpp @@ -9,8 +9,6 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include - #include "AABox.h" #include "AACube.h" #include "Extents.h" @@ -25,7 +23,7 @@ AACube::AACube(const Extents& other) : _corner(other.minimum) { glm::vec3 dimensions = other.maximum - other.minimum; - _scale = glm::max(dimensions.x, dimensions.y, dimensions.z); + _scale = glm::compMax(dimensions); } AACube::AACube(const glm::vec3& corner, float size) : @@ -479,8 +477,8 @@ AACube& AACube::operator += (const glm::vec3& point) { glm::vec3 scaleOld = oldMaximumPoint - _corner; glm::vec3 scalePoint = point - _corner; - _scale = glm::max(_scale, scalePoint.x, scalePoint.y, scalePoint.z); - _scale = glm::max(_scale, scaleOld.x, scaleOld.y, scaleOld.z); + _scale = std::max(_scale, glm::compMax(scalePoint)); + _scale = std::max(_scale, glm::compMax(scaleOld)); return (*this); } diff --git a/libraries/shared/src/Extents.h b/libraries/shared/src/Extents.h index 07fad60a04..850735dd5d 100644 --- a/libraries/shared/src/Extents.h +++ b/libraries/shared/src/Extents.h @@ -14,7 +14,7 @@ #define hifi_Extents_h #include -#include +#include #include #include "StreamUtils.h" @@ -67,7 +67,7 @@ public: void transform(const Transform& transform); glm::vec3 size() const { return maximum - minimum; } - float largestDimension() const {glm::vec3 s = size(); return glm::max(s[0], s[1], s[2]); } + float largestDimension() const { return glm::compMax(size()); } /// \return new Extents which is original rotated around orign by rotation Extents getRotated(const glm::quat& rotation) const { diff --git a/libraries/shared/src/GLMHelpers.h b/libraries/shared/src/GLMHelpers.h index ef3bfeb674..898dfa873d 100644 --- a/libraries/shared/src/GLMHelpers.h +++ b/libraries/shared/src/GLMHelpers.h @@ -203,19 +203,19 @@ inline float lerp(float x, float y, float a) { // vec2 lerp - linear interpolate template -glm::detail::tvec2 lerp(const glm::detail::tvec2& x, const glm::detail::tvec2& y, T a) { +glm::tvec2 lerp(const glm::tvec2& x, const glm::tvec2& y, T a) { return x * (T(1) - a) + (y * a); } // vec3 lerp - linear interpolate template -glm::detail::tvec3 lerp(const glm::detail::tvec3& x, const glm::detail::tvec3& y, T a) { +glm::tvec3 lerp(const glm::tvec3& x, const glm::tvec3& y, T a) { return x * (T(1) - a) + (y * a); } // vec4 lerp - linear interpolate template -glm::detail::tvec4 lerp(const glm::detail::tvec4& x, const glm::detail::tvec4& y, T a) { +glm::tvec4 lerp(const glm::tvec4& x, const glm::tvec4& y, T a) { return x * (T(1) - a) + (y * a); } diff --git a/libraries/shared/src/SpatiallyNestable.cpp b/libraries/shared/src/SpatiallyNestable.cpp index 453035de0f..b37fcd3699 100644 --- a/libraries/shared/src/SpatiallyNestable.cpp +++ b/libraries/shared/src/SpatiallyNestable.cpp @@ -797,7 +797,7 @@ void SpatiallyNestable::setLocalOrientation(const glm::quat& orientation) { } glm::vec3 SpatiallyNestable::getLocalVelocity() const { - glm::vec3 result(glm::vec3::_null); + glm::vec3 result; _velocityLock.withReadLock([&] { result = _velocity; }); @@ -811,7 +811,7 @@ void SpatiallyNestable::setLocalVelocity(const glm::vec3& velocity) { } glm::vec3 SpatiallyNestable::getLocalAngularVelocity() const { - glm::vec3 result(glm::vec3::_null); + glm::vec3 result; _angularVelocityLock.withReadLock([&] { result = _angularVelocity; }); diff --git a/tests/render-texture-load/CMakeLists.txt b/tests/render-texture-load/CMakeLists.txt index ecf910f434..0e5f32f46a 100644 --- a/tests/render-texture-load/CMakeLists.txt +++ b/tests/render-texture-load/CMakeLists.txt @@ -14,6 +14,9 @@ link_hifi_libraries(shared octree gl gpu gpu-gl render model model-networking ne package_libraries_for_deployment() +target_gli() +target_glm() + target_zlib() add_dependency_external_projects(quazip) find_package(QuaZip REQUIRED) diff --git a/tests/render-texture-load/src/GLIHelpers.cpp b/tests/render-texture-load/src/GLIHelpers.cpp new file mode 100644 index 0000000000..8067993b49 --- /dev/null +++ b/tests/render-texture-load/src/GLIHelpers.cpp @@ -0,0 +1,70 @@ +// +// Created by Bradley Austin Davis on 2016/09/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 "GLIHelpers.h" + +#include +#include + +#include +#include +#include +#include + +gli::format fromQImageFormat(QImage::Format format) { + switch (format) { + case QImage::Format_RGB32: + return gli::format::FORMAT_BGRA8_UNORM_PACK8; + + case QImage::Format_ARGB32: + return gli::format::FORMAT_BGRA8_UNORM_PACK8; + + case QImage::Format_Grayscale8: + return gli::format::FORMAT_L8_UNORM_PACK8; + + default: + return gli::format::FORMAT_UNDEFINED; + } +} + +QString getKtxFileName(const QString& sourceFileName) { + QFileInfo fileInfo(sourceFileName); + QString name = fileInfo.completeBaseName(); + QString ext = fileInfo.suffix(); + QString path = fileInfo.absolutePath(); + return path + "/" + name + ".ktx"; +} + +QString convertTexture(const QString& sourceFile) { + if (sourceFile.endsWith(".ktx") || sourceFile.endsWith(".dds")) { + return sourceFile; + } + QImage sourceImage(sourceFile); + gli::texture2d workTexture( + fromQImageFormat(sourceImage.format()), + gli::extent2d(sourceImage.width(), sourceImage.height())); + auto sourceSize = sourceImage.byteCount(); + assert(sourceSize == workTexture[workTexture.base_level()].size()); + memcpy(workTexture[workTexture.base_level()].data(), sourceImage.constBits(), sourceSize); + + QString resultFile = getKtxFileName(sourceFile) ; + gli::texture2d TextureMipmaped = gli::generate_mipmaps(workTexture, gli::FILTER_LINEAR); + gli::save(TextureMipmaped, resultFile.toLocal8Bit().data()); + gli::texture loaded = gli::load(resultFile.toLocal8Bit().data()); + return sourceFile; +} + + +gpu::TexturePointer processTexture(const QString& sourceFile) { + auto ktxFile = convertTexture(sourceFile); + gli::texture texture = gli::load(ktxFile.toLocal8Bit().data()); + if (texture.empty()) { + return gpu::TexturePointer(); + } + // FIXME load the actual KTX texture + return gpu::TexturePointer(); +} diff --git a/tests/render-texture-load/src/GLIHelpers.h b/tests/render-texture-load/src/GLIHelpers.h new file mode 100644 index 0000000000..c2841311a9 --- /dev/null +++ b/tests/render-texture-load/src/GLIHelpers.h @@ -0,0 +1,47 @@ +// +// Created by Bradley Austin Davis on 2016/09/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 +// +#pragma once +#ifndef _GLIHelpers_H_ +#define _GLIHelpers_H_ + +#include +#include + +// Work around for a bug in the MSVC compiler that chokes when you use GLI and Qt headers together. +#define gli glm + +#ifdef Q_OS_MAC +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunused-variable" +#pragma clang diagnostic ignored "-Wignored-qualifiers" +#endif + +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wempty-body" +#pragma GCC diagnostic ignored "-Wunused-variable" +#pragma GCC diagnostic ignored "-Wunused-but-set-variable" +#pragma GCC diagnostic ignored "-Wunused-result" +#pragma GCC diagnostic ignored "-Wignored-qualifiers" +#endif + +#include + +#ifdef Q_OS_MAC +#pragma clang diagnostic pop +#endif + +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic pop +#endif + +#include + +gpu::TexturePointer processTexture(const QString& file); + +#endif diff --git a/tests/render-texture-load/src/main.cpp b/tests/render-texture-load/src/main.cpp index 04bce72757..a1c5f74777 100644 --- a/tests/render-texture-load/src/main.cpp +++ b/tests/render-texture-load/src/main.cpp @@ -11,9 +11,6 @@ #include #include -#include -#include - #include #include #include @@ -41,6 +38,7 @@ #include +#include "GLIHelpers.h" #include #include #include @@ -55,15 +53,15 @@ #include #include #include -#include -#include -#include + +#include +#include extern QThread* RENDER_THREAD; static const QString DATA_SET = "https://hifi-content.s3.amazonaws.com/austin/textures.zip"; -static const QTemporaryDir DATA_DIR; - +static QDir DATA_DIR = QDir(QString("h:/textures")); +static QTemporaryDir* DOWNLOAD_DIR = nullptr; class FileDownloader : public QObject { Q_OBJECT @@ -81,7 +79,7 @@ public: } } -private slots: + private slots: void fileDownloaded(QNetworkReply* pReply) { _handler(pReply->readAll()); pReply->deleteLater(); @@ -132,8 +130,6 @@ public: _gpuContext = std::make_shared(); _backend = _gpuContext->getBackend(); _context.makeCurrent(); - DependencyManager::get()->init(); - _context.makeCurrent(); initContext.create(); _context.doneCurrent(); std::unique_lock lock(_mutex); @@ -191,7 +187,7 @@ public: _gpuContext->executeFrame(frame); { - + auto geometryCache = DependencyManager::get(); gpu::Batch presentBatch; presentBatch.setViewportTransform({ 0, 0, _size.width(), _size.height() }); @@ -277,16 +273,6 @@ public: } }; -QString fileForPath(const QString& name) { - QCryptographicHash hash(QCryptographicHash::Md5); - hash.addData(name.toLocal8Bit().data(), name.length()); - QString hashStr = QString(hash.result().toHex()); - auto dot = name.lastIndexOf('.'); - QString extension = name.right(name.length() - dot); - QString result = DATA_DIR.path() + "/" + hashStr + extension; - return result; -} - // Create a simple OpenGL window that renders text in various ways class QTestWindow : public QWindow { public: @@ -296,7 +282,6 @@ public: //DependencyManager::registerInheritance(); DependencyManager::set(); DependencyManager::set(NodeType::Agent); - DependencyManager::set(); DependencyManager::set(); DependencyManager::set(); DependencyManager::set(); @@ -316,7 +301,7 @@ public: _currentTexture = _textures.end(); { QStringList stringList; - QFile textFile("h:/textures/loads.txt"); + QFile textFile(DATA_DIR.path() + "/loads.txt"); textFile.open(QFile::ReadOnly); //... (open the file for reading, etc.) QTextStream textStream(&textFile); @@ -332,8 +317,7 @@ public: auto index = s.indexOf(" "); QString timeStr = s.left(index); auto time = timeStr.toUInt(); - QString path = s.right(s.length() - index).trimmed(); - path = fileForPath(path); + QString path = DATA_DIR.path() + "/" + s.right(s.length() - index).trimmed(); qDebug() << "Path " << path; if (!QFileInfo(path).exists()) { continue; @@ -341,7 +325,7 @@ public: _textureLoads.push({ time, path, s }); } } - + installEventFilter(this); QThreadPool::globalInstance()->setMaxThreadCount(2); QThread::currentThread()->setPriority(QThread::HighestPriority); @@ -436,7 +420,7 @@ private: QSize windowSize = _size; auto framebufferCache = DependencyManager::get(); framebufferCache->setFrameBufferSize(windowSize); - + // Final framebuffer that will be handled to the display-plugin render(); @@ -462,8 +446,9 @@ private: qDebug() << "Missing file " << front.file; } else { qDebug() << "Loading " << front.src; + auto file = front.file.toLocal8Bit().toStdString(); + processTexture(file.c_str()); _textures.push_back(DependencyManager::get()->getImageTexture(front.file)); - _currentTexture = _textures.begin(); } _textureLoads.pop(); if (_textureLoads.empty()) { @@ -481,7 +466,7 @@ private: }); PROFILE_RANGE(__FUNCTION__); auto framebuffer = DependencyManager::get()->getFramebuffer(); - + gpu::doInBatch(gpuContext, [&](gpu::Batch& batch) { batch.enableStereo(false); batch.setFramebuffer(framebuffer); @@ -494,8 +479,7 @@ private: } if (_currentTexture == _textures.end()) { _currentTexture = _textures.begin(); - } - + } if (_currentTexture != _textures.end()) { batch.setResourceTexture(0, *_currentTexture); } @@ -505,7 +489,7 @@ private: auto frame = gpuContext->endFrame(); frame->framebuffer = framebuffer; - frame->framebufferRecycler = [](const gpu::FramebufferPointer& framebuffer){ + frame->framebufferRecycler = [](const gpu::FramebufferPointer& framebuffer) { DependencyManager::get()->releaseFramebuffer(framebuffer); }; _renderThread.submitFrame(frame); @@ -546,20 +530,23 @@ hifi.gpu=true )V0G0N"; void unzipTestData(const QByteArray& zipData) { + DOWNLOAD_DIR = new QTemporaryDir(); + QTemporaryDir& tempDir = *DOWNLOAD_DIR; QTemporaryFile zipFile; + if (zipFile.open()) { zipFile.write(zipData); zipFile.close(); } qDebug() << zipFile.fileName(); - if (!DATA_DIR.isValid()) { + if (!tempDir.isValid()) { qFatal("Unable to create temp dir"); } - + DATA_DIR = QDir(tempDir.path()); + //auto files = JlCompress::getFileList(zipData); auto files = JlCompress::extractDir(zipFile.fileName(), DATA_DIR.path()); qDebug() << DATA_DIR.path(); - } int main(int argc, char** argv) { @@ -570,12 +557,14 @@ int main(int argc, char** argv) { qInstallMessageHandler(messageHandler); QLoggingCategory::setFilterRules(LOG_FILTER_RULES); + if (!DATA_DIR.exists()) { + FileDownloader(DATA_SET, [&](const QByteArray& data) { + qDebug() << "Fetched size " << data.size(); + unzipTestData(data); + }).waitForDownload(); + } + - FileDownloader(DATA_SET, [&](const QByteArray& data) { - qDebug() << "Fetched size " << data.size(); - unzipTestData(data); - }).waitForDownload(); - QTestWindow::setup(); QTestWindow window; app.exec();