diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 6668f5cfa0..85172fc73f 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -198,6 +198,8 @@ #include #include +#include + #include "commerce/Ledger.h" #include "commerce/Wallet.h" #include "commerce/QmlCommerce.h" @@ -682,6 +684,8 @@ bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) { DependencyManager::set(); DependencyManager::set(); + DependencyManager::set(); + DependencyManager::set(); DependencyManager::set(); diff --git a/interface/src/SecondaryCamera.cpp b/interface/src/SecondaryCamera.cpp index 56b8b3ef85..9d19b8fb0f 100644 --- a/interface/src/SecondaryCamera.cpp +++ b/interface/src/SecondaryCamera.cpp @@ -18,7 +18,6 @@ using RenderArgsPointer = std::shared_ptr; void MainRenderTask::build(JobModel& task, const render::Varying& inputs, render::Varying& outputs, render::CullFunctor cullFunctor, bool isDeferred) { - task.addJob("RenderShadowTask", cullFunctor); const auto items = task.addJob("FetchCullSort", cullFunctor); assert(items.canCast()); @@ -30,14 +29,6 @@ void MainRenderTask::build(JobModel& task, const render::Varying& inputs, render } class SecondaryCameraJob { // Changes renderContext for our framebuffer and view. - QUuid _attachedEntityId{}; - glm::vec3 _position{}; - glm::quat _orientation{}; - float _vFoV{}; - float _nearClipPlaneDistance{}; - float _farClipPlaneDistance{}; - EntityPropertyFlags _attachedEntityPropertyFlags; - QSharedPointer _entityScriptingInterface; public: using Config = SecondaryCameraJobConfig; using JobModel = render::Job::ModelO; @@ -55,13 +46,15 @@ public: _vFoV = config.vFoV; _nearClipPlaneDistance = config.nearClipPlaneDistance; _farClipPlaneDistance = config.farClipPlaneDistance; + _textureWidth = config.textureWidth; + _textureHeight = config.textureHeight; } void run(const render::RenderContextPointer& renderContext, RenderArgsPointer& cachedArgs) { auto args = renderContext->args; auto textureCache = DependencyManager::get(); gpu::FramebufferPointer destFramebuffer; - destFramebuffer = textureCache->getSpectatorCameraFramebuffer(); // FIXME: Change the destination based on some unimplemented config var + destFramebuffer = textureCache->getSpectatorCameraFramebuffer(_textureWidth, _textureHeight); // FIXME: Change the destination based on some unimplemented config var if (destFramebuffer) { _cachedArgsPointer->_blitFramebuffer = args->_blitFramebuffer; _cachedArgsPointer->_viewport = args->_viewport; @@ -98,6 +91,18 @@ public: protected: RenderArgs _cachedArgs; RenderArgsPointer _cachedArgsPointer; + +private: + QUuid _attachedEntityId; + glm::vec3 _position; + glm::quat _orientation; + float _vFoV; + float _nearClipPlaneDistance; + float _farClipPlaneDistance; + int _textureWidth; + int _textureHeight; + EntityPropertyFlags _attachedEntityPropertyFlags; + QSharedPointer _entityScriptingInterface; }; void SecondaryCameraJobConfig::setPosition(glm::vec3 pos) { @@ -123,16 +128,10 @@ void SecondaryCameraJobConfig::enableSecondaryCameraRenderConfigs(bool enabled) setEnabled(enabled); } -void SecondaryCameraJobConfig::resetSizeSpectatorCamera(int width, int height) { // Carefully adjust the framebuffer / texture. - qApp->getRenderEngine()->getConfiguration()->getConfig()->resetSize(width, height); -} - -void SecondaryCameraRenderTaskConfig::resetSize(int width, int height) { // FIXME: Add an arg here for "destinationFramebuffer" - bool wasEnabled = isEnabled(); - setEnabled(false); - auto textureCache = DependencyManager::get(); - textureCache->resetSpectatorCameraFramebuffer(width, height); // FIXME: Call the correct reset function based on the "destinationFramebuffer" arg - setEnabled(wasEnabled); +void SecondaryCameraJobConfig::resetSizeSpectatorCamera(int width, int height) { + textureWidth = width; + textureHeight = height; + emit dirty(); } class EndSecondaryCameraFrame { // Restores renderContext. diff --git a/interface/src/SecondaryCamera.h b/interface/src/SecondaryCamera.h index 0941959c0a..a9b438ec6f 100644 --- a/interface/src/SecondaryCamera.h +++ b/interface/src/SecondaryCamera.h @@ -18,7 +18,6 @@ #include #include - class MainRenderTask { public: using JobModel = render::Task::Model; @@ -37,12 +36,15 @@ class SecondaryCameraJobConfig : public render::Task::Config { // Exposes second Q_PROPERTY(float nearClipPlaneDistance MEMBER nearClipPlaneDistance NOTIFY dirty) // Secondary camera's near clip plane distance. In meters. Q_PROPERTY(float farClipPlaneDistance MEMBER farClipPlaneDistance NOTIFY dirty) // Secondary camera's far clip plane distance. In meters. public: - QUuid attachedEntityId{}; - glm::vec3 position{}; - glm::quat orientation{}; - float vFoV{ DEFAULT_FIELD_OF_VIEW_DEGREES }; - float nearClipPlaneDistance{ DEFAULT_NEAR_CLIP }; - float farClipPlaneDistance{ DEFAULT_FAR_CLIP }; + QUuid attachedEntityId; + glm::vec3 position; + glm::quat orientation; + float vFoV { DEFAULT_FIELD_OF_VIEW_DEGREES }; + float nearClipPlaneDistance { DEFAULT_NEAR_CLIP }; + float farClipPlaneDistance { DEFAULT_FAR_CLIP }; + int textureWidth { TextureCache::DEFAULT_SPECTATOR_CAM_WIDTH }; + int textureHeight { TextureCache::DEFAULT_SPECTATOR_CAM_HEIGHT }; + SecondaryCameraJobConfig() : render::Task::Config(false) {} signals: void dirty(); @@ -59,9 +61,6 @@ class SecondaryCameraRenderTaskConfig : public render::Task::Config { Q_OBJECT public: SecondaryCameraRenderTaskConfig() : render::Task::Config(false) {} - void resetSize(int width, int height); -signals: - void dirty(); }; class SecondaryCameraRenderTask { diff --git a/libraries/model-networking/src/model-networking/TextureCache.cpp b/libraries/model-networking/src/model-networking/TextureCache.cpp index a4ce892521..5d8f840c85 100644 --- a/libraries/model-networking/src/model-networking/TextureCache.cpp +++ b/libraries/model-networking/src/model-networking/TextureCache.cpp @@ -1003,6 +1003,7 @@ NetworkTexturePointer TextureCache::getResourceTexture(QUrl resourceTextureUrl) if (_spectatorCameraFramebuffer) { texture = _spectatorCameraFramebuffer->getRenderBuffer(0); if (texture) { + texture->setSource(SPECTATOR_CAMERA_FRAME_URL.toString().toStdString()); _spectatorCameraNetworkTexture->setImage(texture, texture->getWidth(), texture->getHeight()); return _spectatorCameraNetworkTexture; } @@ -1016,6 +1017,7 @@ NetworkTexturePointer TextureCache::getResourceTexture(QUrl resourceTextureUrl) if (_hmdPreviewFramebuffer) { texture = _hmdPreviewFramebuffer->getRenderBuffer(0); if (texture) { + texture->setSource(HMD_PREVIEW_FRAME_URL.toString().toStdString()); _hmdPreviewNetworkTexture->setImage(texture, texture->getWidth(), texture->getHeight()); return _hmdPreviewNetworkTexture; } @@ -1033,14 +1035,18 @@ const gpu::FramebufferPointer& TextureCache::getHmdPreviewFramebuffer(int width, } const gpu::FramebufferPointer& TextureCache::getSpectatorCameraFramebuffer() { + // If we're taking a screenshot and the spectator cam buffer hasn't been created yet, reset to the default size if (!_spectatorCameraFramebuffer) { - resetSpectatorCameraFramebuffer(2048, 1024); + return getSpectatorCameraFramebuffer(DEFAULT_SPECTATOR_CAM_WIDTH, DEFAULT_SPECTATOR_CAM_HEIGHT); } return _spectatorCameraFramebuffer; } -void TextureCache::resetSpectatorCameraFramebuffer(int width, int height) { - _spectatorCameraFramebuffer.reset(gpu::Framebuffer::create("spectatorCamera", gpu::Element::COLOR_SRGBA_32, width, height)); - _spectatorCameraNetworkTexture.reset(); - emit spectatorCameraFramebufferReset(); +const gpu::FramebufferPointer& TextureCache::getSpectatorCameraFramebuffer(int width, int height) { + // If we aren't taking a screenshot, we might need to resize or create the camera buffer + if (!_spectatorCameraFramebuffer || _spectatorCameraFramebuffer->getWidth() != width || _spectatorCameraFramebuffer->getHeight() != height) { + _spectatorCameraFramebuffer.reset(gpu::Framebuffer::create("spectatorCamera", gpu::Element::COLOR_SRGBA_32, width, height)); + emit spectatorCameraFramebufferReset(); + } + return _spectatorCameraFramebuffer; } diff --git a/libraries/model-networking/src/model-networking/TextureCache.h b/libraries/model-networking/src/model-networking/TextureCache.h index 5bc5aa7d96..1102694f86 100644 --- a/libraries/model-networking/src/model-networking/TextureCache.h +++ b/libraries/model-networking/src/model-networking/TextureCache.h @@ -167,12 +167,13 @@ public: gpu::TexturePointer getTextureByHash(const std::string& hash); gpu::TexturePointer cacheTextureByHash(const std::string& hash, const gpu::TexturePointer& texture); - - /// SpectatorCamera rendering targets. NetworkTexturePointer getResourceTexture(QUrl resourceTextureUrl); - const gpu::FramebufferPointer& getSpectatorCameraFramebuffer(); - void resetSpectatorCameraFramebuffer(int width, int height); const gpu::FramebufferPointer& getHmdPreviewFramebuffer(int width, int height); + const gpu::FramebufferPointer& getSpectatorCameraFramebuffer(); + const gpu::FramebufferPointer& getSpectatorCameraFramebuffer(int width, int height); + + static const int DEFAULT_SPECTATOR_CAM_WIDTH { 2048 }; + static const int DEFAULT_SPECTATOR_CAM_HEIGHT { 1024 }; signals: void spectatorCameraFramebufferReset(); diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index c67a1c7875..85df1ee8de 100644 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -49,8 +49,8 @@ using namespace render; extern void initOverlay3DPipelines(render::ShapePlumber& plumber, bool depthTest = false); extern void initDeferredPipelines(render::ShapePlumber& plumber, const render::ShapePipeline::BatchSetter& batchSetter, const render::ShapePipeline::ItemSetter& itemSetter); -RenderDeferredTask::RenderDeferredTask() { - DependencyManager::set(); +RenderDeferredTask::RenderDeferredTask() +{ } void RenderDeferredTask::configure(const Config& config)