diff --git a/libraries/display-plugins/src/display-plugins/Basic2DWindowOpenGLDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/Basic2DWindowOpenGLDisplayPlugin.cpp index 4258d4db75..38f7600315 100644 --- a/libraries/display-plugins/src/display-plugins/Basic2DWindowOpenGLDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/Basic2DWindowOpenGLDisplayPlugin.cpp @@ -109,11 +109,25 @@ bool Basic2DWindowOpenGLDisplayPlugin::internalActivate() { return Parent::internalActivate(); } +gpu::PipelinePointer Basic2DWindowOpenGLDisplayPlugin::getRenderTexturePipeline() { +#if defined(Q_OS_ANDROID) + return _linearToSRGBPipeline; +#else + +#ifndef USE_GLES + return _SRGBToLinearPipeline; +#else + return _drawTexturePipeline; +#endif + +#endif +} + gpu::PipelinePointer Basic2DWindowOpenGLDisplayPlugin::getCompositeScenePipeline() { #if defined(Q_OS_ANDROID) - return _linearToSRGBPipeline; + return _linearToSRGBPipeline; #else - return _SRGBToLinearPipeline; + return _drawTexturePipeline; #endif } diff --git a/libraries/display-plugins/src/display-plugins/Basic2DWindowOpenGLDisplayPlugin.h b/libraries/display-plugins/src/display-plugins/Basic2DWindowOpenGLDisplayPlugin.h index 7f654915e1..ae830b2e28 100644 --- a/libraries/display-plugins/src/display-plugins/Basic2DWindowOpenGLDisplayPlugin.h +++ b/libraries/display-plugins/src/display-plugins/Basic2DWindowOpenGLDisplayPlugin.h @@ -37,6 +37,7 @@ public: virtual void pluginUpdate() override {}; + virtual gpu::PipelinePointer getRenderTexturePipeline() override; virtual gpu::PipelinePointer getCompositeScenePipeline() override; virtual gpu::Element getCompositeFBColorSpace() override; diff --git a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp index 73bc1d0aad..c990be6e42 100644 --- a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp @@ -59,19 +59,14 @@ class PresentThread : public QThread, public Dependency { using Lock = std::unique_lock; public: - PresentThread() { - connect(qApp, &QCoreApplication::aboutToQuit, [this] { - shutdown(); - }); + connect(qApp, &QCoreApplication::aboutToQuit, [this] { shutdown(); }); setObjectName("Present"); _refreshRateController = std::make_shared(); } - ~PresentThread() { - shutdown(); - } + ~PresentThread() { shutdown(); } auto getRefreshRateController() { return _refreshRateController; } @@ -82,17 +77,16 @@ public: Lock lock(_mutex); _shutdown = true; - _condition.wait(lock, [&] { return !_shutdown; }); + _condition.wait(lock, [&] { return !_shutdown; }); qCDebug(displayPlugins) << "Present thread shutdown"; } } - void setNewDisplayPlugin(OpenGLDisplayPlugin* plugin) { Lock lock(_mutex); if (isRunning()) { _newPluginQueue.push(plugin); - _condition.wait(lock, [=]()->bool { return _newPluginQueue.empty(); }); + _condition.wait(lock, [=]() -> bool { return _newPluginQueue.empty(); }); } } @@ -104,7 +98,6 @@ public: _context->moveToThread(this); } - virtual void run() override { PROFILE_SET_THREAD_NAME("Present Thread"); @@ -120,8 +113,7 @@ public: CHECK_GL_ERROR(); while (!_shutdown) { if (_pendingOtherThreadOperation) { - PROFILE_RANGE(render, "MainThreadOp") - { + PROFILE_RANGE(render, "MainThreadOp") { Lock lock(_mutex); _context->doneCurrent(); // Move the context to the main thread @@ -131,7 +123,6 @@ public: _condition.notify_one(); } - { // Main thread does it's thing while we wait on the lock to release Lock lock(_mutex); @@ -201,7 +192,7 @@ public: #if defined(Q_OS_MAC) _context->doneCurrent(); #endif - + _refreshRateController->sleepThreadIfNeeded(this, currentPlugin->isHmd()); } @@ -235,23 +226,21 @@ public: _condition.notify_one(); } - private: void makeCurrent(); void doneCurrent(); - bool _shutdown { false }; + bool _shutdown{ false }; Mutex _mutex; // Used to allow the main thread to perform context operations Condition _condition; - - QThread* _targetOperationThread { nullptr }; - bool _pendingOtherThreadOperation { false }; - bool _finishedOtherThreadOperation { false }; + QThread* _targetOperationThread{ nullptr }; + bool _pendingOtherThreadOperation{ false }; + bool _finishedOtherThreadOperation{ false }; std::queue _newPluginQueue; - gl::Context* _context { nullptr }; - std::shared_ptr _refreshRateController { nullptr }; + gl::Context* _context{ nullptr }; + std::shared_ptr _refreshRateController{ nullptr }; }; bool OpenGLDisplayPlugin::activate() { @@ -302,7 +291,6 @@ bool OpenGLDisplayPlugin::activate() { return false; } - // This should not return until the new context has been customized // and the old context (if any) has been uncustomized presentThread->setNewDisplayPlugin(this); @@ -334,7 +322,7 @@ void OpenGLDisplayPlugin::deactivate() { _container->showDisplayPluginsTools(false); if (!_container->currentDisplayActions().isEmpty()) { - foreach(auto itemInfo, _container->currentDisplayActions()) { + foreach (auto itemInfo, _container->currentDisplayActions()) { _container->removeMenuItem(itemInfo.first, itemInfo.second); } _container->currentDisplayActions().clear(); @@ -368,12 +356,9 @@ void OpenGLDisplayPlugin::customizeContext() { image = image.convertToFormat(QImage::Format_ARGB32); } if ((image.width() > 0) && (image.height() > 0)) { - - cursorData.texture = gpu::Texture::createStrict( - gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA), - image.width(), image.height(), - gpu::Texture::MAX_NUM_MIPS, - gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_LINEAR)); + cursorData.texture = gpu::Texture::createStrict(gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA), image.width(), + image.height(), gpu::Texture::MAX_NUM_MIPS, + gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_LINEAR)); cursorData.texture->setSource("cursor texture"); auto usage = gpu::Texture::Usage::Builder().withColor().withAlpha(); cursorData.texture->setUsage(usage.build()); @@ -384,45 +369,39 @@ void OpenGLDisplayPlugin::customizeContext() { } } - if (!_drawTexturePipeline) { + if (!_linearToSRGBPipeline) { gpu::StatePointer blendState = gpu::StatePointer(new gpu::State()); blendState->setDepthTest(gpu::State::DepthTest(false)); - blendState->setBlendFunction(true, - gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, - gpu::State::INV_SRC_ALPHA, - gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, - gpu::State::ONE); + blendState->setBlendFunction(true, gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA, + gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE); gpu::StatePointer scissorState = gpu::StatePointer(new gpu::State()); scissorState->setDepthTest(gpu::State::DepthTest(false)); scissorState->setScissorEnable(true); - _drawTexturePipeline = gpu::Pipeline::create(gpu::Shader::createProgram(DrawTexture), scissorState); + _drawTexturePipeline = gpu::Pipeline::create(gpu::Shader::createProgram(DrawTexture), scissorState); - _linearToSRGBPipeline = gpu::Pipeline::create(gpu::Shader::createProgram(DrawTextureGammaLinearToSRGB), scissorState); + _linearToSRGBPipeline = gpu::Pipeline::create(gpu::Shader::createProgram(DrawTextureGammaLinearToSRGB), scissorState); - _SRGBToLinearPipeline = gpu::Pipeline::create(gpu::Shader::createProgram(DrawTextureGammaSRGBToLinear), scissorState); + _SRGBToLinearPipeline = gpu::Pipeline::create(gpu::Shader::createProgram(DrawTextureGammaSRGBToLinear), scissorState); - _hudPipeline = gpu::Pipeline::create(gpu::Shader::createProgram(DrawTexture), blendState); + _hudPipeline = gpu::Pipeline::create(gpu::Shader::createProgram(DrawTexture), blendState); - _mirrorHUDPipeline = gpu::Pipeline::create(gpu::Shader::createProgram(DrawTextureMirroredX), blendState); + _mirrorHUDPipeline = gpu::Pipeline::create(gpu::Shader::createProgram(DrawTextureMirroredX), blendState); - _cursorPipeline = gpu::Pipeline::create(gpu::Shader::createProgram(DrawTransformedTexture), blendState); + _cursorPipeline = gpu::Pipeline::create(gpu::Shader::createProgram(DrawTransformedTexture), blendState); } - updateCompositeFramebuffer(); } void OpenGLDisplayPlugin::uncustomizeContext() { - _drawTexturePipeline.reset(); _linearToSRGBPipeline.reset(); _SRGBToLinearPipeline.reset(); + _cursorPipeline.reset(); _hudPipeline.reset(); _mirrorHUDPipeline.reset(); - _cursorPipeline.reset(); _compositeFramebuffer.reset(); - withPresentThreadLock([&] { _currentFrame.reset(); _lastFrame = nullptr; @@ -433,7 +412,6 @@ void OpenGLDisplayPlugin::uncustomizeContext() { }); } - // Pressing Alt (and Meta) key alone activates the menubar because its style inherits the // SHMenuBarAltKeyNavigation from QWindowsStyle. This makes it impossible for a scripts to // receive keyPress events for the Alt (and Meta) key in a reliable manner. @@ -477,9 +455,7 @@ bool OpenGLDisplayPlugin::eventFilter(QObject* receiver, QEvent* event) { } void OpenGLDisplayPlugin::submitFrame(const gpu::FramePointer& newFrame) { - withNonPresentThreadLock([&] { - _newFrameQueue.push(newFrame); - }); + withNonPresentThreadLock([&] { _newFrameQueue.push(newFrame); }); } void OpenGLDisplayPlugin::captureFrame(const std::string& filename) const { @@ -493,10 +469,10 @@ void OpenGLDisplayPlugin::captureFrame(const std::string& filename) const { image = QImage{ 1, 1, QImage::Format_ARGB32 }; auto storedImage = texture->accessStoredMipFace(0, 0); memcpy(image.bits(), storedImage->data(), image.sizeInBytes()); - //if (texture == textureCache->getWhiteTexture()) { - //} else if (texture == textureCache->getBlackTexture()) { - //} else if (texture == textureCache->getBlueTexture()) { - //} else if (texture == textureCache->getGrayTexture()) { + //if (texture == textureCache->getWhiteTexture()) { + //} else if (texture == textureCache->getBlackTexture()) { + //} else if (texture == textureCache->getBlueTexture()) { + //} else if (texture == textureCache->getGrayTexture()) { } else { ivec4 rect = { 0, 0, texture->getWidth(), texture->getHeight() }; framebuffer->setRenderBuffer(0, texture, layer); @@ -514,11 +490,18 @@ void OpenGLDisplayPlugin::captureFrame(const std::string& filename) const { }); } -void OpenGLDisplayPlugin::renderFromTexture(gpu::Batch& batch, const gpu::TexturePointer& texture, const glm::ivec4& viewport, const glm::ivec4& scissor) { +void OpenGLDisplayPlugin::renderFromTexture(gpu::Batch& batch, + const gpu::TexturePointer& texture, + const glm::ivec4& viewport, + const glm::ivec4& scissor) { renderFromTexture(batch, texture, viewport, scissor, nullptr); } -void OpenGLDisplayPlugin::renderFromTexture(gpu::Batch& batch, const gpu::TexturePointer& texture, const glm::ivec4& viewport, const glm::ivec4& scissor, const gpu::FramebufferPointer& copyFbo /*=gpu::FramebufferPointer()*/) { +void OpenGLDisplayPlugin::renderFromTexture(gpu::Batch& batch, + const gpu::TexturePointer& texture, + const glm::ivec4& viewport, + const glm::ivec4& scissor, + const gpu::FramebufferPointer& copyFbo /*=gpu::FramebufferPointer()*/) { auto fbo = gpu::FramebufferPointer(); batch.enableStereo(false); batch.resetViewTransform(); @@ -528,18 +511,18 @@ void OpenGLDisplayPlugin::renderFromTexture(gpu::Batch& batch, const gpu::Textur batch.setViewportTransform(viewport); batch.setResourceTexture(0, texture); - batch.setPipeline(_drawTexturePipeline); - + batch.setPipeline(getRenderTexturePipeline()); + batch.draw(gpu::TRIANGLE_STRIP, 4); if (copyFbo) { gpu::Vec4i copyFboRect(0, 0, copyFbo->getWidth(), copyFbo->getHeight()); gpu::Vec4i sourceRect(scissor.x, scissor.y, scissor.x + scissor.z, scissor.y + scissor.w); - float aspectRatio = (float)scissor.w / (float) scissor.z; // height/width + float aspectRatio = (float)scissor.w / (float)scissor.z; // height/width // scale width first int xOffset = 0; int yOffset = 0; int newWidth = copyFbo->getWidth(); - int newHeight = std::round(aspectRatio * (float) copyFbo->getWidth()); + int newHeight = std::round(aspectRatio * (float)copyFbo->getWidth()); if (newHeight > copyFbo->getHeight()) { // ok, so now fill height instead newHeight = copyFbo->getHeight(); @@ -554,7 +537,7 @@ void OpenGLDisplayPlugin::renderFromTexture(gpu::Batch& batch, const gpu::Textur batch.resetViewTransform(); batch.setViewportTransform(copyFboRect); batch.setStateScissorRect(copyFboRect); - batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLOR0, {0.0f, 0.0f, 0.0f, 1.0f}); + batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLOR0, { 0.0f, 0.0f, 0.0f, 1.0f }); batch.blit(fbo, sourceRect, copyFbo, copyRect); } } @@ -589,14 +572,11 @@ std::function OpenGL auto hudStereo = isStereo(); auto hudCompositeFramebufferSize = _compositeFramebuffer->getSize(); std::array hudEyeViewports; - for_each_eye([&](Eye eye) { - hudEyeViewports[eye] = eyeViewport(eye); - }); + for_each_eye([&](Eye eye) { hudEyeViewports[eye] = eyeViewport(eye); }); return [=](gpu::Batch& batch, const gpu::TexturePointer& hudTexture, bool mirror) { - auto pipeline = mirror ? hudMirrorPipeline : hudPipeline; - if (pipeline && hudTexture) { + if (hudPipeline && hudTexture) { batch.enableStereo(false); - batch.setPipeline(pipeline); + batch.setPipeline(mirror ? hudMirrorPipeline : hudPipeline); batch.setResourceTexture(0, hudTexture); if (hudStereo) { for_each_eye([&](Eye eye) { @@ -635,11 +615,6 @@ void OpenGLDisplayPlugin::compositePointer() { }); } -// Overridden by Basic2DWindowDisplayPlugin and OculusDisplayPlugin -gpu::PipelinePointer OpenGLDisplayPlugin::getCompositeScenePipeline() { - return _drawTexturePipeline; -} - void OpenGLDisplayPlugin::compositeScene() { render([&](gpu::Batch& batch) { batch.enableStereo(false); @@ -682,9 +657,10 @@ void OpenGLDisplayPlugin::internalPresent() { render([&](gpu::Batch& batch) { // Note: _displayTexture must currently be the same size as the display. uvec2 dims = _displayTexture ? uvec2(_displayTexture->getDimensions()) : getSurfacePixels(); - auto viewport = ivec4(uvec2(0), dims); - renderFromTexture(batch, _displayTexture ? _displayTexture : _compositeFramebuffer->getRenderBuffer(0), viewport, viewport); - }); + auto viewport = ivec4(uvec2(0), dims); + renderFromTexture(batch, _displayTexture ? _displayTexture : _compositeFramebuffer->getRenderBuffer(0), viewport, + viewport); + }); swapBuffers(); _presentRate.increment(); } @@ -723,7 +699,7 @@ void OpenGLDisplayPlugin::present(const std::shared_ptr& compositeLayers(); } - { // If we have any snapshots this frame, handle them + { // If we have any snapshots this frame, handle them PROFILE_RANGE_EX(render, "snapshotOperators", 0xffff00ff, frameId) while (!_currentFrame->snapshotOperators.empty()) { auto& snapshotOperator = _currentFrame->snapshotOperators.front(); @@ -765,7 +741,7 @@ float OpenGLDisplayPlugin::presentRate() const { return _presentRate.rate(); } -std::function OpenGLDisplayPlugin::getRefreshRateOperator() { +std::function OpenGLDisplayPlugin::getRefreshRateOperator() { return [](int targetRefreshRate) { auto refreshRateController = DependencyManager::get()->getRefreshRateController(); refreshRateController->setRefreshRateLimitPeriod(targetRefreshRate); @@ -781,7 +757,6 @@ float OpenGLDisplayPlugin::renderRate() const { return _renderRate.rate(); } - void OpenGLDisplayPlugin::swapBuffers() { static auto context = _container->getPrimaryWidget()->context(); context->swapBuffers(); @@ -818,7 +793,7 @@ QImage OpenGLDisplayPlugin::getScreenshot(float aspectRatio) { } auto bestSize = size; uvec2 corner(0); - if (aspectRatio != 0.0f) { // Pick out the largest piece of the center that produces the requested width/height aspectRatio + if (aspectRatio != 0.0f) { // Pick out the largest piece of the center that produces the requested width/height aspectRatio if (ceil(size.y * aspectRatio) < size.x) { bestSize.x = round(size.y * aspectRatio); } else { @@ -869,9 +844,7 @@ void OpenGLDisplayPlugin::assertIsPresentThread() const { } bool OpenGLDisplayPlugin::beginFrameRender(uint32_t frameIndex) { - withNonPresentThreadLock([&] { - _compositeHUDAlpha = _hudAlpha; - }); + withNonPresentThreadLock([&] { _compositeHUDAlpha = _hudAlpha; }); return Parent::beginFrameRender(frameIndex); } @@ -909,27 +882,25 @@ void OpenGLDisplayPlugin::render(std::function f) { OpenGLDisplayPlugin::~OpenGLDisplayPlugin() { } -// Added this to allow desktop composite framebuffer to be RGBA while mobile is SRGBA -// Overridden by Basic2DWindowDisplayPlugin -// FIXME: Eventually it would be ideal to have both framebuffers be of the same type -gpu::Element OpenGLDisplayPlugin::getCompositeFBColorSpace() { - return gpu::Element::COLOR_RGBA_32; -} - void OpenGLDisplayPlugin::updateCompositeFramebuffer() { auto renderSize = glm::uvec2(getRecommendedRenderSize()); if (!_compositeFramebuffer || _compositeFramebuffer->getSize() != renderSize) { - _compositeFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create("OpenGLDisplayPlugin::composite", getCompositeFBColorSpace(), renderSize.x, renderSize.y)); + _compositeFramebuffer = + gpu::FramebufferPointer(gpu::Framebuffer::create("OpenGLDisplayPlugin::composite", gpu::Element::COLOR_RGBA_32, + renderSize.x, renderSize.y)); + // _compositeFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create("OpenGLDisplayPlugin::composite", gpu::Element::COLOR_SRGBA_32, renderSize.x, renderSize.y)); } } -void OpenGLDisplayPlugin::copyTextureToQuickFramebuffer(NetworkTexturePointer networkTexture, QOpenGLFramebufferObject* target, GLsync* fenceSync) { +void OpenGLDisplayPlugin::copyTextureToQuickFramebuffer(NetworkTexturePointer networkTexture, + QOpenGLFramebufferObject* target, + GLsync* fenceSync) { #if !defined(USE_GLES) auto glBackend = const_cast(*this).getGLBackend(); withOtherThreadContext([&] { GLuint sourceTexture = glBackend->getTextureID(networkTexture->getGPUTexture()); GLuint targetTexture = target->texture(); - GLuint fbo[2] {0, 0}; + GLuint fbo[2]{ 0, 0 }; // need mipmaps for blitting texture glGenerateTextureMipmap(sourceTexture); @@ -950,14 +921,13 @@ void OpenGLDisplayPlugin::copyTextureToQuickFramebuffer(NetworkTexturePointer ne glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT); - // maintain aspect ratio, filling the width first if possible. If that makes the height too // much, fill height instead. TODO: only do this when texture changes GLint newX = 0; GLint newY = 0; float aspectRatio = (float)texHeight / (float)texWidth; GLint newWidth = target->width(); - GLint newHeight = std::round(aspectRatio * (float) target->width()); + GLint newHeight = std::round(aspectRatio * (float)target->width()); if (newHeight > target->height()) { newHeight = target->height(); newWidth = std::round((float)target->height() / aspectRatio); @@ -966,7 +936,8 @@ void OpenGLDisplayPlugin::copyTextureToQuickFramebuffer(NetworkTexturePointer ne newY = (target->height() - newHeight) / 2; } - glBlitNamedFramebuffer(fbo[0], fbo[1], 0, 0, texWidth, texHeight, newX, newY, newX + newWidth, newY + newHeight, GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT, GL_NEAREST); + glBlitNamedFramebuffer(fbo[0], fbo[1], 0, 0, texWidth, texHeight, newX, newY, newX + newWidth, newY + newHeight, + GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT, GL_NEAREST); // don't delete the textures! glDeleteFramebuffers(2, fbo); @@ -975,3 +946,14 @@ void OpenGLDisplayPlugin::copyTextureToQuickFramebuffer(NetworkTexturePointer ne #endif } +gpu::PipelinePointer OpenGLDisplayPlugin::getRenderTexturePipeline() { + return _drawTexturePipeline; +} + +gpu::PipelinePointer OpenGLDisplayPlugin::getCompositeScenePipeline() { + return _drawTexturePipeline; +} + +gpu::Element OpenGLDisplayPlugin::getCompositeFBColorSpace() { + return gpu::Element::COLOR_RGBA_32; +} diff --git a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.h b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.h index eae9f86710..d5d9bad8a6 100644 --- a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.h +++ b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.h @@ -23,11 +23,9 @@ #include -namespace gpu { - namespace gl { - class GLBackend; - } -} +namespace gpu { namespace gl { +class GLBackend; +}} // namespace gpu::gl class RefreshRateController; @@ -35,10 +33,12 @@ class OpenGLDisplayPlugin : public DisplayPlugin { Q_OBJECT Q_PROPERTY(float hudAlpha MEMBER _hudAlpha) using Parent = DisplayPlugin; + protected: using Mutex = std::mutex; using Lock = std::unique_lock; using Condition = std::condition_variable; + public: ~OpenGLDisplayPlugin(); // These must be final to ensure proper ordering of operations @@ -55,13 +55,9 @@ public: void captureFrame(const std::string& outputName) const override; void submitFrame(const gpu::FramePointer& newFrame) override; - glm::uvec2 getRecommendedRenderSize() const override { - return getSurfacePixels(); - } + glm::uvec2 getRecommendedRenderSize() const override { return getSurfacePixels(); } - glm::uvec2 getRecommendedUiSize() const override { - return getSurfaceSize(); - } + glm::uvec2 getRecommendedUiSize() const override { return getSurfaceSize(); } virtual bool setDisplayTexture(const QString& name) override; virtual bool onDisplayTextureReset() { return false; }; @@ -84,9 +80,9 @@ public: // Three threads, one for rendering, one for texture transfers, one reserved for the GL driver int getRequiredThreadCount() const override { return 3; } - void copyTextureToQuickFramebuffer(NetworkTexturePointer source, QOpenGLFramebufferObject* target, GLsync* fenceSync) override; - - virtual std::function getHUDOperator() override; + void copyTextureToQuickFramebuffer(NetworkTexturePointer source, + QOpenGLFramebufferObject* target, + GLsync* fenceSync) override; protected: friend class PresentThread; @@ -104,11 +100,9 @@ protected: virtual QThread::Priority getPresentPriority() { return QThread::HighPriority; } virtual void compositeLayers(); virtual void compositeScene(); + virtual std::function getHUDOperator(); virtual void compositePointer(); - virtual void compositeExtra() {}; - - virtual gpu::PipelinePointer getCompositeScenePipeline(); - virtual gpu::Element getCompositeFBColorSpace(); + virtual void compositeExtra(){}; // These functions must only be called on the presentation thread virtual void customizeContext(); @@ -125,8 +119,15 @@ protected: // Plugin specific functionality to send the composed scene to the output window or device virtual void internalPresent(); - void renderFromTexture(gpu::Batch& batch, const gpu::TexturePointer& texture, const glm::ivec4& viewport, const glm::ivec4& scissor, const gpu::FramebufferPointer& fbo); - void renderFromTexture(gpu::Batch& batch, const gpu::TexturePointer& texture, const glm::ivec4& viewport, const glm::ivec4& scissor); + void renderFromTexture(gpu::Batch& batch, + const gpu::TexturePointer& texture, + const glm::ivec4& viewport, + const glm::ivec4& scissor, + const gpu::FramebufferPointer& fbo); + void renderFromTexture(gpu::Batch& batch, + const gpu::TexturePointer& texture, + const glm::ivec4& viewport, + const glm::ivec4& scissor); virtual void updateFrameData(); virtual glm::mat4 getViewCorrection() { return glm::mat4(); } @@ -138,7 +139,7 @@ protected: void render(std::function f); - bool _vsyncEnabled { true }; + bool _vsyncEnabled{ true }; QThread* _presentThread{ nullptr }; std::queue _newFrameQueue; RateCounter<200> _droppedFrameRate; @@ -147,7 +148,7 @@ protected: RateCounter<200> _renderRate; gpu::FramePointer _currentFrame; - gpu::Frame* _lastFrame { nullptr }; + gpu::Frame* _lastFrame{ nullptr }; mat4 _prevRenderView; gpu::FramebufferPointer _compositeFramebuffer; gpu::PipelinePointer _hudPipeline; @@ -157,9 +158,12 @@ protected: gpu::PipelinePointer _linearToSRGBPipeline; gpu::PipelinePointer _SRGBToLinearPipeline; gpu::PipelinePointer _cursorPipeline; - gpu::TexturePointer _displayTexture{}; - float _compositeHUDAlpha { 1.0f }; + float _compositeHUDAlpha{ 1.0f }; + + virtual gpu::PipelinePointer getRenderTexturePipeline(); + virtual gpu::PipelinePointer getCompositeScenePipeline(); + virtual gpu::Element getCompositeFBColorSpace(); struct CursorData { QImage image; @@ -169,19 +173,19 @@ protected: }; std::map _cursorsData; - bool _lockCurrentTexture { false }; + bool _lockCurrentTexture{ false }; void assertNotPresentThread() const; void assertIsPresentThread() const; - template + template void withPresentThreadLock(F f) const { assertIsPresentThread(); Lock lock(_presentMutex); f(); } - template + template void withNonPresentThreadLock(F f) const { assertNotPresentThread(); Lock lock(_presentMutex); @@ -198,4 +202,3 @@ protected: QImage getScreenshot(float aspectRatio); QImage getSecondaryCameraScreenshot(); }; - diff --git a/plugins/oculus/src/OculusDisplayPlugin.cpp b/plugins/oculus/src/OculusDisplayPlugin.cpp index c493588992..43eabf3544 100644 --- a/plugins/oculus/src/OculusDisplayPlugin.cpp +++ b/plugins/oculus/src/OculusDisplayPlugin.cpp @@ -167,6 +167,7 @@ void OculusDisplayPlugin::hmdPresent() { batch.setStateScissorRect(ivec4(uvec2(), _outputFramebuffer->getSize())); batch.resetViewTransform(); batch.setProjectionTransform(mat4()); + //batch.setPipeline(_drawTexturePipeline); batch.setPipeline(_drawTexturePipeline); batch.setResourceTexture(0, _compositeFramebuffer->getRenderBuffer(0)); batch.draw(gpu::TRIANGLE_STRIP, 4); diff --git a/plugins/oculus/src/OculusDisplayPlugin.h b/plugins/oculus/src/OculusDisplayPlugin.h index 8eda599fa9..b220ee0214 100644 --- a/plugins/oculus/src/OculusDisplayPlugin.h +++ b/plugins/oculus/src/OculusDisplayPlugin.h @@ -24,6 +24,8 @@ public: virtual QJsonObject getHardwareStats() const; + virtual gpu::PipelinePointer getCompositeScenePipeline() override; + protected: QThread::Priority getPresentPriority() override { return QThread::TimeCriticalPriority; } @@ -34,8 +36,6 @@ protected: void uncustomizeContext() override; void cycleDebugOutput() override; - virtual gpu::PipelinePointer getCompositeScenePipeline() override; - private: static const char* NAME; ovrTextureSwapChain _textureSwapChain;