From 17163a1ce87a3a6577d1e560b7642a8c4e9137d2 Mon Sep 17 00:00:00 2001 From: Anna Date: Fri, 21 Jun 2019 13:41:41 -0700 Subject: [PATCH] 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);