From 0c50cb670aa128a0a648608868567d9456022872 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Mon, 13 Jul 2015 12:40:26 -0700 Subject: [PATCH 01/17] Moving boostconfig folder in IDEs --- cmake/externals/boostconfig/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/cmake/externals/boostconfig/CMakeLists.txt b/cmake/externals/boostconfig/CMakeLists.txt index 8494bb0114..ed3413a894 100644 --- a/cmake/externals/boostconfig/CMakeLists.txt +++ b/cmake/externals/boostconfig/CMakeLists.txt @@ -16,3 +16,4 @@ ExternalProject_Get_Property(${EXTERNAL_NAME} SOURCE_DIR) set(${EXTERNAL_NAME_UPPER}_INCLUDE_DIRS ${SOURCE_DIR}/include CACHE TYPE INTERNAL) +set_target_properties(${EXTERNAL_NAME} PROPERTIES FOLDER "hidden/externals") From 0af62ca946a3a9631bff51481f4fbc26a00ebf79 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Tue, 14 Jul 2015 16:39:12 -0700 Subject: [PATCH 02/17] Convert tabs to spaces --- interface/src/avatar/MyAvatar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 79c600b7ec..1c7da32ea4 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -79,7 +79,7 @@ const float MyAvatar::ZOOM_MAX = 25.0f; const float MyAvatar::ZOOM_DEFAULT = 1.5f; MyAvatar::MyAvatar() : - Avatar(), + Avatar(), _gravity(0.0f, 0.0f, 0.0f), _wasPushing(false), _isPushing(false), From fc0ae17a87a06abac5758d5d57f48fe9b36a3d33 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Tue, 14 Jul 2015 16:42:46 -0700 Subject: [PATCH 03/17] Mirror head when using face tracker in fullscreen mirror Mirror translation, yaw, and roll in the same manner as done for HMD case, to mimic what you would expect to see in a mirror. --- interface/src/avatar/MyAvatar.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 1c7da32ea4..0cc762cf6c 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -253,6 +253,9 @@ void MyAvatar::updateFromTrackers(float deltaTime) { return; } + FaceTracker* tracker = Application::getInstance()->getActiveFaceTracker(); + bool inFacetracker = tracker && !tracker->isMuted(); + if (inHmd) { estimatedPosition = qApp->getHeadPosition(); estimatedPosition.x *= -1.0f; @@ -260,12 +263,17 @@ void MyAvatar::updateFromTrackers(float deltaTime) { const float OCULUS_LEAN_SCALE = 0.05f; estimatedPosition /= OCULUS_LEAN_SCALE; - } else { - FaceTracker* tracker = Application::getInstance()->getActiveFaceTracker(); - if (tracker && !tracker->isMuted()) { - estimatedPosition = tracker->getHeadTranslation(); - _trackedHeadPosition = estimatedPosition; - estimatedRotation = glm::degrees(safeEulerAngles(tracker->getHeadRotation())); + } else if (inFacetracker) { + estimatedPosition = tracker->getHeadTranslation(); + _trackedHeadPosition = estimatedPosition; + estimatedRotation = glm::degrees(safeEulerAngles(tracker->getHeadRotation())); + if (Application::getInstance()->getCamera()->getMode() == CAMERA_MODE_MIRROR) { + // Invert yaw and roll when in mirror mode + // NOTE: this is kinda a hack, it's the same hack we use to make the head tilt. But it's not really a mirror + // it just makes you feel like you're looking in a mirror because the body movements of the avatar appear to + // match your body movements. + YAW(estimatedRotation) *= -1.0f; + ROLL(estimatedRotation) *= -1.0f; } } @@ -312,7 +320,7 @@ void MyAvatar::updateFromTrackers(float deltaTime) { // NOTE: this is kinda a hack, it's the same hack we use to make the head tilt. But it's not really a mirror // it just makes you feel like you're looking in a mirror because the body movements of the avatar appear to // match your body movements. - if (inHmd && Application::getInstance()->getCamera()->getMode() == CAMERA_MODE_MIRROR) { + if ((inHmd || inFacetracker) && Application::getInstance()->getCamera()->getMode() == CAMERA_MODE_MIRROR) { relativePosition.x = -relativePosition.x; } From c0859ffd4caf3e44deddba8f91583d2dfa4e70e1 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Mon, 20 Jul 2015 14:33:10 -0700 Subject: [PATCH 04/17] Removing some dead forward declarations --- interface/src/Application.cpp | 26 ++------------------------ interface/src/ui/ApplicationOverlay.h | 2 -- libraries/ui/src/OffscreenUi.cpp | 1 - 3 files changed, 2 insertions(+), 27 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index ce156354fb..24b20a830e 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -9,11 +9,9 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include +#include "Application.h" -#include -#include -#include +#include #include #include @@ -92,7 +90,6 @@ #include #include -#include "Application.h" #include "AudioClient.h" #include "DiscoverabilityManager.h" #include "GLCanvas.h" @@ -766,25 +763,6 @@ void Application::initializeGL() { } #endif - qCDebug(interfaceapp) << "GL Version: " << QString((const char*) glGetString(GL_VERSION)); - qCDebug(interfaceapp) << "GL Shader Language Version: " << QString((const char*) glGetString(GL_SHADING_LANGUAGE_VERSION)); - qCDebug(interfaceapp) << "GL Vendor: " << QString((const char*) glGetString(GL_VENDOR)); - qCDebug(interfaceapp) << "GL Renderer: " << QString((const char*) glGetString(GL_RENDERER)); - - #ifdef WIN32 - GLenum err = glewInit(); - if (GLEW_OK != err) { - /* Problem: glewInit failed, something is seriously wrong. */ - qCDebug(interfaceapp, "Error: %s\n", glewGetErrorString(err)); - } - qCDebug(interfaceapp, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION)); - - if (wglewGetExtension("WGL_EXT_swap_control")) { - int swapInterval = wglGetSwapIntervalEXT(); - qCDebug(interfaceapp, "V-Sync is %s\n", (swapInterval > 0 ? "ON" : "OFF")); - } - #endif - #if defined(Q_OS_LINUX) // TODO: Write the correct code for Linux... /* if (wglewGetExtension("WGL_EXT_swap_control")) { diff --git a/interface/src/ui/ApplicationOverlay.h b/interface/src/ui/ApplicationOverlay.h index 92485fba82..532fea23dc 100644 --- a/interface/src/ui/ApplicationOverlay.h +++ b/interface/src/ui/ApplicationOverlay.h @@ -13,7 +13,6 @@ #define hifi_ApplicationOverlay_h #include -class QOpenGLFramebufferObject; // Handles the drawing of the overlays to the screen // TODO, move divide up the rendering, displaying and input handling @@ -50,7 +49,6 @@ private: gpu::TexturePointer _overlayDepthTexture; gpu::TexturePointer _overlayColorTexture; gpu::FramebufferPointer _overlayFramebuffer; - }; #endif // hifi_ApplicationOverlay_h diff --git a/libraries/ui/src/OffscreenUi.cpp b/libraries/ui/src/OffscreenUi.cpp index 916cdf8659..d581f12473 100644 --- a/libraries/ui/src/OffscreenUi.cpp +++ b/libraries/ui/src/OffscreenUi.cpp @@ -9,7 +9,6 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // #include "OffscreenUi.h" -#include #include #include #include From 94d57a2e43bcb6c1d3f8810e9221b43b45cca140 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Mon, 20 Jul 2015 16:51:01 -0700 Subject: [PATCH 05/17] fixing missing glew init --- interface/src/Application.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 24b20a830e..096859e723 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -763,6 +763,20 @@ void Application::initializeGL() { } #endif +#ifdef WIN32 + GLenum err = glewInit(); + if (GLEW_OK != err) { + /* Problem: glewInit failed, something is seriously wrong. */ + qCDebug(interfaceapp, "Error: %s\n", glewGetErrorString(err)); + } + qCDebug(interfaceapp, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION)); + + if (wglewGetExtension("WGL_EXT_swap_control")) { + int swapInterval = wglGetSwapIntervalEXT(); + qCDebug(interfaceapp, "V-Sync is %s\n", (swapInterval > 0 ? "ON" : "OFF")); + } +#endif + #if defined(Q_OS_LINUX) // TODO: Write the correct code for Linux... /* if (wglewGetExtension("WGL_EXT_swap_control")) { From c3a2b72c139a77d01162925a538c9fafb5279260 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Mon, 20 Jul 2015 17:26:26 -0700 Subject: [PATCH 06/17] Breaking framebuffer ops out of texture cache --- interface/src/Application.cpp | 22 ++- interface/src/Application.h | 1 - interface/src/devices/OculusManager.cpp | 5 +- libraries/gpu/src/gpu/Framebuffer.h | 44 +++--- libraries/gpu/src/gpu/Texture.cpp | 2 +- .../src/DeferredLightingEffect.cpp | 34 ++--- .../render-utils/src/FramebufferCache.cpp | 112 ++++++++++++++ libraries/render-utils/src/FramebufferCache.h | 59 +++++++ libraries/render-utils/src/TextureCache.cpp | 144 +----------------- libraries/render-utils/src/TextureCache.h | 49 ------ 10 files changed, 236 insertions(+), 236 deletions(-) create mode 100644 libraries/render-utils/src/FramebufferCache.cpp create mode 100644 libraries/render-utils/src/FramebufferCache.h diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 096859e723..0ee15246e7 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -59,6 +59,7 @@ #include #include #include +#include #include #include #include @@ -85,6 +86,7 @@ #include #include #include +#include #include #include #include @@ -263,6 +265,8 @@ bool setupEssentials(int& argc, char** argv) { auto audioScope = DependencyManager::set(); auto deferredLightingEffect = DependencyManager::set(); auto textureCache = DependencyManager::set(); + auto framebufferCache = DependencyManager::set(); + auto animationCache = DependencyManager::set(); auto ddeFaceTracker = DependencyManager::set(); auto modelBlender = DependencyManager::set(); @@ -730,6 +734,7 @@ Application::~Application() { DependencyManager::destroy(); DependencyManager::destroy(); DependencyManager::destroy(); + DependencyManager::destroy(); DependencyManager::destroy(); DependencyManager::destroy(); DependencyManager::destroy(); @@ -889,6 +894,8 @@ void Application::paintGL() { PerformanceWarning warn(showWarnings, "Application::paintGL()"); resizeGL(); + glEnable(GL_LINE_SMOOTH); + { PerformanceTimer perfTimer("renderOverlay"); @@ -899,7 +906,6 @@ void Application::paintGL() { _applicationOverlay.renderOverlay(&renderArgs); } - glEnable(GL_LINE_SMOOTH); if (_myCamera.getMode() == CAMERA_MODE_FIRST_PERSON || _myCamera.getMode() == CAMERA_MODE_THIRD_PERSON) { Menu::getInstance()->setIsOptionChecked(MenuOption::FirstPerson, _myAvatar->getBoomLength() <= MyAvatar::ZOOM_MIN); @@ -976,7 +982,7 @@ void Application::paintGL() { { gpu::Batch batch; - auto primaryFbo = DependencyManager::get()->getPrimaryFramebuffer(); + auto primaryFbo = DependencyManager::get()->getPrimaryFramebuffer(); batch.setFramebuffer(primaryFbo); // clear the normal and specular buffers batch.clearFramebuffer( @@ -987,7 +993,7 @@ void Application::paintGL() { vec4(vec3(0), 1), 1.0, 0.0); // Viewport is assigned to the size of the framebuffer - QSize size = DependencyManager::get()->getFrameBufferSize(); + QSize size = DependencyManager::get()->getFrameBufferSize(); renderArgs._viewport = glm::ivec4(0, 0, size.width(), size.height()); batch.setViewportTransform(renderArgs._viewport); renderArgs._context->render(batch); @@ -1003,7 +1009,7 @@ void Application::paintGL() { { auto geometryCache = DependencyManager::get(); - auto primaryFbo = DependencyManager::get()->getPrimaryFramebuffer(); + auto primaryFbo = DependencyManager::get()->getPrimaryFramebuffer(); gpu::Batch batch; batch.blit(primaryFbo, glm::ivec4(0, 0, _renderResolution.x, _renderResolution.y), nullptr, glm::ivec4(0, 0, _glWidget->getDeviceSize().width(), _glWidget->getDeviceSize().height())); @@ -1077,7 +1083,7 @@ void Application::resizeGL() { if (_renderResolution != toGlm(renderSize)) { _renderResolution = toGlm(renderSize); - DependencyManager::get()->setFrameBufferSize(renderSize); + DependencyManager::get()->setFrameBufferSize(renderSize); updateProjectionMatrix(); } @@ -2997,7 +3003,7 @@ PickRay Application::computePickRay(float x, float y) const { } QImage Application::renderAvatarBillboard(RenderArgs* renderArgs) { - auto primaryFramebuffer = DependencyManager::get()->getPrimaryFramebuffer(); + auto primaryFramebuffer = DependencyManager::get()->getPrimaryFramebuffer(); glBindFramebuffer(GL_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(primaryFramebuffer)); // clear the alpha channel so the background is transparent @@ -3475,11 +3481,11 @@ void Application::renderRearViewMirror(RenderArgs* renderArgs, const QRect& regi // set the bounds of rear mirror view gpu::Vec4i viewport; if (billboard) { - QSize size = DependencyManager::get()->getFrameBufferSize(); + QSize size = DependencyManager::get()->getFrameBufferSize(); viewport = gpu::Vec4i(region.x(), size.height() - region.y() - region.height(), region.width(), region.height()); } else { // if not rendering the billboard, the region is in device independent coordinates; must convert to device - QSize size = DependencyManager::get()->getFrameBufferSize(); + QSize size = DependencyManager::get()->getFrameBufferSize(); float ratio = (float)QApplication::desktop()->windowHandle()->devicePixelRatio() * getRenderResolutionScale(); int x = region.x() * ratio, y = region.y() * ratio, width = region.width() * ratio, height = region.height() * ratio; viewport = gpu::Vec4i(x, size.height() - y - height, width, height); diff --git a/interface/src/Application.h b/interface/src/Application.h index 2f18104f86..05d06d6272 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -34,7 +34,6 @@ #include #include #include -#include #include #include diff --git a/interface/src/devices/OculusManager.cpp b/interface/src/devices/OculusManager.cpp index 9395584a66..9a9ec63e3b 100644 --- a/interface/src/devices/OculusManager.cpp +++ b/interface/src/devices/OculusManager.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include @@ -644,7 +645,7 @@ void OculusManager::display(QGLWidget * glCanvas, RenderArgs* renderArgs, const return; } - auto primaryFBO = DependencyManager::get()->getPrimaryFramebuffer(); + auto primaryFBO = DependencyManager::get()->getPrimaryFramebuffer(); glBindFramebuffer(GL_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(primaryFBO)); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -704,7 +705,7 @@ void OculusManager::display(QGLWidget * glCanvas, RenderArgs* renderArgs, const _activeEye = ovrEye_Count; gpu::FramebufferPointer finalFbo; - finalFbo = DependencyManager::get()->getPrimaryFramebuffer(); + finalFbo = DependencyManager::get()->getPrimaryFramebuffer(); glBindFramebuffer(GL_FRAMEBUFFER, 0); // restore our normal viewport diff --git a/libraries/gpu/src/gpu/Framebuffer.h b/libraries/gpu/src/gpu/Framebuffer.h index 50f42ed4fb..5a1504d25c 100755 --- a/libraries/gpu/src/gpu/Framebuffer.h +++ b/libraries/gpu/src/gpu/Framebuffer.h @@ -1,19 +1,21 @@ -// -// Framebuffer.h -// libraries/gpu/src/gpu -// -// Created by Sam Gateau on 4/12/2015. -// Copyright 2014 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// -#ifndef hifi_gpu_Framebuffer_h -#define hifi_gpu_Framebuffer_h - -#include "Texture.h" +// +// Framebuffer.h +// libraries/gpu/src/gpu +// +// Created by Sam Gateau on 4/12/2015. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// +#ifndef hifi_gpu_Framebuffer_h +#define hifi_gpu_Framebuffer_h + +#include "Texture.h" #include +class QImage; + namespace gpu { typedef Element Format; @@ -130,7 +132,9 @@ public: void resize( uint16 width, uint16 height, uint16 samples = 1 ); static const uint32 MAX_NUM_RENDER_BUFFERS = 8; - static uint32 getMaxNumRenderBuffers() { return MAX_NUM_RENDER_BUFFERS; } + static uint32 getMaxNumRenderBuffers() { return MAX_NUM_RENDER_BUFFERS; } + + void getImage(QImage* result) const; protected: SwapchainPointer _swapchain; @@ -151,10 +155,10 @@ protected: // Non exposed Framebuffer(const Framebuffer& framebuffer) {} Framebuffer() {} - - // This shouldn't be used by anything else than the Backend class with the proper casting. - mutable GPUObject* _gpuObject = NULL; - void setGPUObject(GPUObject* gpuObject) const { _gpuObject = gpuObject; } + + // This shouldn't be used by anything else than the Backend class with the proper casting. + mutable GPUObject* _gpuObject = NULL; + void setGPUObject(GPUObject* gpuObject) const { _gpuObject = gpuObject; } GPUObject* getGPUObject() const { return _gpuObject; } friend class Backend; }; @@ -162,4 +166,4 @@ typedef std::shared_ptr FramebufferPointer; } -#endif \ No newline at end of file +#endif diff --git a/libraries/gpu/src/gpu/Texture.cpp b/libraries/gpu/src/gpu/Texture.cpp index 69c00336f1..8a55603cb7 100755 --- a/libraries/gpu/src/gpu/Texture.cpp +++ b/libraries/gpu/src/gpu/Texture.cpp @@ -10,7 +10,7 @@ // #include "Texture.h" -#include + #include #include diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 582864991a..4f7121b7a7 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -23,6 +23,7 @@ #include "GeometryCache.h" #include "RenderUtil.h" #include "TextureCache.h" +#include "FramebufferCache.h" #include "simple_vert.h" @@ -215,8 +216,6 @@ void DeferredLightingEffect::addSpotLight(const glm::vec3& position, float radiu } void DeferredLightingEffect::prepare(RenderArgs* args) { - - auto textureCache = DependencyManager::get(); gpu::Batch batch; // clear the normal and specular buffers @@ -232,25 +231,23 @@ void DeferredLightingEffect::render(RenderArgs* args) { gpu::Batch batch; // perform deferred lighting, rendering to free fbo - auto textureCache = DependencyManager::get(); + auto framebufferCache = DependencyManager::get(); - QSize framebufferSize = textureCache->getFrameBufferSize(); + QSize framebufferSize = framebufferCache->getFrameBufferSize(); // binding the first framebuffer - auto freeFBO = DependencyManager::get()->getSecondaryFramebuffer(); + auto freeFBO = framebufferCache->getSecondaryFramebuffer(); batch.setFramebuffer(freeFBO); batch.setViewportTransform(args->_viewport); batch.clearColorFramebuffer(freeFBO->getBufferMask(), glm::vec4(0.0f, 0.0f, 0.0f, 0.0f)); - batch.setResourceTexture(0, textureCache->getPrimaryColorTexture()); - - batch.setResourceTexture(1, textureCache->getPrimaryNormalTexture()); - - batch.setResourceTexture(2, textureCache->getPrimarySpecularTexture()); - - batch.setResourceTexture(3, textureCache->getPrimaryDepthTexture()); + auto primaryFramebuffer = framebufferCache->getPrimaryFramebuffer(); + for (int i = 0; i < 3; ++i) { + batch.setResourceTexture(i, primaryFramebuffer->getRenderBuffer(i)); + } + batch.setResourceTexture(3, primaryFramebuffer->getDepthStencilBuffer()); float sMin = args->_viewport.x / (float)framebufferSize.width(); float sWidth = args->_viewport.z / (float)framebufferSize.width(); @@ -267,7 +264,7 @@ void DeferredLightingEffect::render(RenderArgs* args) { const LightLocations* locations = &_directionalLightLocations; bool shadowsEnabled = _viewState->getShadowsEnabled(); if (shadowsEnabled) { - batch.setResourceTexture(4, textureCache->getShadowFramebuffer()->getDepthStencilBuffer()); + batch.setResourceTexture(4, framebufferCache->getShadowFramebuffer()->getDepthStencilBuffer()); program = _directionalLightShadowMap; locations = &_directionalLightShadowMapLocations; @@ -294,7 +291,7 @@ void DeferredLightingEffect::render(RenderArgs* args) { } batch.setPipeline(program); } - batch._glUniform1f(locations->shadowScale, 1.0f / textureCache->getShadowFramebuffer()->getWidth()); + batch._glUniform1f(locations->shadowScale, 1.0f / framebufferCache->getShadowFramebuffer()->getWidth()); } else { if (useSkyboxCubemap) { @@ -537,12 +534,12 @@ void DeferredLightingEffect::render(RenderArgs* args) { void DeferredLightingEffect::copyBack(RenderArgs* args) { gpu::Batch batch; - auto textureCache = DependencyManager::get(); - QSize framebufferSize = textureCache->getFrameBufferSize(); + auto framebufferCache = DependencyManager::get(); + QSize framebufferSize = framebufferCache->getFrameBufferSize(); - auto freeFBO = DependencyManager::get()->getSecondaryFramebuffer(); + auto freeFBO = framebufferCache->getSecondaryFramebuffer(); - batch.setFramebuffer(textureCache->getPrimaryFramebuffer()); + batch.setFramebuffer(framebufferCache->getPrimaryFramebuffer()); batch.setPipeline(_blitLightBuffer); batch.setResourceTexture(0, freeFBO->getRenderBuffer(0)); @@ -564,7 +561,6 @@ void DeferredLightingEffect::copyBack(RenderArgs* args) { batch.draw(gpu::TRIANGLE_STRIP, 4); - args->_context->syncCache(); args->_context->render(batch); } diff --git a/libraries/render-utils/src/FramebufferCache.cpp b/libraries/render-utils/src/FramebufferCache.cpp new file mode 100644 index 0000000000..c699da2e81 --- /dev/null +++ b/libraries/render-utils/src/FramebufferCache.cpp @@ -0,0 +1,112 @@ +// +// FramebufferCache.cpp +// interface/src/renderer +// +// Created by Andrzej Kapolka on 8/6/13. +// Copyright 2013 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include "FramebufferCache.h" + +#include + +#include + +#include +#include +#include +#include +#include "RenderUtilsLogging.h" + +static QQueue _cachedFramebuffers; + +FramebufferCache::FramebufferCache() { +} + +FramebufferCache::~FramebufferCache() { + _cachedFramebuffers.clear(); +} + +void FramebufferCache::setFrameBufferSize(QSize frameBufferSize) { + //If the size changed, we need to delete our FBOs + if (_frameBufferSize != frameBufferSize) { + _frameBufferSize = frameBufferSize; + _primaryFramebuffer.reset(); + } +} + +void FramebufferCache::createPrimaryFramebuffer() { + _primaryFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create()); + + static auto colorFormat = gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA); + static auto depthFormat = gpu::Element(gpu::SCALAR, gpu::FLOAT, gpu::DEPTH); + + auto width = _frameBufferSize.width(); + auto height = _frameBufferSize.height(); + + auto defaultSampler = gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_POINT); + auto colorTexture = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width, height, defaultSampler)); + auto normalTexture = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width, height, defaultSampler)); + auto specularTexture = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width, height, defaultSampler)); + + _primaryFramebuffer->setRenderBuffer(0, colorTexture); + _primaryFramebuffer->setRenderBuffer(1, normalTexture); + _primaryFramebuffer->setRenderBuffer(2, specularTexture); + + + auto depthTexture = gpu::TexturePointer(gpu::Texture::create2D(depthFormat, width, height, defaultSampler)); + _primaryFramebuffer->setDepthStencilBuffer(depthTexture, depthFormat); +} + +gpu::FramebufferPointer FramebufferCache::getPrimaryFramebuffer() { + if (!_primaryFramebuffer) { + createPrimaryFramebuffer(); + } + return _primaryFramebuffer; +} + +void FramebufferCache::setPrimaryDrawBuffers(gpu::Batch& batch, bool color, bool normal, bool specular) { + GLenum buffers[3]; + int bufferCount = 0; + if (color) { + buffers[bufferCount++] = GL_COLOR_ATTACHMENT0; + } + if (normal) { + buffers[bufferCount++] = GL_COLOR_ATTACHMENT1; + } + if (specular) { + buffers[bufferCount++] = GL_COLOR_ATTACHMENT2; + } + batch._glDrawBuffers(bufferCount, buffers); +} + + +gpu::FramebufferPointer FramebufferCache::getFramebuffer() { + if (_cachedFramebuffers.isEmpty()) { + _cachedFramebuffers.push_back(gpu::FramebufferPointer(gpu::Framebuffer::create(gpu::Element::COLOR_RGBA_32, _frameBufferSize.width(), _frameBufferSize.height()))); + } + gpu::FramebufferPointer result = _cachedFramebuffers.front(); + _cachedFramebuffers.pop_front(); + return result; +} + + +void FramebufferCache::releaseFramebuffer(const gpu::FramebufferPointer& framebuffer) { + _cachedFramebuffers.push_back(framebuffer); +} + +gpu::FramebufferPointer FramebufferCache::getSecondaryFramebuffer() { + static auto _secondaryFramebuffer = getFramebuffer(); + return _secondaryFramebuffer; +} + +gpu::FramebufferPointer FramebufferCache::getShadowFramebuffer() { + if (!_shadowFramebuffer) { + const int SHADOW_MAP_SIZE = 2048; + _shadowFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::createShadowmap(SHADOW_MAP_SIZE)); + } + return _shadowFramebuffer; +} diff --git a/libraries/render-utils/src/FramebufferCache.h b/libraries/render-utils/src/FramebufferCache.h new file mode 100644 index 0000000000..e756286ccd --- /dev/null +++ b/libraries/render-utils/src/FramebufferCache.h @@ -0,0 +1,59 @@ +// +// Created by Bradley Austin Davis on 2015/07/20 +// Copyright 2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_FramebufferCache_h +#define hifi_FramebufferCache_h + +#include + +#include +#include + +namespace gpu { +class Batch; +} + +/// Stores cached textures, including render-to-texture targets. +class FramebufferCache : public Dependency { + SINGLETON_DEPENDENCY + +public: + /// Sets the desired texture resolution for the framebuffer objects. + void setFrameBufferSize(QSize frameBufferSize); + const QSize& getFrameBufferSize() const { return _frameBufferSize; } + + /// Returns a pointer to the primary framebuffer object. This render target includes a depth component, and is + /// used for scene rendering. + gpu::FramebufferPointer getPrimaryFramebuffer(); + + gpu::FramebufferPointer getSecondaryFramebuffer(); + + /// Returns the framebuffer object used to render shadow maps; + gpu::FramebufferPointer getShadowFramebuffer(); + + /// Enables or disables draw buffers on the primary framebuffer. Note: the primary framebuffer must be bound. + void setPrimaryDrawBuffers(gpu::Batch& batch, bool color, bool normal = false, bool specular = false); + + /// Returns a free framebuffer with a single color attachment for temp or intra-frame operations + gpu::FramebufferPointer getFramebuffer(); + // TODO add sync functionality to the release, so we don't reuse a framebuffer being read from + /// Releases a free framebuffer back for reuse + void releaseFramebuffer(const gpu::FramebufferPointer& framebuffer); + +private: + FramebufferCache(); + virtual ~FramebufferCache(); + + void createPrimaryFramebuffer(); + + gpu::FramebufferPointer _primaryFramebuffer; + gpu::FramebufferPointer _shadowFramebuffer; + QSize _frameBufferSize{ 100, 100 }; +}; + +#endif // hifi_FramebufferCache_h diff --git a/libraries/render-utils/src/TextureCache.cpp b/libraries/render-utils/src/TextureCache.cpp index 910cf3386b..8f08be2b1d 100644 --- a/libraries/render-utils/src/TextureCache.cpp +++ b/libraries/render-utils/src/TextureCache.cpp @@ -9,6 +9,13 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include "TextureCache.h" + +#include + +#include +#include + #include #include #include @@ -19,21 +26,10 @@ #include #include -#include -#include #include "RenderUtilsLogging.h" -#include "TextureCache.h" - -#include - -TextureCache::TextureCache() : - _permutationNormalTexture(0), - _whiteTexture(0), - _blueTexture(0), - _frameBufferSize(100, 100) -{ +TextureCache::TextureCache() { const qint64 TEXTURE_DEFAULT_UNUSED_MAX_SIZE = DEFAULT_UNUSED_MAX_SIZE; setUnusedResourceCacheSize(TEXTURE_DEFAULT_UNUSED_MAX_SIZE); } @@ -41,23 +37,6 @@ TextureCache::TextureCache() : TextureCache::~TextureCache() { } -void TextureCache::setFrameBufferSize(QSize frameBufferSize) { - //If the size changed, we need to delete our FBOs - if (_frameBufferSize != frameBufferSize) { - _frameBufferSize = frameBufferSize; - - _primaryFramebuffer.reset(); - _primaryDepthTexture.reset(); - _primaryColorTexture.reset(); - _primaryNormalTexture.reset(); - _primarySpecularTexture.reset(); - - _secondaryFramebuffer.reset(); - - _tertiaryFramebuffer.reset(); - } -} - // use fixed table of permutations. Could also make ordered list programmatically // and then shuffle algorithm. For testing, this ensures consistent behavior in each run. // this list taken from Ken Perlin's Improved Noise reference implementation (orig. in Java) at @@ -175,113 +154,6 @@ NetworkTexturePointer TextureCache::getTexture(const QUrl& url, TextureType type return texture; } -void TextureCache::createPrimaryFramebuffer() { - _primaryFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create()); - - auto colorFormat = gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA); - auto width = _frameBufferSize.width(); - auto height = _frameBufferSize.height(); - - auto defaultSampler = gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_POINT); - _primaryColorTexture = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width, height, defaultSampler)); - _primaryNormalTexture = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width, height, defaultSampler)); - _primarySpecularTexture = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width, height, defaultSampler)); - - _primaryFramebuffer->setRenderBuffer(0, _primaryColorTexture); - _primaryFramebuffer->setRenderBuffer(1, _primaryNormalTexture); - _primaryFramebuffer->setRenderBuffer(2, _primarySpecularTexture); - - - auto depthFormat = gpu::Element(gpu::SCALAR, gpu::FLOAT, gpu::DEPTH); - _primaryDepthTexture = gpu::TexturePointer(gpu::Texture::create2D(depthFormat, width, height, defaultSampler)); - - _primaryFramebuffer->setDepthStencilBuffer(_primaryDepthTexture, depthFormat); -} - -gpu::FramebufferPointer TextureCache::getPrimaryFramebuffer() { - if (!_primaryFramebuffer) { - createPrimaryFramebuffer(); - } - return _primaryFramebuffer; -} - -gpu::TexturePointer TextureCache::getPrimaryDepthTexture() { - if (!_primaryDepthTexture) { - createPrimaryFramebuffer(); - } - return _primaryDepthTexture; -} - -gpu::TexturePointer TextureCache::getPrimaryColorTexture() { - if (!_primaryColorTexture) { - createPrimaryFramebuffer(); - } - return _primaryColorTexture; -} - -gpu::TexturePointer TextureCache::getPrimaryNormalTexture() { - if (!_primaryNormalTexture) { - createPrimaryFramebuffer(); - } - return _primaryNormalTexture; -} - -gpu::TexturePointer TextureCache::getPrimarySpecularTexture() { - if (!_primarySpecularTexture) { - createPrimaryFramebuffer(); - } - return _primarySpecularTexture; -} - -GLuint TextureCache::getPrimaryDepthTextureID() { - return gpu::GLBackend::getTextureID(getPrimaryDepthTexture()); -} - -void TextureCache::setPrimaryDrawBuffers(bool color, bool normal, bool specular) { - gpu::Batch batch; - setPrimaryDrawBuffers(batch, color, normal, specular); - gpu::GLBackend::renderBatch(batch); -} - -void TextureCache::setPrimaryDrawBuffers(gpu::Batch& batch, bool color, bool normal, bool specular) { - GLenum buffers[3]; - int bufferCount = 0; - if (color) { - buffers[bufferCount++] = GL_COLOR_ATTACHMENT0; - } - if (normal) { - buffers[bufferCount++] = GL_COLOR_ATTACHMENT1; - } - if (specular) { - buffers[bufferCount++] = GL_COLOR_ATTACHMENT2; - } - batch._glDrawBuffers(bufferCount, buffers); -} - -gpu::FramebufferPointer TextureCache::getSecondaryFramebuffer() { - if (!_secondaryFramebuffer) { - _secondaryFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create(gpu::Element::COLOR_RGBA_32, _frameBufferSize.width(), _frameBufferSize.height())); - } - return _secondaryFramebuffer; -} - -gpu::FramebufferPointer TextureCache::getTertiaryFramebuffer() { - if (!_tertiaryFramebuffer) { - _tertiaryFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create(gpu::Element::COLOR_RGBA_32, _frameBufferSize.width(), _frameBufferSize.height())); - } - return _tertiaryFramebuffer; -} - -gpu::FramebufferPointer TextureCache::getShadowFramebuffer() { - if (!_shadowFramebuffer) { - const int SHADOW_MAP_SIZE = 2048; - _shadowFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::createShadowmap(SHADOW_MAP_SIZE)); - - _shadowTexture = _shadowFramebuffer->getDepthStencilBuffer(); - } - return _shadowFramebuffer; -} - /// Returns a texture version of an image file gpu::TexturePointer TextureCache::getImageTexture(const QString& path) { QImage image = QImage(path).mirrored(false, true); diff --git a/libraries/render-utils/src/TextureCache.h b/libraries/render-utils/src/TextureCache.h index 6b4fff4f6b..8f60382e9b 100644 --- a/libraries/render-utils/src/TextureCache.h +++ b/libraries/render-utils/src/TextureCache.h @@ -13,8 +13,6 @@ #define hifi_TextureCache_h #include -#include - #include #include @@ -39,10 +37,6 @@ class TextureCache : public ResourceCache, public Dependency { SINGLETON_DEPENDENCY public: - /// Sets the desired texture resolution for the framebuffer objects. - void setFrameBufferSize(QSize frameBufferSize); - const QSize& getFrameBufferSize() const { return _frameBufferSize; } - /// Returns the ID of the permutation/normal texture used for Perlin noise shader programs. This texture /// has two lines: the first, a set of random numbers in [0, 255] to be used as permutation offsets, and /// the second, a set of random unit vectors to be used as noise gradients. @@ -67,33 +61,6 @@ public: NetworkTexturePointer getTexture(const QUrl& url, TextureType type = DEFAULT_TEXTURE, bool dilatable = false, const QByteArray& content = QByteArray()); - /// Returns a pointer to the primary framebuffer object. This render target includes a depth component, and is - /// used for scene rendering. - gpu::FramebufferPointer getPrimaryFramebuffer(); - - gpu::TexturePointer getPrimaryDepthTexture(); - gpu::TexturePointer getPrimaryColorTexture(); - gpu::TexturePointer getPrimaryNormalTexture(); - gpu::TexturePointer getPrimarySpecularTexture(); - - /// Returns the ID of the primary framebuffer object's depth texture. This contains the Z buffer used in rendering. - uint32_t getPrimaryDepthTextureID(); - - /// Enables or disables draw buffers on the primary framebuffer. Note: the primary framebuffer must be bound. - void setPrimaryDrawBuffers(bool color, bool normal = false, bool specular = false); - void setPrimaryDrawBuffers(gpu::Batch& batch, bool color, bool normal = false, bool specular = false); - - /// Returns a pointer to the secondary framebuffer object, used as an additional render target when performing full - /// screen effects. - gpu::FramebufferPointer getSecondaryFramebuffer(); - - /// Returns a pointer to the tertiary framebuffer object, used as an additional render target when performing full - /// screen effects. - gpu::FramebufferPointer getTertiaryFramebuffer(); - - /// Returns the framebuffer object used to render shadow maps; - gpu::FramebufferPointer getShadowFramebuffer(); - protected: virtual QSharedPointer createResource(const QUrl& url, @@ -110,23 +77,7 @@ private: gpu::TexturePointer _blueTexture; gpu::TexturePointer _blackTexture; - QHash > _dilatableNetworkTextures; - - gpu::TexturePointer _primaryDepthTexture; - gpu::TexturePointer _primaryColorTexture; - gpu::TexturePointer _primaryNormalTexture; - gpu::TexturePointer _primarySpecularTexture; - gpu::FramebufferPointer _primaryFramebuffer; - void createPrimaryFramebuffer(); - - gpu::FramebufferPointer _secondaryFramebuffer; - gpu::FramebufferPointer _tertiaryFramebuffer; - - gpu::FramebufferPointer _shadowFramebuffer; - gpu::TexturePointer _shadowTexture; - - QSize _frameBufferSize; }; /// A simple object wrapper for an OpenGL texture. From 89eed589e2755803c788441a0b9e3fddbbd49f3e Mon Sep 17 00:00:00 2001 From: bwent Date: Mon, 20 Jul 2015 10:59:55 -0700 Subject: [PATCH 07/17] Add Vec3 function to convert vec3 to/from euler angles --- examples/edit.js | 47 +-------------------- libraries/script-engine/src/Vec3.cpp | 62 ++++++++++++++++++++++++++++ libraries/script-engine/src/Vec3.h | 2 + 3 files changed, 66 insertions(+), 45 deletions(-) diff --git a/examples/edit.js b/examples/edit.js index 544f3c94b6..edf60110c4 100644 --- a/examples/edit.js +++ b/examples/edit.js @@ -1211,49 +1211,6 @@ PropertiesTool = function(opts) { webView.setVisible(visible); }; - vecToPolar = function(direction) { - var x = direction.x; - var y = direction.y; - var z = direction.z; - var pitch, yaw; - pitch = -Math.asin(y); - var c = Math.cos(-pitch); - if (Math.abs(pitch) > (Math.PI / 2.0 - epsilon)) { - //handle gymbal lock - if (pitch > 0) { - pitch = Math.PI / 2.0; - } else { - pitch = -Math.PI / 2.0; - } - yaw = 0.0; - } else { - if (z < 0) { - if(x > 0 && x < 1) { - yaw = Math.PI - Math.asin(x / c); - } else { - yaw = -Math.asin(x / c) - Math.PI; - } - } else { - yaw = Math.asin(x / c); - } - } - return { - x: pitch * RADIANS_TO_DEGREES, - y: yaw * RADIANS_TO_DEGREES, - z: 0.0 //discard roll component - }; - }; - - polarToVec = function(orientation) { - var pitch = orientation.x * DEGREES_TO_RADIANS; - var yaw = orientation.y * DEGREES_TO_RADIANS; - return { - x: Math.cos(pitch) * Math.sin(yaw), - y: Math.sin(-pitch), - z: Math.cos(pitch) * Math.cos(yaw) - }; - } - selectionManager.addEventListener(function() { data = { type: 'update', @@ -1267,7 +1224,7 @@ PropertiesTool = function(opts) { entity.properties.rotation = Quat.safeEulerAngles(entity.properties.rotation); } if (entity.properties.keyLightDirection !== undefined) { - entity.properties.keyLightDirection = vecToPolar(entity.properties.keyLightDirection); + entity.properties.keyLightDirection = Vec3.toPolar(entity.properties.keyLightDirection); } selections.push(entity); } @@ -1297,7 +1254,7 @@ PropertiesTool = function(opts) { data.properties.rotation = Quat.fromPitchYawRollDegrees(rotation.x, rotation.y, rotation.z); } if (data.properties.keyLightDirection !== undefined) { - data.properties.keyLightDirection = polarToVec(data.properties.keyLightDirection); + data.properties.keyLightDirection = Vec3.fromPolar(data.properties.keyLightDirection.x, data.properties.keyLightDirection.y); } Entities.editEntity(selectionManager.selections[0], data.properties); if (data.properties.name != undefined) { diff --git a/libraries/script-engine/src/Vec3.cpp b/libraries/script-engine/src/Vec3.cpp index 49a2ad2cbe..2bb28180d9 100644 --- a/libraries/script-engine/src/Vec3.cpp +++ b/libraries/script-engine/src/Vec3.cpp @@ -14,6 +14,7 @@ #include #include "ScriptEngineLogging.h" +#include "NumericalConstants.h" #include "Vec3.h" glm::vec3 Vec3::reflect(const glm::vec3& v1, const glm::vec3& v2) { @@ -73,3 +74,64 @@ void Vec3::print(const QString& lable, const glm::vec3& v) { bool Vec3::equal(const glm::vec3& v1, const glm::vec3& v2) { return v1 == v2; } + +glm::vec3 Vec3::toPolar(const glm::vec3& v) { + glm::vec3 u = normalize(v); + float pitch, yaw, temp; + pitch = glm::asin(-u.y); + temp = glm::cos(pitch); + if (glm::abs(pitch) >= (PI - EPSILON)) { + yaw = 0.0; + if (pitch > 0) { + pitch = PI_OVER_TWO; + } else { + pitch = -PI_OVER_TWO; + } + } else { + if (u.z < 0.0) { + if (u.x > 0.0 && u.x < 1.0) { + yaw = PI - glm::asin(u.x / temp); + } else { + yaw = -PI - glm::asin(u.x / temp); + } + } else { + yaw = glm::asin(u.x / temp); + } + } + + // Round small values to 0 + if (glm::abs(pitch) < EPSILON) { + pitch = 0.0; + } + if (glm::abs(yaw) < EPSILON) { + yaw = 0.0; + } + + // Neglect roll component + return glm::vec3(glm::degrees(pitch), glm::degrees(yaw), 0.0); +} + +glm::vec3 Vec3::fromPolar(float pitch, float yaw) { + pitch = glm::radians(pitch); + yaw = glm::radians(yaw); + + float x = glm::cos(pitch) * glm::sin(yaw); + float y = glm::sin(-pitch); + float z = glm::cos(pitch) * glm::cos(yaw); + + // Round small values to 0 + if (glm::abs(x) < EPSILON) { + x = 0.0; + } + if (glm::abs(y) < EPSILON) { + y = 0.0; + } + if (glm::abs(z) < EPSILON) { + z = 0.0; + } + + return glm::vec3(x, y, z); +} + + + diff --git a/libraries/script-engine/src/Vec3.h b/libraries/script-engine/src/Vec3.h index 2a2e145e8e..198d65004c 100644 --- a/libraries/script-engine/src/Vec3.h +++ b/libraries/script-engine/src/Vec3.h @@ -40,6 +40,8 @@ public slots: glm::vec3 mix(const glm::vec3& v1, const glm::vec3& v2, float m); void print(const QString& lable, const glm::vec3& v); bool equal(const glm::vec3& v1, const glm::vec3& v2); + glm::vec3 toPolar(const glm::vec3& v); + glm::vec3 fromPolar(float pitch, float yaw); }; From 30d4b9f6354fecc1b49f360a26d58f6802b348e5 Mon Sep 17 00:00:00 2001 From: bwent Date: Mon, 20 Jul 2015 16:14:56 -0700 Subject: [PATCH 08/17] switch to radians, overload fromPolar, use atan2 --- libraries/script-engine/src/Vec3.cpp | 66 ++++++++++------------------ libraries/script-engine/src/Vec3.h | 1 + 2 files changed, 25 insertions(+), 42 deletions(-) diff --git a/libraries/script-engine/src/Vec3.cpp b/libraries/script-engine/src/Vec3.cpp index 2bb28180d9..71b04eb321 100644 --- a/libraries/script-engine/src/Vec3.cpp +++ b/libraries/script-engine/src/Vec3.cpp @@ -77,61 +77,43 @@ bool Vec3::equal(const glm::vec3& v1, const glm::vec3& v2) { glm::vec3 Vec3::toPolar(const glm::vec3& v) { glm::vec3 u = normalize(v); - float pitch, yaw, temp; - pitch = glm::asin(-u.y); - temp = glm::cos(pitch); - if (glm::abs(pitch) >= (PI - EPSILON)) { - yaw = 0.0; - if (pitch > 0) { - pitch = PI_OVER_TWO; - } else { - pitch = -PI_OVER_TWO; - } - } else { - if (u.z < 0.0) { - if (u.x > 0.0 && u.x < 1.0) { - yaw = PI - glm::asin(u.x / temp); - } else { - yaw = -PI - glm::asin(u.x / temp); - } - } else { - yaw = glm::asin(u.x / temp); - } - } + float azimuth, elevation; - // Round small values to 0 - if (glm::abs(pitch) < EPSILON) { - pitch = 0.0; - } - if (glm::abs(yaw) < EPSILON) { - yaw = 0.0; - } + azimuth = glm::asin(-u.y); + elevation = atan2(v.x, v.z); - // Neglect roll component - return glm::vec3(glm::degrees(pitch), glm::degrees(yaw), 0.0); + // Round off small decimal values + if (glm::abs(azimuth) < EPSILON) { + azimuth = 0.0f; + } + if (glm::abs(elevation) < EPSILON) { + elevation = 0.0f; + } + + return glm::vec3(azimuth, elevation, length(v)); } -glm::vec3 Vec3::fromPolar(float pitch, float yaw) { - pitch = glm::radians(pitch); - yaw = glm::radians(yaw); - - float x = glm::cos(pitch) * glm::sin(yaw); - float y = glm::sin(-pitch); - float z = glm::cos(pitch) * glm::cos(yaw); +glm::vec3 Vec3::fromPolar(const glm::vec3& polar) { + float x = glm::cos(polar.x) * glm::sin(polar.y); + float y = glm::sin(-polar.x); + float z = glm::cos(polar.x) * glm::cos(polar.y); // Round small values to 0 if (glm::abs(x) < EPSILON) { - x = 0.0; + x = 0.0f; } if (glm::abs(y) < EPSILON) { - y = 0.0; + y = 0.0f; } if (glm::abs(z) < EPSILON) { - z = 0.0; + z = 0.0f; } - return glm::vec3(x, y, z); + return multiply(polar.z, glm::vec3(x, y, z)); } - +glm::vec3 Vec3::fromPolar(float azimuth, float elevation) { + glm::vec3 v = glm::vec3(azimuth, elevation, 1.0f); + return fromPolar(v); +} diff --git a/libraries/script-engine/src/Vec3.h b/libraries/script-engine/src/Vec3.h index 198d65004c..2b202b7a2d 100644 --- a/libraries/script-engine/src/Vec3.h +++ b/libraries/script-engine/src/Vec3.h @@ -41,6 +41,7 @@ public slots: void print(const QString& lable, const glm::vec3& v); bool equal(const glm::vec3& v1, const glm::vec3& v2); glm::vec3 toPolar(const glm::vec3& v); + glm::vec3 fromPolar(const glm::vec3& polar); glm::vec3 fromPolar(float pitch, float yaw); }; From d688e5f915187b33a55f30f5f30678d48b076d51 Mon Sep 17 00:00:00 2001 From: bwent Date: Tue, 21 Jul 2015 10:50:56 -0700 Subject: [PATCH 09/17] fix case where v not normalizable --- libraries/script-engine/src/Vec3.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/libraries/script-engine/src/Vec3.cpp b/libraries/script-engine/src/Vec3.cpp index 71b04eb321..17e7c56276 100644 --- a/libraries/script-engine/src/Vec3.cpp +++ b/libraries/script-engine/src/Vec3.cpp @@ -76,7 +76,12 @@ bool Vec3::equal(const glm::vec3& v1, const glm::vec3& v2) { } glm::vec3 Vec3::toPolar(const glm::vec3& v) { - glm::vec3 u = normalize(v); + float radius = length(v); + if (glm::abs(radius) < EPSILON) { + return glm::vec3(0.0f, 0.0f, 0.0f); + } + glm::vec3 u = v / radius; + float azimuth, elevation; azimuth = glm::asin(-u.y); @@ -109,7 +114,7 @@ glm::vec3 Vec3::fromPolar(const glm::vec3& polar) { z = 0.0f; } - return multiply(polar.z, glm::vec3(x, y, z)); + return polar.z * glm::vec3(x, y, z); } glm::vec3 Vec3::fromPolar(float azimuth, float elevation) { From 2b745395ec4b743d79dc91b84061f76bf8e61f59 Mon Sep 17 00:00:00 2001 From: bwent Date: Tue, 21 Jul 2015 11:38:10 -0700 Subject: [PATCH 10/17] use radius for z-component --- libraries/script-engine/src/Vec3.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/script-engine/src/Vec3.cpp b/libraries/script-engine/src/Vec3.cpp index 17e7c56276..26ef298493 100644 --- a/libraries/script-engine/src/Vec3.cpp +++ b/libraries/script-engine/src/Vec3.cpp @@ -95,7 +95,7 @@ glm::vec3 Vec3::toPolar(const glm::vec3& v) { elevation = 0.0f; } - return glm::vec3(azimuth, elevation, length(v)); + return glm::vec3(azimuth, elevation, radius); } glm::vec3 Vec3::fromPolar(const glm::vec3& polar) { From 5a8106a04935a34d111c9b90ba94e6fc89f107e7 Mon Sep 17 00:00:00 2001 From: bwent Date: Tue, 21 Jul 2015 13:15:24 -0700 Subject: [PATCH 11/17] fixes in edit.js UI --- examples/edit.js | 6 ++++-- libraries/script-engine/src/Vec3.cpp | 21 +++++++++++---------- libraries/script-engine/src/Vec3.h | 2 +- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/examples/edit.js b/examples/edit.js index edf60110c4..b33f47c2b7 100644 --- a/examples/edit.js +++ b/examples/edit.js @@ -1224,7 +1224,8 @@ PropertiesTool = function(opts) { entity.properties.rotation = Quat.safeEulerAngles(entity.properties.rotation); } if (entity.properties.keyLightDirection !== undefined) { - entity.properties.keyLightDirection = Vec3.toPolar(entity.properties.keyLightDirection); + entity.properties.keyLightDirection = Vec3.multiply(RADIANS_TO_DEGREES, Vec3.toPolar(entity.properties.keyLightDirection)); + entity.properties.keyLightDirection.z = 0.0; } selections.push(entity); } @@ -1254,7 +1255,8 @@ PropertiesTool = function(opts) { data.properties.rotation = Quat.fromPitchYawRollDegrees(rotation.x, rotation.y, rotation.z); } if (data.properties.keyLightDirection !== undefined) { - data.properties.keyLightDirection = Vec3.fromPolar(data.properties.keyLightDirection.x, data.properties.keyLightDirection.y); + data.properties.keyLightDirection = Vec3.fromPolar( + data.properties.keyLightDirection.x * DEGREES_TO_RADIANS, data.properties.keyLightDirection.y * DEGREES_TO_RADIANS); } Entities.editEntity(selectionManager.selections[0], data.properties); if (data.properties.name != undefined) { diff --git a/libraries/script-engine/src/Vec3.cpp b/libraries/script-engine/src/Vec3.cpp index 26ef298493..4ed16b2ef0 100644 --- a/libraries/script-engine/src/Vec3.cpp +++ b/libraries/script-engine/src/Vec3.cpp @@ -80,22 +80,23 @@ glm::vec3 Vec3::toPolar(const glm::vec3& v) { if (glm::abs(radius) < EPSILON) { return glm::vec3(0.0f, 0.0f, 0.0f); } + glm::vec3 u = v / radius; - float azimuth, elevation; + float elevation, azimuth; - azimuth = glm::asin(-u.y); - elevation = atan2(v.x, v.z); + elevation = glm::asin(-u.y); + azimuth = atan2(v.x, v.z); // Round off small decimal values - if (glm::abs(azimuth) < EPSILON) { - azimuth = 0.0f; - } if (glm::abs(elevation) < EPSILON) { elevation = 0.0f; } + if (glm::abs(azimuth) < EPSILON) { + azimuth = 0.0f; + } - return glm::vec3(azimuth, elevation, radius); + return glm::vec3(elevation, azimuth, radius); } glm::vec3 Vec3::fromPolar(const glm::vec3& polar) { @@ -113,12 +114,12 @@ glm::vec3 Vec3::fromPolar(const glm::vec3& polar) { if (glm::abs(z) < EPSILON) { z = 0.0f; } - + return polar.z * glm::vec3(x, y, z); } -glm::vec3 Vec3::fromPolar(float azimuth, float elevation) { - glm::vec3 v = glm::vec3(azimuth, elevation, 1.0f); +glm::vec3 Vec3::fromPolar(float elevation, float azimuth) { + glm::vec3 v = glm::vec3(elevation, azimuth, 1.0f); return fromPolar(v); } diff --git a/libraries/script-engine/src/Vec3.h b/libraries/script-engine/src/Vec3.h index 2b202b7a2d..82062ca80d 100644 --- a/libraries/script-engine/src/Vec3.h +++ b/libraries/script-engine/src/Vec3.h @@ -42,7 +42,7 @@ public slots: bool equal(const glm::vec3& v1, const glm::vec3& v2); glm::vec3 toPolar(const glm::vec3& v); glm::vec3 fromPolar(const glm::vec3& polar); - glm::vec3 fromPolar(float pitch, float yaw); + glm::vec3 fromPolar(float elevation, float azimuth); }; From d6994c6dfd98601365ff55d78eabf727dce36f77 Mon Sep 17 00:00:00 2001 From: Bradley Austin Davis Date: Tue, 21 Jul 2015 19:22:10 -0400 Subject: [PATCH 12/17] Restoring star size and color variation --- interface/src/Stars.cpp | 105 ++++++++++++++++------- libraries/render-utils/src/stars.slf | 62 ++----------- libraries/render-utils/src/stars.slv | 32 +++++++ libraries/render-utils/src/starsGrid.slf | 63 ++++++++++++++ 4 files changed, 178 insertions(+), 84 deletions(-) create mode 100644 libraries/render-utils/src/stars.slv create mode 100644 libraries/render-utils/src/starsGrid.slf diff --git a/interface/src/Stars.cpp b/interface/src/Stars.cpp index 5f15363ab1..da61926399 100644 --- a/interface/src/Stars.cpp +++ b/interface/src/Stars.cpp @@ -14,7 +14,7 @@ #include #include - +#include #include #include #include @@ -24,14 +24,17 @@ #include #include -#include "../../libraries/render-utils/standardTransformPNTC_vert.h" +#include "../../libraries/render-utils/stars_vert.h" #include "../../libraries/render-utils/stars_frag.h" +#include "../../libraries/render-utils/standardTransformPNTC_vert.h" +#include "../../libraries/render-utils/starsGrid_frag.h" + //static const float TILT = 0.23f; static const float TILT = 0.0f; static const unsigned int STARFIELD_NUM_STARS = 50000; static const unsigned int STARFIELD_SEED = 1; -//static const float STAR_COLORIZATION = 0.1f; +static const float STAR_COLORIZATION = 0.1f; static const float TAU = 6.28318530717958f; //static const float HALF_TAU = TAU / 2.0f; @@ -109,52 +112,81 @@ unsigned computeStarColor(float colorization) { return red | (green << 8) | (blue << 16); } +struct StarVertex { + vec4 position; + vec4 colorAndSize; +}; + // FIXME star colors void Stars::render(RenderArgs* renderArgs, float alpha) { static gpu::BufferPointer vertexBuffer; static gpu::Stream::FormatPointer streamFormat; static gpu::Element positionElement, colorElement; - static gpu::PipelinePointer _pipeline; + static gpu::PipelinePointer _gridPipeline; + static gpu::PipelinePointer _starsPipeline; static int32_t _timeSlot{ -1 }; static std::once_flag once; const int VERTICES_SLOT = 0; - //const int COLOR_SLOT = 2; + const int COLOR_SLOT = 1; std::call_once(once, [&] { + { + auto vs = gpu::ShaderPointer(gpu::Shader::createVertex(std::string(standardTransformPNTC_vert))); + auto ps = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(starsGrid_frag))); + auto program = gpu::ShaderPointer(gpu::Shader::createProgram(vs, ps)); + gpu::Shader::makeProgram((*program)); + _timeSlot = program->getBuffers().findLocation(UNIFORM_TIME_NAME); + if (_timeSlot == gpu::Shader::INVALID_LOCATION) { + _timeSlot = program->getUniforms().findLocation(UNIFORM_TIME_NAME); + } + auto state = gpu::StatePointer(new gpu::State()); + // enable decal blend + state->setDepthTest(gpu::State::DepthTest(false)); + state->setBlendFunction(true, gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA); + _gridPipeline.reset(gpu::Pipeline::create(program, state)); + } + { + auto vs = gpu::ShaderPointer(gpu::Shader::createVertex(std::string(stars_vert))); + auto ps = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(stars_frag))); + auto program = gpu::ShaderPointer(gpu::Shader::createProgram(vs, ps)); + gpu::Shader::makeProgram((*program)); + auto state = gpu::StatePointer(new gpu::State()); + // enable decal blend + state->setDepthTest(gpu::State::DepthTest(false)); + state->setBlendFunction(true, gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA); + _starsPipeline.reset(gpu::Pipeline::create(program, state)); + + } + QElapsedTimer startTime; startTime.start(); vertexBuffer.reset(new gpu::Buffer); srand(STARFIELD_SEED); unsigned limit = STARFIELD_NUM_STARS; - std::vector points; + std::vector points; points.resize(limit); for (size_t star = 0; star < limit; ++star) { - points[star] = fromPolar(randPolar()); - //auto color = computeStarColor(STAR_COLORIZATION); - //vertexBuffer->append(sizeof(color), (const gpu::Byte*)&color); + points[star].position = vec4(fromPolar(randPolar()), 1); + float size = frand() * 5.0f + 0.5f; + if (frand() < STAR_COLORIZATION) { + vec3 color(frand() / 2.0f + 0.5f, frand() / 2.0f + 0.5f, frand() / 2.0f + 0.5f); + points[star].colorAndSize = vec4(color, size); + } else { + vec3 color(frand() / 2.0f + 0.5f); + points[star].colorAndSize = vec4(color, size); + } } - vertexBuffer->append(sizeof(vec3) * limit, (const gpu::Byte*)&points[0]); - streamFormat.reset(new gpu::Stream::Format()); // 1 for everyone - streamFormat->setAttribute(gpu::Stream::POSITION, VERTICES_SLOT, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ), 0); - positionElement = streamFormat->getAttributes().at(gpu::Stream::POSITION)._element; double timeDiff = (double)startTime.nsecsElapsed() / 1000000.0; // ns to ms qDebug() << "Total time to generate stars: " << timeDiff << " msec"; - auto vs = gpu::ShaderPointer(gpu::Shader::createVertex(std::string(standardTransformPNTC_vert))); - auto ps = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(stars_frag))); - auto program = gpu::ShaderPointer(gpu::Shader::createProgram(vs, ps)); - gpu::Shader::makeProgram((*program)); - _timeSlot = program->getBuffers().findLocation(UNIFORM_TIME_NAME); - if (_timeSlot == gpu::Shader::INVALID_LOCATION) { - _timeSlot = program->getUniforms().findLocation(UNIFORM_TIME_NAME); - } - auto state = gpu::StatePointer(new gpu::State()); - // enable decal blend - state->setDepthTest(gpu::State::DepthTest(false)); - state->setBlendFunction(true, gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA); - _pipeline.reset(gpu::Pipeline::create(program, state)); + vertexBuffer->append(sizeof(StarVertex) * limit, (const gpu::Byte*)&points[0]); + streamFormat.reset(new gpu::Stream::Format()); // 1 for everyone + streamFormat->setAttribute(gpu::Stream::POSITION, VERTICES_SLOT, gpu::Element(gpu::VEC4, gpu::FLOAT, gpu::XYZW), 0); + streamFormat->setAttribute(gpu::Stream::COLOR, COLOR_SLOT, gpu::Element(gpu::VEC4, gpu::FLOAT, gpu::RGBA)); + positionElement = streamFormat->getAttributes().at(gpu::Stream::POSITION)._element; + colorElement = streamFormat->getAttributes().at(gpu::Stream::COLOR)._element; }); auto geometryCache = DependencyManager::get(); @@ -168,18 +200,31 @@ void Stars::render(RenderArgs* renderArgs, float alpha) { batch.setResourceTexture(0, textureCache->getWhiteTexture()); // Render the world lines - batch.setPipeline(_pipeline); + batch.setPipeline(_gridPipeline); static auto start = usecTimestampNow(); float msecs = (float)(usecTimestampNow() - start) / (float)USECS_PER_MSEC; float secs = msecs / (float)MSECS_PER_SECOND; batch._glUniform1f(_timeSlot, secs); geometryCache->renderUnitCube(batch); - + glHint(GL_POINT_SMOOTH_HINT, GL_NICEST); + + static const size_t VERTEX_STRIDE = sizeof(StarVertex); + size_t offset = offsetof(StarVertex, position); + gpu::BufferView posView(vertexBuffer, offset, vertexBuffer->getSize(), VERTEX_STRIDE, positionElement); + offset = offsetof(StarVertex, colorAndSize); + gpu::BufferView colView(vertexBuffer, offset, vertexBuffer->getSize(), VERTEX_STRIDE, colorElement); + // Render the stars - geometryCache->useSimpleDrawPipeline(batch); + batch.setPipeline(_starsPipeline); + batch._glEnable(GL_PROGRAM_POINT_SIZE_EXT); + batch._glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); + batch._glEnable(GL_POINT_SMOOTH); + batch.setInputFormat(streamFormat); - batch.setInputBuffer(VERTICES_SLOT, gpu::BufferView(vertexBuffer, positionElement)); + batch.setInputBuffer(VERTICES_SLOT, posView); + batch.setInputBuffer(COLOR_SLOT, colView); batch.draw(gpu::Primitive::POINTS, STARFIELD_NUM_STARS); + renderArgs->_context->render(batch); } diff --git a/libraries/render-utils/src/stars.slf b/libraries/render-utils/src/stars.slf index ed338deaef..7e1c96bc5b 100644 --- a/libraries/render-utils/src/stars.slf +++ b/libraries/render-utils/src/stars.slf @@ -1,63 +1,17 @@ <@include gpu/Config.slh@> <$VERSION_HEADER$> -#line __LINE__ // Generated on <$_SCRIBE_DATE$> -// stars.frag // fragment shader // -// Created by Bradley Austin Davis on 2015/06/19 +// Created by Bradley Austin Davis on 6/10/15. +// Copyright 2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// -varying vec2 varTexcoord; -varying vec3 varNomral; -varying vec3 varPosition; - -uniform float iGlobalTime; - -const float PI = 3.14159; -const float TAU = 3.14159 * 2.0; -const int latitudeCount = 5; -const float latitudeDist = PI / 2.0 / float(latitudeCount); -const int meridianCount = 4; -const float merdianDist = PI / float(meridianCount); - - -float clampLine(float val, float target) { - return clamp((1.0 - abs((val - target)) - 0.998) * 500.0, 0.0, 1.0); -} - -float latitude(vec2 pos, float angle) { - float result = clampLine(pos.y, angle); - if (angle != 0.0) { - result += clampLine(pos.y, -angle); - } - return result; -} - -float meridian(vec2 pos, float angle) { - return clampLine(pos.x, angle) + clampLine(pos.x + PI, angle); -} - -vec2 toPolar(in vec3 dir) { - vec2 polar = vec2(atan(dir.z, dir.x), asin(dir.y)); - return polar; -} - -void mainVR( out vec4 fragColor, in vec2 fragCoord, in vec3 fragRayOri, in vec3 fragRayDir ) -{ - vec2 polar = toPolar(fragRayDir); - //polar.x += mod(iGlobalTime / 12.0, PI / 4.0) - PI / 4.0; - float c = 0.0; - for (int i = 0; i < latitudeCount - 1; ++i) { - c += latitude(polar, float(i) * latitudeDist); - } - for (int i = 0; i < meridianCount; ++i) { - c += meridian(polar, float(i) * merdianDist); - } - const vec3 col_lines = vec3(102.0 / 255.0, 136.0 / 255.0, 221.0 / 255.0); - fragColor = vec4(c * col_lines, 0.2); -} +varying vec4 varColor; void main(void) { - mainVR(gl_FragColor, gl_FragCoord.xy, vec3(0.0), normalize(varPosition)); + gl_FragColor = varColor; //vec4(varColor, 1.0); } - diff --git a/libraries/render-utils/src/stars.slv b/libraries/render-utils/src/stars.slv new file mode 100644 index 0000000000..98241321fa --- /dev/null +++ b/libraries/render-utils/src/stars.slv @@ -0,0 +1,32 @@ +<@include gpu/Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// standardTransformPNTC.slv +// vertex shader +// +// Created by Sam Gateau on 6/10/2015. +// Copyright 2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +<@include gpu/Transform.slh@> + +<$declareStandardTransform()$> + +varying vec3 varPosition; +varying vec4 varColor; + + +void main(void) { + varColor = gl_Color.rgba; + + // standard transform + TransformCamera cam = getTransformCamera(); + TransformObject obj = getTransformObject(); + <$transformModelToClipPos(cam, obj, gl_Vertex, gl_Position)$> + varPosition = gl_Vertex.xyz; + gl_PointSize = gl_Color.a; +} \ No newline at end of file diff --git a/libraries/render-utils/src/starsGrid.slf b/libraries/render-utils/src/starsGrid.slf new file mode 100644 index 0000000000..12dfd0317c --- /dev/null +++ b/libraries/render-utils/src/starsGrid.slf @@ -0,0 +1,63 @@ +<@include gpu/Config.slh@> +<$VERSION_HEADER$> +#line __LINE__ +// Generated on <$_SCRIBE_DATE$> +// stars.frag +// fragment shader +// +// Created by Bradley Austin Davis on 2015/06/19 + +varying vec2 varTexcoord; +varying vec3 varNomral; +varying vec3 varPosition; + +uniform float iGlobalTime; + +const float PI = 3.14159; +const float TAU = 3.14159 * 2.0; +const int latitudeCount = 5; +const float latitudeDist = PI / 2.0 / float(latitudeCount); +const int meridianCount = 4; +const float merdianDist = PI / float(meridianCount); + + +float clampLine(float val, float target) { + return clamp((1.0 - abs((val - target)) - 0.998) * 500.0, 0.0, 1.0); +} + +float latitude(vec2 pos, float angle) { + float result = clampLine(pos.y, angle); + if (angle != 0.0) { + result += clampLine(pos.y, -angle); + } + return result; +} + +float meridian(vec2 pos, float angle) { + return clampLine(pos.x, angle) + clampLine(pos.x + PI, angle); +} + +vec2 toPolar(in vec3 dir) { + vec2 polar = vec2(atan(dir.z, dir.x), asin(dir.y)); + return polar; +} + +void mainVR( out vec4 fragColor, in vec2 fragCoord, in vec3 fragRayOri, in vec3 fragRayDir ) +{ + vec2 polar = toPolar(fragRayDir); + //polar.x += mod(iGlobalTime / 12.0, PI / 4.0) - PI / 4.0; + float c = 0.0; + for (int i = 0; i < latitudeCount - 1; ++i) { + c += latitude(polar, float(i) * latitudeDist); + } + for (int i = 0; i < meridianCount; ++i) { + c += meridian(polar, float(i) * merdianDist); + } + const vec3 col_lines = vec3(102.0 / 255.0, 136.0 / 255.0, 221.0 / 255.0); + fragColor = vec4(c * col_lines, 0.2); +} + +void main(void) { + mainVR(gl_FragColor, gl_FragCoord.xy, vec3(0.0), normalize(varPosition)); +} + From ae539afafba44022ca1c36fed6f47a85d581f523 Mon Sep 17 00:00:00 2001 From: Bradley Austin Davis Date: Wed, 22 Jul 2015 07:23:12 -0400 Subject: [PATCH 13/17] Fix deadlock when using textoverlay from main thread --- interface/src/Application.cpp | 6 +++++- interface/src/ui/overlays/TextOverlay.cpp | 11 ++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index f0dcdd1a8a..e194e99688 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -4474,7 +4474,11 @@ void Application::friendsWindowClosed() { } void Application::postLambdaEvent(std::function f) { - QCoreApplication::postEvent(this, new LambdaEvent(f)); + if (this->thread() == QThread::currentThread()) { + f(); + } else { + QCoreApplication::postEvent(this, new LambdaEvent(f)); + } } void Application::initPlugins() { diff --git a/interface/src/ui/overlays/TextOverlay.cpp b/interface/src/ui/overlays/TextOverlay.cpp index 467014427d..ea0c4f6026 100644 --- a/interface/src/ui/overlays/TextOverlay.cpp +++ b/interface/src/ui/overlays/TextOverlay.cpp @@ -85,7 +85,6 @@ TextOverlay::TextOverlay() : _topMargin(DEFAULT_MARGIN), _fontSize(DEFAULT_FONTSIZE) { - qApp->postLambdaEvent([=] { static std::once_flag once; std::call_once(once, [] { @@ -117,7 +116,7 @@ TextOverlay::TextOverlay(const TextOverlay* textOverlay) : }); }); while (!_qmlElement) { - QThread::sleep(1); + QThread::msleep(1); } } @@ -147,14 +146,12 @@ xColor TextOverlay::getBackgroundColor() { } void TextOverlay::render(RenderArgs* args) { + if (!_qmlElement) { + return; + } if (_visible != _qmlElement->isVisible()) { _qmlElement->setVisible(_visible); } - float pulseLevel = updatePulse(); - static float _oldPulseLevel = 0.0f; - if (pulseLevel != _oldPulseLevel) { - - } } From 9596452c32e567ed00a702fcc01803274dcc3198 Mon Sep 17 00:00:00 2001 From: Bradley Austin Davis Date: Wed, 22 Jul 2015 08:07:44 -0400 Subject: [PATCH 14/17] Trying to fix oculus rendering --- interface/src/ui/ApplicationCompositor.cpp | 4 +- interface/src/ui/ApplicationOverlay.h | 1 + .../src/DeferredLightingEffect.cpp | 27 ++++---- .../render-utils/src/FramebufferCache.cpp | 61 ++++++++++++++----- libraries/render-utils/src/FramebufferCache.h | 10 ++- 5 files changed, 73 insertions(+), 30 deletions(-) diff --git a/interface/src/ui/ApplicationCompositor.cpp b/interface/src/ui/ApplicationCompositor.cpp index 943d958cff..afdeb7b94e 100644 --- a/interface/src/ui/ApplicationCompositor.cpp +++ b/interface/src/ui/ApplicationCompositor.cpp @@ -270,8 +270,8 @@ void ApplicationCompositor::displayOverlayTextureHmd(RenderArgs* renderArgs, int gpu::Batch batch; geometryCache->useSimpleDrawPipeline(batch); - batch._glDisable(GL_DEPTH_TEST); - batch._glDisable(GL_CULL_FACE); + //batch._glDisable(GL_DEPTH_TEST); + //batch._glDisable(GL_CULL_FACE); //batch._glBindTexture(GL_TEXTURE_2D, texture); //batch._glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); //batch._glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); diff --git a/interface/src/ui/ApplicationOverlay.h b/interface/src/ui/ApplicationOverlay.h index 532fea23dc..ae09aa0b10 100644 --- a/interface/src/ui/ApplicationOverlay.h +++ b/interface/src/ui/ApplicationOverlay.h @@ -49,6 +49,7 @@ private: gpu::TexturePointer _overlayDepthTexture; gpu::TexturePointer _overlayColorTexture; gpu::FramebufferPointer _overlayFramebuffer; + }; #endif // hifi_ApplicationOverlay_h diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 26d12ef0ce..e6f2b520c7 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -227,6 +227,8 @@ void DeferredLightingEffect::prepare(RenderArgs* args) { args->_context->render(batch); } +gpu::FramebufferPointer _copyFBO; + void DeferredLightingEffect::render(RenderArgs* args) { gpu::Batch batch; @@ -236,18 +238,20 @@ void DeferredLightingEffect::render(RenderArgs* args) { QSize framebufferSize = framebufferCache->getFrameBufferSize(); // binding the first framebuffer - auto freeFBO = framebufferCache->getSecondaryFramebuffer(); - batch.setFramebuffer(freeFBO); + _copyFBO = framebufferCache->getFramebuffer(); + batch.setFramebuffer(_copyFBO); batch.setViewportTransform(args->_viewport); - batch.clearColorFramebuffer(freeFBO->getBufferMask(), glm::vec4(0.0f, 0.0f, 0.0f, 0.0f)); + batch.clearColorFramebuffer(_copyFBO->getBufferMask(), glm::vec4(0.0f, 0.0f, 0.0f, 0.0f)); - auto primaryFramebuffer = framebufferCache->getPrimaryFramebuffer(); - for (int i = 0; i < 3; ++i) { - batch.setResourceTexture(i, primaryFramebuffer->getRenderBuffer(i)); - } - batch.setResourceTexture(3, primaryFramebuffer->getDepthStencilBuffer()); + batch.setResourceTexture(0, framebufferCache->getPrimaryColorTexture()); + + batch.setResourceTexture(1, framebufferCache->getPrimaryNormalTexture()); + + batch.setResourceTexture(2, framebufferCache->getPrimarySpecularTexture()); + + batch.setResourceTexture(3, framebufferCache->getPrimaryDepthTexture()); float sMin = args->_viewport.x / (float)framebufferSize.width(); float sWidth = args->_viewport.z / (float)framebufferSize.width(); @@ -532,17 +536,16 @@ void DeferredLightingEffect::render(RenderArgs* args) { // End of the Lighting pass } + void DeferredLightingEffect::copyBack(RenderArgs* args) { gpu::Batch batch; auto framebufferCache = DependencyManager::get(); QSize framebufferSize = framebufferCache->getFrameBufferSize(); - auto freeFBO = framebufferCache->getSecondaryFramebuffer(); - batch.setFramebuffer(framebufferCache->getPrimaryFramebuffer()); batch.setPipeline(_blitLightBuffer); - batch.setResourceTexture(0, freeFBO->getRenderBuffer(0)); + batch.setResourceTexture(0, _copyFBO->getRenderBuffer(0)); batch.setProjectionTransform(glm::mat4()); batch.setViewTransform(Transform()); @@ -561,8 +564,10 @@ void DeferredLightingEffect::copyBack(RenderArgs* args) { batch.draw(gpu::TRIANGLE_STRIP, 4); + args->_context->syncCache(); args->_context->render(batch); + framebufferCache->releaseFramebuffer(_copyFBO); } void DeferredLightingEffect::setupTransparent(RenderArgs* args, int lightBufferUnit) { diff --git a/libraries/render-utils/src/FramebufferCache.cpp b/libraries/render-utils/src/FramebufferCache.cpp index c699da2e81..ba724d05e8 100644 --- a/libraries/render-utils/src/FramebufferCache.cpp +++ b/libraries/render-utils/src/FramebufferCache.cpp @@ -35,30 +35,34 @@ void FramebufferCache::setFrameBufferSize(QSize frameBufferSize) { if (_frameBufferSize != frameBufferSize) { _frameBufferSize = frameBufferSize; _primaryFramebuffer.reset(); + _primaryDepthTexture.reset(); + _primaryColorTexture.reset(); + _primaryNormalTexture.reset(); + _primarySpecularTexture.reset(); } } void FramebufferCache::createPrimaryFramebuffer() { _primaryFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create()); - static auto colorFormat = gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA); - static auto depthFormat = gpu::Element(gpu::SCALAR, gpu::FLOAT, gpu::DEPTH); - + auto colorFormat = gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA); auto width = _frameBufferSize.width(); auto height = _frameBufferSize.height(); auto defaultSampler = gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_POINT); - auto colorTexture = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width, height, defaultSampler)); - auto normalTexture = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width, height, defaultSampler)); - auto specularTexture = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width, height, defaultSampler)); + _primaryColorTexture = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width, height, defaultSampler)); + _primaryNormalTexture = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width, height, defaultSampler)); + _primarySpecularTexture = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width, height, defaultSampler)); - _primaryFramebuffer->setRenderBuffer(0, colorTexture); - _primaryFramebuffer->setRenderBuffer(1, normalTexture); - _primaryFramebuffer->setRenderBuffer(2, specularTexture); + _primaryFramebuffer->setRenderBuffer(0, _primaryColorTexture); + _primaryFramebuffer->setRenderBuffer(1, _primaryNormalTexture); + _primaryFramebuffer->setRenderBuffer(2, _primarySpecularTexture); - auto depthTexture = gpu::TexturePointer(gpu::Texture::create2D(depthFormat, width, height, defaultSampler)); - _primaryFramebuffer->setDepthStencilBuffer(depthTexture, depthFormat); + auto depthFormat = gpu::Element(gpu::SCALAR, gpu::FLOAT, gpu::DEPTH); + _primaryDepthTexture = gpu::TexturePointer(gpu::Texture::create2D(depthFormat, width, height, defaultSampler)); + + _primaryFramebuffer->setDepthStencilBuffer(_primaryDepthTexture, depthFormat); } gpu::FramebufferPointer FramebufferCache::getPrimaryFramebuffer() { @@ -68,6 +72,36 @@ gpu::FramebufferPointer FramebufferCache::getPrimaryFramebuffer() { return _primaryFramebuffer; } + + +gpu::TexturePointer FramebufferCache::getPrimaryDepthTexture() { + if (!_primaryDepthTexture) { + createPrimaryFramebuffer(); + } + return _primaryDepthTexture; +} + +gpu::TexturePointer FramebufferCache::getPrimaryColorTexture() { + if (!_primaryColorTexture) { + createPrimaryFramebuffer(); + } + return _primaryColorTexture; +} + +gpu::TexturePointer FramebufferCache::getPrimaryNormalTexture() { + if (!_primaryNormalTexture) { + createPrimaryFramebuffer(); + } + return _primaryNormalTexture; +} + +gpu::TexturePointer FramebufferCache::getPrimarySpecularTexture() { + if (!_primarySpecularTexture) { + createPrimaryFramebuffer(); + } + return _primarySpecularTexture; +} + void FramebufferCache::setPrimaryDrawBuffers(gpu::Batch& batch, bool color, bool normal, bool specular) { GLenum buffers[3]; int bufferCount = 0; @@ -98,11 +132,6 @@ void FramebufferCache::releaseFramebuffer(const gpu::FramebufferPointer& framebu _cachedFramebuffers.push_back(framebuffer); } -gpu::FramebufferPointer FramebufferCache::getSecondaryFramebuffer() { - static auto _secondaryFramebuffer = getFramebuffer(); - return _secondaryFramebuffer; -} - gpu::FramebufferPointer FramebufferCache::getShadowFramebuffer() { if (!_shadowFramebuffer) { const int SHADOW_MAP_SIZE = 2048; diff --git a/libraries/render-utils/src/FramebufferCache.h b/libraries/render-utils/src/FramebufferCache.h index e756286ccd..348c4818f9 100644 --- a/libraries/render-utils/src/FramebufferCache.h +++ b/libraries/render-utils/src/FramebufferCache.h @@ -31,7 +31,10 @@ public: /// used for scene rendering. gpu::FramebufferPointer getPrimaryFramebuffer(); - gpu::FramebufferPointer getSecondaryFramebuffer(); + gpu::TexturePointer getPrimaryDepthTexture(); + gpu::TexturePointer getPrimaryColorTexture(); + gpu::TexturePointer getPrimaryNormalTexture(); + gpu::TexturePointer getPrimarySpecularTexture(); /// Returns the framebuffer object used to render shadow maps; gpu::FramebufferPointer getShadowFramebuffer(); @@ -52,6 +55,11 @@ private: void createPrimaryFramebuffer(); gpu::FramebufferPointer _primaryFramebuffer; + gpu::TexturePointer _primaryDepthTexture; + gpu::TexturePointer _primaryColorTexture; + gpu::TexturePointer _primaryNormalTexture; + gpu::TexturePointer _primarySpecularTexture; + gpu::FramebufferPointer _shadowFramebuffer; QSize _frameBufferSize{ 100, 100 }; }; From a93e17d622df832e35389525db46e93f6362f187 Mon Sep 17 00:00:00 2001 From: Bradley Austin Davis Date: Wed, 22 Jul 2015 08:27:51 -0400 Subject: [PATCH 15/17] Fix domain connection status border --- interface/src/ui/ApplicationOverlay.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index 87462e4c3e..a7f03db24f 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -209,7 +209,8 @@ void ApplicationOverlay::renderDomainConnectionStatusBorder(RenderArgs* renderAr auto geometryCache = DependencyManager::get(); geometryCache->useSimpleDrawPipeline(batch); batch.setProjectionTransform(mat4()); - batch.setModelTransform(mat4()); + batch.setModelTransform(Transform()); + batch.setViewTransform(Transform()); batch.setResourceTexture(0, DependencyManager::get()->getWhiteTexture()); batch._glLineWidth(CONNECTION_STATUS_BORDER_LINE_WIDTH); From 2f13488f116ba358c2236105e3b93ea6e1eae6ac Mon Sep 17 00:00:00 2001 From: Bradley Austin Davis Date: Wed, 22 Jul 2015 11:28:36 -0400 Subject: [PATCH 16/17] Fixing FBO bug on resizing windows --- interface/src/Application.cpp | 3 +-- libraries/render-utils/src/FramebufferCache.cpp | 5 ++++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index d78c63b5d0..742517998f 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -893,8 +893,6 @@ void Application::paintGL() { PerformanceWarning warn(showWarnings, "Application::paintGL()"); resizeGL(); - glEnable(GL_LINE_SMOOTH); - { PerformanceTimer perfTimer("renderOverlay"); @@ -905,6 +903,7 @@ void Application::paintGL() { _applicationOverlay.renderOverlay(&renderArgs); } + glEnable(GL_LINE_SMOOTH); if (_myCamera.getMode() == CAMERA_MODE_FIRST_PERSON || _myCamera.getMode() == CAMERA_MODE_THIRD_PERSON) { Menu::getInstance()->setIsOptionChecked(MenuOption::FirstPerson, _myAvatar->getBoomLength() <= MyAvatar::ZOOM_MIN); diff --git a/libraries/render-utils/src/FramebufferCache.cpp b/libraries/render-utils/src/FramebufferCache.cpp index ba724d05e8..8e16eeec62 100644 --- a/libraries/render-utils/src/FramebufferCache.cpp +++ b/libraries/render-utils/src/FramebufferCache.cpp @@ -39,6 +39,7 @@ void FramebufferCache::setFrameBufferSize(QSize frameBufferSize) { _primaryColorTexture.reset(); _primaryNormalTexture.reset(); _primarySpecularTexture.reset(); + _cachedFramebuffers.clear(); } } @@ -129,7 +130,9 @@ gpu::FramebufferPointer FramebufferCache::getFramebuffer() { void FramebufferCache::releaseFramebuffer(const gpu::FramebufferPointer& framebuffer) { - _cachedFramebuffers.push_back(framebuffer); + if (QSize(framebuffer->getSize().x, framebuffer->getSize().y) == _frameBufferSize) { + _cachedFramebuffers.push_back(framebuffer); + } } gpu::FramebufferPointer FramebufferCache::getShadowFramebuffer() { From 68cf3776f0eaab73d51cc89b9f801547ef9905d4 Mon Sep 17 00:00:00 2001 From: Bradley Austin Davis Date: Wed, 22 Jul 2015 13:44:37 -0400 Subject: [PATCH 17/17] Make stars a little smaller --- interface/src/Stars.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/Stars.cpp b/interface/src/Stars.cpp index da61926399..ebfddee38c 100644 --- a/interface/src/Stars.cpp +++ b/interface/src/Stars.cpp @@ -169,7 +169,7 @@ void Stars::render(RenderArgs* renderArgs, float alpha) { points.resize(limit); for (size_t star = 0; star < limit; ++star) { points[star].position = vec4(fromPolar(randPolar()), 1); - float size = frand() * 5.0f + 0.5f; + float size = frand() * 2.5f + 0.5f; if (frand() < STAR_COLORIZATION) { vec3 color(frand() / 2.0f + 0.5f, frand() / 2.0f + 0.5f, frand() / 2.0f + 0.5f); points[star].colorAndSize = vec4(color, size);