From 28f2dc62ea20806b99d2a172148ee75091b7f459 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 15 Dec 2014 11:49:01 -0800 Subject: [PATCH 01/46] add windowshacks.h to GPUConfig.h and move it to shared --- libraries/gpu/src/gpu/GPUConfig.h | 1 + {interface => libraries/shared}/src/windowshacks.h | 0 2 files changed, 1 insertion(+) rename {interface => libraries/shared}/src/windowshacks.h (100%) diff --git a/libraries/gpu/src/gpu/GPUConfig.h b/libraries/gpu/src/gpu/GPUConfig.h index 393a476182..c399f51b66 100644 --- a/libraries/gpu/src/gpu/GPUConfig.h +++ b/libraries/gpu/src/gpu/GPUConfig.h @@ -19,6 +19,7 @@ #include #elif defined(WIN32) +#include #include #include diff --git a/interface/src/windowshacks.h b/libraries/shared/src/windowshacks.h similarity index 100% rename from interface/src/windowshacks.h rename to libraries/shared/src/windowshacks.h From 4e7368b643a36f6bddc9ebcd3a7af93c895d6f2d Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 15 Dec 2014 12:09:30 -0800 Subject: [PATCH 02/46] more windows hackery --- libraries/shared/src/windowshacks.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libraries/shared/src/windowshacks.h b/libraries/shared/src/windowshacks.h index fcd2f5a7f2..3fd9d29fb3 100644 --- a/libraries/shared/src/windowshacks.h +++ b/libraries/shared/src/windowshacks.h @@ -15,6 +15,11 @@ #define hifi_windowshacks_h #ifdef WIN32 +// apparently needed to get M_PI and other defines from cmath/math.h +#define _USE_MATH_DEFINES +// needed to make sure windows doesn't go to crazy with its defines +#define WINDOWS_LEAN_AND_MEAN + #undef NOMINMAX #include From 95d820ee8b1265c50391a72f9f2110b407037218 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 15 Dec 2014 12:16:01 -0800 Subject: [PATCH 03/46] more windows hackery --- libraries/shared/src/windowshacks.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/shared/src/windowshacks.h b/libraries/shared/src/windowshacks.h index 3fd9d29fb3..e7397b29ee 100644 --- a/libraries/shared/src/windowshacks.h +++ b/libraries/shared/src/windowshacks.h @@ -20,7 +20,7 @@ // needed to make sure windows doesn't go to crazy with its defines #define WINDOWS_LEAN_AND_MEAN -#undef NOMINMAX +//#undef NOMINMAX #include inline double roundf(double value) { From 0b95403949d86d27b217e4bd2facd0af9b06dee2 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 15 Dec 2014 12:25:20 -0800 Subject: [PATCH 04/46] cleanup the windows hackery a little --- libraries/shared/src/windowshacks.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/libraries/shared/src/windowshacks.h b/libraries/shared/src/windowshacks.h index e7397b29ee..67c6f8be0c 100644 --- a/libraries/shared/src/windowshacks.h +++ b/libraries/shared/src/windowshacks.h @@ -15,12 +15,6 @@ #define hifi_windowshacks_h #ifdef WIN32 -// apparently needed to get M_PI and other defines from cmath/math.h -#define _USE_MATH_DEFINES -// needed to make sure windows doesn't go to crazy with its defines -#define WINDOWS_LEAN_AND_MEAN - -//#undef NOMINMAX #include inline double roundf(double value) { From a92b65b0e9d871d91b38a356b63890c27870bec7 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 15 Dec 2014 12:42:04 -0800 Subject: [PATCH 05/46] now lets see if this works --- interface/src/renderer/GeometryCache.h | 2 +- interface/src/renderer/TextureCache.cpp | 2 +- interface/src/renderer/TextureCache.h | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/interface/src/renderer/GeometryCache.h b/interface/src/renderer/GeometryCache.h index 2d813ece09..22857125af 100644 --- a/interface/src/renderer/GeometryCache.h +++ b/interface/src/renderer/GeometryCache.h @@ -13,7 +13,7 @@ #define hifi_GeometryCache_h // include this before QOpenGLBuffer, which includes an earlier version of OpenGL -#include "InterfaceConfig.h" +#include #include #include diff --git a/interface/src/renderer/TextureCache.cpp b/interface/src/renderer/TextureCache.cpp index 123a8a5384..1591f5cb26 100644 --- a/interface/src/renderer/TextureCache.cpp +++ b/interface/src/renderer/TextureCache.cpp @@ -10,7 +10,7 @@ // // include this before QGLWidget, which includes an earlier version of OpenGL -#include "InterfaceConfig.h" +#include #include #include diff --git a/interface/src/renderer/TextureCache.h b/interface/src/renderer/TextureCache.h index 2bdfda3217..56e29bc5fb 100644 --- a/interface/src/renderer/TextureCache.h +++ b/interface/src/renderer/TextureCache.h @@ -12,6 +12,8 @@ #ifndef hifi_TextureCache_h #define hifi_TextureCache_h +#include + #include #include #include @@ -19,8 +21,6 @@ #include #include -#include "InterfaceConfig.h" - class QOpenGLFramebufferObject; class NetworkTexture; From 7b973453b42bab53ee0a2cef396f3f9a94a22de1 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 15 Dec 2014 13:14:16 -0800 Subject: [PATCH 06/46] move TextureCache to library --- interface/CMakeLists.txt | 2 +- interface/src/Application.h | 4 +- interface/src/MetavoxelSystem.h | 2 +- interface/src/avatar/Avatar.cpp | 4 +- interface/src/renderer/GeometryCache.cpp | 2 +- interface/src/renderer/Model.h | 2 +- interface/src/ui/UpdateDialog.cpp | 2 +- interface/src/ui/overlays/BillboardOverlay.h | 3 +- libraries/render-utils/CMakeLists.txt | 46 +++++++++++++++++++ .../render-utils/src}/TextureCache.cpp | 0 .../render-utils/src}/TextureCache.h | 0 11 files changed, 59 insertions(+), 8 deletions(-) create mode 100644 libraries/render-utils/CMakeLists.txt rename {interface/src/renderer => libraries/render-utils/src}/TextureCache.cpp (100%) rename {interface/src/renderer => libraries/render-utils/src}/TextureCache.h (100%) diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index 38dd02c655..ffc401ba63 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -107,7 +107,7 @@ endif() add_executable(${TARGET_NAME} MACOSX_BUNDLE ${INTERFACE_SRCS} ${QM}) # link required hifi libraries -link_hifi_libraries(shared octree voxels gpu fbx metavoxels networking entities avatars audio animation script-engine physics) +link_hifi_libraries(shared octree voxels gpu fbx metavoxels networking entities avatars audio animation script-engine physics render-utils) # find any optional and required libraries find_package(ZLIB REQUIRED) diff --git a/interface/src/Application.h b/interface/src/Application.h index d4a681f060..5a693ac21e 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -15,6 +15,8 @@ #include #include +#include + #include #include #include @@ -37,6 +39,7 @@ #include #include #include +#include #include #include @@ -61,7 +64,6 @@ #include "renderer/DeferredLightingEffect.h" #include "renderer/GeometryCache.h" #include "renderer/GlowEffect.h" -#include "renderer/TextureCache.h" #include "scripting/ControllerScriptingInterface.h" #include "ui/BandwidthDialog.h" #include "ui/BandwidthMeter.h" diff --git a/interface/src/MetavoxelSystem.h b/interface/src/MetavoxelSystem.h index 2ebf7e1146..0c0f9b49b7 100644 --- a/interface/src/MetavoxelSystem.h +++ b/interface/src/MetavoxelSystem.h @@ -20,9 +20,9 @@ #include #include +#include #include "renderer/ProgramObject.h" -#include "renderer/TextureCache.h" class HeightfieldBaseLayerBatch; class HeightfieldSplatBatch; diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 49a6f436df..39fc522852 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -11,6 +11,8 @@ #include +#include + #include #include @@ -25,6 +27,7 @@ #include #include #include +#include #include "Application.h" #include "Avatar.h" @@ -36,7 +39,6 @@ #include "Recorder.h" #include "world.h" #include "devices/OculusManager.h" -#include "renderer/TextureCache.h" #include "ui/TextRenderer.h" using namespace std; diff --git a/interface/src/renderer/GeometryCache.cpp b/interface/src/renderer/GeometryCache.cpp index 974a542b0e..4eae148259 100644 --- a/interface/src/renderer/GeometryCache.cpp +++ b/interface/src/renderer/GeometryCache.cpp @@ -19,9 +19,9 @@ #include #include +#include #include "GeometryCache.h" -#include "TextureCache.h" GeometryCache::GeometryCache() { } diff --git a/interface/src/renderer/Model.h b/interface/src/renderer/Model.h index 9b609de1d0..334730b23b 100644 --- a/interface/src/renderer/Model.h +++ b/interface/src/renderer/Model.h @@ -22,13 +22,13 @@ #include #include #include +#include #include "AnimationHandle.h" #include "GeometryCache.h" #include "InterfaceConfig.h" #include "JointState.h" #include "ProgramObject.h" -#include "TextureCache.h" class QScriptEngine; diff --git a/interface/src/ui/UpdateDialog.cpp b/interface/src/ui/UpdateDialog.cpp index 33024586be..bd02ca910a 100644 --- a/interface/src/ui/UpdateDialog.cpp +++ b/interface/src/ui/UpdateDialog.cpp @@ -8,10 +8,10 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include "Application.h" // HACK ATTACK WARNING: for windows build to work, we need this ahead of QtGui #include #include "ui_updateDialog.h" +#include "Application.h" #include "UpdateDialog.h" diff --git a/interface/src/ui/overlays/BillboardOverlay.h b/interface/src/ui/overlays/BillboardOverlay.h index c095a544b7..dcb8ab8b0c 100644 --- a/interface/src/ui/overlays/BillboardOverlay.h +++ b/interface/src/ui/overlays/BillboardOverlay.h @@ -15,8 +15,9 @@ #include #include +#include + #include "Base3DOverlay.h" -#include "renderer/TextureCache.h" class BillboardOverlay : public Base3DOverlay { Q_OBJECT diff --git a/libraries/render-utils/CMakeLists.txt b/libraries/render-utils/CMakeLists.txt new file mode 100644 index 0000000000..dea83a12a4 --- /dev/null +++ b/libraries/render-utils/CMakeLists.txt @@ -0,0 +1,46 @@ +set(TARGET_NAME render-utils) + +# use setup_hifi_library macro to setup our project and link appropriate Qt modules +setup_hifi_library(Widgets OpenGL Network) + +include_glm() + +link_hifi_libraries(shared gpu) +if (APPLE) + # link in required OS X frameworks and include the right GL headers + find_library(OpenGL OpenGL) + + target_link_libraries(${TARGET_NAME} ${OpenGL}) + +else (APPLE) + find_package(OpenGL REQUIRED) + + if (${OPENGL_INCLUDE_DIR}) + include_directories(SYSTEM "${OPENGL_INCLUDE_DIR}") + endif () + + #target_link_libraries(${TARGET_NAME} "${OPENGL_LIBRARY}") + + # link target to external libraries + if (WIN32) + find_package(GLEW REQUIRED) + include_directories(${GLEW_INCLUDE_DIRS}) + + # we're using static GLEW, so define GLEW_STATIC + add_definitions(-DGLEW_STATIC) + + #target_link_libraries(${TARGET_NAME} "${GLEW_LIBRARIES}" "${NSIGHT_LIBRARIES}" opengl32.lib) + + # try to find the Nsight package and add it to the build if we find it + #find_package(NSIGHT) + #if (NSIGHT_FOUND) + # include_directories(${NSIGHT_INCLUDE_DIRS}) + # add_definitions(-DNSIGHT_FOUND) + # #target_link_libraries(${TARGET_NAME} "${NSIGHT_LIBRARIES}") + #endif () + + endif() +endif (APPLE) + +# call macro to link our dependencies and bubble them up via a property on our target +link_shared_dependencies() diff --git a/interface/src/renderer/TextureCache.cpp b/libraries/render-utils/src/TextureCache.cpp similarity index 100% rename from interface/src/renderer/TextureCache.cpp rename to libraries/render-utils/src/TextureCache.cpp diff --git a/interface/src/renderer/TextureCache.h b/libraries/render-utils/src/TextureCache.h similarity index 100% rename from interface/src/renderer/TextureCache.h rename to libraries/render-utils/src/TextureCache.h From ea6d6e9f7265048ec21376215869f87e11a71ddd Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 15 Dec 2014 13:26:27 -0800 Subject: [PATCH 07/46] windows build hackery --- interface/src/ui/UpdateDialog.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/interface/src/ui/UpdateDialog.cpp b/interface/src/ui/UpdateDialog.cpp index bd02ca910a..4c75a10f1d 100644 --- a/interface/src/ui/UpdateDialog.cpp +++ b/interface/src/ui/UpdateDialog.cpp @@ -8,6 +8,8 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include + #include #include "ui_updateDialog.h" From dee8f69722587765f505965cb050b0ad8ee2f93b Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 15 Dec 2014 13:33:47 -0800 Subject: [PATCH 08/46] windows build hackery --- interface/src/voxels/VoxelSystem.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/interface/src/voxels/VoxelSystem.cpp b/interface/src/voxels/VoxelSystem.cpp index 357bfe9c3e..61ec4d6e6c 100644 --- a/interface/src/voxels/VoxelSystem.cpp +++ b/interface/src/voxels/VoxelSystem.cpp @@ -14,6 +14,8 @@ #include // to load voxels from file #include // to load voxels from file +#include + #include #include #include @@ -23,7 +25,6 @@ #include #include "Application.h" -#include "InterfaceConfig.h" #include "Menu.h" #include "renderer/ProgramObject.h" #include "VoxelConstants.h" From 49cacd85bd3abdce2524027ad83382bfbc110bff Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 15 Dec 2014 14:00:41 -0800 Subject: [PATCH 09/46] move GeometryCache to library --- interface/src/Application.h | 2 +- interface/src/renderer/Model.h | 4 ++-- libraries/render-utils/CMakeLists.txt | 2 +- .../renderer => libraries/render-utils/src}/GeometryCache.cpp | 2 +- .../renderer => libraries/render-utils/src}/GeometryCache.h | 0 5 files changed, 5 insertions(+), 5 deletions(-) rename {interface/src/renderer => libraries/render-utils/src}/GeometryCache.cpp (99%) rename {interface/src/renderer => libraries/render-utils/src}/GeometryCache.h (100%) diff --git a/interface/src/Application.h b/interface/src/Application.h index 5a693ac21e..64ef0970d7 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -34,6 +34,7 @@ #include #include +#include #include #include #include @@ -62,7 +63,6 @@ #include "entities/EntityTreeRenderer.h" #include "renderer/AmbientOcclusionEffect.h" #include "renderer/DeferredLightingEffect.h" -#include "renderer/GeometryCache.h" #include "renderer/GlowEffect.h" #include "scripting/ControllerScriptingInterface.h" #include "ui/BandwidthDialog.h" diff --git a/interface/src/renderer/Model.h b/interface/src/renderer/Model.h index 334730b23b..c061bd85ac 100644 --- a/interface/src/renderer/Model.h +++ b/interface/src/renderer/Model.h @@ -16,16 +16,16 @@ #include #include -#include "Transform.h" #include #include #include +#include #include #include #include +#include #include "AnimationHandle.h" -#include "GeometryCache.h" #include "InterfaceConfig.h" #include "JointState.h" #include "ProgramObject.h" diff --git a/libraries/render-utils/CMakeLists.txt b/libraries/render-utils/CMakeLists.txt index dea83a12a4..bde26ea5ca 100644 --- a/libraries/render-utils/CMakeLists.txt +++ b/libraries/render-utils/CMakeLists.txt @@ -1,7 +1,7 @@ set(TARGET_NAME render-utils) # use setup_hifi_library macro to setup our project and link appropriate Qt modules -setup_hifi_library(Widgets OpenGL Network) +setup_hifi_library(Widgets OpenGL Network Script) include_glm() diff --git a/interface/src/renderer/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp similarity index 99% rename from interface/src/renderer/GeometryCache.cpp rename to libraries/render-utils/src/GeometryCache.cpp index 4eae148259..54239f1678 100644 --- a/interface/src/renderer/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -19,8 +19,8 @@ #include #include -#include +#include "TextureCache.h" #include "GeometryCache.h" GeometryCache::GeometryCache() { diff --git a/interface/src/renderer/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h similarity index 100% rename from interface/src/renderer/GeometryCache.h rename to libraries/render-utils/src/GeometryCache.h From df7e115556357717cf449fa37a91c97df54fb059 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 15 Dec 2014 14:21:22 -0800 Subject: [PATCH 10/46] move ProgramObject to libraries --- interface/src/Application.cpp | 2 +- interface/src/Environment.cpp | 2 +- interface/src/MetavoxelSystem.h | 3 +-- interface/src/avatar/Hand.cpp | 2 +- interface/src/devices/OculusManager.h | 3 ++- interface/src/renderer/AmbientOcclusionEffect.cpp | 2 +- interface/src/renderer/DeferredLightingEffect.h | 3 +-- interface/src/renderer/GlowEffect.cpp | 2 +- interface/src/renderer/Model.h | 2 +- interface/src/starfield/Config.h | 3 ++- interface/src/ui/MetavoxelEditor.h | 3 ++- interface/src/ui/overlays/Grid3DOverlay.h | 4 ++-- interface/src/voxels/VoxelSystem.cpp | 2 +- .../renderer => libraries/render-utils/src}/ProgramObject.cpp | 3 ++- .../renderer => libraries/render-utils/src}/ProgramObject.h | 0 15 files changed, 19 insertions(+), 17 deletions(-) rename {interface/src/renderer => libraries/render-utils/src}/ProgramObject.cpp (99%) rename {interface/src/renderer => libraries/render-utils/src}/ProgramObject.h (100%) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 766424ef4b..990f05d0de 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -66,6 +66,7 @@ #include #include #include +#include #include #include #include @@ -85,7 +86,6 @@ #include "devices/TV3DManager.h" #include "devices/Visage.h" -#include "renderer/ProgramObject.h" #include "gpu/Batch.h" #include "gpu/GLBackend.h" diff --git a/interface/src/Environment.cpp b/interface/src/Environment.cpp index fa8f18ac3f..c482095494 100644 --- a/interface/src/Environment.cpp +++ b/interface/src/Environment.cpp @@ -17,11 +17,11 @@ #include #include +#include #include #include "Application.h" #include "Camera.h" -#include "renderer/ProgramObject.h" #include "world.h" #include "Environment.h" diff --git a/interface/src/MetavoxelSystem.h b/interface/src/MetavoxelSystem.h index 0c0f9b49b7..a21cd2c1a4 100644 --- a/interface/src/MetavoxelSystem.h +++ b/interface/src/MetavoxelSystem.h @@ -20,10 +20,9 @@ #include #include +#include #include -#include "renderer/ProgramObject.h" - class HeightfieldBaseLayerBatch; class HeightfieldSplatBatch; class HermiteBatch; diff --git a/interface/src/avatar/Hand.cpp b/interface/src/avatar/Hand.cpp index 9d1ee52fde..9d7626266d 100644 --- a/interface/src/avatar/Hand.cpp +++ b/interface/src/avatar/Hand.cpp @@ -13,13 +13,13 @@ #include #include +#include #include "Application.h" #include "Avatar.h" #include "Hand.h" #include "Menu.h" #include "Util.h" -#include "renderer/ProgramObject.h" using namespace std; diff --git a/interface/src/devices/OculusManager.h b/interface/src/devices/OculusManager.h index 2e0354f61a..d9700d9530 100644 --- a/interface/src/devices/OculusManager.h +++ b/interface/src/devices/OculusManager.h @@ -17,7 +17,8 @@ #include #endif -#include "renderer/ProgramObject.h" +#include + #include "ui/overlays/Text3DOverlay.h" const float DEFAULT_OCULUS_UI_ANGULAR_SIZE = 72.0f; diff --git a/interface/src/renderer/AmbientOcclusionEffect.cpp b/interface/src/renderer/AmbientOcclusionEffect.cpp index 3354f715cb..415b850abd 100644 --- a/interface/src/renderer/AmbientOcclusionEffect.cpp +++ b/interface/src/renderer/AmbientOcclusionEffect.cpp @@ -16,10 +16,10 @@ #include +#include #include #include "Application.h" -#include "ProgramObject.h" #include "RenderUtil.h" #include "AmbientOcclusionEffect.h" diff --git a/interface/src/renderer/DeferredLightingEffect.h b/interface/src/renderer/DeferredLightingEffect.h index ce8b2b9759..effcea27d2 100644 --- a/interface/src/renderer/DeferredLightingEffect.h +++ b/interface/src/renderer/DeferredLightingEffect.h @@ -14,10 +14,9 @@ #include +#include #include -#include "ProgramObject.h" - class PostLightingRenderable; /// Handles deferred lighting for the bits that require it (voxels, metavoxels...) diff --git a/interface/src/renderer/GlowEffect.cpp b/interface/src/renderer/GlowEffect.cpp index b6896eeaad..77d002dc89 100644 --- a/interface/src/renderer/GlowEffect.cpp +++ b/interface/src/renderer/GlowEffect.cpp @@ -15,10 +15,10 @@ #include #include +#include #include "Application.h" #include "GlowEffect.h" -#include "ProgramObject.h" #include "RenderUtil.h" GlowEffect::GlowEffect() diff --git a/interface/src/renderer/Model.h b/interface/src/renderer/Model.h index c061bd85ac..1f0a571872 100644 --- a/interface/src/renderer/Model.h +++ b/interface/src/renderer/Model.h @@ -22,13 +22,13 @@ #include #include #include +#include #include #include #include "AnimationHandle.h" #include "InterfaceConfig.h" #include "JointState.h" -#include "ProgramObject.h" class QScriptEngine; diff --git a/interface/src/starfield/Config.h b/interface/src/starfield/Config.h index 7777c5207b..00f827dad7 100644 --- a/interface/src/starfield/Config.h +++ b/interface/src/starfield/Config.h @@ -13,7 +13,6 @@ #define hifi_Config_h #include "InterfaceConfig.h" -#include "renderer/ProgramObject.h" #include #include @@ -35,6 +34,8 @@ #include #include +#include + #include "AngleUtil.h" #include "Radix2InplaceSort.h" #include "Radix2IntegerScanner.h" diff --git a/interface/src/ui/MetavoxelEditor.h b/interface/src/ui/MetavoxelEditor.h index c154d7bc59..391b01270a 100644 --- a/interface/src/ui/MetavoxelEditor.h +++ b/interface/src/ui/MetavoxelEditor.h @@ -15,8 +15,9 @@ #include #include +#include + #include "MetavoxelSystem.h" -#include "renderer/ProgramObject.h" class QColorEditor; class QComboBox; diff --git a/interface/src/ui/overlays/Grid3DOverlay.h b/interface/src/ui/overlays/Grid3DOverlay.h index b162ff3d74..d6c85a10ee 100644 --- a/interface/src/ui/overlays/Grid3DOverlay.h +++ b/interface/src/ui/overlays/Grid3DOverlay.h @@ -18,12 +18,12 @@ #include #include + +#include #include #include "Base3DOverlay.h" -#include "renderer/ProgramObject.h" - class Grid3DOverlay : public Base3DOverlay { Q_OBJECT diff --git a/interface/src/voxels/VoxelSystem.cpp b/interface/src/voxels/VoxelSystem.cpp index 61ec4d6e6c..064cead160 100644 --- a/interface/src/voxels/VoxelSystem.cpp +++ b/interface/src/voxels/VoxelSystem.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -26,7 +27,6 @@ #include "Application.h" #include "Menu.h" -#include "renderer/ProgramObject.h" #include "VoxelConstants.h" #include "VoxelSystem.h" diff --git a/interface/src/renderer/ProgramObject.cpp b/libraries/render-utils/src/ProgramObject.cpp similarity index 99% rename from interface/src/renderer/ProgramObject.cpp rename to libraries/render-utils/src/ProgramObject.cpp index ff2b1cc11e..56fd48bff7 100644 --- a/interface/src/renderer/ProgramObject.cpp +++ b/libraries/render-utils/src/ProgramObject.cpp @@ -9,9 +9,10 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include "ProgramObject.h" #include +#include "ProgramObject.h" + ProgramObject::ProgramObject(QObject* parent) : QGLShaderProgram(parent) { } diff --git a/interface/src/renderer/ProgramObject.h b/libraries/render-utils/src/ProgramObject.h similarity index 100% rename from interface/src/renderer/ProgramObject.h rename to libraries/render-utils/src/ProgramObject.h From f802e99a24c89c34a5003caf7c90625019adff59 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 15 Dec 2014 14:32:33 -0800 Subject: [PATCH 11/46] windows build hackery --- interface/src/renderer/Model.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/interface/src/renderer/Model.h b/interface/src/renderer/Model.h index 1f0a571872..c79a6c2efd 100644 --- a/interface/src/renderer/Model.h +++ b/interface/src/renderer/Model.h @@ -12,6 +12,8 @@ #ifndef hifi_Model_h #define hifi_Model_h +#include + #include #include #include @@ -27,7 +29,6 @@ #include #include "AnimationHandle.h" -#include "InterfaceConfig.h" #include "JointState.h" class QScriptEngine; From bc78beb05fcea9ce536a0fabc5c88078cbb12439 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 15 Dec 2014 14:41:15 -0800 Subject: [PATCH 12/46] windows build hackery --- interface/src/avatar/ModelReferential.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/interface/src/avatar/ModelReferential.cpp b/interface/src/avatar/ModelReferential.cpp index df6e272da7..d37879c6e1 100644 --- a/interface/src/avatar/ModelReferential.cpp +++ b/interface/src/avatar/ModelReferential.cpp @@ -9,6 +9,8 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include // hack to get windows to build + #include #include From 0c14b0f8fc9acfbc6ce68a139b149d9f6dbd8f1b Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 15 Dec 2014 14:47:26 -0800 Subject: [PATCH 13/46] windows build hackery --- interface/src/avatar/Hand.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/interface/src/avatar/Hand.cpp b/interface/src/avatar/Hand.cpp index 9d7626266d..91d59ae2fa 100644 --- a/interface/src/avatar/Hand.cpp +++ b/interface/src/avatar/Hand.cpp @@ -8,6 +8,8 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include // hack to get windows to build + #include #include From 753dc07cdd61039ad2d87ef78002d95e9f3b605a Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 15 Dec 2014 14:58:47 -0800 Subject: [PATCH 14/46] cleanup windows hackery --- interface/src/avatar/ModelReferential.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/interface/src/avatar/ModelReferential.cpp b/interface/src/avatar/ModelReferential.cpp index d37879c6e1..df6e272da7 100644 --- a/interface/src/avatar/ModelReferential.cpp +++ b/interface/src/avatar/ModelReferential.cpp @@ -9,8 +9,6 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include // hack to get windows to build - #include #include From bfcc78c57d7fa4a9c19f514c079e5b05bcda6f06 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 15 Dec 2014 15:20:18 -0800 Subject: [PATCH 15/46] replaced Application::resourcesPath() with PathUtils::resourcesPath() --- interface/src/Application.cpp | 16 ++--- interface/src/Application.h | 1 - interface/src/Audio.cpp | 7 +- interface/src/Environment.cpp | 3 +- interface/src/Menu.cpp | 3 +- interface/src/MetavoxelSystem.cpp | 21 +++--- interface/src/avatar/Avatar.cpp | 5 +- interface/src/devices/OculusManager.cpp | 5 +- interface/src/devices/Visage.cpp | 7 +- .../src/renderer/AmbientOcclusionEffect.cpp | 9 +-- .../src/renderer/DeferredLightingEffect.cpp | 10 +-- interface/src/renderer/GlowEffect.cpp | 3 +- interface/src/renderer/Model.cpp | 65 ++++++++++--------- interface/src/ui/AddressBarDialog.cpp | 10 +-- interface/src/ui/ApplicationOverlay.cpp | 6 +- interface/src/ui/ChatWindow.cpp | 7 +- interface/src/ui/FramelessDialog.cpp | 8 ++- interface/src/ui/InfoView.cpp | 9 ++- interface/src/ui/JSConsole.cpp | 9 +-- interface/src/ui/LogDialog.cpp | 6 +- interface/src/ui/LoginDialog.cpp | 7 +- interface/src/ui/MetavoxelEditor.cpp | 3 +- interface/src/ui/RearMirrorTools.cpp | 11 ++-- interface/src/ui/RunningScriptsWidget.cpp | 4 +- interface/src/ui/VoxelImportDialog.cpp | 22 ++++--- interface/src/ui/overlays/Grid3DOverlay.cpp | 5 +- interface/src/voxels/VoxelSystem.cpp | 9 +-- libraries/shared/src/PathUtils.cpp | 25 +++++++ libraries/shared/src/PathUtils.h | 22 +++++++ 29 files changed, 194 insertions(+), 124 deletions(-) create mode 100644 libraries/shared/src/PathUtils.cpp create mode 100644 libraries/shared/src/PathUtils.h diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 990f05d0de..76247d1d9d 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -65,6 +65,7 @@ #include #include #include +#include #include #include #include @@ -133,15 +134,6 @@ void messageHandler(QtMsgType type, const QMessageLogContext& context, const QSt } } -QString& Application::resourcesPath() { -#ifdef Q_OS_MAC - static QString staticResourcePath = QCoreApplication::applicationDirPath() + "/../Resources/"; -#else - static QString staticResourcePath = QCoreApplication::applicationDirPath() + "/resources/"; -#endif - return staticResourcePath; -} - Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : QApplication(argc, argv), _window(new MainWindow(desktop())), @@ -195,7 +187,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : _aboutToQuit(false) { // read the ApplicationInfo.ini file for Name/Version/Domain information - QSettings applicationInfo(Application::resourcesPath() + "info/ApplicationInfo.ini", QSettings::IniFormat); + QSettings applicationInfo(PathUtils::resourcesPath() + "info/ApplicationInfo.ini", QSettings::IniFormat); // set the associated application properties applicationInfo.beginGroup("INFO"); @@ -213,7 +205,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : _applicationStartupTime = startup_time; - QFontDatabase::addApplicationFont(Application::resourcesPath() + "styles/Inconsolata.otf"); + QFontDatabase::addApplicationFont(PathUtils::resourcesPath() + "styles/Inconsolata.otf"); _window->setWindowTitle("Interface"); qInstallMessageHandler(messageHandler); @@ -4369,7 +4361,7 @@ void Application::skipVersion(QString latestVersion) { void Application::takeSnapshot() { QMediaPlayer* player = new QMediaPlayer(); - QFileInfo inf = QFileInfo(Application::resourcesPath() + "sounds/snap.wav"); + QFileInfo inf = QFileInfo(PathUtils::resourcesPath() + "sounds/snap.wav"); player->setMedia(QUrl::fromLocalFile(inf.absoluteFilePath())); player->play(); diff --git a/interface/src/Application.h b/interface/src/Application.h index 64ef0970d7..0e1feafb7e 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -138,7 +138,6 @@ class Application : public QApplication { public: static Application* getInstance() { return static_cast(QCoreApplication::instance()); } - static QString& resourcesPath(); static const glm::vec3& getPositionForPath() { return getInstance()->_myAvatar->getPosition(); } static glm::quat getOrientationForPath() { return getInstance()->_myAvatar->getOrientation(); } diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index 101d16d3ba..74ee9736a7 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -140,9 +141,9 @@ Audio::Audio(QObject* parent) : } void Audio::init(QGLWidget *parent) { - _micTextureId = parent->bindTexture(QImage(Application::resourcesPath() + "images/mic.svg")); - _muteTextureId = parent->bindTexture(QImage(Application::resourcesPath() + "images/mic-mute.svg")); - _boxTextureId = parent->bindTexture(QImage(Application::resourcesPath() + "images/audio-box.svg")); + _micTextureId = parent->bindTexture(QImage(PathUtils::resourcesPath() + "images/mic.svg")); + _muteTextureId = parent->bindTexture(QImage(PathUtils::resourcesPath() + "images/mic-mute.svg")); + _boxTextureId = parent->bindTexture(QImage(PathUtils::resourcesPath() + "images/audio-box.svg")); } void Audio::reset() { diff --git a/interface/src/Environment.cpp b/interface/src/Environment.cpp index c482095494..1fd3c7a73c 100644 --- a/interface/src/Environment.cpp +++ b/interface/src/Environment.cpp @@ -17,6 +17,7 @@ #include #include +#include #include #include @@ -188,7 +189,7 @@ int Environment::parseData(const HifiSockAddr& senderAddress, const QByteArray& ProgramObject* Environment::createSkyProgram(const char* from, int* locations) { ProgramObject* program = new ProgramObject(); - QByteArray prefix = QString(Application::resourcesPath() + "/shaders/SkyFrom" + from).toUtf8(); + QByteArray prefix = QString(PathUtils::resourcesPath() + "/shaders/SkyFrom" + from).toUtf8(); program->addShaderFromSourceFile(QGLShader::Vertex, prefix + ".vert"); program->addShaderFromSourceFile(QGLShader::Fragment, prefix + ".frag"); program->link(); diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 6c2c3966fc..fbb23504b0 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -246,7 +247,7 @@ Menu::Menu() : connect(&xmppClient, &QXmppClient::connected, this, &Menu::toggleChat); connect(&xmppClient, &QXmppClient::disconnected, this, &Menu::toggleChat); - QDir::setCurrent(Application::resourcesPath()); + QDir::setCurrent(PathUtils::resourcesPath()); // init chat window to listen chat _chatWindow = new ChatWindow(Application::getInstance()->getWindow()); #endif diff --git a/interface/src/MetavoxelSystem.cpp b/interface/src/MetavoxelSystem.cpp index 84ccf0f406..372c5214f7 100644 --- a/interface/src/MetavoxelSystem.cpp +++ b/interface/src/MetavoxelSystem.cpp @@ -26,6 +26,7 @@ #include #include +#include #include #include "Application.h" @@ -63,9 +64,9 @@ void MetavoxelSystem::init() { _voxelBufferAttribute->setLODThresholdMultiplier( AttributeRegistry::getInstance()->getVoxelColorAttribute()->getLODThresholdMultiplier()); - _baseHeightfieldProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + + _baseHeightfieldProgram.addShaderFromSourceFile(QGLShader::Vertex, PathUtils::resourcesPath() + "shaders/metavoxel_heightfield_base.vert"); - _baseHeightfieldProgram.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + + _baseHeightfieldProgram.addShaderFromSourceFile(QGLShader::Fragment, PathUtils::resourcesPath() + "shaders/metavoxel_heightfield_base.frag"); _baseHeightfieldProgram.link(); @@ -78,9 +79,9 @@ void MetavoxelSystem::init() { loadSplatProgram("heightfield", _splatHeightfieldProgram, _splatHeightfieldLocations); - _heightfieldCursorProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + + _heightfieldCursorProgram.addShaderFromSourceFile(QGLShader::Vertex, PathUtils::resourcesPath() + "shaders/metavoxel_heightfield_cursor.vert"); - _heightfieldCursorProgram.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + + _heightfieldCursorProgram.addShaderFromSourceFile(QGLShader::Fragment, PathUtils::resourcesPath() + "shaders/metavoxel_cursor.frag"); _heightfieldCursorProgram.link(); @@ -88,17 +89,17 @@ void MetavoxelSystem::init() { _heightfieldCursorProgram.setUniformValue("heightMap", 0); _heightfieldCursorProgram.release(); - _baseVoxelProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + + _baseVoxelProgram.addShaderFromSourceFile(QGLShader::Vertex, PathUtils::resourcesPath() + "shaders/metavoxel_voxel_base.vert"); - _baseVoxelProgram.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + + _baseVoxelProgram.addShaderFromSourceFile(QGLShader::Fragment, PathUtils::resourcesPath() + "shaders/metavoxel_voxel_base.frag"); _baseVoxelProgram.link(); loadSplatProgram("voxel", _splatVoxelProgram, _splatVoxelLocations); - _voxelCursorProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + + _voxelCursorProgram.addShaderFromSourceFile(QGLShader::Vertex, PathUtils::resourcesPath() + "shaders/metavoxel_voxel_cursor.vert"); - _voxelCursorProgram.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + + _voxelCursorProgram.addShaderFromSourceFile(QGLShader::Fragment, PathUtils::resourcesPath() + "shaders/metavoxel_cursor.frag"); _voxelCursorProgram.link(); } @@ -836,9 +837,9 @@ void MetavoxelSystem::guideToAugmented(MetavoxelVisitor& visitor, bool render) { } void MetavoxelSystem::loadSplatProgram(const char* type, ProgramObject& program, SplatLocations& locations) { - program.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + + program.addShaderFromSourceFile(QGLShader::Vertex, PathUtils::resourcesPath() + "shaders/metavoxel_" + type + "_splat.vert"); - program.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + + program.addShaderFromSourceFile(QGLShader::Fragment, PathUtils::resourcesPath() + "shaders/metavoxel_" + type + "_splat.frag"); program.link(); diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 39fc522852..e0896364f6 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -915,13 +916,13 @@ void Avatar::scaleVectorRelativeToPosition(glm::vec3 &positionToScale) const { void Avatar::setFaceModelURL(const QUrl& faceModelURL) { AvatarData::setFaceModelURL(faceModelURL); - const QUrl DEFAULT_FACE_MODEL_URL = QUrl::fromLocalFile(Application::resourcesPath() + "meshes/defaultAvatar_head.fst"); + const QUrl DEFAULT_FACE_MODEL_URL = QUrl::fromLocalFile(PathUtils::resourcesPath() + "meshes/defaultAvatar_head.fst"); getHead()->getFaceModel().setURL(_faceModelURL, DEFAULT_FACE_MODEL_URL, true, !isMyAvatar()); } void Avatar::setSkeletonModelURL(const QUrl& skeletonModelURL) { AvatarData::setSkeletonModelURL(skeletonModelURL); - const QUrl DEFAULT_SKELETON_MODEL_URL = QUrl::fromLocalFile(Application::resourcesPath() + "meshes/defaultAvatar_body.fst"); + const QUrl DEFAULT_SKELETON_MODEL_URL = QUrl::fromLocalFile(PathUtils::resourcesPath() + "meshes/defaultAvatar_body.fst"); _skeletonModel.setURL(_skeletonModelURL, DEFAULT_SKELETON_MODEL_URL, true, !isMyAvatar()); } diff --git a/interface/src/devices/OculusManager.cpp b/interface/src/devices/OculusManager.cpp index d27ab09876..7f5c2cd668 100644 --- a/interface/src/devices/OculusManager.cpp +++ b/interface/src/devices/OculusManager.cpp @@ -21,6 +21,7 @@ #include +#include #include #include @@ -136,8 +137,8 @@ void OculusManager::connect() { if (!_programInitialized) { // Shader program _programInitialized = true; - _program.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + "shaders/oculus.vert"); - _program.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + "shaders/oculus.frag"); + _program.addShaderFromSourceFile(QGLShader::Vertex, PathUtils::resourcesPath() + "shaders/oculus.vert"); + _program.addShaderFromSourceFile(QGLShader::Fragment, PathUtils::resourcesPath() + "shaders/oculus.frag"); _program.link(); // Uniforms diff --git a/interface/src/devices/Visage.cpp b/interface/src/devices/Visage.cpp index 51b927df75..189ad90e12 100644 --- a/interface/src/devices/Visage.cpp +++ b/interface/src/devices/Visage.cpp @@ -14,6 +14,7 @@ #include #include +#include #include #include @@ -45,12 +46,12 @@ Visage::Visage() : #ifdef HAVE_VISAGE #ifdef WIN32 - QByteArray licensePath = Application::resourcesPath().toLatin1() + "visage"; + QByteArray licensePath = PathUtils::resourcesPath().toLatin1() + "visage"; #else - QByteArray licensePath = Application::resourcesPath().toLatin1() + "visage/license.vlc"; + QByteArray licensePath = PathUtils::resourcesPath().toLatin1() + "visage/license.vlc"; #endif initializeLicenseManager(licensePath.data()); - _tracker = new VisageTracker2(Application::resourcesPath().toLatin1() + "visage/tracker.cfg"); + _tracker = new VisageTracker2(PathUtils::resourcesPath().toLatin1() + "visage/tracker.cfg"); _data = new FaceData(); #endif } diff --git a/interface/src/renderer/AmbientOcclusionEffect.cpp b/interface/src/renderer/AmbientOcclusionEffect.cpp index 415b850abd..08ad6703e6 100644 --- a/interface/src/renderer/AmbientOcclusionEffect.cpp +++ b/interface/src/renderer/AmbientOcclusionEffect.cpp @@ -16,6 +16,7 @@ #include +#include #include #include @@ -30,9 +31,9 @@ const int ROTATION_HEIGHT = 4; void AmbientOcclusionEffect::init() { _occlusionProgram = new ProgramObject(); - _occlusionProgram->addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + _occlusionProgram->addShaderFromSourceFile(QGLShader::Vertex, PathUtils::resourcesPath() + "shaders/ambient_occlusion.vert"); - _occlusionProgram->addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + _occlusionProgram->addShaderFromSourceFile(QGLShader::Fragment, PathUtils::resourcesPath() + "shaders/ambient_occlusion.frag"); _occlusionProgram->link(); @@ -82,8 +83,8 @@ void AmbientOcclusionEffect::init() { glBindTexture(GL_TEXTURE_2D, 0); _blurProgram = new ProgramObject(); - _blurProgram->addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + "shaders/ambient_occlusion.vert"); - _blurProgram->addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + "shaders/occlusion_blur.frag"); + _blurProgram->addShaderFromSourceFile(QGLShader::Vertex, PathUtils::resourcesPath() + "shaders/ambient_occlusion.vert"); + _blurProgram->addShaderFromSourceFile(QGLShader::Fragment, PathUtils::resourcesPath() + "shaders/occlusion_blur.frag"); _blurProgram->link(); _blurProgram->bind(); diff --git a/interface/src/renderer/DeferredLightingEffect.cpp b/interface/src/renderer/DeferredLightingEffect.cpp index 22ac5d82b6..79b89d03f9 100644 --- a/interface/src/renderer/DeferredLightingEffect.cpp +++ b/interface/src/renderer/DeferredLightingEffect.cpp @@ -14,13 +14,15 @@ #include +#include + #include "Application.h" #include "DeferredLightingEffect.h" #include "RenderUtil.h" void DeferredLightingEffect::init() { - _simpleProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + "shaders/simple.vert"); - _simpleProgram.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + "shaders/simple.frag"); + _simpleProgram.addShaderFromSourceFile(QGLShader::Vertex, PathUtils::resourcesPath() + "shaders/simple.vert"); + _simpleProgram.addShaderFromSourceFile(QGLShader::Fragment, PathUtils::resourcesPath() + "shaders/simple.frag"); _simpleProgram.link(); _simpleProgram.bind(); @@ -394,9 +396,9 @@ void DeferredLightingEffect::render() { } void DeferredLightingEffect::loadLightProgram(const char* name, bool limited, ProgramObject& program, LightLocations& locations) { - program.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + + program.addShaderFromSourceFile(QGLShader::Vertex, PathUtils::resourcesPath() + (limited ? "shaders/deferred_light_limited.vert" : "shaders/deferred_light.vert")); - program.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + name); + program.addShaderFromSourceFile(QGLShader::Fragment, PathUtils::resourcesPath() + name); program.link(); program.bind(); diff --git a/interface/src/renderer/GlowEffect.cpp b/interface/src/renderer/GlowEffect.cpp index 77d002dc89..a53c9f878b 100644 --- a/interface/src/renderer/GlowEffect.cpp +++ b/interface/src/renderer/GlowEffect.cpp @@ -14,6 +14,7 @@ #include +#include #include #include @@ -47,7 +48,7 @@ QOpenGLFramebufferObject* GlowEffect::getFreeFramebufferObject() const { static ProgramObject* createProgram(const QString& name) { ProgramObject* program = new ProgramObject(); - program->addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + "shaders/" + name + ".frag"); + program->addShaderFromSourceFile(QGLShader::Fragment, PathUtils::resourcesPath() + "shaders/" + name + ".frag"); program->link(); program->bind(); diff --git a/interface/src/renderer/Model.cpp b/interface/src/renderer/Model.cpp index 2a6988a984..71f0fb24f3 100644 --- a/interface/src/renderer/Model.cpp +++ b/interface/src/renderer/Model.cpp @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -222,109 +223,109 @@ void Model::initJointTransforms() { void Model::init() { if (!_program.isLinked()) { - _program.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + "shaders/model.vert"); - _program.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + "shaders/model.frag"); + _program.addShaderFromSourceFile(QGLShader::Vertex, PathUtils::resourcesPath() + "shaders/model.vert"); + _program.addShaderFromSourceFile(QGLShader::Fragment, PathUtils::resourcesPath() + "shaders/model.frag"); initProgram(_program, _locations); _normalMapProgram.addShaderFromSourceFile(QGLShader::Vertex, - Application::resourcesPath() + "shaders/model_normal_map.vert"); + PathUtils::resourcesPath() + "shaders/model_normal_map.vert"); _normalMapProgram.addShaderFromSourceFile(QGLShader::Fragment, - Application::resourcesPath() + "shaders/model_normal_map.frag"); + PathUtils::resourcesPath() + "shaders/model_normal_map.frag"); initProgram(_normalMapProgram, _normalMapLocations); _specularMapProgram.addShaderFromSourceFile(QGLShader::Vertex, - Application::resourcesPath() + "shaders/model.vert"); + PathUtils::resourcesPath() + "shaders/model.vert"); _specularMapProgram.addShaderFromSourceFile(QGLShader::Fragment, - Application::resourcesPath() + "shaders/model_specular_map.frag"); + PathUtils::resourcesPath() + "shaders/model_specular_map.frag"); initProgram(_specularMapProgram, _specularMapLocations); _normalSpecularMapProgram.addShaderFromSourceFile(QGLShader::Vertex, - Application::resourcesPath() + "shaders/model_normal_map.vert"); + PathUtils::resourcesPath() + "shaders/model_normal_map.vert"); _normalSpecularMapProgram.addShaderFromSourceFile(QGLShader::Fragment, - Application::resourcesPath() + "shaders/model_normal_specular_map.frag"); + PathUtils::resourcesPath() + "shaders/model_normal_specular_map.frag"); initProgram(_normalSpecularMapProgram, _normalSpecularMapLocations); _translucentProgram.addShaderFromSourceFile(QGLShader::Vertex, - Application::resourcesPath() + "shaders/model.vert"); + PathUtils::resourcesPath() + "shaders/model.vert"); _translucentProgram.addShaderFromSourceFile(QGLShader::Fragment, - Application::resourcesPath() + "shaders/model_translucent.frag"); + PathUtils::resourcesPath() + "shaders/model_translucent.frag"); initProgram(_translucentProgram, _translucentLocations); // Lightmap - _lightmapProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + "shaders/model_lightmap.vert"); - _lightmapProgram.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + "shaders/model_lightmap.frag"); + _lightmapProgram.addShaderFromSourceFile(QGLShader::Vertex, PathUtils::resourcesPath() + "shaders/model_lightmap.vert"); + _lightmapProgram.addShaderFromSourceFile(QGLShader::Fragment, PathUtils::resourcesPath() + "shaders/model_lightmap.frag"); initProgram(_lightmapProgram, _lightmapLocations); _lightmapNormalMapProgram.addShaderFromSourceFile(QGLShader::Vertex, - Application::resourcesPath() + "shaders/model_lightmap_normal_map.vert"); + PathUtils::resourcesPath() + "shaders/model_lightmap_normal_map.vert"); _lightmapNormalMapProgram.addShaderFromSourceFile(QGLShader::Fragment, - Application::resourcesPath() + "shaders/model_lightmap_normal_map.frag"); + PathUtils::resourcesPath() + "shaders/model_lightmap_normal_map.frag"); initProgram(_lightmapNormalMapProgram, _lightmapNormalMapLocations); _lightmapSpecularMapProgram.addShaderFromSourceFile(QGLShader::Vertex, - Application::resourcesPath() + "shaders/model_lightmap.vert"); + PathUtils::resourcesPath() + "shaders/model_lightmap.vert"); _lightmapSpecularMapProgram.addShaderFromSourceFile(QGLShader::Fragment, - Application::resourcesPath() + "shaders/model_lightmap_specular_map.frag"); + PathUtils::resourcesPath() + "shaders/model_lightmap_specular_map.frag"); initProgram(_lightmapSpecularMapProgram, _lightmapSpecularMapLocations); _lightmapNormalSpecularMapProgram.addShaderFromSourceFile(QGLShader::Vertex, - Application::resourcesPath() + "shaders/model_lightmap_normal_map.vert"); + PathUtils::resourcesPath() + "shaders/model_lightmap_normal_map.vert"); _lightmapNormalSpecularMapProgram.addShaderFromSourceFile(QGLShader::Fragment, - Application::resourcesPath() + "shaders/model_lightmap_normal_specular_map.frag"); + PathUtils::resourcesPath() + "shaders/model_lightmap_normal_specular_map.frag"); initProgram(_lightmapNormalSpecularMapProgram, _lightmapNormalSpecularMapLocations); // end lightmap - _shadowProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + "shaders/model_shadow.vert"); + _shadowProgram.addShaderFromSourceFile(QGLShader::Vertex, PathUtils::resourcesPath() + "shaders/model_shadow.vert"); _shadowProgram.addShaderFromSourceFile(QGLShader::Fragment, - Application::resourcesPath() + "shaders/model_shadow.frag"); + PathUtils::resourcesPath() + "shaders/model_shadow.frag"); - _skinProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + "shaders/skin_model.vert"); - _skinProgram.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + "shaders/model.frag"); + _skinProgram.addShaderFromSourceFile(QGLShader::Vertex, PathUtils::resourcesPath() + "shaders/skin_model.vert"); + _skinProgram.addShaderFromSourceFile(QGLShader::Fragment, PathUtils::resourcesPath() + "shaders/model.frag"); initSkinProgram(_skinProgram, _skinLocations); _skinNormalMapProgram.addShaderFromSourceFile(QGLShader::Vertex, - Application::resourcesPath() + "shaders/skin_model_normal_map.vert"); + PathUtils::resourcesPath() + "shaders/skin_model_normal_map.vert"); _skinNormalMapProgram.addShaderFromSourceFile(QGLShader::Fragment, - Application::resourcesPath() + "shaders/model_normal_map.frag"); + PathUtils::resourcesPath() + "shaders/model_normal_map.frag"); initSkinProgram(_skinNormalMapProgram, _skinNormalMapLocations); _skinSpecularMapProgram.addShaderFromSourceFile(QGLShader::Vertex, - Application::resourcesPath() + "shaders/skin_model.vert"); + PathUtils::resourcesPath() + "shaders/skin_model.vert"); _skinSpecularMapProgram.addShaderFromSourceFile(QGLShader::Fragment, - Application::resourcesPath() + "shaders/model_specular_map.frag"); + PathUtils::resourcesPath() + "shaders/model_specular_map.frag"); initSkinProgram(_skinSpecularMapProgram, _skinSpecularMapLocations); _skinNormalSpecularMapProgram.addShaderFromSourceFile(QGLShader::Vertex, - Application::resourcesPath() + "shaders/skin_model_normal_map.vert"); + PathUtils::resourcesPath() + "shaders/skin_model_normal_map.vert"); _skinNormalSpecularMapProgram.addShaderFromSourceFile(QGLShader::Fragment, - Application::resourcesPath() + "shaders/model_normal_specular_map.frag"); + PathUtils::resourcesPath() + "shaders/model_normal_specular_map.frag"); initSkinProgram(_skinNormalSpecularMapProgram, _skinNormalSpecularMapLocations); _skinShadowProgram.addShaderFromSourceFile(QGLShader::Vertex, - Application::resourcesPath() + "shaders/skin_model_shadow.vert"); + PathUtils::resourcesPath() + "shaders/skin_model_shadow.vert"); _skinShadowProgram.addShaderFromSourceFile(QGLShader::Fragment, - Application::resourcesPath() + "shaders/model_shadow.frag"); + PathUtils::resourcesPath() + "shaders/model_shadow.frag"); initSkinProgram(_skinShadowProgram, _skinShadowLocations); _skinTranslucentProgram.addShaderFromSourceFile(QGLShader::Vertex, - Application::resourcesPath() + "shaders/skin_model.vert"); + PathUtils::resourcesPath() + "shaders/skin_model.vert"); _skinTranslucentProgram.addShaderFromSourceFile(QGLShader::Fragment, - Application::resourcesPath() + "shaders/model_translucent.frag"); + PathUtils::resourcesPath() + "shaders/model_translucent.frag"); initSkinProgram(_skinTranslucentProgram, _skinTranslucentLocations); } diff --git a/interface/src/ui/AddressBarDialog.cpp b/interface/src/ui/AddressBarDialog.cpp index dbc29be71a..32161b018f 100644 --- a/interface/src/ui/AddressBarDialog.cpp +++ b/interface/src/ui/AddressBarDialog.cpp @@ -9,6 +9,8 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include + #include "AddressBarDialog.h" #include "AddressManager.h" #include "Application.h" @@ -82,7 +84,7 @@ void AddressBarDialog::setupUI() { _goButton->setSizePolicy(sizePolicy); _goButton->setMinimumSize(QSize(GO_BUTTON_SIZE, GO_BUTTON_SIZE)); _goButton->setMaximumSize(QSize(GO_BUTTON_SIZE, GO_BUTTON_SIZE)); - _goButton->setIcon(QIcon(Application::resourcesPath() + ADDRESSBAR_GO_BUTTON_ICON)); + _goButton->setIcon(QIcon(PathUtils::resourcesPath() + ADDRESSBAR_GO_BUTTON_ICON)); _goButton->setIconSize(QSize(GO_BUTTON_SIZE, GO_BUTTON_SIZE)); _goButton->setDefault(true); _goButton->setFlat(true); @@ -99,7 +101,7 @@ void AddressBarDialog::setupUI() { _closeButton->setSizePolicy(sizePolicy); _closeButton->setMinimumSize(QSize(CLOSE_BUTTON_SIZE, CLOSE_BUTTON_SIZE)); _closeButton->setMaximumSize(QSize(CLOSE_BUTTON_SIZE, CLOSE_BUTTON_SIZE)); - QIcon icon(Application::resourcesPath() + CLOSE_BUTTON_ICON); + QIcon icon(PathUtils::resourcesPath() + CLOSE_BUTTON_ICON); _closeButton->setIcon(icon); _closeButton->setIconSize(QSize(CLOSE_BUTTON_SIZE, CLOSE_BUTTON_SIZE)); _closeButton->setFlat(true); @@ -112,7 +114,7 @@ void AddressBarDialog::setupUI() { } void AddressBarDialog::showEvent(QShowEvent* event) { - _goButton->setIcon(QIcon(Application::resourcesPath() + ADDRESSBAR_GO_BUTTON_ICON)); + _goButton->setIcon(QIcon(PathUtils::resourcesPath() + ADDRESSBAR_GO_BUTTON_ICON)); _addressLineEdit->setText(QString()); _addressLineEdit->setFocus(); FramelessDialog::showEvent(event); @@ -120,7 +122,7 @@ void AddressBarDialog::showEvent(QShowEvent* event) { void AddressBarDialog::accept() { if (!_addressLineEdit->text().isEmpty()) { - _goButton->setIcon(QIcon(Application::resourcesPath() + ADDRESSBAR_GO_BUTTON_ACTIVE_ICON)); + _goButton->setIcon(QIcon(PathUtils::resourcesPath() + ADDRESSBAR_GO_BUTTON_ACTIVE_ICON)); AddressManager& addressManager = AddressManager::getInstance(); connect(&addressManager, &AddressManager::lookupResultsFinished, this, &QDialog::hide); addressManager.handleLookupString(_addressLineEdit->text()); diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index f4e0c9769d..32fffd3d40 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -12,6 +12,8 @@ #include "InterfaceConfig.h" #include + +#include #include #include "Application.h" @@ -379,7 +381,7 @@ void ApplicationOverlay::displayOverlayTexture3DTV(Camera& whichCamera, float as glEnd(); if (_crosshairTexture == 0) { - _crosshairTexture = Application::getInstance()->getGLWidget()->bindTexture(QImage(Application::resourcesPath() + "images/sixense-reticle.png")); + _crosshairTexture = Application::getInstance()->getGLWidget()->bindTexture(QImage(PathUtils::resourcesPath() + "images/sixense-reticle.png")); } //draw the mouse pointer @@ -513,7 +515,7 @@ void ApplicationOverlay::renderPointers() { //lazily load crosshair texture if (_crosshairTexture == 0) { - _crosshairTexture = Application::getInstance()->getGLWidget()->bindTexture(QImage(Application::resourcesPath() + "images/sixense-reticle.png")); + _crosshairTexture = Application::getInstance()->getGLWidget()->bindTexture(QImage(PathUtils::resourcesPath() + "images/sixense-reticle.png")); } glEnable(GL_TEXTURE_2D); diff --git a/interface/src/ui/ChatWindow.cpp b/interface/src/ui/ChatWindow.cpp index 747b4ae68d..22ceb0d367 100644 --- a/interface/src/ui/ChatWindow.cpp +++ b/interface/src/ui/ChatWindow.cpp @@ -19,6 +19,7 @@ #include #include +#include #include "Application.h" #include "ChatMessageArea.h" @@ -92,9 +93,9 @@ ChatWindow::ChatWindow(QWidget* parent) : connect(&_trayIcon, SIGNAL(messageClicked()), this, SLOT(notificationClicked())); #endif // HAVE_QXMPP - QDir mentionSoundsDir(Application::resourcesPath() + mentionSoundsPath); + QDir mentionSoundsDir(PathUtils::resourcesPath() + mentionSoundsPath); _mentionSounds = mentionSoundsDir.entryList(QDir::Files); - _trayIcon.setIcon(QIcon( Application::resourcesPath() + "/images/hifi-logo.svg")); + _trayIcon.setIcon(QIcon( PathUtils::resourcesPath() + "/images/hifi-logo.svg")); } ChatWindow::~ChatWindow() { @@ -385,7 +386,7 @@ void ChatWindow::messageReceived(const QXmppMessage& message) { if (_effectPlayer.state() != QMediaPlayer::PlayingState) { // get random sound - QFileInfo inf = QFileInfo(Application::resourcesPath() + + QFileInfo inf = QFileInfo(PathUtils::resourcesPath() + mentionSoundsPath + _mentionSounds.at(rand() % _mentionSounds.size())); _effectPlayer.setMedia(QUrl::fromLocalFile(inf.absoluteFilePath())); diff --git a/interface/src/ui/FramelessDialog.cpp b/interface/src/ui/FramelessDialog.cpp index 280354d974..bae6217083 100644 --- a/interface/src/ui/FramelessDialog.cpp +++ b/interface/src/ui/FramelessDialog.cpp @@ -12,6 +12,8 @@ #include #include +#include + #include "Application.h" #include "FramelessDialog.h" #include "Menu.h" @@ -80,10 +82,10 @@ bool FramelessDialog::eventFilter(QObject* sender, QEvent* event) { } void FramelessDialog::setStyleSheetFile(const QString& fileName) { - QFile globalStyleSheet(Application::resourcesPath() + "styles/global.qss"); - QFile styleSheet(Application::resourcesPath() + fileName); + QFile globalStyleSheet(PathUtils::resourcesPath() + "styles/global.qss"); + QFile styleSheet(PathUtils::resourcesPath() + fileName); if (styleSheet.open(QIODevice::ReadOnly) && globalStyleSheet.open(QIODevice::ReadOnly) ) { - QDir::setCurrent(Application::resourcesPath()); + QDir::setCurrent(PathUtils::resourcesPath()); setStyleSheet(globalStyleSheet.readAll() + styleSheet.readAll()); } } diff --git a/interface/src/ui/InfoView.cpp b/interface/src/ui/InfoView.cpp index f306514e80..0c04e07841 100644 --- a/interface/src/ui/InfoView.cpp +++ b/interface/src/ui/InfoView.cpp @@ -9,14 +9,17 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include "InfoView.h" #include -#include "Application.h" #include #include #include +#include + +#include "Application.h" +#include "InfoView.h" + #define SETTINGS_VERSION_KEY "info-version" #define MAX_DIALOG_HEIGHT_RATIO 0.9 @@ -25,7 +28,7 @@ InfoView::InfoView(bool forced, QString path) : { setWindowFlags(Qt::WindowStaysOnTopHint | Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint); - QString absPath = QFileInfo(Application::resourcesPath() + path).absoluteFilePath(); + QString absPath = QFileInfo(PathUtils::resourcesPath() + path).absoluteFilePath(); QUrl url = QUrl::fromLocalFile(absPath); load(url); diff --git a/interface/src/ui/JSConsole.cpp b/interface/src/ui/JSConsole.cpp index 8dbece41f0..700781df69 100644 --- a/interface/src/ui/JSConsole.cpp +++ b/interface/src/ui/JSConsole.cpp @@ -13,10 +13,11 @@ #include #include -#include "Application.h" -#include "ScriptHighlighting.h" +#include +#include "Application.h" #include "JSConsole.h" +#include "ScriptHighlighting.h" const int NO_CURRENT_HISTORY_COMMAND = -1; const int MAX_HISTORY_SIZE = 64; @@ -41,9 +42,9 @@ JSConsole::JSConsole(QWidget* parent, ScriptEngine* scriptEngine) : _ui->promptTextEdit->setWordWrapMode(QTextOption::NoWrap); _ui->promptTextEdit->installEventFilter(this); - QFile styleSheet(Application::resourcesPath() + "styles/console.qss"); + QFile styleSheet(PathUtils::resourcesPath() + "styles/console.qss"); if (styleSheet.open(QIODevice::ReadOnly)) { - QDir::setCurrent(Application::resourcesPath()); + QDir::setCurrent(PathUtils::resourcesPath()); setStyleSheet(styleSheet.readAll()); } diff --git a/interface/src/ui/LogDialog.cpp b/interface/src/ui/LogDialog.cpp index 7136ed2d25..a1a52f1d77 100644 --- a/interface/src/ui/LogDialog.cpp +++ b/interface/src/ui/LogDialog.cpp @@ -15,10 +15,10 @@ #include #include +#include #include #include "Application.h" - #include "ui/LogDialog.h" const int TOP_BAR_HEIGHT = 46; @@ -44,9 +44,9 @@ LogDialog::LogDialog(QWidget* parent, AbstractLoggerInterface* logger) : QDialog setWindowTitle("Log"); setAttribute(Qt::WA_DeleteOnClose); - QFile styleSheet(Application::resourcesPath() + "styles/log_dialog.qss"); + QFile styleSheet(PathUtils::resourcesPath() + "styles/log_dialog.qss"); if (styleSheet.open(QIODevice::ReadOnly)) { - QDir::setCurrent(Application::resourcesPath()); + QDir::setCurrent(PathUtils::resourcesPath()); setStyleSheet(styleSheet.readAll()); } diff --git a/interface/src/ui/LoginDialog.cpp b/interface/src/ui/LoginDialog.cpp index b3d8cb1e53..298efa6b1a 100644 --- a/interface/src/ui/LoginDialog.cpp +++ b/interface/src/ui/LoginDialog.cpp @@ -14,11 +14,12 @@ #include #include +#include + #include "Application.h" #include "Menu.h" #include "AccountManager.h" #include "ui_loginDialog.h" - #include "LoginDialog.h" const QString FORGOT_PASSWORD_URL = "https://data.highfidelity.io/users/password/new"; @@ -30,8 +31,8 @@ LoginDialog::LoginDialog(QWidget* parent) : _ui->setupUi(this); _ui->errorLabel->hide(); _ui->emailLineEdit->setFocus(); - _ui->logoLabel->setPixmap(QPixmap(Application::resourcesPath() + "images/hifi-logo.svg")); - _ui->loginButton->setIcon(QIcon(Application::resourcesPath() + "images/login.svg")); + _ui->logoLabel->setPixmap(QPixmap(PathUtils::resourcesPath() + "images/hifi-logo.svg")); + _ui->loginButton->setIcon(QIcon(PathUtils::resourcesPath() + "images/login.svg")); _ui->infoLabel->setVisible(false); _ui->errorLabel->setVisible(false); diff --git a/interface/src/ui/MetavoxelEditor.cpp b/interface/src/ui/MetavoxelEditor.cpp index 158532e19a..1a85e84b72 100644 --- a/interface/src/ui/MetavoxelEditor.cpp +++ b/interface/src/ui/MetavoxelEditor.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include "Application.h" #include "MetavoxelEditor.h" @@ -145,7 +146,7 @@ MetavoxelEditor::MetavoxelEditor() : return; } - _gridProgram.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + "shaders/grid.frag"); + _gridProgram.addShaderFromSourceFile(QGLShader::Fragment, PathUtils::resourcesPath() + "shaders/grid.frag"); _gridProgram.link(); } diff --git a/interface/src/ui/RearMirrorTools.cpp b/interface/src/ui/RearMirrorTools.cpp index fb6ef63647..fd3fc34adb 100644 --- a/interface/src/ui/RearMirrorTools.cpp +++ b/interface/src/ui/RearMirrorTools.cpp @@ -13,12 +13,13 @@ #include +#include #include #include "Application.h" +#include "RearMirrorTools.h" #include "Util.h" -#include "RearMirrorTools.h" const char SETTINGS_GROUP_NAME[] = "Rear View Tools"; const char ZOOM_LEVEL_SETTINGS[] = "ZoomLevel"; @@ -32,13 +33,13 @@ RearMirrorTools::RearMirrorTools(QGLWidget* parent, QRect& bounds, QSettings* se _fullScreen(false) { _zoomLevel = HEAD; - _closeTextureId = _parent->bindTexture(QImage(Application::resourcesPath() + "images/close.svg")); + _closeTextureId = _parent->bindTexture(QImage(PathUtils::resourcesPath() + "images/close.svg")); // Disabled for now https://worklist.net/19548 - // _resetTextureId = _parent->bindTexture(QImage(Application::resourcesPath() + "images/reset.png")); + // _resetTextureId = _parent->bindTexture(QImage(PathUtils::resourcesPath() + "images/reset.png")); - _zoomHeadTextureId = _parent->bindTexture(QImage(Application::resourcesPath() + "images/plus.svg")); - _zoomBodyTextureId = _parent->bindTexture(QImage(Application::resourcesPath() + "images/minus.svg")); + _zoomHeadTextureId = _parent->bindTexture(QImage(PathUtils::resourcesPath() + "images/plus.svg")); + _zoomBodyTextureId = _parent->bindTexture(QImage(PathUtils::resourcesPath() + "images/minus.svg")); _shrinkIconRect = QRect(ICON_PADDING, ICON_PADDING, ICON_SIZE, ICON_SIZE); _closeIconRect = QRect(_bounds.left() + ICON_PADDING, _bounds.top() + ICON_PADDING, ICON_SIZE, ICON_SIZE); diff --git a/interface/src/ui/RunningScriptsWidget.cpp b/interface/src/ui/RunningScriptsWidget.cpp index cfd7428482..57c0532777 100644 --- a/interface/src/ui/RunningScriptsWidget.cpp +++ b/interface/src/ui/RunningScriptsWidget.cpp @@ -21,6 +21,8 @@ #include #include +#include + #include "Application.h" #include "Menu.h" #include "ScriptsModel.h" @@ -109,7 +111,7 @@ void RunningScriptsWidget::setRunningScripts(const QStringList& list) { QPushButton* closeButton = new QPushButton(row); closeButton->setFlat(true); closeButton->setIcon( - QIcon(QPixmap(Application::resourcesPath() + "images/kill-script.svg").scaledToHeight(CLOSE_ICON_HEIGHT))); + QIcon(QPixmap(PathUtils::resourcesPath() + "images/kill-script.svg").scaledToHeight(CLOSE_ICON_HEIGHT))); closeButton->setSizePolicy(QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred)); closeButton->setStyleSheet("border: 0;"); closeButton->setCursor(Qt::PointingHandCursor); diff --git a/interface/src/ui/VoxelImportDialog.cpp b/interface/src/ui/VoxelImportDialog.cpp index 2d1b71ba7f..930fed133d 100644 --- a/interface/src/ui/VoxelImportDialog.cpp +++ b/interface/src/ui/VoxelImportDialog.cpp @@ -18,6 +18,8 @@ #include #include +#include + #include "Application.h" #include "VoxelImportDialog.h" @@ -64,7 +66,7 @@ QIcon HiFiIconProvider::icon(QFileIconProvider::IconType type) const { break; } - return QIcon(Application::resourcesPath() + "icons/" + typeString + ".svg"); + return QIcon(PathUtils::resourcesPath() + "icons/" + typeString + ".svg"); } QIcon HiFiIconProvider::icon(const QFileInfo &info) const { @@ -72,21 +74,21 @@ QIcon HiFiIconProvider::icon(const QFileInfo &info) const { if (info.isDir()) { if (info.absoluteFilePath() == QDir::homePath()) { - return QIcon(Application::resourcesPath() + "icons/home.svg"); + return QIcon(PathUtils::resourcesPath() + "icons/home.svg"); } else if (info.absoluteFilePath() == QStandardPaths::writableLocation(QStandardPaths::DesktopLocation)) { - return QIcon(Application::resourcesPath() + "icons/desktop.svg"); + return QIcon(PathUtils::resourcesPath() + "icons/desktop.svg"); } else if (info.absoluteFilePath() == QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)) { - return QIcon(Application::resourcesPath() + "icons/documents.svg"); + return QIcon(PathUtils::resourcesPath() + "icons/documents.svg"); } - return QIcon(Application::resourcesPath() + "icons/folder.svg"); + return QIcon(PathUtils::resourcesPath() + "icons/folder.svg"); } - QFileInfo iconFile(Application::resourcesPath() + "icons/" + iconsMap[ext]); + QFileInfo iconFile(PathUtils::resourcesPath() + "icons/" + iconsMap[ext]); if (iconFile.exists() && iconFile.isFile()) { return QIcon(iconFile.filePath()); } - return QIcon(Application::resourcesPath() + "icons/file.svg"); + return QIcon(PathUtils::resourcesPath() + "icons/file.svg"); } QString HiFiIconProvider::type(const QFileInfo &info) const { @@ -307,16 +309,16 @@ void VoxelImportDialog::setLayout() { widget = findChild("treeView"); widget->setAttribute(Qt::WA_MacShowFocusRect, false); - QFile styleSheet(Application::resourcesPath() + "styles/import_dialog.qss"); + QFile styleSheet(PathUtils::resourcesPath() + "styles/import_dialog.qss"); if (styleSheet.open(QIODevice::ReadOnly)) { - QDir::setCurrent(Application::resourcesPath()); + QDir::setCurrent(PathUtils::resourcesPath()); setStyleSheet(styleSheet.readAll()); } } void VoxelImportDialog::setImportTypes() { - QFile config(Application::resourcesPath() + "config/config.json"); + QFile config(PathUtils::resourcesPath() + "config/config.json"); config.open(QFile::ReadOnly | QFile::Text); QJsonDocument document = QJsonDocument::fromJson(config.readAll()); if (!document.isNull() && !document.isEmpty()) { diff --git a/interface/src/ui/overlays/Grid3DOverlay.cpp b/interface/src/ui/overlays/Grid3DOverlay.cpp index d1086ae534..953a288cb6 100644 --- a/interface/src/ui/overlays/Grid3DOverlay.cpp +++ b/interface/src/ui/overlays/Grid3DOverlay.cpp @@ -9,9 +9,10 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include "Grid3DOverlay.h" +#include #include "Application.h" +#include "Grid3DOverlay.h" ProgramObject Grid3DOverlay::_gridProgram; @@ -36,7 +37,7 @@ void Grid3DOverlay::render(RenderArgs* args) { } if (!_gridProgram.isLinked()) { - if (!_gridProgram.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + "shaders/grid.frag")) { + if (!_gridProgram.addShaderFromSourceFile(QGLShader::Fragment, PathUtils::resourcesPath() + "shaders/grid.frag")) { qDebug() << "Failed to compile: " + _gridProgram.log(); return; } diff --git a/interface/src/voxels/VoxelSystem.cpp b/interface/src/voxels/VoxelSystem.cpp index 064cead160..114b6ba481 100644 --- a/interface/src/voxels/VoxelSystem.cpp +++ b/interface/src/voxels/VoxelSystem.cpp @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -372,9 +373,9 @@ void VoxelSystem::initVoxelMemory() { // create our simple fragment shader if we're the first system to init if (!_program.isLinked()) { _program.addShaderFromSourceFile(QGLShader::Vertex, - Application::resourcesPath() + "shaders/voxel.vert"); + PathUtils::resourcesPath() + "shaders/voxel.vert"); _program.addShaderFromSourceFile(QGLShader::Fragment, - Application::resourcesPath() + "shaders/voxel.frag"); + PathUtils::resourcesPath() + "shaders/voxel.frag"); _program.link(); } _initialized = true; @@ -1645,9 +1646,9 @@ unsigned long VoxelSystem::getVoxelMemoryUsageGPU() { void VoxelSystem::bindPerlinModulateProgram() { if (!_perlinModulateProgram.isLinked()) { _perlinModulateProgram.addShaderFromSourceFile(QGLShader::Vertex, - Application::resourcesPath() + "shaders/perlin_modulate.vert"); + PathUtils::resourcesPath() + "shaders/perlin_modulate.vert"); _perlinModulateProgram.addShaderFromSourceFile(QGLShader::Fragment, - Application::resourcesPath() + "shaders/perlin_modulate.frag"); + PathUtils::resourcesPath() + "shaders/perlin_modulate.frag"); _perlinModulateProgram.link(); _perlinModulateProgram.bind(); diff --git a/libraries/shared/src/PathUtils.cpp b/libraries/shared/src/PathUtils.cpp new file mode 100644 index 0000000000..0b99f22228 --- /dev/null +++ b/libraries/shared/src/PathUtils.cpp @@ -0,0 +1,25 @@ +// +// PathUtils.cpp +// libraries/shared/src +// +// Created by Brad Hefta-Gaub on 12/15/14. +// Copyright 2014 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 +#include + +#include "PathUtils.h" + + +QString& PathUtils::resourcesPath() { +#ifdef Q_OS_MAC + static QString staticResourcePath = QCoreApplication::applicationDirPath() + "/../Resources/"; +#else + static QString staticResourcePath = QCoreApplication::applicationDirPath() + "/resources/"; +#endif + return staticResourcePath; +} diff --git a/libraries/shared/src/PathUtils.h b/libraries/shared/src/PathUtils.h new file mode 100644 index 0000000000..71cabc727d --- /dev/null +++ b/libraries/shared/src/PathUtils.h @@ -0,0 +1,22 @@ +// +// PathUtils.h +// libraries/shared/src +// +// Created by Brad Hefta-Gaub on 12/15/14. +// Copyright 2014 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 +// + +#ifndef hifi_PathUtils_h +#define hifi_PathUtils_h + + +#include + +namespace PathUtils { + QString& resourcesPath(); +} + +#endif // hifi_PathUtils_h \ No newline at end of file From 50c1e9fb4037cd9f225177ff9e6e5603c11c4776 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Mon, 15 Dec 2014 22:41:35 -0800 Subject: [PATCH 16/46] Fixes for missing audio device. --- interface/src/Audio.cpp | 7 ++++++- libraries/audio/src/AudioRingBuffer.h | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index 101d16d3ba..bf176e0415 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -450,7 +450,9 @@ void Audio::start() { qDebug() << "Unable to set up audio output because of a problem with output format."; } - _inputFrameBuffer.initialize( _inputFormat.channelCount(), _audioInput->bufferSize() * 8 ); + if (_audioInput) { + _inputFrameBuffer.initialize( _inputFormat.channelCount(), _audioInput->bufferSize() * 8 ); + } _inputGain.initialize(); _sourceGain.initialize(); _noiseSource.initialize(); @@ -1935,6 +1937,9 @@ int Audio::calculateNumberOfFrameSamples(int numBytes) const { } float Audio::getAudioOutputMsecsUnplayed() const { + if (!_audioOutput) { + return 0.0f; + } int bytesAudioOutputUnplayed = _audioOutput->bufferSize() - _audioOutput->bytesFree(); float msecsAudioOutputUnplayed = bytesAudioOutputUnplayed / (float)_outputFormat.bytesForDuration(USECS_PER_MSEC); return msecsAudioOutputUnplayed; diff --git a/libraries/audio/src/AudioRingBuffer.h b/libraries/audio/src/AudioRingBuffer.h index f033ffa80f..9239527df3 100644 --- a/libraries/audio/src/AudioRingBuffer.h +++ b/libraries/audio/src/AudioRingBuffer.h @@ -62,7 +62,7 @@ public: float getNextOutputFrameLoudness() const; int samplesAvailable() const; - int framesAvailable() const { return samplesAvailable() / _numFrameSamples; } + int framesAvailable() const { return (_numFrameSamples == 0) ? 0 : samplesAvailable() / _numFrameSamples; } int getNumFrameSamples() const { return _numFrameSamples; } From b1d1cfee44420bc9f14a2749ca746a10389b3aaa Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 15 Dec 2014 15:29:05 -0800 Subject: [PATCH 17/46] cmake cleanup --- libraries/render-utils/CMakeLists.txt | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/libraries/render-utils/CMakeLists.txt b/libraries/render-utils/CMakeLists.txt index bde26ea5ca..eb96e7c5ec 100644 --- a/libraries/render-utils/CMakeLists.txt +++ b/libraries/render-utils/CMakeLists.txt @@ -10,7 +10,7 @@ if (APPLE) # link in required OS X frameworks and include the right GL headers find_library(OpenGL OpenGL) - target_link_libraries(${TARGET_NAME} ${OpenGL}) + #target_link_libraries(${TARGET_NAME} ${OpenGL}) else (APPLE) find_package(OpenGL REQUIRED) @@ -19,8 +19,6 @@ else (APPLE) include_directories(SYSTEM "${OPENGL_INCLUDE_DIR}") endif () - #target_link_libraries(${TARGET_NAME} "${OPENGL_LIBRARY}") - # link target to external libraries if (WIN32) find_package(GLEW REQUIRED) @@ -28,17 +26,6 @@ else (APPLE) # we're using static GLEW, so define GLEW_STATIC add_definitions(-DGLEW_STATIC) - - #target_link_libraries(${TARGET_NAME} "${GLEW_LIBRARIES}" "${NSIGHT_LIBRARIES}" opengl32.lib) - - # try to find the Nsight package and add it to the build if we find it - #find_package(NSIGHT) - #if (NSIGHT_FOUND) - # include_directories(${NSIGHT_INCLUDE_DIRS}) - # add_definitions(-DNSIGHT_FOUND) - # #target_link_libraries(${TARGET_NAME} "${NSIGHT_LIBRARIES}") - #endif () - endif() endif (APPLE) From 892141fe14f485c55e3c17738eec5d66a197d39b Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Mon, 15 Dec 2014 16:36:26 -0800 Subject: [PATCH 18/46] Fix for crash on exit due to cache references' not being cleared. --- libraries/networking/src/ResourceCache.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/libraries/networking/src/ResourceCache.cpp b/libraries/networking/src/ResourceCache.cpp index 097ede23d0..5bb327fe63 100644 --- a/libraries/networking/src/ResourceCache.cpp +++ b/libraries/networking/src/ResourceCache.cpp @@ -28,9 +28,13 @@ ResourceCache::ResourceCache(QObject* parent) : } ResourceCache::~ResourceCache() { - // make sure our unused resources know we're out of commission - foreach (const QSharedPointer& resource, _unusedResources) { - resource->setCache(NULL); + // the unused resources may themselves reference resources that will be added to the unused + // list on destruction, so keep clearing until there are no references left + while (!_unusedResources.isEmpty()) { + foreach (const QSharedPointer& resource, _unusedResources) { + resource->setCache(NULL); + } + _unusedResources.clear(); } } From e53833b3060fe5094ef8d0c2a066820026088602 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 15 Dec 2014 17:29:48 -0800 Subject: [PATCH 19/46] make GlowEffect support DependencyManager --- interface/src/Application.cpp | 10 +++++--- interface/src/Application.h | 3 --- interface/src/avatar/Avatar.cpp | 1 + interface/src/avatar/AvatarManager.cpp | 3 ++- interface/src/avatar/Head.cpp | 5 ++-- interface/src/devices/OculusManager.cpp | 5 ++-- interface/src/devices/TV3DManager.cpp | 5 ++-- interface/src/entities/EntityTreeRenderer.cpp | 2 ++ .../src/renderer/AmbientOcclusionEffect.cpp | 3 ++- .../src/renderer/DeferredLightingEffect.cpp | 5 ++-- interface/src/renderer/GlowEffect.cpp | 24 ++++++++++++------- interface/src/renderer/GlowEffect.h | 17 +++++++++---- interface/src/renderer/Model.cpp | 5 +++- .../src/ui/overlays/LocalModelsOverlay.cpp | 1 + .../src/ui/overlays/LocalVoxelsOverlay.cpp | 1 + interface/src/ui/overlays/ModelOverlay.cpp | 1 + interface/src/voxels/VoxelFade.cpp | 5 ++-- 17 files changed, 64 insertions(+), 32 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 76247d1d9d..4bc4b0d339 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -90,6 +90,8 @@ #include "gpu/Batch.h" #include "gpu/GLBackend.h" +#include "renderer/GlowEffect.h" + #include "scripting/AccountScriptingInterface.h" #include "scripting/AudioDeviceScriptingInterface.h" #include "scripting/ClipboardScriptingInterface.h" @@ -702,7 +704,7 @@ void Application::paintGL() { TV3DManager::display(*whichCamera); } else { - _glowEffect.prepare(); + DependencyManager::get()->prepare(); // Viewport is assigned to the size of the framebuffer QSize size = DependencyManager::get()->getPrimaryFramebufferObject()->size(); @@ -721,7 +723,7 @@ void Application::paintGL() { renderRearViewMirror(_mirrorViewRect); } - _glowEffect.render(); + DependencyManager::get()->render(); { PerformanceTimer perfTimer("renderOverlay"); @@ -1913,7 +1915,6 @@ void Application::init() { _environment.init(); _deferredLightingEffect.init(); - _glowEffect.init(); _ambientOcclusionEffect.init(); // TODO: move _myAvatar out of Application. Move relevant code to MyAvataar or AvatarManager @@ -2036,6 +2037,9 @@ void Application::init() { // make sure our texture cache knows about window size changes DependencyManager::get()->associateWithWidget(getGLWidget()); + + // initialize the GlowEffect with our widget + DependencyManager::get()->init(getGLWidget()); } void Application::closeMirrorView() { diff --git a/interface/src/Application.h b/interface/src/Application.h index 0e1feafb7e..716d67c661 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -63,7 +63,6 @@ #include "entities/EntityTreeRenderer.h" #include "renderer/AmbientOcclusionEffect.h" #include "renderer/DeferredLightingEffect.h" -#include "renderer/GlowEffect.h" #include "scripting/ControllerScriptingInterface.h" #include "ui/BandwidthDialog.h" #include "ui/BandwidthMeter.h" @@ -252,7 +251,6 @@ public: AnimationCache* getAnimationCache() { return &_animationCache; } DeferredLightingEffect* getDeferredLightingEffect() { return &_deferredLightingEffect; } - GlowEffect* getGlowEffect() { return &_glowEffect; } ControllerScriptingInterface* getControllerScriptingInterface() { return &_controllerScriptingInterface; } AvatarManager& getAvatarManager() { return _avatarManager; } @@ -571,7 +569,6 @@ private: AnimationCache _animationCache; DeferredLightingEffect _deferredLightingEffect; - GlowEffect _glowEffect; AmbientOcclusionEffect _ambientOcclusionEffect; Audio _audio; diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index e0896364f6..83de09c4f5 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -40,6 +40,7 @@ #include "Recorder.h" #include "world.h" #include "devices/OculusManager.h" +#include "renderer/GlowEffect.h" #include "ui/TextRenderer.h" using namespace std; diff --git a/interface/src/avatar/AvatarManager.cpp b/interface/src/avatar/AvatarManager.cpp index ca6a6db4a7..2de272bb29 100644 --- a/interface/src/avatar/AvatarManager.cpp +++ b/interface/src/avatar/AvatarManager.cpp @@ -21,10 +21,11 @@ #include "Application.h" #include "Avatar.h" +#include "AvatarManager.h" #include "Menu.h" #include "MyAvatar.h" -#include "AvatarManager.h" +#include "renderer/GlowEffect.h" // We add _myAvatar into the hash with all the other AvatarData, and we use the default NULL QUid as the key. const QUuid MY_AVATAR_KEY; // NULL key diff --git a/interface/src/avatar/Head.cpp b/interface/src/avatar/Head.cpp index 42b3c968e1..fb20ccdbde 100644 --- a/interface/src/avatar/Head.cpp +++ b/interface/src/avatar/Head.cpp @@ -22,6 +22,7 @@ #include "Menu.h" #include "Util.h" #include "devices/OculusManager.h" +#include "renderer/GlowEffect.h" using namespace std; @@ -331,7 +332,7 @@ void Head::addLeanDeltas(float sideways, float forward) { void Head::renderLookatVectors(glm::vec3 leftEyePosition, glm::vec3 rightEyePosition, glm::vec3 lookatPosition) { - Application::getInstance()->getGlowEffect()->begin(); + DependencyManager::get()->begin(); glLineWidth(2.0); glBegin(GL_LINES); @@ -345,7 +346,7 @@ void Head::renderLookatVectors(glm::vec3 leftEyePosition, glm::vec3 rightEyePosi glVertex3f(lookatPosition.x, lookatPosition.y, lookatPosition.z); glEnd(); - Application::getInstance()->getGlowEffect()->end(); + DependencyManager::get()->end(); } diff --git a/interface/src/devices/OculusManager.cpp b/interface/src/devices/OculusManager.cpp index 7f5c2cd668..b000d6436b 100644 --- a/interface/src/devices/OculusManager.cpp +++ b/interface/src/devices/OculusManager.cpp @@ -26,6 +26,7 @@ #include #include "Application.h" +#include "renderer/GlowEffect.h" #ifdef HAVE_LIBOVR @@ -448,7 +449,7 @@ void OculusManager::display(const glm::quat &bodyOrientation, const glm::vec3 &p //Bind our framebuffer object. If we are rendering the glow effect, we let the glow effect shader take care of it if (Menu::getInstance()->isOptionChecked(MenuOption::EnableGlowEffect)) { - Application::getInstance()->getGlowEffect()->prepare(); + DependencyManager::get()->prepare(); } else { DependencyManager::get()->getPrimaryFramebufferObject()->bind(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -553,7 +554,7 @@ void OculusManager::display(const glm::quat &bodyOrientation, const glm::vec3 &p //Bind the output texture from the glow shader. If glow effect is disabled, we just grab the texture if (Menu::getInstance()->isOptionChecked(MenuOption::EnableGlowEffect)) { - QOpenGLFramebufferObject* fbo = Application::getInstance()->getGlowEffect()->render(true); + QOpenGLFramebufferObject* fbo = DependencyManager::get()->render(true); glBindTexture(GL_TEXTURE_2D, fbo->texture()); } else { DependencyManager::get()->getPrimaryFramebufferObject()->release(); diff --git a/interface/src/devices/TV3DManager.cpp b/interface/src/devices/TV3DManager.cpp index d7d7353b24..b756ccf41e 100644 --- a/interface/src/devices/TV3DManager.cpp +++ b/interface/src/devices/TV3DManager.cpp @@ -19,6 +19,7 @@ #include "TV3DManager.h" #include "Menu.h" +#include "renderer/GlowEffect.h" int TV3DManager::_screenWidth = 1; int TV3DManager::_screenHeight = 1; @@ -103,7 +104,7 @@ void TV3DManager::display(Camera& whichCamera) { applicationOverlay.renderOverlay(true); const bool displayOverlays = Menu::getInstance()->isOptionChecked(MenuOption::UserInterface); - Application::getInstance()->getGlowEffect()->prepare(); + DependencyManager::get()->prepare(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -169,7 +170,7 @@ void TV3DManager::display(Camera& whichCamera) { // reset the viewport to how we started glViewport(0, 0, deviceSize.width(), deviceSize.height()); - Application::getInstance()->getGlowEffect()->render(); + DependencyManager::get()->render(); } void TV3DManager::overrideOffAxisFrustum(float& left, float& right, float& bottom, float& top, float& nearVal, diff --git a/interface/src/entities/EntityTreeRenderer.cpp b/interface/src/entities/EntityTreeRenderer.cpp index 2c2b81fa3a..aca111e731 100644 --- a/interface/src/entities/EntityTreeRenderer.cpp +++ b/interface/src/entities/EntityTreeRenderer.cpp @@ -36,6 +36,8 @@ #include "RenderableSphereEntityItem.h" #include "RenderableTextEntityItem.h" +#include "renderer/GlowEffect.h" + QThread* EntityTreeRenderer::getMainThread() { return Application::getInstance()->getEntities()->thread(); diff --git a/interface/src/renderer/AmbientOcclusionEffect.cpp b/interface/src/renderer/AmbientOcclusionEffect.cpp index 08ad6703e6..c5aa193024 100644 --- a/interface/src/renderer/AmbientOcclusionEffect.cpp +++ b/interface/src/renderer/AmbientOcclusionEffect.cpp @@ -24,6 +24,7 @@ #include "RenderUtil.h" #include "AmbientOcclusionEffect.h" +#include "renderer/GlowEffect.h" const int ROTATION_WIDTH = 4; const int ROTATION_HEIGHT = 4; @@ -105,7 +106,7 @@ void AmbientOcclusionEffect::render() { glBindTexture(GL_TEXTURE_2D, _rotationTextureID); // render with the occlusion shader to the secondary/tertiary buffer - QOpenGLFramebufferObject* freeFBO = Application::getInstance()->getGlowEffect()->getFreeFramebufferObject(); + QOpenGLFramebufferObject* freeFBO = DependencyManager::get()->getFreeFramebufferObject(); freeFBO->bind(); float left, right, bottom, top, nearVal, farVal; diff --git a/interface/src/renderer/DeferredLightingEffect.cpp b/interface/src/renderer/DeferredLightingEffect.cpp index 79b89d03f9..b365307a44 100644 --- a/interface/src/renderer/DeferredLightingEffect.cpp +++ b/interface/src/renderer/DeferredLightingEffect.cpp @@ -19,6 +19,7 @@ #include "Application.h" #include "DeferredLightingEffect.h" #include "RenderUtil.h" +#include "renderer/GlowEffect.h" void DeferredLightingEffect::init() { _simpleProgram.addShaderFromSourceFile(QGLShader::Vertex, PathUtils::resourcesPath() + "shaders/simple.vert"); @@ -41,7 +42,7 @@ void DeferredLightingEffect::init() { void DeferredLightingEffect::bindSimpleProgram() { DependencyManager::get()->setPrimaryDrawBuffers(true, true, true); _simpleProgram.bind(); - _simpleProgram.setUniformValue(_glowIntensityLocation, Application::getInstance()->getGlowEffect()->getIntensity()); + _simpleProgram.setUniformValue(_glowIntensityLocation, DependencyManager::get()->getIntensity()); glDisable(GL_BLEND); } @@ -146,7 +147,7 @@ void DeferredLightingEffect::render() { QOpenGLFramebufferObject* primaryFBO = textureCache->getPrimaryFramebufferObject(); primaryFBO->release(); - QOpenGLFramebufferObject* freeFBO = Application::getInstance()->getGlowEffect()->getFreeFramebufferObject(); + QOpenGLFramebufferObject* freeFBO = DependencyManager::get()->getFreeFramebufferObject(); freeFBO->bind(); glClear(GL_COLOR_BUFFER_BIT); diff --git a/interface/src/renderer/GlowEffect.cpp b/interface/src/renderer/GlowEffect.cpp index a53c9f878b..4ec0a994b7 100644 --- a/interface/src/renderer/GlowEffect.cpp +++ b/interface/src/renderer/GlowEffect.cpp @@ -13,6 +13,7 @@ #include "InterfaceConfig.h" #include +#include #include #include @@ -58,7 +59,7 @@ static ProgramObject* createProgram(const QString& name) { return program; } -void GlowEffect::init() { +void GlowEffect::init(QGLWidget* widget) { if (_initialized) { qDebug("[ERROR] GlowEffeect is already initialized."); return; @@ -86,8 +87,18 @@ void GlowEffect::init() { _diffusionScaleLocation = _diffuseProgram->uniformLocation("diffusionScale"); _initialized = true; + _widget = widget; } +int GlowEffect::getDeviceWidth() const { + return _widget->width() * (_widget->windowHandle() ? _widget->windowHandle()->devicePixelRatio() : 1.0f); +} + +int GlowEffect::getDeviceHeight() const { + return _widget->height() * (_widget->windowHandle() ? _widget->windowHandle()->devicePixelRatio() : 1.0f); +} + + void GlowEffect::prepare() { DependencyManager::get()->getPrimaryFramebufferObject()->bind(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -148,8 +159,7 @@ QOpenGLFramebufferObject* GlowEffect::render(bool toTexture) { } else { maybeBind(destFBO); if (!destFBO) { - glViewport(0, 0, Application::getInstance()->getGLWidget()->getDeviceWidth(), - Application::getInstance()->getGLWidget()->getDeviceHeight()); + glViewport(0, 0, getDeviceWidth(), getDeviceHeight()); } glEnable(GL_TEXTURE_2D); glDisable(GL_LIGHTING); @@ -196,9 +206,7 @@ QOpenGLFramebufferObject* GlowEffect::render(bool toTexture) { } maybeBind(destFBO); if (!destFBO) { - glViewport(0, 0, - Application::getInstance()->getGLWidget()->getDeviceWidth(), - Application::getInstance()->getGLWidget()->getDeviceHeight()); + glViewport(0, 0, getDeviceWidth(), getDeviceHeight()); } _addSeparateProgram->bind(); renderFullscreenQuad(); @@ -226,10 +234,10 @@ QOpenGLFramebufferObject* GlowEffect::render(bool toTexture) { } Glower::Glower(float amount) { - Application::getInstance()->getGlowEffect()->begin(amount); + DependencyManager::get()->begin(amount); } Glower::~Glower() { - Application::getInstance()->getGlowEffect()->end(); + DependencyManager::get()->end(); } diff --git a/interface/src/renderer/GlowEffect.h b/interface/src/renderer/GlowEffect.h index f02774accc..42863019f3 100644 --- a/interface/src/renderer/GlowEffect.h +++ b/interface/src/renderer/GlowEffect.h @@ -15,23 +15,23 @@ #include #include +#include + class QOpenGLFramebufferObject; class ProgramObject; /// A generic full screen glow effect. -class GlowEffect : public QObject { +class GlowEffect : public QObject, public DependencyManager::Dependency { Q_OBJECT public: - GlowEffect(); - ~GlowEffect(); - + /// Returns a pointer to the framebuffer object that the glow effect is *not* using for persistent state /// (either the secondary or the tertiary). QOpenGLFramebufferObject* getFreeFramebufferObject() const; - void init(); + void init(QGLWidget* widget); /// Prepares the glow effect for rendering the current frame. To be called before rendering the scene. void prepare(); @@ -52,6 +52,12 @@ public: QOpenGLFramebufferObject* render(bool toTexture = false); private: + GlowEffect(); + virtual ~GlowEffect(); + friend class DependencyManager; + + int getDeviceWidth() const; + int getDeviceHeight() const; bool _initialized; @@ -69,6 +75,7 @@ private: float _intensity; QStack _intensityStack; + QGLWidget* _widget; }; /// RAII-style glow handler. Applies glow when in scope. diff --git a/interface/src/renderer/Model.cpp b/interface/src/renderer/Model.cpp index 71f0fb24f3..3e1784b680 100644 --- a/interface/src/renderer/Model.cpp +++ b/interface/src/renderer/Model.cpp @@ -33,6 +33,8 @@ #define GLBATCH( call ) batch._##call //#define GLBATCH( call ) call +#include "renderer/GlowEffect.h" + using namespace std; static int modelPointerTypeId = qRegisterMetaType >(); @@ -2327,6 +2329,7 @@ int Model::renderMeshesFromList(QVector& list, gpu::Batch& batch, RenderMod bool dontReduceMaterialSwitches = Menu::getInstance()->isOptionChecked(MenuOption::DontReduceMaterialSwitches); TextureCache* textureCache = DependencyManager::get(); + GlowEffect* glowEffect = DependencyManager::get(); QString lastMaterialID; int meshPartsRendered = 0; updateVisibleJointStates(); @@ -2431,7 +2434,7 @@ int Model::renderMeshesFromList(QVector& list, gpu::Batch& batch, RenderMod glm::vec4 diffuse = glm::vec4(part.diffuseColor, part.opacity); if (!(translucent && alphaThreshold == 0.0f)) { - GLBATCH(glAlphaFunc)(GL_EQUAL, diffuse.a = Application::getInstance()->getGlowEffect()->getIntensity()); + GLBATCH(glAlphaFunc)(GL_EQUAL, diffuse.a = glowEffect->getIntensity()); } glm::vec4 specular = glm::vec4(part.specularColor, 1.0f); GLBATCH(glMaterialfv)(GL_FRONT, GL_AMBIENT, (const float*)&diffuse); diff --git a/interface/src/ui/overlays/LocalModelsOverlay.cpp b/interface/src/ui/overlays/LocalModelsOverlay.cpp index d8555c85ba..d2af86e43b 100644 --- a/interface/src/ui/overlays/LocalModelsOverlay.cpp +++ b/interface/src/ui/overlays/LocalModelsOverlay.cpp @@ -12,6 +12,7 @@ #include "Application.h" #include "LocalModelsOverlay.h" +#include "renderer/GlowEffect.h" LocalModelsOverlay::LocalModelsOverlay(EntityTreeRenderer* entityTreeRenderer) : Volume3DOverlay(), diff --git a/interface/src/ui/overlays/LocalVoxelsOverlay.cpp b/interface/src/ui/overlays/LocalVoxelsOverlay.cpp index 9cb3df8bf3..b49320c087 100644 --- a/interface/src/ui/overlays/LocalVoxelsOverlay.cpp +++ b/interface/src/ui/overlays/LocalVoxelsOverlay.cpp @@ -18,6 +18,7 @@ #include #include "LocalVoxelsOverlay.h" +#include "renderer/GlowEffect.h" #include "voxels/VoxelSystem.h" QMap LocalVoxelsOverlay::_voxelSystemMap; diff --git a/interface/src/ui/overlays/ModelOverlay.cpp b/interface/src/ui/overlays/ModelOverlay.cpp index ecce137f4d..58fe0ec899 100644 --- a/interface/src/ui/overlays/ModelOverlay.cpp +++ b/interface/src/ui/overlays/ModelOverlay.cpp @@ -11,6 +11,7 @@ #include "../../Menu.h" #include "ModelOverlay.h" +#include "renderer/GlowEffect.h" ModelOverlay::ModelOverlay() : _model(), diff --git a/interface/src/voxels/VoxelFade.cpp b/interface/src/voxels/VoxelFade.cpp index c720717d7c..918cafe9c6 100644 --- a/interface/src/voxels/VoxelFade.cpp +++ b/interface/src/voxels/VoxelFade.cpp @@ -15,6 +15,7 @@ #include "Application.h" #include "VoxelFade.h" +#include "renderer/GlowEffect.h" const float VoxelFade::FADE_OUT_START = 0.5f; const float VoxelFade::FADE_OUT_END = 0.05f; @@ -36,7 +37,7 @@ VoxelFade::VoxelFade(FadeDirection direction, float red, float green, float blue } void VoxelFade::render() { - Application::getInstance()->getGlowEffect()->begin(); + DependencyManager::get()->begin(); glDisable(GL_LIGHTING); glPushMatrix(); @@ -52,7 +53,7 @@ void VoxelFade::render() { glEnable(GL_LIGHTING); - Application::getInstance()->getGlowEffect()->end(); + DependencyManager::get()->end(); opacity *= (direction == FADE_OUT) ? FADE_OUT_STEP : FADE_IN_STEP; } From 37abe8e89c48e7ffdfb23402721accedbe89e671 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 15 Dec 2014 17:35:26 -0800 Subject: [PATCH 20/46] move RenderUtils.cpp/h to libraries --- interface/src/renderer/AmbientOcclusionEffect.cpp | 2 +- interface/src/renderer/DeferredLightingEffect.cpp | 2 +- interface/src/renderer/GlowEffect.cpp | 5 +++-- .../renderer => libraries/render-utils/src}/RenderUtil.cpp | 2 +- .../src/renderer => libraries/render-utils/src}/RenderUtil.h | 0 5 files changed, 6 insertions(+), 5 deletions(-) rename {interface/src/renderer => libraries/render-utils/src}/RenderUtil.cpp (95%) rename {interface/src/renderer => libraries/render-utils/src}/RenderUtil.h (100%) diff --git a/interface/src/renderer/AmbientOcclusionEffect.cpp b/interface/src/renderer/AmbientOcclusionEffect.cpp index c5aa193024..9c89eae75e 100644 --- a/interface/src/renderer/AmbientOcclusionEffect.cpp +++ b/interface/src/renderer/AmbientOcclusionEffect.cpp @@ -18,10 +18,10 @@ #include #include +#include #include #include "Application.h" -#include "RenderUtil.h" #include "AmbientOcclusionEffect.h" #include "renderer/GlowEffect.h" diff --git a/interface/src/renderer/DeferredLightingEffect.cpp b/interface/src/renderer/DeferredLightingEffect.cpp index b365307a44..ae0743e2a6 100644 --- a/interface/src/renderer/DeferredLightingEffect.cpp +++ b/interface/src/renderer/DeferredLightingEffect.cpp @@ -15,10 +15,10 @@ #include #include +#include #include "Application.h" #include "DeferredLightingEffect.h" -#include "RenderUtil.h" #include "renderer/GlowEffect.h" void DeferredLightingEffect::init() { diff --git a/interface/src/renderer/GlowEffect.cpp b/interface/src/renderer/GlowEffect.cpp index 4ec0a994b7..ee5642e654 100644 --- a/interface/src/renderer/GlowEffect.cpp +++ b/interface/src/renderer/GlowEffect.cpp @@ -18,10 +18,11 @@ #include #include #include +#include +#include -#include "Application.h" +#include "Menu.h" #include "GlowEffect.h" -#include "RenderUtil.h" GlowEffect::GlowEffect() : _initialized(false), diff --git a/interface/src/renderer/RenderUtil.cpp b/libraries/render-utils/src/RenderUtil.cpp similarity index 95% rename from interface/src/renderer/RenderUtil.cpp rename to libraries/render-utils/src/RenderUtil.cpp index c2f05d373e..d70c972c87 100644 --- a/interface/src/renderer/RenderUtil.cpp +++ b/libraries/render-utils/src/RenderUtil.cpp @@ -9,7 +9,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include "InterfaceConfig.h" +#include #include "RenderUtil.h" void renderFullscreenQuad(float sMin, float sMax, float tMin, float tMax) { diff --git a/interface/src/renderer/RenderUtil.h b/libraries/render-utils/src/RenderUtil.h similarity index 100% rename from interface/src/renderer/RenderUtil.h rename to libraries/render-utils/src/RenderUtil.h From e52338d25c0cb9b9e046d106895026cf708f45f5 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 15 Dec 2014 17:38:57 -0800 Subject: [PATCH 21/46] get rid of InterfaceConfig.h in GlowEffect --- interface/src/renderer/GlowEffect.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/renderer/GlowEffect.cpp b/interface/src/renderer/GlowEffect.cpp index ee5642e654..7ad553decf 100644 --- a/interface/src/renderer/GlowEffect.cpp +++ b/interface/src/renderer/GlowEffect.cpp @@ -10,7 +10,7 @@ // // include this before QOpenGLFramebufferObject, which includes an earlier version of OpenGL -#include "InterfaceConfig.h" +#include #include #include From 4eef4c2438ec0018b3fc01fdecaff248ac359089 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 15 Dec 2014 18:52:40 -0800 Subject: [PATCH 22/46] move RenderUtils.cpp/h to libraries --- interface/src/MetavoxelSystem.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/interface/src/MetavoxelSystem.cpp b/interface/src/MetavoxelSystem.cpp index 372c5214f7..824f1e3313 100644 --- a/interface/src/MetavoxelSystem.cpp +++ b/interface/src/MetavoxelSystem.cpp @@ -32,7 +32,6 @@ #include "Application.h" #include "MetavoxelSystem.h" #include "renderer/Model.h" -#include "renderer/RenderUtil.h" REGISTER_META_OBJECT(DefaultMetavoxelRendererImplementation) REGISTER_META_OBJECT(SphereRenderer) From 8f3d23c5b32208581b8067ed34435b2fe214d969 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 15 Dec 2014 19:06:54 -0800 Subject: [PATCH 23/46] remove Menu dependency from GlowEffect --- interface/src/Application.cpp | 2 +- interface/src/Menu.cpp | 4 +++- interface/src/renderer/GlowEffect.cpp | 14 ++++++++++---- interface/src/renderer/GlowEffect.h | 6 +++++- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 4bc4b0d339..834587a26a 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2039,7 +2039,7 @@ void Application::init() { DependencyManager::get()->associateWithWidget(getGLWidget()); // initialize the GlowEffect with our widget - DependencyManager::get()->init(getGLWidget()); + DependencyManager::get()->init(getGLWidget(), Menu::getInstance()->isOptionChecked(MenuOption::EnableGlowEffect)); } void Application::closeMirrorView() { diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index fbb23504b0..55a1254e3f 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -54,6 +54,7 @@ #include "ui/ModelsBrowser.h" #include "ui/LoginDialog.h" #include "ui/NodeBounds.h" +#include "renderer/GlowEffect.h" Menu* Menu::_instance = NULL; @@ -425,7 +426,8 @@ Menu::Menu() : true, appInstance, SLOT(setRenderVoxels(bool))); - addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::EnableGlowEffect, 0, true); + addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::EnableGlowEffect, 0, true, + DependencyManager::get(), SLOT(toggleGlowEffect(bool))); addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::Wireframe, Qt::ALT | Qt::Key_W, false); addActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::LodTools, Qt::SHIFT | Qt::Key_L, this, SLOT(lodTools())); diff --git a/interface/src/renderer/GlowEffect.cpp b/interface/src/renderer/GlowEffect.cpp index 7ad553decf..13513c140b 100644 --- a/interface/src/renderer/GlowEffect.cpp +++ b/interface/src/renderer/GlowEffect.cpp @@ -21,14 +21,15 @@ #include #include -#include "Menu.h" #include "GlowEffect.h" GlowEffect::GlowEffect() : _initialized(false), _isOddFrame(false), _isFirstFrame(true), - _intensity(0.0f) { + _intensity(0.0f), + _widget(NULL), + _enabled(false) { } GlowEffect::~GlowEffect() { @@ -60,7 +61,7 @@ static ProgramObject* createProgram(const QString& name) { return program; } -void GlowEffect::init(QGLWidget* widget) { +void GlowEffect::init(QGLWidget* widget, bool enabled) { if (_initialized) { qDebug("[ERROR] GlowEffeect is already initialized."); return; @@ -89,6 +90,7 @@ void GlowEffect::init(QGLWidget* widget) { _initialized = true; _widget = widget; + _enabled = enabled; } int GlowEffect::getDeviceWidth() const { @@ -153,7 +155,7 @@ QOpenGLFramebufferObject* GlowEffect::render(bool toTexture) { QOpenGLFramebufferObject* destFBO = toTexture ? textureCache->getSecondaryFramebufferObject() : NULL; - if (!Menu::getInstance()->isOptionChecked(MenuOption::EnableGlowEffect) || _isEmpty) { + if (!_enabled || _isEmpty) { // copy the primary to the screen if (destFBO && QOpenGLFramebufferObject::hasOpenGLFramebufferBlit()) { QOpenGLFramebufferObject::blitFramebuffer(destFBO, primaryFBO); @@ -234,6 +236,10 @@ QOpenGLFramebufferObject* GlowEffect::render(bool toTexture) { return destFBO; } +void GlowEffect::toggleGlowEffect(bool enabled) { + _enabled = enabled; +} + Glower::Glower(float amount) { DependencyManager::get()->begin(amount); } diff --git a/interface/src/renderer/GlowEffect.h b/interface/src/renderer/GlowEffect.h index 42863019f3..d27f32c244 100644 --- a/interface/src/renderer/GlowEffect.h +++ b/interface/src/renderer/GlowEffect.h @@ -31,7 +31,7 @@ public: /// (either the secondary or the tertiary). QOpenGLFramebufferObject* getFreeFramebufferObject() const; - void init(QGLWidget* widget); + void init(QGLWidget* widget, bool enabled); /// Prepares the glow effect for rendering the current frame. To be called before rendering the scene. void prepare(); @@ -51,6 +51,9 @@ public: /// \return the framebuffer object to which we rendered, or NULL if to the frame buffer QOpenGLFramebufferObject* render(bool toTexture = false); +public slots: + void toggleGlowEffect(bool enabled); + private: GlowEffect(); virtual ~GlowEffect(); @@ -76,6 +79,7 @@ private: float _intensity; QStack _intensityStack; QGLWidget* _widget; + bool _enabled; }; /// RAII-style glow handler. Applies glow when in scope. From 41c135c4e5618cefc74ddc97382166d1a9123d99 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 15 Dec 2014 19:19:21 -0800 Subject: [PATCH 24/46] move GlowEffect to libraries --- interface/src/Application.cpp | 2 +- interface/src/Menu.cpp | 3 +-- interface/src/avatar/Avatar.cpp | 2 +- interface/src/avatar/AvatarManager.cpp | 2 +- interface/src/avatar/Head.cpp | 6 +++--- interface/src/devices/OculusManager.cpp | 2 +- interface/src/devices/TV3DManager.cpp | 3 ++- interface/src/entities/EntityTreeRenderer.cpp | 5 +---- interface/src/renderer/AmbientOcclusionEffect.cpp | 2 +- interface/src/renderer/DeferredLightingEffect.cpp | 2 +- interface/src/renderer/Model.cpp | 3 +-- interface/src/ui/overlays/Circle3DOverlay.cpp | 2 +- interface/src/ui/overlays/Cube3DOverlay.cpp | 3 ++- interface/src/ui/overlays/Line3DOverlay.cpp | 3 ++- interface/src/ui/overlays/LocalModelsOverlay.cpp | 3 ++- interface/src/ui/overlays/LocalVoxelsOverlay.cpp | 4 ++-- interface/src/ui/overlays/ModelOverlay.cpp | 4 +++- interface/src/ui/overlays/Rectangle3DOverlay.cpp | 3 ++- interface/src/ui/overlays/Sphere3DOverlay.cpp | 3 ++- interface/src/voxels/VoxelFade.cpp | 2 +- .../render-utils/src}/GlowEffect.cpp | 8 +++++--- .../renderer => libraries/render-utils/src}/GlowEffect.h | 1 + 22 files changed, 37 insertions(+), 31 deletions(-) rename {interface/src/renderer => libraries/render-utils/src}/GlowEffect.cpp (98%) rename {interface/src/renderer => libraries/render-utils/src}/GlowEffect.h (99%) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 834587a26a..f3ac53c33b 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -57,6 +57,7 @@ #include #include #include +#include #include #include #include @@ -90,7 +91,6 @@ #include "gpu/Batch.h" #include "gpu/GLBackend.h" -#include "renderer/GlowEffect.h" #include "scripting/AccountScriptingInterface.h" #include "scripting/AudioDeviceScriptingInterface.h" diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 55a1254e3f..80fdec5202 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -54,8 +55,6 @@ #include "ui/ModelsBrowser.h" #include "ui/LoginDialog.h" #include "ui/NodeBounds.h" -#include "renderer/GlowEffect.h" - Menu* Menu::_instance = NULL; diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 83de09c4f5..4b7c5dfdf3 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -40,7 +41,6 @@ #include "Recorder.h" #include "world.h" #include "devices/OculusManager.h" -#include "renderer/GlowEffect.h" #include "ui/TextRenderer.h" using namespace std; diff --git a/interface/src/avatar/AvatarManager.cpp b/interface/src/avatar/AvatarManager.cpp index 2de272bb29..8c13dd3c54 100644 --- a/interface/src/avatar/AvatarManager.cpp +++ b/interface/src/avatar/AvatarManager.cpp @@ -15,6 +15,7 @@ #include +#include #include #include #include @@ -25,7 +26,6 @@ #include "Menu.h" #include "MyAvatar.h" -#include "renderer/GlowEffect.h" // We add _myAvatar into the hash with all the other AvatarData, and we use the default NULL QUid as the key. const QUuid MY_AVATAR_KEY; // NULL key diff --git a/interface/src/avatar/Head.cpp b/interface/src/avatar/Head.cpp index fb20ccdbde..5d84c2d939 100644 --- a/interface/src/avatar/Head.cpp +++ b/interface/src/avatar/Head.cpp @@ -11,8 +11,7 @@ #include #include -#include -#include +#include #include #include "Application.h" @@ -21,8 +20,9 @@ #include "Head.h" #include "Menu.h" #include "Util.h" +#include "devices/DdeFaceTracker.h" +#include "devices/Faceshift.h" #include "devices/OculusManager.h" -#include "renderer/GlowEffect.h" using namespace std; diff --git a/interface/src/devices/OculusManager.cpp b/interface/src/devices/OculusManager.cpp index b000d6436b..96615112dd 100644 --- a/interface/src/devices/OculusManager.cpp +++ b/interface/src/devices/OculusManager.cpp @@ -21,12 +21,12 @@ #include +#include #include #include #include #include "Application.h" -#include "renderer/GlowEffect.h" #ifdef HAVE_LIBOVR diff --git a/interface/src/devices/TV3DManager.cpp b/interface/src/devices/TV3DManager.cpp index b756ccf41e..f665765d70 100644 --- a/interface/src/devices/TV3DManager.cpp +++ b/interface/src/devices/TV3DManager.cpp @@ -15,11 +15,12 @@ #include +#include + #include "Application.h" #include "TV3DManager.h" #include "Menu.h" -#include "renderer/GlowEffect.h" int TV3DManager::_screenWidth = 1; int TV3DManager::_screenHeight = 1; diff --git a/interface/src/entities/EntityTreeRenderer.cpp b/interface/src/entities/EntityTreeRenderer.cpp index aca111e731..59b3f697c8 100644 --- a/interface/src/entities/EntityTreeRenderer.cpp +++ b/interface/src/entities/EntityTreeRenderer.cpp @@ -18,6 +18,7 @@ #include "InterfaceConfig.h" #include +#include #include #include #include @@ -36,15 +37,11 @@ #include "RenderableSphereEntityItem.h" #include "RenderableTextEntityItem.h" -#include "renderer/GlowEffect.h" - QThread* EntityTreeRenderer::getMainThread() { return Application::getInstance()->getEntities()->thread(); } - - EntityTreeRenderer::EntityTreeRenderer(bool wantScripts) : OctreeRenderer(), _wantScripts(wantScripts), diff --git a/interface/src/renderer/AmbientOcclusionEffect.cpp b/interface/src/renderer/AmbientOcclusionEffect.cpp index 9c89eae75e..bcae662085 100644 --- a/interface/src/renderer/AmbientOcclusionEffect.cpp +++ b/interface/src/renderer/AmbientOcclusionEffect.cpp @@ -16,6 +16,7 @@ #include +#include #include #include #include @@ -24,7 +25,6 @@ #include "Application.h" #include "AmbientOcclusionEffect.h" -#include "renderer/GlowEffect.h" const int ROTATION_WIDTH = 4; const int ROTATION_HEIGHT = 4; diff --git a/interface/src/renderer/DeferredLightingEffect.cpp b/interface/src/renderer/DeferredLightingEffect.cpp index ae0743e2a6..18a93aa042 100644 --- a/interface/src/renderer/DeferredLightingEffect.cpp +++ b/interface/src/renderer/DeferredLightingEffect.cpp @@ -14,12 +14,12 @@ #include +#include #include #include #include "Application.h" #include "DeferredLightingEffect.h" -#include "renderer/GlowEffect.h" void DeferredLightingEffect::init() { _simpleProgram.addShaderFromSourceFile(QGLShader::Vertex, PathUtils::resourcesPath() + "shaders/simple.vert"); diff --git a/interface/src/renderer/Model.cpp b/interface/src/renderer/Model.cpp index 3e1784b680..877f43a563 100644 --- a/interface/src/renderer/Model.cpp +++ b/interface/src/renderer/Model.cpp @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -33,8 +34,6 @@ #define GLBATCH( call ) batch._##call //#define GLBATCH( call ) call -#include "renderer/GlowEffect.h" - using namespace std; static int modelPointerTypeId = qRegisterMetaType >(); diff --git a/interface/src/ui/overlays/Circle3DOverlay.cpp b/interface/src/ui/overlays/Circle3DOverlay.cpp index 68d589d20b..32ae7f0a07 100644 --- a/interface/src/ui/overlays/Circle3DOverlay.cpp +++ b/interface/src/ui/overlays/Circle3DOverlay.cpp @@ -12,11 +12,11 @@ #include "InterfaceConfig.h" #include +#include #include #include #include "Circle3DOverlay.h" -#include "renderer/GlowEffect.h" Circle3DOverlay::Circle3DOverlay() : _startAt(0.0f), diff --git a/interface/src/ui/overlays/Cube3DOverlay.cpp b/interface/src/ui/overlays/Cube3DOverlay.cpp index 8e37dedd77..f518c309a1 100644 --- a/interface/src/ui/overlays/Cube3DOverlay.cpp +++ b/interface/src/ui/overlays/Cube3DOverlay.cpp @@ -12,12 +12,13 @@ #include "InterfaceConfig.h" #include + +#include #include #include #include "Application.h" #include "Cube3DOverlay.h" -#include "renderer/GlowEffect.h" Cube3DOverlay::Cube3DOverlay() : _borderSize(0) { } diff --git a/interface/src/ui/overlays/Line3DOverlay.cpp b/interface/src/ui/overlays/Line3DOverlay.cpp index ae67bf9d92..4facd779de 100644 --- a/interface/src/ui/overlays/Line3DOverlay.cpp +++ b/interface/src/ui/overlays/Line3DOverlay.cpp @@ -11,8 +11,9 @@ // include this before QGLWidget, which includes an earlier version of OpenGL #include "InterfaceConfig.h" +#include + #include "Line3DOverlay.h" -#include "renderer/GlowEffect.h" Line3DOverlay::Line3DOverlay() { diff --git a/interface/src/ui/overlays/LocalModelsOverlay.cpp b/interface/src/ui/overlays/LocalModelsOverlay.cpp index d2af86e43b..e6fae4ff3d 100644 --- a/interface/src/ui/overlays/LocalModelsOverlay.cpp +++ b/interface/src/ui/overlays/LocalModelsOverlay.cpp @@ -9,10 +9,11 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include + #include "Application.h" #include "LocalModelsOverlay.h" -#include "renderer/GlowEffect.h" LocalModelsOverlay::LocalModelsOverlay(EntityTreeRenderer* entityTreeRenderer) : Volume3DOverlay(), diff --git a/interface/src/ui/overlays/LocalVoxelsOverlay.cpp b/interface/src/ui/overlays/LocalVoxelsOverlay.cpp index b49320c087..b3dac02468 100644 --- a/interface/src/ui/overlays/LocalVoxelsOverlay.cpp +++ b/interface/src/ui/overlays/LocalVoxelsOverlay.cpp @@ -15,10 +15,10 @@ #include #include -#include +#include +#include "Application.h" #include "LocalVoxelsOverlay.h" -#include "renderer/GlowEffect.h" #include "voxels/VoxelSystem.h" QMap LocalVoxelsOverlay::_voxelSystemMap; diff --git a/interface/src/ui/overlays/ModelOverlay.cpp b/interface/src/ui/overlays/ModelOverlay.cpp index 58fe0ec899..58d42598f2 100644 --- a/interface/src/ui/overlays/ModelOverlay.cpp +++ b/interface/src/ui/overlays/ModelOverlay.cpp @@ -8,10 +8,12 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // + +#include + #include "../../Menu.h" #include "ModelOverlay.h" -#include "renderer/GlowEffect.h" ModelOverlay::ModelOverlay() : _model(), diff --git a/interface/src/ui/overlays/Rectangle3DOverlay.cpp b/interface/src/ui/overlays/Rectangle3DOverlay.cpp index bcca759cd4..8e8c17743d 100644 --- a/interface/src/ui/overlays/Rectangle3DOverlay.cpp +++ b/interface/src/ui/overlays/Rectangle3DOverlay.cpp @@ -12,10 +12,11 @@ #include "InterfaceConfig.h" #include + +#include #include #include "Rectangle3DOverlay.h" -#include "renderer/GlowEffect.h" Rectangle3DOverlay::Rectangle3DOverlay() { } diff --git a/interface/src/ui/overlays/Sphere3DOverlay.cpp b/interface/src/ui/overlays/Sphere3DOverlay.cpp index ded1b3917c..eb95672399 100644 --- a/interface/src/ui/overlays/Sphere3DOverlay.cpp +++ b/interface/src/ui/overlays/Sphere3DOverlay.cpp @@ -12,11 +12,12 @@ #include "InterfaceConfig.h" #include + +#include #include #include "Sphere3DOverlay.h" #include "Application.h" -#include "renderer/GlowEffect.h" Sphere3DOverlay::Sphere3DOverlay() { } diff --git a/interface/src/voxels/VoxelFade.cpp b/interface/src/voxels/VoxelFade.cpp index 918cafe9c6..367090291c 100644 --- a/interface/src/voxels/VoxelFade.cpp +++ b/interface/src/voxels/VoxelFade.cpp @@ -11,11 +11,11 @@ #include "InterfaceConfig.h" +#include #include #include "Application.h" #include "VoxelFade.h" -#include "renderer/GlowEffect.h" const float VoxelFade::FADE_OUT_START = 0.5f; const float VoxelFade::FADE_OUT_END = 0.05f; diff --git a/interface/src/renderer/GlowEffect.cpp b/libraries/render-utils/src/GlowEffect.cpp similarity index 98% rename from interface/src/renderer/GlowEffect.cpp rename to libraries/render-utils/src/GlowEffect.cpp index 13513c140b..174436d155 100644 --- a/interface/src/renderer/GlowEffect.cpp +++ b/libraries/render-utils/src/GlowEffect.cpp @@ -12,16 +12,18 @@ // include this before QOpenGLFramebufferObject, which includes an earlier version of OpenGL #include +#include #include #include #include #include -#include -#include -#include #include "GlowEffect.h" +#include "ProgramObject.h" +#include "RenderUtil.h" +#include "TextureCache.h" + GlowEffect::GlowEffect() : _initialized(false), diff --git a/interface/src/renderer/GlowEffect.h b/libraries/render-utils/src/GlowEffect.h similarity index 99% rename from interface/src/renderer/GlowEffect.h rename to libraries/render-utils/src/GlowEffect.h index d27f32c244..3ad1577d14 100644 --- a/interface/src/renderer/GlowEffect.h +++ b/libraries/render-utils/src/GlowEffect.h @@ -13,6 +13,7 @@ #define hifi_GlowEffect_h #include +#include #include #include From fac6ff572ba3da1d53b39f2858be1c5153e3e8e7 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 15 Dec 2014 19:29:53 -0800 Subject: [PATCH 25/46] see if this works --- libraries/render-utils/src/GlowEffect.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libraries/render-utils/src/GlowEffect.h b/libraries/render-utils/src/GlowEffect.h index 3ad1577d14..cc3e6e5867 100644 --- a/libraries/render-utils/src/GlowEffect.h +++ b/libraries/render-utils/src/GlowEffect.h @@ -12,6 +12,8 @@ #ifndef hifi_GlowEffect_h #define hifi_GlowEffect_h +#include + #include #include #include From 02737a4ec402f8b97e07a08fca86b15c978996a0 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 15 Dec 2014 19:38:30 -0800 Subject: [PATCH 26/46] move JointState to libraries --- interface/src/avatar/SkeletonRagdoll.h | 3 +- interface/src/renderer/Model.h | 2 +- libraries/render-utils/src/JointState.cpp | 281 ++++++++++++++++++++++ libraries/render-utils/src/JointState.h | 129 ++++++++++ 4 files changed, 412 insertions(+), 3 deletions(-) create mode 100644 libraries/render-utils/src/JointState.cpp create mode 100644 libraries/render-utils/src/JointState.h diff --git a/interface/src/avatar/SkeletonRagdoll.h b/interface/src/avatar/SkeletonRagdoll.h index ae9bec9116..2f8ce1f712 100644 --- a/interface/src/avatar/SkeletonRagdoll.h +++ b/interface/src/avatar/SkeletonRagdoll.h @@ -14,10 +14,9 @@ #include +#include #include -#include "../renderer/JointState.h" - class MuscleConstraint; class Model; diff --git a/interface/src/renderer/Model.h b/interface/src/renderer/Model.h index c79a6c2efd..8000e7385b 100644 --- a/interface/src/renderer/Model.h +++ b/interface/src/renderer/Model.h @@ -23,13 +23,13 @@ #include #include #include +#include #include #include #include #include #include "AnimationHandle.h" -#include "JointState.h" class QScriptEngine; diff --git a/libraries/render-utils/src/JointState.cpp b/libraries/render-utils/src/JointState.cpp new file mode 100644 index 0000000000..96561758da --- /dev/null +++ b/libraries/render-utils/src/JointState.cpp @@ -0,0 +1,281 @@ +// +// JointState.cpp +// interface/src/renderer +// +// Created by Andrzej Kapolka on 10/18/13. +// Copyright 2013 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 + +#include + +#include +#include + +#include "JointState.h" + +JointState::JointState() : + _animationPriority(0.0f), + _transformChanged(true), + _rotationIsValid(false), + _positionInParentFrame(0.0f), + _distanceToParent(0.0f), + _fbxJoint(NULL), + _constraint(NULL) { +} + +JointState::JointState(const JointState& other) : _constraint(NULL) { + _transformChanged = other._transformChanged; + _transform = other._transform; + _rotationIsValid = other._rotationIsValid; + _rotation = other._rotation; + _rotationInConstrainedFrame = other._rotationInConstrainedFrame; + _positionInParentFrame = other._positionInParentFrame; + _distanceToParent = other._distanceToParent; + _animationPriority = other._animationPriority; + _fbxJoint = other._fbxJoint; + // DO NOT copy _constraint +} + +JointState::~JointState() { + delete _constraint; + _constraint = NULL; + if (_constraint) { + delete _constraint; + _constraint = NULL; + } +} + +glm::quat JointState::getRotation() const { + if (!_rotationIsValid) { + const_cast(this)->_rotation = extractRotation(_transform); + const_cast(this)->_rotationIsValid = true; + } + + return _rotation; +} + +void JointState::setFBXJoint(const FBXJoint* joint) { + assert(joint != NULL); + _rotationInConstrainedFrame = joint->rotation; + _transformChanged = true; + _rotationIsValid = false; + + // NOTE: JointState does not own the FBXJoint to which it points. + _fbxJoint = joint; + if (_constraint) { + delete _constraint; + _constraint = NULL; + } +} + +void JointState::buildConstraint() { + if (_constraint) { + delete _constraint; + _constraint = NULL; + } + if (glm::distance2(glm::vec3(-PI), _fbxJoint->rotationMin) > EPSILON || + glm::distance2(glm::vec3(PI), _fbxJoint->rotationMax) > EPSILON ) { + // this joint has rotation constraints + _constraint = AngularConstraint::newAngularConstraint(_fbxJoint->rotationMin, _fbxJoint->rotationMax); + } +} + +void JointState::copyState(const JointState& state) { + _animationPriority = state._animationPriority; + _transformChanged = state._transformChanged; + _transform = state._transform; + _rotationIsValid = state._rotationIsValid; + _rotation = state._rotation; + _rotationInConstrainedFrame = state._rotationInConstrainedFrame; + _positionInParentFrame = state._positionInParentFrame; + _distanceToParent = state._distanceToParent; + + _visibleTransform = state._visibleTransform; + _visibleRotation = extractRotation(_visibleTransform); + _visibleRotationInConstrainedFrame = state._visibleRotationInConstrainedFrame; + // DO NOT copy _fbxJoint or _constraint +} + +void JointState::initTransform(const glm::mat4& parentTransform) { + computeTransform(parentTransform); + _positionInParentFrame = glm::inverse(extractRotation(parentTransform)) * (extractTranslation(_transform) - extractTranslation(parentTransform)); + _distanceToParent = glm::length(_positionInParentFrame); +} + +void JointState::computeTransform(const glm::mat4& parentTransform, bool parentTransformChanged, bool synchronousRotationCompute) { + if (!parentTransformChanged && !_transformChanged) { + return; + } + + glm::quat rotationInParentFrame = _fbxJoint->preRotation * _rotationInConstrainedFrame * _fbxJoint->postRotation; + glm::mat4 transformInParentFrame = _fbxJoint->preTransform * glm::mat4_cast(rotationInParentFrame) * _fbxJoint->postTransform; + glm::mat4 newTransform = parentTransform * glm::translate(_fbxJoint->translation) * transformInParentFrame; + + if (newTransform != _transform) { + _transform = newTransform; + _transformChanged = true; + _rotationIsValid = false; + } +} + +void JointState::computeVisibleTransform(const glm::mat4& parentTransform) { + glm::quat rotationInParentFrame = _fbxJoint->preRotation * _visibleRotationInConstrainedFrame * _fbxJoint->postRotation; + glm::mat4 transformInParentFrame = _fbxJoint->preTransform * glm::mat4_cast(rotationInParentFrame) * _fbxJoint->postTransform; + _visibleTransform = parentTransform * glm::translate(_fbxJoint->translation) * transformInParentFrame; + _visibleRotation = extractRotation(_visibleTransform); +} + +glm::quat JointState::getRotationInBindFrame() const { + return getRotation() * _fbxJoint->inverseBindRotation; +} + +glm::quat JointState::getRotationInParentFrame() const { + return _fbxJoint->preRotation * _rotationInConstrainedFrame * _fbxJoint->postRotation; +} + +glm::quat JointState::getVisibleRotationInParentFrame() const { + return _fbxJoint->preRotation * _visibleRotationInConstrainedFrame * _fbxJoint->postRotation; +} + +void JointState::restoreRotation(float fraction, float priority) { + assert(_fbxJoint != NULL); + if (priority == _animationPriority || _animationPriority == 0.0f) { + setRotationInConstrainedFrameInternal(safeMix(_rotationInConstrainedFrame, _fbxJoint->rotation, fraction)); + _animationPriority = 0.0f; + } +} + +void JointState::setRotationInBindFrame(const glm::quat& rotation, float priority, bool constrain) { + // rotation is from bind- to model-frame + assert(_fbxJoint != NULL); + if (priority >= _animationPriority) { + glm::quat targetRotation = _rotationInConstrainedFrame * glm::inverse(getRotation()) * rotation * glm::inverse(_fbxJoint->inverseBindRotation); + if (constrain && _constraint) { + _constraint->softClamp(targetRotation, _rotationInConstrainedFrame, 0.5f); + } + setRotationInConstrainedFrameInternal(targetRotation); + _animationPriority = priority; + } +} + +void JointState::clearTransformTranslation() { + _transform[3][0] = 0.0f; + _transform[3][1] = 0.0f; + _transform[3][2] = 0.0f; + _transformChanged = true; + _visibleTransform[3][0] = 0.0f; + _visibleTransform[3][1] = 0.0f; + _visibleTransform[3][2] = 0.0f; +} + +void JointState::applyRotationDelta(const glm::quat& delta, bool constrain, float priority) { + // NOTE: delta is in model-frame + assert(_fbxJoint != NULL); + if (priority < _animationPriority || delta.null) { + return; + } + _animationPriority = priority; + glm::quat targetRotation = _rotationInConstrainedFrame * glm::inverse(getRotation()) * delta * getRotation(); + if (!constrain || _constraint == NULL) { + // no constraints + _rotationInConstrainedFrame = targetRotation; + _transformChanged = true; + + _rotation = delta * getRotation(); + return; + } + setRotationInConstrainedFrameInternal(targetRotation); +} + +/// Applies delta rotation to joint but mixes a little bit of the default pose as well. +/// This helps keep an IK solution stable. +void JointState::mixRotationDelta(const glm::quat& delta, float mixFactor, float priority) { + // NOTE: delta is in model-frame + assert(_fbxJoint != NULL); + if (priority < _animationPriority) { + return; + } + _animationPriority = priority; + glm::quat targetRotation = _rotationInConstrainedFrame * glm::inverse(getRotation()) * delta * getRotation(); + if (mixFactor > 0.0f && mixFactor <= 1.0f) { + targetRotation = safeMix(targetRotation, _fbxJoint->rotation, mixFactor); + } + if (_constraint) { + _constraint->softClamp(targetRotation, _rotationInConstrainedFrame, 0.5f); + } + setRotationInConstrainedFrameInternal(targetRotation); +} + +void JointState::mixVisibleRotationDelta(const glm::quat& delta, float mixFactor) { + // NOTE: delta is in model-frame + assert(_fbxJoint != NULL); + glm::quat targetRotation = _visibleRotationInConstrainedFrame * glm::inverse(_visibleRotation) * delta * _visibleRotation; + if (mixFactor > 0.0f && mixFactor <= 1.0f) { + //targetRotation = safeMix(targetRotation, _fbxJoint->rotation, mixFactor); + targetRotation = safeMix(targetRotation, _rotationInConstrainedFrame, mixFactor); + } + setVisibleRotationInConstrainedFrame(targetRotation); +} + +glm::quat JointState::computeParentRotation() const { + // R = Rp * Rpre * r * Rpost + // Rp = R * (Rpre * r * Rpost)^ + return getRotation() * glm::inverse(_fbxJoint->preRotation * _rotationInConstrainedFrame * _fbxJoint->postRotation); +} + +glm::quat JointState::computeVisibleParentRotation() const { + return _visibleRotation * glm::inverse(_fbxJoint->preRotation * _visibleRotationInConstrainedFrame * _fbxJoint->postRotation); +} + +void JointState::setRotationInConstrainedFrame(glm::quat targetRotation, float priority, bool constrain) { + if (priority >= _animationPriority || _animationPriority == 0.0f) { + if (constrain && _constraint) { + _constraint->softClamp(targetRotation, _rotationInConstrainedFrame, 0.5f); + } + setRotationInConstrainedFrameInternal(targetRotation); + _animationPriority = priority; + } +} + +void JointState::setRotationInConstrainedFrameInternal(const glm::quat& targetRotation) { + glm::quat parentRotation = computeParentRotation(); + _rotationInConstrainedFrame = targetRotation; + _transformChanged = true; + // R' = Rp * Rpre * r' * Rpost + _rotation = parentRotation * _fbxJoint->preRotation * _rotationInConstrainedFrame * _fbxJoint->postRotation; +} + +void JointState::setVisibleRotationInConstrainedFrame(const glm::quat& targetRotation) { + glm::quat parentRotation = computeVisibleParentRotation(); + _visibleRotationInConstrainedFrame = targetRotation; + _visibleRotation = parentRotation * _fbxJoint->preRotation * _visibleRotationInConstrainedFrame * _fbxJoint->postRotation; +} + +const bool JointState::rotationIsDefault(const glm::quat& rotation, float tolerance) const { + glm::quat defaultRotation = _fbxJoint->rotation; + return glm::abs(rotation.x - defaultRotation.x) < tolerance && + glm::abs(rotation.y - defaultRotation.y) < tolerance && + glm::abs(rotation.z - defaultRotation.z) < tolerance && + glm::abs(rotation.w - defaultRotation.w) < tolerance; +} + +glm::quat JointState::getDefaultRotationInParentFrame() const { + // NOTE: the result is constant and could be cached in the FBXJoint + return _fbxJoint->preRotation * _fbxJoint->rotation * _fbxJoint->postRotation; +} + +const glm::vec3& JointState::getDefaultTranslationInConstrainedFrame() const { + assert(_fbxJoint != NULL); + return _fbxJoint->translation; +} + +void JointState::slaveVisibleTransform() { + _visibleTransform = _transform; + _visibleRotation = getRotation(); + _visibleRotationInConstrainedFrame = _rotationInConstrainedFrame; +} diff --git a/libraries/render-utils/src/JointState.h b/libraries/render-utils/src/JointState.h new file mode 100644 index 0000000000..b502083463 --- /dev/null +++ b/libraries/render-utils/src/JointState.h @@ -0,0 +1,129 @@ +// +// JointState.h +// interface/src/renderer +// +// Created by Andrzej Kapolka on 10/18/13. +// Copyright 2013 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 +// + +#ifndef hifi_JointState_h +#define hifi_JointState_h + +#include +#include +#include + +#include +#include + +const float DEFAULT_PRIORITY = 3.0f; + +class AngularConstraint; + +class JointState { +public: + JointState(); + JointState(const JointState& other); + ~JointState(); + + void setFBXJoint(const FBXJoint* joint); + const FBXJoint& getFBXJoint() const { return *_fbxJoint; } + + void buildConstraint(); + void copyState(const JointState& state); + + void initTransform(const glm::mat4& parentTransform); + // if synchronousRotationCompute is true, then _transform is still computed synchronously, + // but _rotation will be asynchronously extracted + void computeTransform(const glm::mat4& parentTransform, bool parentTransformChanged = true, bool synchronousRotationCompute = false); + + void computeVisibleTransform(const glm::mat4& parentTransform); + const glm::mat4& getVisibleTransform() const { return _visibleTransform; } + glm::quat getVisibleRotation() const { return _visibleRotation; } + glm::vec3 getVisiblePosition() const { return extractTranslation(_visibleTransform); } + + const glm::mat4& getTransform() const { return _transform; } + void resetTransformChanged() { _transformChanged = false; } + bool getTransformChanged() const { return _transformChanged; } + + glm::quat getRotation() const; + glm::vec3 getPosition() const { return extractTranslation(_transform); } + + /// \return rotation from bind to model frame + glm::quat getRotationInBindFrame() const; + + glm::quat getRotationInParentFrame() const; + glm::quat getVisibleRotationInParentFrame() const; + const glm::vec3& getPositionInParentFrame() const { return _positionInParentFrame; } + float getDistanceToParent() const { return _distanceToParent; } + + int getParentIndex() const { return _fbxJoint->parentIndex; } + + /// \param delta is in the model-frame + void applyRotationDelta(const glm::quat& delta, bool constrain = true, float priority = 1.0f); + + /// Applies delta rotation to joint but mixes a little bit of the default pose as well. + /// This helps keep an IK solution stable. + /// \param delta rotation change in model-frame + /// \param mixFactor fraction in range [0,1] of how much default pose to blend in (0 is none, 1 is all) + /// \param priority priority level of this animation blend + void mixRotationDelta(const glm::quat& delta, float mixFactor, float priority = 1.0f); + void mixVisibleRotationDelta(const glm::quat& delta, float mixFactor); + + /// Blends a fraciton of default pose into joint rotation. + /// \param fraction fraction in range [0,1] of how much default pose to blend in (0 is none, 1 is all) + /// \param priority priority level of this animation blend + void restoreRotation(float fraction, float priority); + + /// \param rotation is from bind- to model-frame + /// computes and sets new _rotationInConstrainedFrame + /// NOTE: the JointState's model-frame transform/rotation are NOT updated! + void setRotationInBindFrame(const glm::quat& rotation, float priority, bool constrain = false); + + void setRotationInConstrainedFrame(glm::quat targetRotation, float priority, bool constrain = false); + void setVisibleRotationInConstrainedFrame(const glm::quat& targetRotation); + const glm::quat& getRotationInConstrainedFrame() const { return _rotationInConstrainedFrame; } + const glm::quat& getVisibleRotationInConstrainedFrame() const { return _visibleRotationInConstrainedFrame; } + + const bool rotationIsDefault(const glm::quat& rotation, float tolerance = EPSILON) const; + + glm::quat getDefaultRotationInParentFrame() const; + const glm::vec3& getDefaultTranslationInConstrainedFrame() const; + + + void clearTransformTranslation(); + + void slaveVisibleTransform(); + + float _animationPriority; // the priority of the animation affecting this joint + + /// \return parent model-frame rotation + // (used to keep _rotation consistent when modifying _rotationInWorldFrame directly) + glm::quat computeParentRotation() const; + glm::quat computeVisibleParentRotation() const; + +private: + void setRotationInConstrainedFrameInternal(const glm::quat& targetRotation); + /// debug helper function + void loadBindRotation(); + + bool _transformChanged; + glm::mat4 _transform; // joint- to model-frame + bool _rotationIsValid; + glm::quat _rotation; // joint- to model-frame + glm::quat _rotationInConstrainedFrame; // rotation in frame where angular constraints would be applied + glm::vec3 _positionInParentFrame; // only changes when the Model is scaled + float _distanceToParent; + + glm::mat4 _visibleTransform; + glm::quat _visibleRotation; + glm::quat _visibleRotationInConstrainedFrame; + + const FBXJoint* _fbxJoint; // JointState does NOT own its FBXJoint + AngularConstraint* _constraint; // JointState owns its AngularConstraint +}; + +#endif // hifi_JointState_h From 660bf2720e0ffbd6971e3699ef7fa7efd7293ee0 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 15 Dec 2014 19:48:15 -0800 Subject: [PATCH 27/46] convert AnimationCache to DependencyManager --- .../src/avatars/ScriptableAvatar.cpp | 2 +- interface/src/Application.cpp | 2 +- interface/src/Application.h | 3 --- interface/src/renderer/AnimationHandle.cpp | 4 ++-- libraries/animation/src/AnimationCache.h | 17 +++++++++-------- libraries/entities/src/ModelEntityItem.cpp | 3 +-- libraries/script-engine/src/ScriptEngine.cpp | 3 +-- libraries/script-engine/src/ScriptEngine.h | 2 -- 8 files changed, 15 insertions(+), 21 deletions(-) diff --git a/assignment-client/src/avatars/ScriptableAvatar.cpp b/assignment-client/src/avatars/ScriptableAvatar.cpp index 0f721ac98c..e2f0449216 100644 --- a/assignment-client/src/avatars/ScriptableAvatar.cpp +++ b/assignment-client/src/avatars/ScriptableAvatar.cpp @@ -28,7 +28,7 @@ void ScriptableAvatar::startAnimation(const QString& url, float fps, float prior Q_ARG(float, lastFrame), Q_ARG(const QStringList&, maskedJoints)); return; } - _animation = _scriptEngine->getAnimationCache()->getAnimation(url); + _animation = DependencyManager::get()->getAnimation(url); _animationDetails = AnimationDetails("", QUrl(url), fps, 0, loop, hold, false, firstFrame, lastFrame, true, firstFrame); _maskedJoints = maskedJoints; } diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index f3ac53c33b..5f0f4a700a 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -4003,7 +4003,7 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri scriptEngine->registerGlobalObject("Menu", MenuScriptingInterface::getInstance()); scriptEngine->registerGlobalObject("Settings", SettingsScriptingInterface::getInstance()); scriptEngine->registerGlobalObject("AudioDevice", AudioDeviceScriptingInterface::getInstance()); - scriptEngine->registerGlobalObject("AnimationCache", &_animationCache); + scriptEngine->registerGlobalObject("AnimationCache", DependencyManager::get()); scriptEngine->registerGlobalObject("SoundCache", &SoundCache::getInstance()); scriptEngine->registerGlobalObject("Account", AccountScriptingInterface::getInstance()); scriptEngine->registerGlobalObject("Metavoxels", &_metavoxels); diff --git a/interface/src/Application.h b/interface/src/Application.h index 716d67c661..992d8d31d3 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -249,7 +249,6 @@ public: ToolWindow* getToolWindow() { return _toolWindow ; } - AnimationCache* getAnimationCache() { return &_animationCache; } DeferredLightingEffect* getDeferredLightingEffect() { return &_deferredLightingEffect; } ControllerScriptingInterface* getControllerScriptingInterface() { return &_controllerScriptingInterface; } @@ -566,8 +565,6 @@ private: QSet _keysPressed; - AnimationCache _animationCache; - DeferredLightingEffect _deferredLightingEffect; AmbientOcclusionEffect _ambientOcclusionEffect; diff --git a/interface/src/renderer/AnimationHandle.cpp b/interface/src/renderer/AnimationHandle.cpp index 89c265875b..30edf97a33 100644 --- a/interface/src/renderer/AnimationHandle.cpp +++ b/interface/src/renderer/AnimationHandle.cpp @@ -10,11 +10,11 @@ // #include "AnimationHandle.h" -#include "Application.h" +#include "Model.h" void AnimationHandle::setURL(const QUrl& url) { if (_url != url) { - _animation = Application::getInstance()->getAnimationCache()->getAnimation(_url = url); + _animation = DependencyManager::get()->getAnimation(_url = url); _jointMappings.clear(); } } diff --git a/libraries/animation/src/AnimationCache.h b/libraries/animation/src/AnimationCache.h index 8a9e371cb0..5f3f305461 100644 --- a/libraries/animation/src/AnimationCache.h +++ b/libraries/animation/src/AnimationCache.h @@ -15,30 +15,31 @@ #include #include -#include - +#include #include +#include class Animation; typedef QSharedPointer AnimationPointer; /// Scriptable interface for FBX animation loading. -class AnimationCache : public ResourceCache { +class AnimationCache : public ResourceCache, public DependencyManager::Dependency { Q_OBJECT public: - - AnimationCache(QObject* parent = NULL); - Q_INVOKABLE AnimationPointer getAnimation(const QString& url) { return getAnimation(QUrl(url)); } - Q_INVOKABLE AnimationPointer getAnimation(const QUrl& url); protected: virtual QSharedPointer createResource(const QUrl& url, - const QSharedPointer& fallback, bool delayLoad, const void* extra); + const QSharedPointer& fallback, bool delayLoad, const void* extra); +private: + AnimationCache(QObject* parent = NULL); + virtual ~AnimationCache() { } + friend class DependencyManager; + }; Q_DECLARE_METATYPE(AnimationPointer) diff --git a/libraries/entities/src/ModelEntityItem.cpp b/libraries/entities/src/ModelEntityItem.cpp index b9bf75178f..b14248b3bc 100644 --- a/libraries/entities/src/ModelEntityItem.cpp +++ b/libraries/entities/src/ModelEntityItem.cpp @@ -285,7 +285,6 @@ void ModelEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBit QMap ModelEntityItem::_loadedAnimations; // TODO: improve cleanup by leveraging the AnimationPointer(s) -AnimationCache ModelEntityItem::_animationCache; // This class/instance will cleanup the animations once unloaded. class EntityAnimationsBookkeeper { @@ -309,7 +308,7 @@ Animation* ModelEntityItem::getAnimation(const QString& url) { // if we don't already have this model then create it and initialize it if (_loadedAnimations.find(url) == _loadedAnimations.end()) { - animation = _animationCache.getAnimation(url); + animation = DependencyManager::get()->getAnimation(url); _loadedAnimations[url] = animation; } else { animation = _loadedAnimations[url]; diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index 70c536e116..ec5f2bc0e7 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -94,7 +94,6 @@ ScriptEngine::ScriptEngine(const QString& scriptContents, const QString& fileNam _quatLibrary(), _vec3Library(), _uuidLibrary(), - _animationCache(this), _isUserLoaded(false), _arrayBufferClass(new ArrayBufferClass(this)) { @@ -256,7 +255,7 @@ void ScriptEngine::init() { registerGlobalObject("Quat", &_quatLibrary); registerGlobalObject("Vec3", &_vec3Library); registerGlobalObject("Uuid", &_uuidLibrary); - registerGlobalObject("AnimationCache", &_animationCache); + registerGlobalObject("AnimationCache", DependencyManager::get()); registerGlobalObject("Voxels", &_voxelsScriptingInterface); diff --git a/libraries/script-engine/src/ScriptEngine.h b/libraries/script-engine/src/ScriptEngine.h index fd28e98cab..3b074d7c73 100644 --- a/libraries/script-engine/src/ScriptEngine.h +++ b/libraries/script-engine/src/ScriptEngine.h @@ -51,7 +51,6 @@ public: static EntityScriptingInterface* getEntityScriptingInterface() { return &_entityScriptingInterface; } ArrayBufferClass* getArrayBufferClass() { return _arrayBufferClass; } - AnimationCache* getAnimationCache() { return &_animationCache; } /// sets the script contents, will return false if failed, will fail if script is already running bool setScriptContents(const QString& scriptContents, const QString& fileNameString = QString("")); @@ -149,7 +148,6 @@ private: Quat _quatLibrary; Vec3 _vec3Library; ScriptUUID _uuidLibrary; - AnimationCache _animationCache; bool _isUserLoaded; ArrayBufferClass* _arrayBufferClass; From 5cba44fd5b3d52fc2774c410b605388c19a139e0 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 15 Dec 2014 19:49:16 -0800 Subject: [PATCH 28/46] moved JointState --- interface/src/renderer/JointState.cpp | 281 -------------------------- interface/src/renderer/JointState.h | 129 ------------ 2 files changed, 410 deletions(-) delete mode 100644 interface/src/renderer/JointState.cpp delete mode 100644 interface/src/renderer/JointState.h diff --git a/interface/src/renderer/JointState.cpp b/interface/src/renderer/JointState.cpp deleted file mode 100644 index 96561758da..0000000000 --- a/interface/src/renderer/JointState.cpp +++ /dev/null @@ -1,281 +0,0 @@ -// -// JointState.cpp -// interface/src/renderer -// -// Created by Andrzej Kapolka on 10/18/13. -// Copyright 2013 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 - -#include - -#include -#include - -#include "JointState.h" - -JointState::JointState() : - _animationPriority(0.0f), - _transformChanged(true), - _rotationIsValid(false), - _positionInParentFrame(0.0f), - _distanceToParent(0.0f), - _fbxJoint(NULL), - _constraint(NULL) { -} - -JointState::JointState(const JointState& other) : _constraint(NULL) { - _transformChanged = other._transformChanged; - _transform = other._transform; - _rotationIsValid = other._rotationIsValid; - _rotation = other._rotation; - _rotationInConstrainedFrame = other._rotationInConstrainedFrame; - _positionInParentFrame = other._positionInParentFrame; - _distanceToParent = other._distanceToParent; - _animationPriority = other._animationPriority; - _fbxJoint = other._fbxJoint; - // DO NOT copy _constraint -} - -JointState::~JointState() { - delete _constraint; - _constraint = NULL; - if (_constraint) { - delete _constraint; - _constraint = NULL; - } -} - -glm::quat JointState::getRotation() const { - if (!_rotationIsValid) { - const_cast(this)->_rotation = extractRotation(_transform); - const_cast(this)->_rotationIsValid = true; - } - - return _rotation; -} - -void JointState::setFBXJoint(const FBXJoint* joint) { - assert(joint != NULL); - _rotationInConstrainedFrame = joint->rotation; - _transformChanged = true; - _rotationIsValid = false; - - // NOTE: JointState does not own the FBXJoint to which it points. - _fbxJoint = joint; - if (_constraint) { - delete _constraint; - _constraint = NULL; - } -} - -void JointState::buildConstraint() { - if (_constraint) { - delete _constraint; - _constraint = NULL; - } - if (glm::distance2(glm::vec3(-PI), _fbxJoint->rotationMin) > EPSILON || - glm::distance2(glm::vec3(PI), _fbxJoint->rotationMax) > EPSILON ) { - // this joint has rotation constraints - _constraint = AngularConstraint::newAngularConstraint(_fbxJoint->rotationMin, _fbxJoint->rotationMax); - } -} - -void JointState::copyState(const JointState& state) { - _animationPriority = state._animationPriority; - _transformChanged = state._transformChanged; - _transform = state._transform; - _rotationIsValid = state._rotationIsValid; - _rotation = state._rotation; - _rotationInConstrainedFrame = state._rotationInConstrainedFrame; - _positionInParentFrame = state._positionInParentFrame; - _distanceToParent = state._distanceToParent; - - _visibleTransform = state._visibleTransform; - _visibleRotation = extractRotation(_visibleTransform); - _visibleRotationInConstrainedFrame = state._visibleRotationInConstrainedFrame; - // DO NOT copy _fbxJoint or _constraint -} - -void JointState::initTransform(const glm::mat4& parentTransform) { - computeTransform(parentTransform); - _positionInParentFrame = glm::inverse(extractRotation(parentTransform)) * (extractTranslation(_transform) - extractTranslation(parentTransform)); - _distanceToParent = glm::length(_positionInParentFrame); -} - -void JointState::computeTransform(const glm::mat4& parentTransform, bool parentTransformChanged, bool synchronousRotationCompute) { - if (!parentTransformChanged && !_transformChanged) { - return; - } - - glm::quat rotationInParentFrame = _fbxJoint->preRotation * _rotationInConstrainedFrame * _fbxJoint->postRotation; - glm::mat4 transformInParentFrame = _fbxJoint->preTransform * glm::mat4_cast(rotationInParentFrame) * _fbxJoint->postTransform; - glm::mat4 newTransform = parentTransform * glm::translate(_fbxJoint->translation) * transformInParentFrame; - - if (newTransform != _transform) { - _transform = newTransform; - _transformChanged = true; - _rotationIsValid = false; - } -} - -void JointState::computeVisibleTransform(const glm::mat4& parentTransform) { - glm::quat rotationInParentFrame = _fbxJoint->preRotation * _visibleRotationInConstrainedFrame * _fbxJoint->postRotation; - glm::mat4 transformInParentFrame = _fbxJoint->preTransform * glm::mat4_cast(rotationInParentFrame) * _fbxJoint->postTransform; - _visibleTransform = parentTransform * glm::translate(_fbxJoint->translation) * transformInParentFrame; - _visibleRotation = extractRotation(_visibleTransform); -} - -glm::quat JointState::getRotationInBindFrame() const { - return getRotation() * _fbxJoint->inverseBindRotation; -} - -glm::quat JointState::getRotationInParentFrame() const { - return _fbxJoint->preRotation * _rotationInConstrainedFrame * _fbxJoint->postRotation; -} - -glm::quat JointState::getVisibleRotationInParentFrame() const { - return _fbxJoint->preRotation * _visibleRotationInConstrainedFrame * _fbxJoint->postRotation; -} - -void JointState::restoreRotation(float fraction, float priority) { - assert(_fbxJoint != NULL); - if (priority == _animationPriority || _animationPriority == 0.0f) { - setRotationInConstrainedFrameInternal(safeMix(_rotationInConstrainedFrame, _fbxJoint->rotation, fraction)); - _animationPriority = 0.0f; - } -} - -void JointState::setRotationInBindFrame(const glm::quat& rotation, float priority, bool constrain) { - // rotation is from bind- to model-frame - assert(_fbxJoint != NULL); - if (priority >= _animationPriority) { - glm::quat targetRotation = _rotationInConstrainedFrame * glm::inverse(getRotation()) * rotation * glm::inverse(_fbxJoint->inverseBindRotation); - if (constrain && _constraint) { - _constraint->softClamp(targetRotation, _rotationInConstrainedFrame, 0.5f); - } - setRotationInConstrainedFrameInternal(targetRotation); - _animationPriority = priority; - } -} - -void JointState::clearTransformTranslation() { - _transform[3][0] = 0.0f; - _transform[3][1] = 0.0f; - _transform[3][2] = 0.0f; - _transformChanged = true; - _visibleTransform[3][0] = 0.0f; - _visibleTransform[3][1] = 0.0f; - _visibleTransform[3][2] = 0.0f; -} - -void JointState::applyRotationDelta(const glm::quat& delta, bool constrain, float priority) { - // NOTE: delta is in model-frame - assert(_fbxJoint != NULL); - if (priority < _animationPriority || delta.null) { - return; - } - _animationPriority = priority; - glm::quat targetRotation = _rotationInConstrainedFrame * glm::inverse(getRotation()) * delta * getRotation(); - if (!constrain || _constraint == NULL) { - // no constraints - _rotationInConstrainedFrame = targetRotation; - _transformChanged = true; - - _rotation = delta * getRotation(); - return; - } - setRotationInConstrainedFrameInternal(targetRotation); -} - -/// Applies delta rotation to joint but mixes a little bit of the default pose as well. -/// This helps keep an IK solution stable. -void JointState::mixRotationDelta(const glm::quat& delta, float mixFactor, float priority) { - // NOTE: delta is in model-frame - assert(_fbxJoint != NULL); - if (priority < _animationPriority) { - return; - } - _animationPriority = priority; - glm::quat targetRotation = _rotationInConstrainedFrame * glm::inverse(getRotation()) * delta * getRotation(); - if (mixFactor > 0.0f && mixFactor <= 1.0f) { - targetRotation = safeMix(targetRotation, _fbxJoint->rotation, mixFactor); - } - if (_constraint) { - _constraint->softClamp(targetRotation, _rotationInConstrainedFrame, 0.5f); - } - setRotationInConstrainedFrameInternal(targetRotation); -} - -void JointState::mixVisibleRotationDelta(const glm::quat& delta, float mixFactor) { - // NOTE: delta is in model-frame - assert(_fbxJoint != NULL); - glm::quat targetRotation = _visibleRotationInConstrainedFrame * glm::inverse(_visibleRotation) * delta * _visibleRotation; - if (mixFactor > 0.0f && mixFactor <= 1.0f) { - //targetRotation = safeMix(targetRotation, _fbxJoint->rotation, mixFactor); - targetRotation = safeMix(targetRotation, _rotationInConstrainedFrame, mixFactor); - } - setVisibleRotationInConstrainedFrame(targetRotation); -} - -glm::quat JointState::computeParentRotation() const { - // R = Rp * Rpre * r * Rpost - // Rp = R * (Rpre * r * Rpost)^ - return getRotation() * glm::inverse(_fbxJoint->preRotation * _rotationInConstrainedFrame * _fbxJoint->postRotation); -} - -glm::quat JointState::computeVisibleParentRotation() const { - return _visibleRotation * glm::inverse(_fbxJoint->preRotation * _visibleRotationInConstrainedFrame * _fbxJoint->postRotation); -} - -void JointState::setRotationInConstrainedFrame(glm::quat targetRotation, float priority, bool constrain) { - if (priority >= _animationPriority || _animationPriority == 0.0f) { - if (constrain && _constraint) { - _constraint->softClamp(targetRotation, _rotationInConstrainedFrame, 0.5f); - } - setRotationInConstrainedFrameInternal(targetRotation); - _animationPriority = priority; - } -} - -void JointState::setRotationInConstrainedFrameInternal(const glm::quat& targetRotation) { - glm::quat parentRotation = computeParentRotation(); - _rotationInConstrainedFrame = targetRotation; - _transformChanged = true; - // R' = Rp * Rpre * r' * Rpost - _rotation = parentRotation * _fbxJoint->preRotation * _rotationInConstrainedFrame * _fbxJoint->postRotation; -} - -void JointState::setVisibleRotationInConstrainedFrame(const glm::quat& targetRotation) { - glm::quat parentRotation = computeVisibleParentRotation(); - _visibleRotationInConstrainedFrame = targetRotation; - _visibleRotation = parentRotation * _fbxJoint->preRotation * _visibleRotationInConstrainedFrame * _fbxJoint->postRotation; -} - -const bool JointState::rotationIsDefault(const glm::quat& rotation, float tolerance) const { - glm::quat defaultRotation = _fbxJoint->rotation; - return glm::abs(rotation.x - defaultRotation.x) < tolerance && - glm::abs(rotation.y - defaultRotation.y) < tolerance && - glm::abs(rotation.z - defaultRotation.z) < tolerance && - glm::abs(rotation.w - defaultRotation.w) < tolerance; -} - -glm::quat JointState::getDefaultRotationInParentFrame() const { - // NOTE: the result is constant and could be cached in the FBXJoint - return _fbxJoint->preRotation * _fbxJoint->rotation * _fbxJoint->postRotation; -} - -const glm::vec3& JointState::getDefaultTranslationInConstrainedFrame() const { - assert(_fbxJoint != NULL); - return _fbxJoint->translation; -} - -void JointState::slaveVisibleTransform() { - _visibleTransform = _transform; - _visibleRotation = getRotation(); - _visibleRotationInConstrainedFrame = _rotationInConstrainedFrame; -} diff --git a/interface/src/renderer/JointState.h b/interface/src/renderer/JointState.h deleted file mode 100644 index b502083463..0000000000 --- a/interface/src/renderer/JointState.h +++ /dev/null @@ -1,129 +0,0 @@ -// -// JointState.h -// interface/src/renderer -// -// Created by Andrzej Kapolka on 10/18/13. -// Copyright 2013 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 -// - -#ifndef hifi_JointState_h -#define hifi_JointState_h - -#include -#include -#include - -#include -#include - -const float DEFAULT_PRIORITY = 3.0f; - -class AngularConstraint; - -class JointState { -public: - JointState(); - JointState(const JointState& other); - ~JointState(); - - void setFBXJoint(const FBXJoint* joint); - const FBXJoint& getFBXJoint() const { return *_fbxJoint; } - - void buildConstraint(); - void copyState(const JointState& state); - - void initTransform(const glm::mat4& parentTransform); - // if synchronousRotationCompute is true, then _transform is still computed synchronously, - // but _rotation will be asynchronously extracted - void computeTransform(const glm::mat4& parentTransform, bool parentTransformChanged = true, bool synchronousRotationCompute = false); - - void computeVisibleTransform(const glm::mat4& parentTransform); - const glm::mat4& getVisibleTransform() const { return _visibleTransform; } - glm::quat getVisibleRotation() const { return _visibleRotation; } - glm::vec3 getVisiblePosition() const { return extractTranslation(_visibleTransform); } - - const glm::mat4& getTransform() const { return _transform; } - void resetTransformChanged() { _transformChanged = false; } - bool getTransformChanged() const { return _transformChanged; } - - glm::quat getRotation() const; - glm::vec3 getPosition() const { return extractTranslation(_transform); } - - /// \return rotation from bind to model frame - glm::quat getRotationInBindFrame() const; - - glm::quat getRotationInParentFrame() const; - glm::quat getVisibleRotationInParentFrame() const; - const glm::vec3& getPositionInParentFrame() const { return _positionInParentFrame; } - float getDistanceToParent() const { return _distanceToParent; } - - int getParentIndex() const { return _fbxJoint->parentIndex; } - - /// \param delta is in the model-frame - void applyRotationDelta(const glm::quat& delta, bool constrain = true, float priority = 1.0f); - - /// Applies delta rotation to joint but mixes a little bit of the default pose as well. - /// This helps keep an IK solution stable. - /// \param delta rotation change in model-frame - /// \param mixFactor fraction in range [0,1] of how much default pose to blend in (0 is none, 1 is all) - /// \param priority priority level of this animation blend - void mixRotationDelta(const glm::quat& delta, float mixFactor, float priority = 1.0f); - void mixVisibleRotationDelta(const glm::quat& delta, float mixFactor); - - /// Blends a fraciton of default pose into joint rotation. - /// \param fraction fraction in range [0,1] of how much default pose to blend in (0 is none, 1 is all) - /// \param priority priority level of this animation blend - void restoreRotation(float fraction, float priority); - - /// \param rotation is from bind- to model-frame - /// computes and sets new _rotationInConstrainedFrame - /// NOTE: the JointState's model-frame transform/rotation are NOT updated! - void setRotationInBindFrame(const glm::quat& rotation, float priority, bool constrain = false); - - void setRotationInConstrainedFrame(glm::quat targetRotation, float priority, bool constrain = false); - void setVisibleRotationInConstrainedFrame(const glm::quat& targetRotation); - const glm::quat& getRotationInConstrainedFrame() const { return _rotationInConstrainedFrame; } - const glm::quat& getVisibleRotationInConstrainedFrame() const { return _visibleRotationInConstrainedFrame; } - - const bool rotationIsDefault(const glm::quat& rotation, float tolerance = EPSILON) const; - - glm::quat getDefaultRotationInParentFrame() const; - const glm::vec3& getDefaultTranslationInConstrainedFrame() const; - - - void clearTransformTranslation(); - - void slaveVisibleTransform(); - - float _animationPriority; // the priority of the animation affecting this joint - - /// \return parent model-frame rotation - // (used to keep _rotation consistent when modifying _rotationInWorldFrame directly) - glm::quat computeParentRotation() const; - glm::quat computeVisibleParentRotation() const; - -private: - void setRotationInConstrainedFrameInternal(const glm::quat& targetRotation); - /// debug helper function - void loadBindRotation(); - - bool _transformChanged; - glm::mat4 _transform; // joint- to model-frame - bool _rotationIsValid; - glm::quat _rotation; // joint- to model-frame - glm::quat _rotationInConstrainedFrame; // rotation in frame where angular constraints would be applied - glm::vec3 _positionInParentFrame; // only changes when the Model is scaled - float _distanceToParent; - - glm::mat4 _visibleTransform; - glm::quat _visibleRotation; - glm::quat _visibleRotationInConstrainedFrame; - - const FBXJoint* _fbxJoint; // JointState does NOT own its FBXJoint - AngularConstraint* _constraint; // JointState owns its AngularConstraint -}; - -#endif // hifi_JointState_h From cd95f7bd23a0d43088cbefdbd442ce63341bc185 Mon Sep 17 00:00:00 2001 From: DaveDubUK Date: Tue, 16 Dec 2014 13:20:11 +0000 Subject: [PATCH 29/46] Window.nonBlockingForm active status was not being tested correctly. Was causing unexpected fail on second attempt to show form --- interface/src/scripting/WindowScriptingInterface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/scripting/WindowScriptingInterface.cpp b/interface/src/scripting/WindowScriptingInterface.cpp index 591ae87560..bbb4e695e7 100644 --- a/interface/src/scripting/WindowScriptingInterface.cpp +++ b/interface/src/scripting/WindowScriptingInterface.cpp @@ -200,7 +200,7 @@ void WindowScriptingInterface::showNonBlockingForm(const QString& title, QScript } // what should we do if someone calls us while we still think we have a dialog showing??? - if (_editDialog) { + if (_nonBlockingFormActive) { qDebug() << "Show Non-Blocking Form called when form already active."; return; } From 9493440d323f65b33f5c60d28fd9b75dd3a91959 Mon Sep 17 00:00:00 2001 From: DaveDubUK Date: Tue, 16 Dec 2014 13:33:10 +0000 Subject: [PATCH 30/46] Window.nonBlockingForm-fix --- interface/src/scripting/WindowScriptingInterface.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/interface/src/scripting/WindowScriptingInterface.cpp b/interface/src/scripting/WindowScriptingInterface.cpp index bbb4e695e7..fa6de82bfe 100644 --- a/interface/src/scripting/WindowScriptingInterface.cpp +++ b/interface/src/scripting/WindowScriptingInterface.cpp @@ -201,6 +201,7 @@ void WindowScriptingInterface::showNonBlockingForm(const QString& title, QScript // what should we do if someone calls us while we still think we have a dialog showing??? if (_nonBlockingFormActive) { + qDebug() << "Show Non-Blocking Form called when form already active."; return; } From 7ab9dfbfe1ab1cf8010cf50a4035d04c111e3e04 Mon Sep 17 00:00:00 2001 From: DaveDubUK Date: Tue, 16 Dec 2014 14:48:28 +0000 Subject: [PATCH 31/46] Window.nonBlockingForm-fix --- interface/src/scripting/WindowScriptingInterface.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/interface/src/scripting/WindowScriptingInterface.cpp b/interface/src/scripting/WindowScriptingInterface.cpp index fa6de82bfe..bbb4e695e7 100644 --- a/interface/src/scripting/WindowScriptingInterface.cpp +++ b/interface/src/scripting/WindowScriptingInterface.cpp @@ -201,7 +201,6 @@ void WindowScriptingInterface::showNonBlockingForm(const QString& title, QScript // what should we do if someone calls us while we still think we have a dialog showing??? if (_nonBlockingFormActive) { - qDebug() << "Show Non-Blocking Form called when form already active."; return; } From 4d79a08533534458491c110db6eadd21968c0397 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 16 Dec 2014 10:32:03 -0800 Subject: [PATCH 32/46] remove Application dependencies from AmbientOcclusion and DeferredLightingEffect --- interface/src/Application.cpp | 12 +++++-- interface/src/Application.h | 11 ++++-- .../src/renderer/AmbientOcclusionEffect.cpp | 9 +++-- .../src/renderer/AmbientOcclusionEffect.h | 6 ++-- .../src/renderer/DeferredLightingEffect.cpp | 23 ++++++------ .../src/renderer/DeferredLightingEffect.h | 5 ++- .../render-utils/src/ViewStateInterface.h | 36 +++++++++++++++++++ 7 files changed, 78 insertions(+), 24 deletions(-) create mode 100644 libraries/render-utils/src/ViewStateInterface.h diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 5f0f4a700a..57b3b57224 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1914,8 +1914,8 @@ void Application::init() { _environment.init(); - _deferredLightingEffect.init(); - _ambientOcclusionEffect.init(); + _deferredLightingEffect.init(this); + _ambientOcclusionEffect.init(this); // TODO: move _myAvatar out of Application. Move relevant code to MyAvataar or AvatarManager _avatarManager.init(); @@ -3235,6 +3235,14 @@ void Application::computeOffAxisFrustum(float& left, float& right, float& bottom } } +bool Application::getShadowsEnabled() { + return Menu::getInstance()->getShadowsEnabled(); +} + +bool Application::getCascadeShadowsEnabled() { + return Menu::getInstance()->isOptionChecked(MenuOption::CascadedShadows); +} + glm::vec2 Application::getScaledScreenPoint(glm::vec2 projectedPoint) { float horizontalScale = _glWidget->getDeviceWidth() / 2.0f; float verticalScale = _glWidget->getDeviceHeight() / 2.0f; diff --git a/interface/src/Application.h b/interface/src/Application.h index 992d8d31d3..9ca363254a 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -42,6 +42,7 @@ #include #include #include +#include #include #include "MainWindow.h" @@ -128,7 +129,7 @@ static const quint64 TOO_LONG_SINCE_LAST_SEND_DOWNSTREAM_AUDIO_STATS = 1 * USECS static const QString INFO_HELP_PATH = "html/interface-welcome-allsvg.html"; static const QString INFO_EDIT_ENTITIES_PATH = "html/edit-entities-commands.html"; -class Application : public QApplication { +class Application : public QApplication, public ViewStateInterface { Q_OBJECT friend class OctreePacketProcessor; @@ -276,12 +277,16 @@ public: void getModelViewMatrix(glm::dmat4* modelViewMatrix); void getProjectionMatrix(glm::dmat4* projectionMatrix); - const glm::vec3& getShadowDistances() const { return _shadowDistances; } + virtual const glm::vec3& getShadowDistances() const { return _shadowDistances; } /// Computes the off-axis frustum parameters for the view frustum, taking mirroring into account. - void computeOffAxisFrustum(float& left, float& right, float& bottom, float& top, float& nearVal, + virtual void computeOffAxisFrustum(float& left, float& right, float& bottom, float& top, float& nearVal, float& farVal, glm::vec4& nearClipPlane, glm::vec4& farClipPlane) const; + virtual ViewFrustum* getCurrentViewFrustum() { return getDisplayViewFrustum(); } + virtual bool getShadowsEnabled(); + virtual bool getCascadeShadowsEnabled(); + NodeBounds& getNodeBoundsDisplay() { return _nodeBoundsDisplay; } FileLogger* getLogger() { return _logger; } diff --git a/interface/src/renderer/AmbientOcclusionEffect.cpp b/interface/src/renderer/AmbientOcclusionEffect.cpp index bcae662085..4362d21645 100644 --- a/interface/src/renderer/AmbientOcclusionEffect.cpp +++ b/interface/src/renderer/AmbientOcclusionEffect.cpp @@ -21,15 +21,15 @@ #include #include #include - -#include "Application.h" +#include #include "AmbientOcclusionEffect.h" const int ROTATION_WIDTH = 4; const int ROTATION_HEIGHT = 4; -void AmbientOcclusionEffect::init() { +void AmbientOcclusionEffect::init(ViewStateInterface* viewState) { + _viewState = viewState; // we will use this for view state services _occlusionProgram = new ProgramObject(); _occlusionProgram->addShaderFromSourceFile(QGLShader::Vertex, PathUtils::resourcesPath() @@ -111,8 +111,7 @@ void AmbientOcclusionEffect::render() { float left, right, bottom, top, nearVal, farVal; glm::vec4 nearClipPlane, farClipPlane; - Application::getInstance()->computeOffAxisFrustum( - left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane); + _viewState->computeOffAxisFrustum(left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane); int viewport[4]; glGetIntegerv(GL_VIEWPORT, viewport); diff --git a/interface/src/renderer/AmbientOcclusionEffect.h b/interface/src/renderer/AmbientOcclusionEffect.h index 3b22c7629a..444b76a3c9 100644 --- a/interface/src/renderer/AmbientOcclusionEffect.h +++ b/interface/src/renderer/AmbientOcclusionEffect.h @@ -12,6 +12,8 @@ #ifndef hifi_AmbientOcclusionEffect_h #define hifi_AmbientOcclusionEffect_h +#include + class ProgramObject; /// A screen space ambient occlusion effect. See John Chapman's tutorial at @@ -19,8 +21,7 @@ class ProgramObject; class AmbientOcclusionEffect { public: - void init(); - + void init(ViewStateInterface* viewState); void render(); private: @@ -38,6 +39,7 @@ private: int _blurScaleLocation; GLuint _rotationTextureID; + ViewStateInterface* _viewState; }; #endif // hifi_AmbientOcclusionEffect_h diff --git a/interface/src/renderer/DeferredLightingEffect.cpp b/interface/src/renderer/DeferredLightingEffect.cpp index 18a93aa042..d3145b9d5d 100644 --- a/interface/src/renderer/DeferredLightingEffect.cpp +++ b/interface/src/renderer/DeferredLightingEffect.cpp @@ -14,14 +14,17 @@ #include +#include +#include #include #include #include +#include -#include "Application.h" #include "DeferredLightingEffect.h" -void DeferredLightingEffect::init() { +void DeferredLightingEffect::init(ViewStateInterface* viewState) { + _viewState = viewState; _simpleProgram.addShaderFromSourceFile(QGLShader::Vertex, PathUtils::resourcesPath() + "shaders/simple.vert"); _simpleProgram.addShaderFromSourceFile(QGLShader::Fragment, PathUtils::resourcesPath() + "shaders/simple.frag"); _simpleProgram.link(); @@ -176,19 +179,18 @@ void DeferredLightingEffect::render() { ProgramObject* program = &_directionalLight; const LightLocations* locations = &_directionalLightLocations; - bool shadowsEnabled = Menu::getInstance()->getShadowsEnabled(); - if (shadowsEnabled) { + bool shadowsEnabled = _viewState->getShadowsEnabled(); + if (shadowsEnabled) { glActiveTexture(GL_TEXTURE4); glBindTexture(GL_TEXTURE_2D, textureCache->getShadowDepthTextureID()); program = &_directionalLightShadowMap; locations = &_directionalLightShadowMapLocations; - if (Menu::getInstance()->isOptionChecked(MenuOption::CascadedShadows)) { + if (_viewState->getCascadeShadowsEnabled()) { program = &_directionalLightCascadedShadowMap; locations = &_directionalLightCascadedShadowMapLocations; _directionalLightCascadedShadowMap.bind(); - _directionalLightCascadedShadowMap.setUniform(locations->shadowDistances, - Application::getInstance()->getShadowDistances()); + _directionalLightCascadedShadowMap.setUniform(locations->shadowDistances, _viewState->getShadowDistances()); } else { program->bind(); @@ -202,8 +204,7 @@ void DeferredLightingEffect::render() { float left, right, bottom, top, nearVal, farVal; glm::vec4 nearClipPlane, farClipPlane; - Application::getInstance()->computeOffAxisFrustum( - left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane); + _viewState->computeOffAxisFrustum(left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane); program->setUniformValue(locations->nearLocation, nearVal); float depthScale = (farVal - nearVal) / farVal; program->setUniformValue(locations->depthScale, depthScale); @@ -238,8 +239,8 @@ void DeferredLightingEffect::render() { // enlarge the scales slightly to account for tesselation const float SCALE_EXPANSION = 0.05f; - const glm::vec3& eyePoint = Application::getInstance()->getDisplayViewFrustum()->getPosition(); - float nearRadius = glm::distance(eyePoint, Application::getInstance()->getDisplayViewFrustum()->getNearTopLeft()); + const glm::vec3& eyePoint = _viewState->getCurrentViewFrustum()->getPosition(); + float nearRadius = glm::distance(eyePoint, _viewState->getCurrentViewFrustum()->getNearTopLeft()); GeometryCache* geometryCache = DependencyManager::get(); diff --git a/interface/src/renderer/DeferredLightingEffect.h b/interface/src/renderer/DeferredLightingEffect.h index effcea27d2..40182e0917 100644 --- a/interface/src/renderer/DeferredLightingEffect.h +++ b/interface/src/renderer/DeferredLightingEffect.h @@ -16,6 +16,7 @@ #include #include +#include class PostLightingRenderable; @@ -23,7 +24,7 @@ class PostLightingRenderable; class DeferredLightingEffect { public: - void init(); + void init(ViewStateInterface* viewState); /// Returns a reference to a simple program suitable for rendering static /// untextured geometry (such as that generated by glutSolidSphere, etc.) @@ -118,6 +119,8 @@ private: QVector _pointLights; QVector _spotLights; QVector _postLightingRenderables; + + ViewStateInterface* _viewState; }; /// Simple interface for objects that require something to be rendered after deferred lighting. diff --git a/libraries/render-utils/src/ViewStateInterface.h b/libraries/render-utils/src/ViewStateInterface.h new file mode 100644 index 0000000000..decccdc401 --- /dev/null +++ b/libraries/render-utils/src/ViewStateInterface.h @@ -0,0 +1,36 @@ +// +// ViewStateInterface.h +// interface/src/renderer +// +// Created by Brad Hefta-Gaub on 12/16/14. +// Copyright 2014 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 +// + +#ifndef hifi_ViewStateInterface_h +#define hifi_ViewStateInterface_h + +#include + +/// Interface provided by Application to other objects that need access to the current view state details +class ViewStateInterface { +public: + + /// Returns the shadow distances for the current view state + virtual const glm::vec3& getShadowDistances() const = 0; + + /// Computes the off-axis frustum parameters for the view frustum, taking mirroring into account. + virtual void computeOffAxisFrustum(float& left, float& right, float& bottom, float& top, float& nearVal, + float& farVal, glm::vec4& nearClipPlane, glm::vec4& farClipPlane) const = 0; + + /// gets the current view frustum for rendering the view state + virtual ViewFrustum* getCurrentViewFrustum() = 0; + + virtual bool getShadowsEnabled() = 0; + virtual bool getCascadeShadowsEnabled() = 0; +}; + + +#endif // hifi_ViewStateInterface_h From fc1e1ecfc04fdc3475fb990c3e19f29e343b978d Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 16 Dec 2014 11:27:44 -0800 Subject: [PATCH 33/46] move DeferredLightingEffect and AmbientOcclusionEffect to libraries, make them DependencyManager enabled --- interface/src/Application.cpp | 13 +++++--- interface/src/Application.h | 7 ---- interface/src/MetavoxelSystem.cpp | 9 ++--- interface/src/avatar/Avatar.cpp | 3 +- .../src/entities/RenderableBoxEntityItem.cpp | 7 ++-- .../entities/RenderableLightEntityItem.cpp | 33 ++++++++++--------- .../entities/RenderableModelEntityItem.cpp | 7 ++-- .../entities/RenderableSphereEntityItem.cpp | 5 +-- interface/src/renderer/Model.cpp | 3 +- interface/src/ui/overlays/Cube3DOverlay.cpp | 7 ++-- interface/src/ui/overlays/Sphere3DOverlay.cpp | 1 - .../src}/AmbientOcclusionEffect.cpp | 10 +++--- .../src}/AmbientOcclusionEffect.h | 9 +++-- .../src}/DeferredLightingEffect.cpp | 20 ++++++++--- .../src}/DeferredLightingEffect.h | 11 +++++-- 15 files changed, 84 insertions(+), 61 deletions(-) rename {interface/src/renderer => libraries/render-utils/src}/AmbientOcclusionEffect.cpp (98%) rename {interface/src/renderer => libraries/render-utils/src}/AmbientOcclusionEffect.h (81%) rename {interface/src/renderer => libraries/render-utils/src}/DeferredLightingEffect.cpp (98%) rename {interface/src/renderer => libraries/render-utils/src}/DeferredLightingEffect.h (94%) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 57b3b57224..c9309616ae 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -54,7 +54,9 @@ #include #include +#include #include +#include #include #include #include @@ -110,6 +112,7 @@ #include "ui/TextRenderer.h" + using namespace std; // Starfield information @@ -1914,8 +1917,8 @@ void Application::init() { _environment.init(); - _deferredLightingEffect.init(this); - _ambientOcclusionEffect.init(this); + DependencyManager::get()->init(this); + DependencyManager::get()->init(this); // TODO: move _myAvatar out of Application. Move relevant code to MyAvataar or AvatarManager _avatarManager.init(); @@ -3070,7 +3073,7 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly, RenderAr glEnable(GL_LIGHTING); glEnable(GL_DEPTH_TEST); - _deferredLightingEffect.prepare(); + DependencyManager::get()->prepare(); if (!selfAvatarOnly) { // draw a red sphere @@ -3113,7 +3116,7 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly, RenderAr PerformanceTimer perfTimer("ambientOcclusion"); PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "Application::displaySide() ... AmbientOcclusion..."); - _ambientOcclusionEffect.render(); + DependencyManager::get()->render(); } } @@ -3130,7 +3133,7 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly, RenderAr { PROFILE_RANGE("DeferredLighting"); PerformanceTimer perfTimer("lighting"); - _deferredLightingEffect.render(); + DependencyManager::get()->render(); } { diff --git a/interface/src/Application.h b/interface/src/Application.h index 9ca363254a..6b5bcc0770 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -62,8 +62,6 @@ #include "devices/PrioVR.h" #include "devices/SixenseManager.h" #include "entities/EntityTreeRenderer.h" -#include "renderer/AmbientOcclusionEffect.h" -#include "renderer/DeferredLightingEffect.h" #include "scripting/ControllerScriptingInterface.h" #include "ui/BandwidthDialog.h" #include "ui/BandwidthMeter.h" @@ -250,7 +248,6 @@ public: ToolWindow* getToolWindow() { return _toolWindow ; } - DeferredLightingEffect* getDeferredLightingEffect() { return &_deferredLightingEffect; } ControllerScriptingInterface* getControllerScriptingInterface() { return &_controllerScriptingInterface; } AvatarManager& getAvatarManager() { return _avatarManager; } @@ -569,10 +566,6 @@ private: QSet _keysPressed; - - DeferredLightingEffect _deferredLightingEffect; - AmbientOcclusionEffect _ambientOcclusionEffect; - Audio _audio; bool _enableProcessVoxelsThread; diff --git a/interface/src/MetavoxelSystem.cpp b/interface/src/MetavoxelSystem.cpp index 824f1e3313..d34bc4a594 100644 --- a/interface/src/MetavoxelSystem.cpp +++ b/interface/src/MetavoxelSystem.cpp @@ -21,6 +21,7 @@ #include +#include #include #include @@ -470,7 +471,7 @@ void MetavoxelSystem::render() { glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glNormal3f(0.0f, 1.0f, 0.0f); - Application::getInstance()->getDeferredLightingEffect()->bindSimpleProgram(); + DependencyManager::get()->bindSimpleProgram(); foreach (const HermiteBatch& batch, _hermiteBatches) { batch.vertexBuffer->bind(); @@ -482,7 +483,7 @@ void MetavoxelSystem::render() { batch.vertexBuffer->release(); } - Application::getInstance()->getDeferredLightingEffect()->releaseSimpleProgram(); + DependencyManager::get()->releaseSimpleProgram(); glDisableClientState(GL_VERTEX_ARRAY); @@ -1981,7 +1982,7 @@ void SphereRenderer::render(const MetavoxelLOD& lod, bool contained, bool cursor glm::vec3 axis = glm::axis(rotation); glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); - Application::getInstance()->getDeferredLightingEffect()->renderSolidSphere(sphere->getScale(), 32, 32); + DependencyManager::get()->renderSolidSphere(sphere->getScale(), 32, 32); glPopMatrix(); } @@ -2002,7 +2003,7 @@ void CuboidRenderer::render(const MetavoxelLOD& lod, bool contained, bool cursor glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); glScalef(1.0f, cuboid->getAspectY(), cuboid->getAspectZ()); - Application::getInstance()->getDeferredLightingEffect()->renderSolidCube(cuboid->getScale() * 2.0f); + DependencyManager::get()->renderSolidCube(cuboid->getScale() * 2.0f); glPopMatrix(); } diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 4b7c5dfdf3..51fde3df43 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -364,7 +365,7 @@ void Avatar::render(const glm::vec3& cameraPosition, RenderMode renderMode, bool glm::quat orientation = getOrientation(); foreach (const AvatarManager::LocalLight& light, Application::getInstance()->getAvatarManager().getLocalLights()) { glm::vec3 direction = orientation * light.direction; - Application::getInstance()->getDeferredLightingEffect()->addSpotLight(position - direction * distance, + DependencyManager::get()->addSpotLight(position - direction * distance, distance * 2.0f, glm::vec3(), light.color, light.color, 1.0f, 0.5f, 0.0f, direction, LIGHT_EXPONENT, LIGHT_CUTOFF); } diff --git a/interface/src/entities/RenderableBoxEntityItem.cpp b/interface/src/entities/RenderableBoxEntityItem.cpp index 1cc1f72e93..f7b403bff2 100644 --- a/interface/src/entities/RenderableBoxEntityItem.cpp +++ b/interface/src/entities/RenderableBoxEntityItem.cpp @@ -16,6 +16,7 @@ #include "InterfaceConfig.h" #include +#include #include #include @@ -53,7 +54,7 @@ void RenderableBoxEntityItem::render(RenderArgs* args) { glm::vec3 positionToCenter = center - position; glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z); glScalef(dimensions.x, dimensions.y, dimensions.z); - Application::getInstance()->getDeferredLightingEffect()->renderSolidCube(1.0f); + DependencyManager::get()->renderSolidCube(1.0f); glPopMatrix(); glPopMatrix(); } else { @@ -90,7 +91,7 @@ void RenderableBoxEntityItem::render(RenderArgs* args) { glColor4f(getColor()[RED_INDEX] / MAX_COLOR, getColor()[GREEN_INDEX] / MAX_COLOR, getColor()[BLUE_INDEX] / MAX_COLOR, getLocalRenderAlpha()); - Application::getInstance()->getDeferredLightingEffect()->bindSimpleProgram(); + DependencyManager::get()->bindSimpleProgram(); glPushMatrix(); glTranslatef(position.x, position.y, position.z); @@ -105,7 +106,7 @@ void RenderableBoxEntityItem::render(RenderArgs* args) { glPopMatrix(); glPopMatrix(); - Application::getInstance()->getDeferredLightingEffect()->releaseSimpleProgram(); + DependencyManager::get()->releaseSimpleProgram(); glDisableClientState(GL_VERTEX_ARRAY); // disable vertex arrays glDisableClientState(GL_NORMAL_ARRAY); diff --git a/interface/src/entities/RenderableLightEntityItem.cpp b/interface/src/entities/RenderableLightEntityItem.cpp index 77dbb5da0b..48996d5b4c 100644 --- a/interface/src/entities/RenderableLightEntityItem.cpp +++ b/interface/src/entities/RenderableLightEntityItem.cpp @@ -15,6 +15,7 @@ #include "InterfaceConfig.h" +#include #include #include @@ -65,30 +66,30 @@ void RenderableLightEntityItem::render(RenderArgs* args) { if (!disableLights) { if (_isSpotlight) { - Application::getInstance()->getDeferredLightingEffect()->addSpotLight(position, largestDiameter / 2.0f, + DependencyManager::get()->addSpotLight(position, largestDiameter / 2.0f, ambient, diffuse, specular, constantAttenuation, linearAttenuation, quadraticAttenuation, direction, exponent, cutoff); } else { - Application::getInstance()->getDeferredLightingEffect()->addPointLight(position, largestDiameter / 2.0f, + DependencyManager::get()->addPointLight(position, largestDiameter / 2.0f, ambient, diffuse, specular, constantAttenuation, linearAttenuation, quadraticAttenuation); } } - bool wantDebug = false; - if (wantDebug) { - glColor4f(diffuseR, diffuseG, diffuseB, 1.0f); - glPushMatrix(); - glTranslatef(position.x, position.y, position.z); - glm::vec3 axis = glm::axis(rotation); - glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); - glPushMatrix(); - glm::vec3 positionToCenter = center - position; - glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z); - glScalef(dimensions.x, dimensions.y, dimensions.z); - Application::getInstance()->getDeferredLightingEffect()->renderWireSphere(0.5f, 15, 15); - glPopMatrix(); +#ifdef WANT_DEBUG + glColor4f(diffuseR, diffuseG, diffuseB, 1.0f); + glPushMatrix(); + glTranslatef(position.x, position.y, position.z); + glm::vec3 axis = glm::axis(rotation); + glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); + glPushMatrix(); + glm::vec3 positionToCenter = center - position; + glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z); + + glScalef(dimensions.x, dimensions.y, dimensions.z); + DependencyManager::get()->renderWireSphere(0.5f, 15, 15); glPopMatrix(); - } + glPopMatrix(); +#endif }; bool RenderableLightEntityItem::findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction, diff --git a/interface/src/entities/RenderableModelEntityItem.cpp b/interface/src/entities/RenderableModelEntityItem.cpp index 080162dc16..13bc097f27 100644 --- a/interface/src/entities/RenderableModelEntityItem.cpp +++ b/interface/src/entities/RenderableModelEntityItem.cpp @@ -16,6 +16,7 @@ #include "InterfaceConfig.h" #include +#include #include #include @@ -191,7 +192,7 @@ void RenderableModelEntityItem::render(RenderArgs* args) { glColor3ub(getColor()[RED_INDEX],getColor()[GREEN_INDEX],getColor()[BLUE_INDEX]); glPushMatrix(); glTranslatef(position.x, position.y, position.z); - Application::getInstance()->getDeferredLightingEffect()->renderWireCube(size); + DependencyManager::get()->renderWireCube(size); glPopMatrix(); } } else { @@ -199,7 +200,7 @@ void RenderableModelEntityItem::render(RenderArgs* args) { glColor3ub(getColor()[RED_INDEX],getColor()[GREEN_INDEX],getColor()[BLUE_INDEX]); glPushMatrix(); glTranslatef(position.x, position.y, position.z); - Application::getInstance()->getDeferredLightingEffect()->renderWireCube(size); + DependencyManager::get()->renderWireCube(size); glPopMatrix(); } } @@ -208,7 +209,7 @@ void RenderableModelEntityItem::render(RenderArgs* args) { glColor3ub(getColor()[RED_INDEX],getColor()[GREEN_INDEX],getColor()[BLUE_INDEX]); glPushMatrix(); glTranslatef(position.x, position.y, position.z); - Application::getInstance()->getDeferredLightingEffect()->renderWireCube(size); + DependencyManager::get()->renderWireCube(size); glPopMatrix(); } } diff --git a/interface/src/entities/RenderableSphereEntityItem.cpp b/interface/src/entities/RenderableSphereEntityItem.cpp index d561670be8..db10edca73 100644 --- a/interface/src/entities/RenderableSphereEntityItem.cpp +++ b/interface/src/entities/RenderableSphereEntityItem.cpp @@ -15,6 +15,8 @@ #include "InterfaceConfig.h" +#include +#include #include #include @@ -23,7 +25,6 @@ #include "EntityTreeRenderer.h" #include "RenderableSphereEntityItem.h" - EntityItem* RenderableSphereEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { return new RenderableSphereEntityItem(entityID, properties); } @@ -51,7 +52,7 @@ void RenderableSphereEntityItem::render(RenderArgs* args) { glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z); glScalef(dimensions.x, dimensions.y, dimensions.z); - Application::getInstance()->getDeferredLightingEffect()->renderSolidSphere(0.5f, 15, 15); + DependencyManager::get()->renderSolidSphere(0.5f, 15, 15); glPopMatrix(); glPopMatrix(); }; diff --git a/interface/src/renderer/Model.cpp b/interface/src/renderer/Model.cpp index 877f43a563..15db8e4361 100644 --- a/interface/src/renderer/Model.cpp +++ b/interface/src/renderer/Model.cpp @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -493,7 +494,7 @@ bool Model::renderTriangleProxies() { glPushMatrix(); glTranslatef(center.x, center.y, center.z); glScalef(dimensions.x, dimensions.y, dimensions.z); - Application::getInstance()->getDeferredLightingEffect()->renderWireCube(1.0f); + DependencyManager::get()->renderWireCube(1.0f); glPopMatrix(); } diff --git a/interface/src/ui/overlays/Cube3DOverlay.cpp b/interface/src/ui/overlays/Cube3DOverlay.cpp index f518c309a1..c61d68f05d 100644 --- a/interface/src/ui/overlays/Cube3DOverlay.cpp +++ b/interface/src/ui/overlays/Cube3DOverlay.cpp @@ -13,6 +13,7 @@ #include +#include #include #include #include @@ -75,7 +76,7 @@ void Cube3DOverlay::render(RenderArgs* args) { glPushMatrix(); glColor4f(1.0f, 1.0f, 1.0f, alpha); glScalef(dimensions.x * _borderSize, dimensions.y * _borderSize, dimensions.z * _borderSize); - Application::getInstance()->getDeferredLightingEffect()->renderSolidCube(1.0f); + DependencyManager::get()->renderSolidCube(1.0f); glPopMatrix(); glDepthMask(GL_TRUE); } @@ -83,7 +84,7 @@ void Cube3DOverlay::render(RenderArgs* args) { glPushMatrix(); glColor4f(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha); glScalef(dimensions.x, dimensions.y, dimensions.z); - Application::getInstance()->getDeferredLightingEffect()->renderSolidCube(1.0f); + DependencyManager::get()->renderSolidCube(1.0f); glPopMatrix(); } else { glLineWidth(_lineWidth); @@ -117,7 +118,7 @@ void Cube3DOverlay::render(RenderArgs* args) { } else { glScalef(dimensions.x, dimensions.y, dimensions.z); - Application::getInstance()->getDeferredLightingEffect()->renderWireCube(1.0f); + DependencyManager::get()->renderWireCube(1.0f); } } glPopMatrix(); diff --git a/interface/src/ui/overlays/Sphere3DOverlay.cpp b/interface/src/ui/overlays/Sphere3DOverlay.cpp index eb95672399..522902194f 100644 --- a/interface/src/ui/overlays/Sphere3DOverlay.cpp +++ b/interface/src/ui/overlays/Sphere3DOverlay.cpp @@ -62,7 +62,6 @@ void Sphere3DOverlay::render(RenderArgs* args) { glm::vec3 positionToCenter = center - position; glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z); glScalef(dimensions.x, dimensions.y, dimensions.z); - //Application::getInstance()->getDeferredLightingEffect()->renderSolidCube(1.0f); if (_isSolid) { DependencyManager::get()->renderSphere(1.0f, SLICES, SLICES); } else { diff --git a/interface/src/renderer/AmbientOcclusionEffect.cpp b/libraries/render-utils/src/AmbientOcclusionEffect.cpp similarity index 98% rename from interface/src/renderer/AmbientOcclusionEffect.cpp rename to libraries/render-utils/src/AmbientOcclusionEffect.cpp index 4362d21645..b9289204c7 100644 --- a/interface/src/renderer/AmbientOcclusionEffect.cpp +++ b/libraries/render-utils/src/AmbientOcclusionEffect.cpp @@ -10,20 +10,20 @@ // // include this before QOpenGLFramebufferObject, which includes an earlier version of OpenGL -#include "InterfaceConfig.h" +#include #include #include -#include #include -#include -#include #include -#include #include "AmbientOcclusionEffect.h" +#include "GlowEffect.h" +#include "ProgramObject.h" +#include "RenderUtil.h" +#include "TextureCache.h" const int ROTATION_WIDTH = 4; const int ROTATION_HEIGHT = 4; diff --git a/interface/src/renderer/AmbientOcclusionEffect.h b/libraries/render-utils/src/AmbientOcclusionEffect.h similarity index 81% rename from interface/src/renderer/AmbientOcclusionEffect.h rename to libraries/render-utils/src/AmbientOcclusionEffect.h index 444b76a3c9..1ee7269480 100644 --- a/interface/src/renderer/AmbientOcclusionEffect.h +++ b/libraries/render-utils/src/AmbientOcclusionEffect.h @@ -12,19 +12,24 @@ #ifndef hifi_AmbientOcclusionEffect_h #define hifi_AmbientOcclusionEffect_h -#include +#include + +#include "ViewStateInterface.h" class ProgramObject; /// A screen space ambient occlusion effect. See John Chapman's tutorial at /// http://john-chapman-graphics.blogspot.co.uk/2013/01/ssao-tutorial.html for reference. -class AmbientOcclusionEffect { +class AmbientOcclusionEffect: public DependencyManager::Dependency { public: void init(ViewStateInterface* viewState); void render(); private: + AmbientOcclusionEffect() {} + virtual ~AmbientOcclusionEffect() {} + friend class DependencyManager; ProgramObject* _occlusionProgram; int _nearLocation; diff --git a/interface/src/renderer/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp similarity index 98% rename from interface/src/renderer/DeferredLightingEffect.cpp rename to libraries/render-utils/src/DeferredLightingEffect.cpp index d3145b9d5d..ff2df95746 100644 --- a/interface/src/renderer/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -10,18 +10,28 @@ // // include this before QOpenGLFramebufferObject, which includes an earlier version of OpenGL -#include "InterfaceConfig.h" +#include + + +// TODO: remove these once we migrate away from GLUT calls +#if defined(__APPLE__) +#include +#else +#include +#endif #include -#include #include -#include #include -#include -#include + #include "DeferredLightingEffect.h" +#include "GeometryCache.h" +#include "GlowEffect.h" +#include "RenderUtil.h" +#include "TextureCache.h" + void DeferredLightingEffect::init(ViewStateInterface* viewState) { _viewState = viewState; diff --git a/interface/src/renderer/DeferredLightingEffect.h b/libraries/render-utils/src/DeferredLightingEffect.h similarity index 94% rename from interface/src/renderer/DeferredLightingEffect.h rename to libraries/render-utils/src/DeferredLightingEffect.h index 40182e0917..5dcd7d35f4 100644 --- a/interface/src/renderer/DeferredLightingEffect.h +++ b/libraries/render-utils/src/DeferredLightingEffect.h @@ -14,14 +14,16 @@ #include -#include +#include #include -#include + +#include "ProgramObject.h" +#include "ViewStateInterface.h" class PostLightingRenderable; /// Handles deferred lighting for the bits that require it (voxels, metavoxels...) -class DeferredLightingEffect { +class DeferredLightingEffect: public DependencyManager::Dependency { public: void init(ViewStateInterface* viewState); @@ -69,6 +71,9 @@ public: void render(); private: + DeferredLightingEffect() { } + virtual ~DeferredLightingEffect() { } + friend class DependencyManager; class LightLocations { public: From a9b3fdd3ebb6360a589e69f312bf73f807d1904a Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 16 Dec 2014 11:44:15 -0800 Subject: [PATCH 34/46] try this --- libraries/render-utils/src/DeferredLightingEffect.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index ff2df95746..f3bc0f9a22 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -16,6 +16,11 @@ // TODO: remove these once we migrate away from GLUT calls #if defined(__APPLE__) #include +#elif defined(WIN32) +#include +#include +#include +#include #else #include #endif From ec5c33feccf48c1071dbfef9027653ff86ab05cd Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 16 Dec 2014 11:57:06 -0800 Subject: [PATCH 35/46] try this --- libraries/render-utils/src/DeferredLightingEffect.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index f3bc0f9a22..a93f9fc89f 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -17,10 +17,7 @@ #if defined(__APPLE__) #include #elif defined(WIN32) -#include -#include -#include -#include + // nothing? #else #include #endif From ee34dfffc11ac48e7462af14f8876335c014a82b Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 16 Dec 2014 12:05:23 -0800 Subject: [PATCH 36/46] try this --- libraries/render-utils/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/render-utils/CMakeLists.txt b/libraries/render-utils/CMakeLists.txt index eb96e7c5ec..1a23f4c4f0 100644 --- a/libraries/render-utils/CMakeLists.txt +++ b/libraries/render-utils/CMakeLists.txt @@ -26,6 +26,7 @@ else (APPLE) # we're using static GLEW, so define GLEW_STATIC add_definitions(-DGLEW_STATIC) + target_link_libraries(${TARGET_NAME} "${GLEW_LIBRARIES}") endif() endif (APPLE) From 1ed2c62bbf7df6c9f5b5238138e2620e5f312ff5 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 16 Dec 2014 12:15:57 -0800 Subject: [PATCH 37/46] try this --- libraries/render-utils/CMakeLists.txt | 3 +++ libraries/render-utils/src/DeferredLightingEffect.cpp | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/libraries/render-utils/CMakeLists.txt b/libraries/render-utils/CMakeLists.txt index 1a23f4c4f0..0244fa91a6 100644 --- a/libraries/render-utils/CMakeLists.txt +++ b/libraries/render-utils/CMakeLists.txt @@ -24,6 +24,9 @@ else (APPLE) find_package(GLEW REQUIRED) include_directories(${GLEW_INCLUDE_DIRS}) + find_package(GLUT REQUIRED) + include_directories(SYSTEM "${GLUT_INCLUDE_DIRS}") + # we're using static GLEW, so define GLEW_STATIC add_definitions(-DGLEW_STATIC) target_link_libraries(${TARGET_NAME} "${GLEW_LIBRARIES}") diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index a93f9fc89f..9f54b25441 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -17,7 +17,7 @@ #if defined(__APPLE__) #include #elif defined(WIN32) - // nothing? +#include #else #include #endif From 58183515e6b33353f5125df90c8e9f83175c7938 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 16 Dec 2014 12:23:54 -0800 Subject: [PATCH 38/46] more windows shenanigans --- interface/src/renderer/Model.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/interface/src/renderer/Model.cpp b/interface/src/renderer/Model.cpp index 15db8e4361..56d7d30def 100644 --- a/interface/src/renderer/Model.cpp +++ b/interface/src/renderer/Model.cpp @@ -9,6 +9,8 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include + #include #include #include From 16c1e597f15f90cd15a837e85207c4944cfd06b6 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 16 Dec 2014 12:53:22 -0800 Subject: [PATCH 39/46] remove Application dependency from Model --- interface/src/Application.cpp | 2 ++ interface/src/Application.h | 5 +++-- interface/src/renderer/Model.cpp | 19 +++++++++++-------- interface/src/renderer/Model.h | 6 ++++++ .../render-utils/src/ViewStateInterface.h | 7 +++++++ 5 files changed, 29 insertions(+), 10 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index c9309616ae..02dae8e08e 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -429,6 +429,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : #endif this->installEventFilter(this); + + Model::setViewStateInterface(this); // The model class will sometimes need to know view state details from us } void Application::aboutToQuit() { diff --git a/interface/src/Application.h b/interface/src/Application.h index 6b5bcc0770..dea7c80940 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -232,7 +232,7 @@ public: const glm::vec3& getViewMatrixTranslation() const { return _viewMatrixTranslation; } void setViewMatrixTranslation(const glm::vec3& translation) { _viewMatrixTranslation = translation; } - const Transform& getViewTransform() const { return _viewTransform; } + virtual const Transform& getViewTransform() const { return _viewTransform; } void setViewTransform(const Transform& view); /// if you need to access the application settings, use lockSettings()/unlockSettings() @@ -255,7 +255,7 @@ public: void controlledBroadcastToNodes(const QByteArray& packet, const NodeSet& destinationNodeTypes); - void setupWorldLight(); + virtual void setupWorldLight(); QImage renderAvatarBillboard(); @@ -283,6 +283,7 @@ public: virtual ViewFrustum* getCurrentViewFrustum() { return getDisplayViewFrustum(); } virtual bool getShadowsEnabled(); virtual bool getCascadeShadowsEnabled(); + virtual QThread* getMainThread() { return thread(); } NodeBounds& getNodeBoundsDisplay() { return _nodeBoundsDisplay; } diff --git a/interface/src/renderer/Model.cpp b/interface/src/renderer/Model.cpp index 56d7d30def..7fe024b8fe 100644 --- a/interface/src/renderer/Model.cpp +++ b/interface/src/renderer/Model.cpp @@ -22,6 +22,8 @@ #include #include #include +#include +#include #include #include #include @@ -29,11 +31,10 @@ #include #include "AnimationHandle.h" -#include "Application.h" +#include "Menu.h" #include "Model.h" -#include "gpu/Batch.h" -#include "gpu/GLBackend.h" + #define GLBATCH( call ) batch._##call //#define GLBATCH( call ) call @@ -63,7 +64,7 @@ Model::Model(QObject* parent) : _meshGroupsKnown(false) { // we may have been created in the network thread, but we live in the main thread - moveToThread(Application::getInstance()->thread()); + moveToThread(_viewState->getMainThread()); } Model::~Model() { @@ -109,6 +110,8 @@ Model::SkinLocations Model::_skinNormalSpecularMapLocations; Model::SkinLocations Model::_skinShadowLocations; Model::SkinLocations Model::_skinTranslucentLocations; +ViewStateInterface* Model::_viewState = NULL; + void Model::setScale(const glm::vec3& scale) { setScaleInternal(scale); // if anyone sets scale manually, then we are no longer scaled to fit @@ -727,7 +730,7 @@ bool Model::renderCore(float alpha, RenderMode mode, RenderArgs* args) { if (_transforms.empty()) { _transforms.push_back(Transform()); } - _transforms[0] = Application::getInstance()->getViewTransform(); + _transforms[0] = _viewState->getViewTransform(); // apply entity translation offset to the viewTransform in one go (it's a preTranslate because viewTransform goes from world to eye space) _transforms[0].preTranslate(-_translation); @@ -870,7 +873,7 @@ bool Model::renderCore(float alpha, RenderMode mode, RenderArgs* args) { } // restore all the default material settings - Application::getInstance()->setupWorldLight(); + _viewState->setupWorldLight(); if (args) { args->_translucentMeshPartsRendered = translucentMeshPartsRendered; @@ -1670,7 +1673,7 @@ void Model::setupBatchTransform(gpu::Batch& batch) { if (_transforms.empty()) { _transforms.push_back(Transform()); } - _transforms[0] = Application::getInstance()->getViewTransform(); + _transforms[0] = _viewState->getViewTransform(); _transforms[0].preTranslate(-_translation); batch.setViewTransform(_transforms[0]); } @@ -1830,7 +1833,7 @@ void Model::endScene(RenderMode mode, RenderArgs* args) { } // restore all the default material settings - Application::getInstance()->setupWorldLight(); + _viewState->setupWorldLight(); } diff --git a/interface/src/renderer/Model.h b/interface/src/renderer/Model.h index 8000e7385b..2c6b0bd6ae 100644 --- a/interface/src/renderer/Model.h +++ b/interface/src/renderer/Model.h @@ -28,6 +28,7 @@ #include #include #include +#include #include "AnimationHandle.h" @@ -46,6 +47,8 @@ class Model : public QObject, public PhysicsEntity { public: + static void setViewStateInterface(ViewStateInterface* viewState) { _viewState = viewState; } + Model(QObject* parent = NULL); virtual ~Model(); @@ -455,6 +458,9 @@ private: static int renderMeshesForModelsInScene(gpu::Batch& batch, RenderMode mode, bool translucent, float alphaThreshold, bool hasLightmap, bool hasTangents, bool hasSpecular, bool isSkinned, RenderArgs* args); + + static ViewStateInterface* _viewState; + }; Q_DECLARE_METATYPE(QPointer) diff --git a/libraries/render-utils/src/ViewStateInterface.h b/libraries/render-utils/src/ViewStateInterface.h index decccdc401..83501589d0 100644 --- a/libraries/render-utils/src/ViewStateInterface.h +++ b/libraries/render-utils/src/ViewStateInterface.h @@ -14,6 +14,9 @@ #include +class Transform; +class QThread; + /// Interface provided by Application to other objects that need access to the current view state details class ViewStateInterface { public: @@ -30,6 +33,10 @@ public: virtual bool getShadowsEnabled() = 0; virtual bool getCascadeShadowsEnabled() = 0; + + virtual QThread* getMainThread() = 0; + virtual const Transform& getViewTransform() const = 0; + virtual void setupWorldLight() = 0; }; From efa8a752f20fb9092df8279f4adbeabeb210f846 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 16 Dec 2014 13:14:57 -0800 Subject: [PATCH 40/46] remove dependency on Menu from Model --- interface/src/Application.cpp | 8 ++++++-- interface/src/Application.h | 1 + interface/src/renderer/Model.cpp | 16 ++++++++++------ libraries/render-utils/src/ViewStateInterface.h | 1 + 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 02dae8e08e..8b3c5a2fa1 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -191,6 +191,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : _isVSyncOn(true), _aboutToQuit(false) { + Model::setViewStateInterface(this); // The model class will sometimes need to know view state details from us + // read the ApplicationInfo.ini file for Name/Version/Domain information QSettings applicationInfo(PathUtils::resourcesPath() + "info/ApplicationInfo.ini", QSettings::IniFormat); @@ -429,8 +431,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : #endif this->installEventFilter(this); - - Model::setViewStateInterface(this); // The model class will sometimes need to know view state details from us } void Application::aboutToQuit() { @@ -2939,6 +2939,10 @@ void Application::setupWorldLight() { glMateriali(GL_FRONT, GL_SHININESS, 96); } +bool Application::shouldRenderMesh(float largestDimension, float distanceToCamera) { + return Menu::getInstance()->shouldRenderMesh(largestDimension, distanceToCamera); +} + QImage Application::renderAvatarBillboard() { DependencyManager::get()->getPrimaryFramebufferObject()->bind(); diff --git a/interface/src/Application.h b/interface/src/Application.h index dea7c80940..9aca90fac8 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -256,6 +256,7 @@ public: void controlledBroadcastToNodes(const QByteArray& packet, const NodeSet& destinationNodeTypes); virtual void setupWorldLight(); + virtual bool shouldRenderMesh(float largestDimension, float distanceToCamera); QImage renderAvatarBillboard(); diff --git a/interface/src/renderer/Model.cpp b/interface/src/renderer/Model.cpp index 7fe024b8fe..2faeeeea55 100644 --- a/interface/src/renderer/Model.cpp +++ b/interface/src/renderer/Model.cpp @@ -31,7 +31,6 @@ #include #include "AnimationHandle.h" -#include "Menu.h" #include "Model.h" @@ -64,7 +63,9 @@ Model::Model(QObject* parent) : _meshGroupsKnown(false) { // we may have been created in the network thread, but we live in the main thread - moveToThread(_viewState->getMainThread()); + if (_viewState) { + moveToThread(_viewState->getMainThread()); + } } Model::~Model() { @@ -720,6 +721,9 @@ bool Model::render(float alpha, RenderMode mode, RenderArgs* args) { bool Model::renderCore(float alpha, RenderMode mode, RenderArgs* args) { PROFILE_RANGE(__FUNCTION__); + if (!_viewState) { + return false; + } // Let's introduce a gpu::Batch to capture all the calls to the graphics api _renderBatch.clear(); @@ -2329,9 +2333,9 @@ int Model::renderMeshes(gpu::Batch& batch, RenderMode mode, bool translucent, fl int Model::renderMeshesFromList(QVector& list, gpu::Batch& batch, RenderMode mode, bool translucent, float alphaThreshold, RenderArgs* args, Locations* locations, SkinLocations* skinLocations) { PROFILE_RANGE(__FUNCTION__); - bool dontCullOutOfViewMeshParts = Menu::getInstance()->isOptionChecked(MenuOption::DontCullOutOfViewMeshParts); - bool cullTooSmallMeshParts = !Menu::getInstance()->isOptionChecked(MenuOption::DontCullTooSmallMeshParts); - bool dontReduceMaterialSwitches = Menu::getInstance()->isOptionChecked(MenuOption::DontReduceMaterialSwitches); + bool dontCullOutOfViewMeshParts = false; // Menu::getInstance()->isOptionChecked(MenuOption::DontCullOutOfViewMeshParts); + bool cullTooSmallMeshParts = true; // !Menu::getInstance()->isOptionChecked(MenuOption::DontCullTooSmallMeshParts); + bool dontReduceMaterialSwitches = false; // Menu::getInstance()->isOptionChecked(MenuOption::DontReduceMaterialSwitches); TextureCache* textureCache = DependencyManager::get(); GlowEffect* glowEffect = DependencyManager::get(); @@ -2373,7 +2377,7 @@ int Model::renderMeshesFromList(QVector& list, gpu::Batch& batch, RenderMod args->_viewFrustum->boxInFrustum(_calculatedMeshBoxes.at(i)) != ViewFrustum::OUTSIDE; if (shouldRender && cullTooSmallMeshParts) { float distance = args->_viewFrustum->distanceToCamera(_calculatedMeshBoxes.at(i).calcCenter()); - shouldRender = Menu::getInstance()->shouldRenderMesh(_calculatedMeshBoxes.at(i).getLargestDimension(), + shouldRender = !_viewState ? false : _viewState->shouldRenderMesh(_calculatedMeshBoxes.at(i).getLargestDimension(), distance); if (!shouldRender) { args->_meshesTooSmall++; diff --git a/libraries/render-utils/src/ViewStateInterface.h b/libraries/render-utils/src/ViewStateInterface.h index 83501589d0..9110eb8eb6 100644 --- a/libraries/render-utils/src/ViewStateInterface.h +++ b/libraries/render-utils/src/ViewStateInterface.h @@ -37,6 +37,7 @@ public: virtual QThread* getMainThread() = 0; virtual const Transform& getViewTransform() const = 0; virtual void setupWorldLight() = 0; + virtual bool shouldRenderMesh(float largestDimension, float distanceToCamera) = 0; }; From 85c89517349790edd7510c00457bb21fb97d82fd Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 16 Dec 2014 13:57:22 -0800 Subject: [PATCH 41/46] really remove the debug settings from Model rendering --- examples/developerMenuItems.js | 4 ---- interface/src/Menu.h | 3 --- interface/src/renderer/Model.cpp | 10 +++------- 3 files changed, 3 insertions(+), 14 deletions(-) diff --git a/examples/developerMenuItems.js b/examples/developerMenuItems.js index 34bd3b3a75..3a274c7083 100644 --- a/examples/developerMenuItems.js +++ b/examples/developerMenuItems.js @@ -23,12 +23,8 @@ function setupMenus() { Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Display Model Element Bounds", isCheckable: true, isChecked: false }); Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Display Model Element Children", isCheckable: true, isChecked: false }); Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Don't Do Precision Picking", isCheckable: true, isChecked: false }); - Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Don't Attempt to Reduce Material Switches", isCheckable: true, isChecked: false }); Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Don't Attempt Render Entities as Scene", isCheckable: true, isChecked: false }); Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Don't Do Precision Picking", isCheckable: true, isChecked: false }); - Menu.addMenu("Developer > Entities > Culling"); - Menu.addMenuItem({ menuName: "Developer > Entities > Culling", menuItemName: "Don't Cull Out Of View Mesh Parts", isCheckable: true, isChecked: false }); - Menu.addMenuItem({ menuName: "Developer > Entities > Culling", menuItemName: "Don't Cull Too Small Mesh Parts", isCheckable: true, isChecked: false }); Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Disable Light Entities", isCheckable: true, isChecked: false }); } } diff --git a/interface/src/Menu.h b/interface/src/Menu.h index e2c687fff1..77936e7ac4 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -361,9 +361,6 @@ namespace MenuOption { const QString Collisions = "Collisions"; const QString Console = "Console..."; const QString ControlWithSpeech = "Control With Speech"; - const QString DontCullOutOfViewMeshParts = "Don't Cull Out Of View Mesh Parts"; - const QString DontCullTooSmallMeshParts = "Don't Cull Too Small Mesh Parts"; - const QString DontReduceMaterialSwitches = "Don't Attempt to Reduce Material Switches"; const QString DontRenderEntitiesAsScene = "Don't Render Entities as Scene"; const QString DontDoPrecisionPicking = "Don't Do Precision Picking"; const QString DecreaseAvatarSize = "Decrease Avatar Size"; diff --git a/interface/src/renderer/Model.cpp b/interface/src/renderer/Model.cpp index 2faeeeea55..5f160d2e8d 100644 --- a/interface/src/renderer/Model.cpp +++ b/interface/src/renderer/Model.cpp @@ -2333,9 +2333,6 @@ int Model::renderMeshes(gpu::Batch& batch, RenderMode mode, bool translucent, fl int Model::renderMeshesFromList(QVector& list, gpu::Batch& batch, RenderMode mode, bool translucent, float alphaThreshold, RenderArgs* args, Locations* locations, SkinLocations* skinLocations) { PROFILE_RANGE(__FUNCTION__); - bool dontCullOutOfViewMeshParts = false; // Menu::getInstance()->isOptionChecked(MenuOption::DontCullOutOfViewMeshParts); - bool cullTooSmallMeshParts = true; // !Menu::getInstance()->isOptionChecked(MenuOption::DontCullTooSmallMeshParts); - bool dontReduceMaterialSwitches = false; // Menu::getInstance()->isOptionChecked(MenuOption::DontReduceMaterialSwitches); TextureCache* textureCache = DependencyManager::get(); GlowEffect* glowEffect = DependencyManager::get(); @@ -2373,9 +2370,8 @@ int Model::renderMeshesFromList(QVector& list, gpu::Batch& batch, RenderMod args->_meshesConsidered++; if (args->_viewFrustum) { - shouldRender = dontCullOutOfViewMeshParts || - args->_viewFrustum->boxInFrustum(_calculatedMeshBoxes.at(i)) != ViewFrustum::OUTSIDE; - if (shouldRender && cullTooSmallMeshParts) { + shouldRender = args->_viewFrustum->boxInFrustum(_calculatedMeshBoxes.at(i)) != ViewFrustum::OUTSIDE; + if (shouldRender) { float distance = args->_viewFrustum->distanceToCamera(_calculatedMeshBoxes.at(i).calcCenter()); shouldRender = !_viewState ? false : _viewState->shouldRenderMesh(_calculatedMeshBoxes.at(i).getLargestDimension(), distance); @@ -2433,7 +2429,7 @@ int Model::renderMeshesFromList(QVector& list, gpu::Batch& batch, RenderMod GLBATCH(glBindTexture)(GL_TEXTURE_2D, 0); } else { - if (dontReduceMaterialSwitches || lastMaterialID != part.materialID) { + if (lastMaterialID != part.materialID) { const bool wantDebug = false; if (wantDebug) { qDebug() << "Material Changed ---------------------------------------------"; From 89101872bbc94998a92bd41a8da543963450a11b Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 16 Dec 2014 14:04:39 -0800 Subject: [PATCH 42/46] move Model and AnimationHandle to libraries --- interface/src/avatar/FaceModel.h | 2 +- interface/src/avatar/Hand.h | 5 +++-- interface/src/avatar/ModelReferential.cpp | 3 +-- interface/src/avatar/MyAvatar.cpp | 2 +- interface/src/avatar/SkeletonModel.h | 3 ++- interface/src/avatar/SkeletonRagdoll.cpp | 2 +- interface/src/entities/EntityTreeRenderer.h | 2 +- interface/src/ui/overlays/ModelOverlay.h | 4 ++-- .../render-utils/src}/AnimationHandle.cpp | 0 .../render-utils/src}/AnimationHandle.h | 0 .../render-utils/src}/Model.cpp | 4 ++-- .../render-utils/src}/Model.h | 14 +++++++------- 12 files changed, 21 insertions(+), 20 deletions(-) rename {interface/src/renderer => libraries/render-utils/src}/AnimationHandle.cpp (100%) rename {interface/src/renderer => libraries/render-utils/src}/AnimationHandle.h (100%) rename {interface/src/renderer => libraries/render-utils/src}/Model.cpp (99%) rename {interface/src/renderer => libraries/render-utils/src}/Model.h (99%) diff --git a/interface/src/avatar/FaceModel.h b/interface/src/avatar/FaceModel.h index eaaa07e635..6c14beb587 100644 --- a/interface/src/avatar/FaceModel.h +++ b/interface/src/avatar/FaceModel.h @@ -12,7 +12,7 @@ #ifndef hifi_FaceModel_h #define hifi_FaceModel_h -#include "renderer/Model.h" +#include class Head; diff --git a/interface/src/avatar/Hand.h b/interface/src/avatar/Hand.h index ed2fa3e1ab..688af151b4 100644 --- a/interface/src/avatar/Hand.h +++ b/interface/src/avatar/Hand.h @@ -11,6 +11,8 @@ #ifndef hifi_Hand_h #define hifi_Hand_h +#include "InterfaceConfig.h" + #include #include @@ -22,9 +24,8 @@ #include #include #include +#include -#include "InterfaceConfig.h" -#include "renderer/Model.h" #include "world.h" diff --git a/interface/src/avatar/ModelReferential.cpp b/interface/src/avatar/ModelReferential.cpp index df6e272da7..5b72fddae7 100644 --- a/interface/src/avatar/ModelReferential.cpp +++ b/interface/src/avatar/ModelReferential.cpp @@ -10,9 +10,8 @@ // #include - #include -#include "../renderer/Model.h" +#include #include "ModelReferential.h" diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 057b1f1fc6..6976e26e86 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -40,7 +41,6 @@ #include "Recorder.h" #include "devices/Faceshift.h" #include "devices/OculusManager.h" -#include "renderer/AnimationHandle.h" #include "ui/TextRenderer.h" using namespace std; diff --git a/interface/src/avatar/SkeletonModel.h b/interface/src/avatar/SkeletonModel.h index ea732acfd5..0956d27b3f 100644 --- a/interface/src/avatar/SkeletonModel.h +++ b/interface/src/avatar/SkeletonModel.h @@ -12,9 +12,10 @@ #ifndef hifi_SkeletonModel_h #define hifi_SkeletonModel_h -#include "renderer/Model.h" #include +#include + #include "SkeletonRagdoll.h" class Avatar; diff --git a/interface/src/avatar/SkeletonRagdoll.cpp b/interface/src/avatar/SkeletonRagdoll.cpp index 7c0e056826..c944e0bd45 100644 --- a/interface/src/avatar/SkeletonRagdoll.cpp +++ b/interface/src/avatar/SkeletonRagdoll.cpp @@ -11,10 +11,10 @@ #include #include +#include #include "SkeletonRagdoll.h" #include "MuscleConstraint.h" -#include "../renderer/Model.h" SkeletonRagdoll::SkeletonRagdoll(Model* model) : Ragdoll(), _model(model) { assert(_model); diff --git a/interface/src/entities/EntityTreeRenderer.h b/interface/src/entities/EntityTreeRenderer.h index a8695db36d..87f45d5f56 100644 --- a/interface/src/entities/EntityTreeRenderer.h +++ b/interface/src/entities/EntityTreeRenderer.h @@ -17,6 +17,7 @@ #include #include // for RayToEntityIntersectionResult +#include #include #include #include @@ -25,7 +26,6 @@ #include #include -#include "renderer/Model.h" class EntityScriptDetails { public: diff --git a/interface/src/ui/overlays/ModelOverlay.h b/interface/src/ui/overlays/ModelOverlay.h index 567498feb5..8cd095f778 100644 --- a/interface/src/ui/overlays/ModelOverlay.h +++ b/interface/src/ui/overlays/ModelOverlay.h @@ -12,9 +12,9 @@ #ifndef hifi_ModelOverlay_h #define hifi_ModelOverlay_h -#include "Base3DOverlay.h" +#include -#include "../../renderer/Model.h" +#include "Base3DOverlay.h" class ModelOverlay : public Base3DOverlay { Q_OBJECT diff --git a/interface/src/renderer/AnimationHandle.cpp b/libraries/render-utils/src/AnimationHandle.cpp similarity index 100% rename from interface/src/renderer/AnimationHandle.cpp rename to libraries/render-utils/src/AnimationHandle.cpp diff --git a/interface/src/renderer/AnimationHandle.h b/libraries/render-utils/src/AnimationHandle.h similarity index 100% rename from interface/src/renderer/AnimationHandle.h rename to libraries/render-utils/src/AnimationHandle.h diff --git a/interface/src/renderer/Model.cpp b/libraries/render-utils/src/Model.cpp similarity index 99% rename from interface/src/renderer/Model.cpp rename to libraries/render-utils/src/Model.cpp index 5f160d2e8d..16e6b1bf02 100644 --- a/interface/src/renderer/Model.cpp +++ b/libraries/render-utils/src/Model.cpp @@ -19,9 +19,7 @@ #include #include -#include #include -#include #include #include #include @@ -31,6 +29,8 @@ #include #include "AnimationHandle.h" +#include "DeferredLightingEffect.h" +#include "GlowEffect.h" #include "Model.h" diff --git a/interface/src/renderer/Model.h b/libraries/render-utils/src/Model.h similarity index 99% rename from interface/src/renderer/Model.h rename to libraries/render-utils/src/Model.h index 2c6b0bd6ae..d24f349f81 100644 --- a/interface/src/renderer/Model.h +++ b/libraries/render-utils/src/Model.h @@ -21,16 +21,18 @@ #include #include #include -#include #include -#include +#include +#include #include -#include -#include #include -#include #include "AnimationHandle.h" +#include "GeometryCache.h" +#include "JointState.h" +#include "ProgramObject.h" +#include "TextureCache.h" +#include "ViewStateInterface.h" class QScriptEngine; @@ -38,8 +40,6 @@ class Shape; #include "RenderArgs.h" class ViewFrustum; -#include "gpu/Stream.h" -#include "gpu/Batch.h" /// A generic 3D model displaying geometry loaded from a URL. class Model : public QObject, public PhysicsEntity { From b449f650a0c4ac9bffef4511cf187be1fa13f2cd Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 16 Dec 2014 14:22:02 -0800 Subject: [PATCH 43/46] more Model cleanup --- interface/src/MetavoxelSystem.cpp | 2 +- interface/src/entities/RenderableLightEntityItem.cpp | 1 - interface/src/entities/RenderableModelEntityItem.h | 7 ++----- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/interface/src/MetavoxelSystem.cpp b/interface/src/MetavoxelSystem.cpp index d34bc4a594..443c55359b 100644 --- a/interface/src/MetavoxelSystem.cpp +++ b/interface/src/MetavoxelSystem.cpp @@ -23,6 +23,7 @@ #include #include +#include #include #include @@ -32,7 +33,6 @@ #include "Application.h" #include "MetavoxelSystem.h" -#include "renderer/Model.h" REGISTER_META_OBJECT(DefaultMetavoxelRendererImplementation) REGISTER_META_OBJECT(SphereRenderer) diff --git a/interface/src/entities/RenderableLightEntityItem.cpp b/interface/src/entities/RenderableLightEntityItem.cpp index 48996d5b4c..58a3c3f18a 100644 --- a/interface/src/entities/RenderableLightEntityItem.cpp +++ b/interface/src/entities/RenderableLightEntityItem.cpp @@ -34,7 +34,6 @@ void RenderableLightEntityItem::render(RenderArgs* args) { PerformanceTimer perfTimer("RenderableLightEntityItem::render"); assert(getType() == EntityTypes::Light); glm::vec3 position = getPositionInMeters(); - glm::vec3 center = getCenterInMeters(); glm::vec3 dimensions = getDimensions() * (float)TREE_SCALE; glm::quat rotation = getRotation(); float largestDiameter = glm::max(dimensions.x, dimensions.y, dimensions.z); diff --git a/interface/src/entities/RenderableModelEntityItem.h b/interface/src/entities/RenderableModelEntityItem.h index 2401d0ea64..2c194467d2 100644 --- a/interface/src/entities/RenderableModelEntityItem.h +++ b/interface/src/entities/RenderableModelEntityItem.h @@ -16,6 +16,8 @@ #include #include +#include +#include #include #include #include @@ -23,11 +25,6 @@ #include #include -#include "renderer/Model.h" - -#include -#include - class RenderableModelEntityItem : public ModelEntityItem { public: static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties); From 77bc00e4105f0aae31d64abb817516d8375e0a94 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 16 Dec 2014 18:34:39 -0800 Subject: [PATCH 44/46] a simple model for persistent scripts in domain-server --- .../resources/describe-settings.json | 27 +++++++++ domain-server/resources/web/js/settings.js | 8 ++- domain-server/src/DomainServer.cpp | 59 ++++++++++--------- domain-server/src/DomainServer.h | 2 +- 4 files changed, 64 insertions(+), 32 deletions(-) diff --git a/domain-server/resources/describe-settings.json b/domain-server/resources/describe-settings.json index 50de26c518..ae6f116537 100644 --- a/domain-server/resources/describe-settings.json +++ b/domain-server/resources/describe-settings.json @@ -76,6 +76,33 @@ } ] }, + { + "name": "scripts", + "label": "Scripts", + "settings": [ + { + "name": "persistent_scripts", + "type": "table", + "label": "Persistent Scripts", + "help": "Add the URLs for scripts that you would like to ensure are always running in your domain.", + "columns": [ + { + "name": "url", + "label": "Script URL" + }, + { + "name": "num_instances", + "label": "# instances", + "default": 1 + }, + { + "name": "pool", + "label": "Pool" + } + ] + } + ] + }, { "name": "audio_env", "label": "Audio Environment", diff --git a/domain-server/resources/web/js/settings.js b/domain-server/resources/web/js/settings.js index a27965abce..141bd72a26 100644 --- a/domain-server/resources/web/js/settings.js +++ b/domain-server/resources/web/js/settings.js @@ -363,7 +363,8 @@ function makeTableInputs(setting) { _.each(setting.columns, function(col) { html += "\ - \ + \ " }) @@ -389,8 +390,9 @@ function badgeSidebarForDifferences(changedElement) { // badge for any settings we have that are not the same or are not present in initialValues for (var setting in panelJSON) { - if (!_.isEqual(panelJSON[setting], initialPanelJSON[setting]) - && (panelJSON[setting] !== "" || _.has(initialPanelJSON, setting))) { + if ((!_.has(initialPanelJSON, setting) && panelJSON[setting] !== "") || + (!_.isEqual(panelJSON[setting], initialPanelJSON[setting]) + && (panelJSON[setting] !== "" || _.has(initialPanelJSON, setting)))) { badgeValue += 1 } } diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index bf9505671b..470b69be01 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -233,6 +233,9 @@ void DomainServer::setupNodeListAndAssignments(const QUuid& sessionUUID) { parseAssignmentConfigs(parsedTypes); populateDefaultStaticAssignmentsExcludingTypes(parsedTypes); + + // check for scripts the user wants to persist from their domain-server config + populateStaticScriptedAssignmentsFromSettings(); LimitedNodeList* nodeList = LimitedNodeList::createInstance(domainServerPort, domainServerDTLSPort); @@ -451,8 +454,6 @@ void DomainServer::parseAssignmentConfigs(QSet& excludedTypes) if (assignmentType != Assignment::AgentType) { createStaticAssignmentsForType(assignmentType, assignmentList); - } else { - createScriptedAssignmentsFromList(assignmentList); } excludedTypes.insert(assignmentType); @@ -468,35 +469,37 @@ void DomainServer::addStaticAssignmentToAssignmentHash(Assignment* newAssignment _allAssignments.insert(newAssignment->getUUID(), SharedAssignmentPointer(newAssignment)); } -void DomainServer::createScriptedAssignmentsFromList(const QVariantList &configList) { - foreach(const QVariant& configVariant, configList) { - if (configVariant.canConvert(QMetaType::QVariantMap)) { - QVariantMap configMap = configVariant.toMap(); - - // make sure we were passed a URL, otherwise this is an invalid scripted assignment - const QString ASSIGNMENT_URL_KEY = "url"; - QString assignmentURL = configMap[ASSIGNMENT_URL_KEY].toString(); - - if (!assignmentURL.isEmpty()) { - // check the json for a pool - const QString ASSIGNMENT_POOL_KEY = "pool"; - QString assignmentPool = configMap[ASSIGNMENT_POOL_KEY].toString(); - - // check for a number of instances, if not passed then default is 1 - const QString ASSIGNMENT_INSTANCES_KEY = "instances"; - int numInstances = configMap[ASSIGNMENT_INSTANCES_KEY].toInt(); - numInstances = (numInstances == 0 ? 1 : numInstances); - - qDebug() << "Adding a static scripted assignment from" << assignmentURL; - - for (int i = 0; i < numInstances; i++) { +void DomainServer::populateStaticScriptedAssignmentsFromSettings() { + const QString PERSISTENT_SCRIPTS_KEY_PATH = "scripts.persistent_scripts"; + const QVariant* persistentScriptsVariant = valueForKeyPath(_settingsManager.getSettingsMap(), PERSISTENT_SCRIPTS_KEY_PATH); + + if (persistentScriptsVariant) { + QVariantList persistentScriptsList = persistentScriptsVariant->toList(); + foreach(const QVariant& persistentScriptVariant, persistentScriptsList) { + QVariantMap persistentScript = persistentScriptVariant.toMap(); + + const QString PERSISTENT_SCRIPT_URL_KEY = "url"; + const QString PERSISTENT_SCRIPT_NUM_INSTANCES_KEY = "num_instances"; + const QString PERSISTENT_SCRIPT_POOL_KEY = "pool"; + + if (persistentScript.contains(PERSISTENT_SCRIPT_URL_KEY)) { + // check how many instances of this script to add + + int numInstances = persistentScript[PERSISTENT_SCRIPT_NUM_INSTANCES_KEY].toInt(); + QString scriptURL = persistentScript[PERSISTENT_SCRIPT_URL_KEY].toString(); + + QString scriptPool = persistentScript.value(PERSISTENT_SCRIPT_POOL_KEY).toString(); + + qDebug() << "Adding" << numInstances << "of persistent script at URL" << scriptURL << "- pool" << scriptPool; + + for (int i = 0; i < numInstances; ++i) { // add a scripted assignment to the queue for this instance Assignment* scriptAssignment = new Assignment(Assignment::CreateCommand, Assignment::AgentType, - assignmentPool); - scriptAssignment->setPayload(assignmentURL.toUtf8()); - - // scripts passed on CL or via JSON are static - so they are added back to the queue if the node dies + scriptPool); + scriptAssignment->setPayload(scriptURL.toUtf8()); + + // add it to static hash so we know we have to keep giving it back out addStaticAssignmentToAssignmentHash(scriptAssignment); } } diff --git a/domain-server/src/DomainServer.h b/domain-server/src/DomainServer.h index 76ab562f74..f910534eb1 100644 --- a/domain-server/src/DomainServer.h +++ b/domain-server/src/DomainServer.h @@ -100,9 +100,9 @@ private: void parseAssignmentConfigs(QSet& excludedTypes); void addStaticAssignmentToAssignmentHash(Assignment* newAssignment); - void createScriptedAssignmentsFromList(const QVariantList& configList); void createStaticAssignmentsForType(Assignment::Type type, const QVariantList& configList); void populateDefaultStaticAssignmentsExcludingTypes(const QSet& excludedTypes); + void populateStaticScriptedAssignmentsFromSettings(); SharedAssignmentPointer matchingQueuedAssignmentForCheckIn(const QUuid& checkInUUID, NodeType_t nodeType); SharedAssignmentPointer deployableAssignmentForRequest(const Assignment& requestAssignment); From b95eac759e5550330d25474bd52237ab3e1f2b76 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 17 Dec 2014 08:52:48 -0800 Subject: [PATCH 45/46] Fix minor grid spacing not updating --- examples/libraries/gridTool.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/libraries/gridTool.js b/examples/libraries/gridTool.js index 622822e108..b1c258dc31 100644 --- a/examples/libraries/gridTool.js +++ b/examples/libraries/gridTool.js @@ -195,7 +195,7 @@ Grid = function(opts) { Overlays.editOverlay(gridOverlay, { position: { x: origin.y, y: origin.y, z: -origin.y }, visible: that.visible && that.enabled, - minorGridSpacing: minorGridSpacing, + minorGridWidth: minorGridSpacing, majorGridEvery: majorGridEvery, color: gridColor, alpha: gridAlpha, From e36ee2a96130328ecddf1704edfc498905245e6c Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Wed, 17 Dec 2014 12:19:34 -0800 Subject: [PATCH 46/46] more correct creation and edit times for entities --- libraries/entities/src/EntityItem.cpp | 75 ++++++++++++------- libraries/entities/src/EntityItem.h | 5 +- libraries/entities/src/EntityItemProperties.h | 4 +- libraries/entities/src/EntityTypes.cpp | 8 +- 4 files changed, 55 insertions(+), 37 deletions(-) diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index b271439662..22cfeb3674 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -53,14 +53,13 @@ void EntityItem::initFromEntityItemID(const EntityItemID& entityItemID) { _creatorTokenID = entityItemID.creatorTokenID; // init values with defaults before calling setProperties - //uint64_t now = usecTimestampNow(); _lastEdited = 0; _lastEditedFromRemote = 0; _lastEditedFromRemoteInRemoteTime = 0; _lastSimulated = 0; _lastUpdated = 0; - _created = 0; // TODO: when do we actually want to make this "now" + _created = usecTimestampNow(); _changedOnServer = 0; _position = glm::vec3(0,0,0); @@ -99,16 +98,20 @@ EntityItem::EntityItem(const EntityItemID& entityItemID) { EntityItem::EntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) { _type = EntityTypes::Unknown; - _lastEdited = 0; + quint64 now = usecTimestampNow(); + _created = properties.getCreated() < now ? properties.getCreated() : now; + _lastEdited = _lastEditedFromRemote = _lastSimulated = _lastUpdated = _lastEditedFromRemoteInRemoteTime = _created; _lastEditedFromRemote = 0; _lastEditedFromRemoteInRemoteTime = 0; _lastSimulated = 0; _lastUpdated = 0; - _created = properties.getCreated(); _dirtyFlags = 0; _changedOnServer = 0; initFromEntityItemID(entityItemID); setProperties(properties, true); // force copy + if (_lastEdited == 0) { + _lastEdited = _created; + } } EntityPropertyFlags EntityItem::getEntityProperties(EncodeBitstreamParams& params) const { @@ -367,7 +370,12 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef bytesRead += sizeof(createdFromBuffer); createdFromBuffer -= clockSkew; - _created = createdFromBuffer; // TODO: do we ever want to discard this??? + if (createdFromBuffer < _created) { + // the server claims that this entity has an older creation time + // so we accept it and clear _lastEdited + _created = createdFromBuffer; + _lastEdited = 0; + } if (wantDebug) { quint64 lastEdited = getLastEdited(); @@ -416,14 +424,14 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef if (fromSameServerEdit) { // If this is from the same sever packet, then check against any local changes since we got // the most recent packet from this server time - if (_lastEdited > _lastEditedFromRemote) { + if (_lastEdited >= _lastEditedFromRemote) { ignoreServerPacket = true; } } else { // If this isn't from the same sever packet, then honor our skew adjusted times... // If we've changed our local tree more recently than the new data from this packet // then we will not be changing our values, instead we just read and skip the data - if (_lastEdited > lastEditedFromBufferAdjusted) { + if (_lastEdited >= lastEditedFromBufferAdjusted) { ignoreServerPacket = true; } } @@ -439,7 +447,8 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef qDebug() << "USING NEW data from server!!! ****************"; } - _lastEdited = lastEditedFromBufferAdjusted; + // don't allow _lastEdited to be in the future + _lastEdited = lastEditedFromBufferAdjusted < now ? lastEditedFromBufferAdjusted : now; _lastEditedFromRemote = now; _lastEditedFromRemoteInRemoteTime = lastEditedFromBuffer; @@ -451,7 +460,8 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef ByteCountCoded updateDeltaCoder = encodedUpdateDelta; quint64 updateDelta = updateDeltaCoder; if (overwriteLocalData) { - _lastSimulated = _lastUpdated = lastEditedFromBufferAdjusted + updateDelta; // don't adjust for clock skew since we already did that for _lastEdited + _lastUpdated = lastEditedFromBufferAdjusted + updateDelta; // don't adjust for clock skew since we already did that for _lastEdited + _lastSimulated = now; if (wantDebug) { qDebug() << "_lastUpdated =" << _lastUpdated; qDebug() << "_lastEdited=" << _lastEdited; @@ -576,7 +586,7 @@ void EntityItem::simulate(const quint64& now) { float timeElapsed = (float)(now - _lastSimulated) / (float)(USECS_PER_SECOND); if (wantDebug) { - qDebug() << "********** EntityItem::update()"; + qDebug() << "********** EntityItem::simulate()"; qDebug() << " entity ID=" << getEntityItemID(); qDebug() << " now=" << now; qDebug() << " _lastSimulated=" << _lastSimulated; @@ -612,10 +622,8 @@ void EntityItem::simulate(const quint64& now) { } } - _lastSimulated = now; - if (wantDebug) { - qDebug() << " ********** EntityItem::update() .... SETTING _lastSimulated=" << _lastSimulated; + qDebug() << " ********** EntityItem::simulate() .... SETTING _lastSimulated=" << _lastSimulated; } if (hasAngularVelocity()) { @@ -645,13 +653,13 @@ void EntityItem::simulate(const quint64& now) { } } - if (hasVelocity() || hasGravity()) { + if (hasVelocity()) { glm::vec3 position = getPosition(); glm::vec3 velocity = getVelocity(); glm::vec3 newPosition = position + (velocity * timeElapsed); if (wantDebug) { - qDebug() << " EntityItem::update()...."; + qDebug() << " EntityItem::simulate()...."; qDebug() << " timeElapsed:" << timeElapsed; qDebug() << " old AACube:" << getMaximumAACube(); qDebug() << " old position:" << position; @@ -677,15 +685,15 @@ void EntityItem::simulate(const quint64& now) { } // handle gravity.... - if (hasGravity() && !isRestingOnSurface()) { - velocity += getGravity() * timeElapsed; - } - - // handle resting on surface case, this is definitely a bit of a hack, and it only works on the - // "ground" plane of the domain, but for now it - if (hasGravity() && isRestingOnSurface()) { - velocity.y = 0.0f; - position.y = getDistanceToBottomOfEntity(); + if (hasGravity()) { + // handle resting on surface case, this is definitely a bit of a hack, and it only works on the + // "ground" plane of the domain, but for now it what we've got + if (isRestingOnSurface()) { + velocity.y = 0.0f; + position.y = getDistanceToBottomOfEntity(); + } else { + velocity += getGravity() * timeElapsed; + } } // handle damping for velocity @@ -721,10 +729,12 @@ void EntityItem::simulate(const quint64& now) { qDebug() << " old getAABox:" << getAABox(); } } + + _lastSimulated = now; } bool EntityItem::isMoving() const { - return hasVelocity() || (hasGravity() && !isRestingOnSurface()) || hasAngularVelocity(); + return hasVelocity() || hasAngularVelocity(); } bool EntityItem::lifetimeHasExpired() const { @@ -773,10 +783,13 @@ bool EntityItem::setProperties(const EntityItemProperties& properties, bool forc // handle the setting of created timestamps for the basic new entity case if (forceCopy) { + quint64 now = usecTimestampNow(); if (properties.getCreated() == UNKNOWN_CREATED_TIME) { - _created = usecTimestampNow(); + _created = now; } else if (properties.getCreated() != USE_EXISTING_CREATED_TIME) { - _created = properties.getCreated(); + quint64 created = properties.getCreated(); + // don't allow _created to be in the future + _created = created < now ? created : now; } } @@ -803,13 +816,17 @@ bool EntityItem::setProperties(const EntityItemProperties& properties, bool forc if (somethingChanged) { somethingChangedNotification(); // notify derived classes that something has changed bool wantDebug = false; + uint64_t now = usecTimestampNow(); if (wantDebug) { - uint64_t now = usecTimestampNow(); int elapsed = now - getLastEdited(); qDebug() << "EntityItem::setProperties() AFTER update... edited AGO=" << elapsed << "now=" << now << " getLastEdited()=" << getLastEdited(); } - setLastEdited(properties._lastEdited); + // don't allow _lastEdited to be in the future + setLastEdited(properties._lastEdited < now ? properties._lastEdited : now); + if (getDirtyFlags() & EntityItem::DIRTY_POSITION) { + _lastSimulated = usecTimestampNow(); + } } return somethingChanged; diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index d5a4689657..7455b96f6b 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -85,7 +85,7 @@ public: /// Last edited time of this entity universal usecs quint64 getLastEdited() const { return _lastEdited; } void setLastEdited(quint64 lastEdited) - { _lastEdited = _lastSimulated = _lastUpdated = lastEdited; _changedOnServer = glm::max(lastEdited, _changedOnServer); } + { _lastEdited = _lastUpdated = lastEdited; _changedOnServer = glm::max(lastEdited, _changedOnServer); } float getEditedAgo() const /// Elapsed seconds since this entity was last edited { return (float)(usecTimestampNow() - getLastEdited()) / (float)USECS_PER_SECOND; } @@ -120,9 +120,6 @@ public: static int expectedBytes(); - static bool encodeEntityEditMessageDetails(PacketType command, EntityItemID id, const EntityItemProperties& details, - unsigned char* bufferOut, int sizeIn, int& sizeOut); - static void adjustEditPacketForClockSkew(unsigned char* codeColorBuffer, size_t length, int clockSkew); // perform update diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index 642e24beec..e5f78e8fc7 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -95,8 +95,8 @@ enum EntityPropertyList { typedef PropertyFlags EntityPropertyFlags; -const quint64 UNKNOWN_CREATED_TIME = (quint64)(-1); -const quint64 USE_EXISTING_CREATED_TIME = (quint64)(-2); +const quint64 UNKNOWN_CREATED_TIME = 0; +const quint64 USE_EXISTING_CREATED_TIME = 1; /// A collection of properties of an entity item used in the scripting API. Translates between the actual properties of an diff --git a/libraries/entities/src/EntityTypes.cpp b/libraries/entities/src/EntityTypes.cpp index 194df024e0..f7806445bc 100644 --- a/libraries/entities/src/EntityTypes.cpp +++ b/libraries/entities/src/EntityTypes.cpp @@ -71,7 +71,6 @@ bool EntityTypes::registerEntityType(EntityType entityType, const char* name, En EntityItem* EntityTypes::constructEntityItem(EntityType entityType, const EntityItemID& entityID, const EntityItemProperties& properties) { - EntityItem* newEntityItem = NULL; EntityTypeFactory factory = NULL; if (entityType >= 0 && entityType <= LAST) { @@ -129,7 +128,12 @@ EntityItem* EntityTypes::constructEntityItem(const unsigned char* data, int byte EntityItemID tempEntityID(actualID); EntityItemProperties tempProperties; - tempProperties.setCreated(usecTimestampNow()); // this is temporary... + + // we set the Creation and Edit times to 'now', but if the server submits an earlier Creation time + // then it will be accepted + quint64 now = usecTimestampNow(); + tempProperties.setCreated(now); + tempProperties.setLastEdited(now); return constructEntityItem(entityType, tempEntityID, tempProperties); }