From 250d18d7dfdad838dac7ee4b32763cdf0dfd81c5 Mon Sep 17 00:00:00 2001 From: Anna Date: Fri, 21 Jun 2019 11:11:44 -0700 Subject: [PATCH 1/6] restructured gamma correction so snapshots look correct --- .../Basic2DWindowOpenGLDisplayPlugin.cpp | 18 +- .../Basic2DWindowOpenGLDisplayPlugin.h | 1 + .../display-plugins/OpenGLDisplayPlugin.cpp | 174 ++++++++---------- .../src/display-plugins/OpenGLDisplayPlugin.h | 59 +++--- plugins/oculus/src/OculusDisplayPlugin.cpp | 1 + plugins/oculus/src/OculusDisplayPlugin.h | 4 +- 6 files changed, 129 insertions(+), 128 deletions(-) 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; From 3d36c5714fd9fb9a03e6422a9158860f08314095 Mon Sep 17 00:00:00 2001 From: Anna Date: Fri, 21 Jun 2019 11:34:10 -0700 Subject: [PATCH 2/6] added comments and cleaned up --- .../src/display-plugins/OpenGLDisplayPlugin.cpp | 8 ++++++-- plugins/oculus/src/OculusDisplayPlugin.cpp | 1 - 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp index c990be6e42..cdbbc15877 100644 --- a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp @@ -574,9 +574,10 @@ std::function OpenGL std::array hudEyeViewports; for_each_eye([&](Eye eye) { hudEyeViewports[eye] = eyeViewport(eye); }); return [=](gpu::Batch& batch, const gpu::TexturePointer& hudTexture, bool mirror) { - if (hudPipeline && hudTexture) { + auto pipeline = mirror ? hudMirrorPipeline : hudPipeline; + if (pipeline && hudTexture) { batch.enableStereo(false); - batch.setPipeline(mirror ? hudMirrorPipeline : hudPipeline); + batch.setPipeline(pipeline); batch.setResourceTexture(0, hudTexture); if (hudStereo) { for_each_eye([&](Eye eye) { @@ -954,6 +955,9 @@ gpu::PipelinePointer OpenGLDisplayPlugin::getCompositeScenePipeline() { return _drawTexturePipeline; } +// Added this to allow desktop composite framebuffer to be RGBA while mobile is SRGBA, so that tone mapping looks right on both platforms +// Overridden by Basic2DWindowDisplayPlugin to achieve this +// 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; } diff --git a/plugins/oculus/src/OculusDisplayPlugin.cpp b/plugins/oculus/src/OculusDisplayPlugin.cpp index 43eabf3544..c493588992 100644 --- a/plugins/oculus/src/OculusDisplayPlugin.cpp +++ b/plugins/oculus/src/OculusDisplayPlugin.cpp @@ -167,7 +167,6 @@ 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); From 70fbe840a5f95f12209283f04b6184124c4969ad Mon Sep 17 00:00:00 2001 From: Anna Date: Fri, 21 Jun 2019 12:00:20 -0700 Subject: [PATCH 3/6] added getCompositeFBColorSpace back into updateCompositeFramebuffer --- .../display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp index cdbbc15877..b4fb936c5d 100644 --- a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp @@ -887,7 +887,7 @@ void OpenGLDisplayPlugin::updateCompositeFramebuffer() { auto renderSize = glm::uvec2(getRecommendedRenderSize()); if (!_compositeFramebuffer || _compositeFramebuffer->getSize() != renderSize) { _compositeFramebuffer = - gpu::FramebufferPointer(gpu::Framebuffer::create("OpenGLDisplayPlugin::composite", gpu::Element::COLOR_RGBA_32, + gpu::FramebufferPointer(gpu::Framebuffer::create("OpenGLDisplayPlugin::composite", getCompositeFBColorSpace(), renderSize.x, renderSize.y)); // _compositeFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create("OpenGLDisplayPlugin::composite", gpu::Element::COLOR_SRGBA_32, renderSize.x, renderSize.y)); } From 17163a1ce87a3a6577d1e560b7642a8c4e9137d2 Mon Sep 17 00:00:00 2001 From: Anna Date: Fri, 21 Jun 2019 13:41:41 -0700 Subject: [PATCH 4/6] undid some VS auto format changes --- .../display-plugins/OpenGLDisplayPlugin.cpp | 91 +++++++++++-------- 1 file changed, 52 insertions(+), 39 deletions(-) diff --git a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp index b4fb936c5d..7d12825b7e 100644 --- a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp @@ -59,14 +59,19 @@ 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; } @@ -86,7 +91,7 @@ public: Lock lock(_mutex); if (isRunning()) { _newPluginQueue.push(plugin); - _condition.wait(lock, [=]() -> bool { return _newPluginQueue.empty(); }); + _condition.wait(lock, [=]()->bool { return _newPluginQueue.empty(); }); } } @@ -113,7 +118,8 @@ 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 @@ -230,17 +236,17 @@ 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() { @@ -356,9 +362,11 @@ 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()); @@ -372,8 +380,11 @@ void OpenGLDisplayPlugin::customizeContext() { 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)); @@ -391,10 +402,12 @@ void OpenGLDisplayPlugin::customizeContext() { _cursorPipeline = gpu::Pipeline::create(gpu::Shader::createProgram(DrawTransformedTexture), blendState); } + updateCompositeFramebuffer(); } void OpenGLDisplayPlugin::uncustomizeContext() { + _drawTexturePipeline.reset(); _linearToSRGBPipeline.reset(); _SRGBToLinearPipeline.reset(); @@ -402,6 +415,7 @@ void OpenGLDisplayPlugin::uncustomizeContext() { _hudPipeline.reset(); _mirrorHUDPipeline.reset(); _compositeFramebuffer.reset(); + withPresentThreadLock([&] { _currentFrame.reset(); _lastFrame = nullptr; @@ -455,7 +469,9 @@ 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 { @@ -469,10 +485,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); @@ -522,7 +538,7 @@ void OpenGLDisplayPlugin::renderFromTexture(gpu::Batch& batch, 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(); @@ -537,7 +553,7 @@ void OpenGLDisplayPlugin::renderFromTexture(gpu::Batch& batch, 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); } } @@ -572,7 +588,9 @@ 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) { @@ -659,9 +677,8 @@ void OpenGLDisplayPlugin::internalPresent() { // 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); - }); + renderFromTexture(batch, _displayTexture ? _displayTexture : _compositeFramebuffer->getRenderBuffer(0), viewport, viewport); + }); swapBuffers(); _presentRate.increment(); } @@ -700,7 +717,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(); @@ -794,7 +811,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 { @@ -845,7 +862,9 @@ void OpenGLDisplayPlugin::assertIsPresentThread() const { } bool OpenGLDisplayPlugin::beginFrameRender(uint32_t frameIndex) { - withNonPresentThreadLock([&] { _compositeHUDAlpha = _hudAlpha; }); + withNonPresentThreadLock([&] { + _compositeHUDAlpha = _hudAlpha; + }); return Parent::beginFrameRender(frameIndex); } @@ -886,22 +905,17 @@ OpenGLDisplayPlugin::~OpenGLDisplayPlugin() { 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_SRGBA_32, renderSize.x, renderSize.y)); + _compositeFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create("OpenGLDisplayPlugin::composite", getCompositeFBColorSpace(), 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); @@ -937,8 +951,7 @@ 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); From 8c3ddc049ce33c596a1fd1f8f519e9a50ae327b6 Mon Sep 17 00:00:00 2001 From: Anna Date: Fri, 21 Jun 2019 20:08:09 -0700 Subject: [PATCH 5/6] works on desktop, android mobile, rift and quest --- .../Basic2DWindowOpenGLDisplayPlugin.cpp | 17 ----------------- .../Basic2DWindowOpenGLDisplayPlugin.h | 2 -- .../src/display-plugins/OpenGLDisplayPlugin.cpp | 8 +------- .../src/display-plugins/OpenGLDisplayPlugin.h | 1 - plugins/oculus/src/OculusDisplayPlugin.cpp | 5 +++++ plugins/oculus/src/OculusDisplayPlugin.h | 1 + 6 files changed, 7 insertions(+), 27 deletions(-) diff --git a/libraries/display-plugins/src/display-plugins/Basic2DWindowOpenGLDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/Basic2DWindowOpenGLDisplayPlugin.cpp index 38f7600315..b8912d95b6 100644 --- a/libraries/display-plugins/src/display-plugins/Basic2DWindowOpenGLDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/Basic2DWindowOpenGLDisplayPlugin.cpp @@ -123,23 +123,6 @@ gpu::PipelinePointer Basic2DWindowOpenGLDisplayPlugin::getRenderTexturePipeline( #endif } -gpu::PipelinePointer Basic2DWindowOpenGLDisplayPlugin::getCompositeScenePipeline() { -#if defined(Q_OS_ANDROID) - return _linearToSRGBPipeline; -#else - return _drawTexturePipeline; -#endif -} - -gpu::Element Basic2DWindowOpenGLDisplayPlugin::getCompositeFBColorSpace() { -#if defined(Q_OS_ANDROID) - return gpu::Element::COLOR_SRGBA_32; -#else - return gpu::Element::COLOR_RGBA_32; -#endif -} - - void Basic2DWindowOpenGLDisplayPlugin::compositeExtra() { #if defined(Q_OS_ANDROID) auto& virtualPadManager = VirtualPad::Manager::instance(); diff --git a/libraries/display-plugins/src/display-plugins/Basic2DWindowOpenGLDisplayPlugin.h b/libraries/display-plugins/src/display-plugins/Basic2DWindowOpenGLDisplayPlugin.h index ae830b2e28..68301ff8b4 100644 --- a/libraries/display-plugins/src/display-plugins/Basic2DWindowOpenGLDisplayPlugin.h +++ b/libraries/display-plugins/src/display-plugins/Basic2DWindowOpenGLDisplayPlugin.h @@ -38,8 +38,6 @@ public: virtual void pluginUpdate() override {}; virtual gpu::PipelinePointer getRenderTexturePipeline() override; - virtual gpu::PipelinePointer getCompositeScenePipeline() override; - virtual gpu::Element getCompositeFBColorSpace() override; protected: mutable bool _isThrottled = false; diff --git a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp index 7d12825b7e..75cdf5ebef 100644 --- a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp @@ -905,7 +905,7 @@ OpenGLDisplayPlugin::~OpenGLDisplayPlugin() { 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)); } } @@ -968,9 +968,3 @@ gpu::PipelinePointer OpenGLDisplayPlugin::getCompositeScenePipeline() { return _drawTexturePipeline; } -// Added this to allow desktop composite framebuffer to be RGBA while mobile is SRGBA, so that tone mapping looks right on both platforms -// Overridden by Basic2DWindowDisplayPlugin to achieve this -// 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; -} diff --git a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.h b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.h index d5d9bad8a6..a6ab40d2bc 100644 --- a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.h +++ b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.h @@ -163,7 +163,6 @@ protected: virtual gpu::PipelinePointer getRenderTexturePipeline(); virtual gpu::PipelinePointer getCompositeScenePipeline(); - virtual gpu::Element getCompositeFBColorSpace(); struct CursorData { QImage image; diff --git a/plugins/oculus/src/OculusDisplayPlugin.cpp b/plugins/oculus/src/OculusDisplayPlugin.cpp index c493588992..f928ccb8a4 100644 --- a/plugins/oculus/src/OculusDisplayPlugin.cpp +++ b/plugins/oculus/src/OculusDisplayPlugin.cpp @@ -124,6 +124,11 @@ void OculusDisplayPlugin::uncustomizeContext() { Parent::uncustomizeContext(); } +gpu::PipelinePointer OculusDisplayPlugin::getRenderTexturePipeline() { + //return _SRGBToLinearPipeline; + return _drawTexturePipeline; +} + gpu::PipelinePointer OculusDisplayPlugin::getCompositeScenePipeline() { return _SRGBToLinearPipeline; } diff --git a/plugins/oculus/src/OculusDisplayPlugin.h b/plugins/oculus/src/OculusDisplayPlugin.h index b220ee0214..a892d27534 100644 --- a/plugins/oculus/src/OculusDisplayPlugin.h +++ b/plugins/oculus/src/OculusDisplayPlugin.h @@ -24,6 +24,7 @@ public: virtual QJsonObject getHardwareStats() const; + virtual gpu::PipelinePointer getRenderTexturePipeline() override; virtual gpu::PipelinePointer getCompositeScenePipeline() override; protected: From 792cef1a91fb5e9a59b9bd88424b2cc287f8c262 Mon Sep 17 00:00:00 2001 From: Anna Date: Mon, 24 Jun 2019 15:57:09 -0700 Subject: [PATCH 6/6] fixed bad merge --- .../display-plugins/src/display-plugins/OpenGLDisplayPlugin.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.h b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.h index a6ab40d2bc..777c74822a 100644 --- a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.h +++ b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.h @@ -80,6 +80,7 @@ public: // Three threads, one for rendering, one for texture transfers, one reserved for the GL driver int getRequiredThreadCount() const override { return 3; } + virtual std::function getHUDOperator() override; void copyTextureToQuickFramebuffer(NetworkTexturePointer source, QOpenGLFramebufferObject* target, GLsync* fenceSync) override; @@ -100,7 +101,6 @@ protected: virtual QThread::Priority getPresentPriority() { return QThread::HighPriority; } virtual void compositeLayers(); virtual void compositeScene(); - virtual std::function getHUDOperator(); virtual void compositePointer(); virtual void compositeExtra(){};