diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 742517998f..7de69ef602 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -767,27 +767,8 @@ 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")) { - int swapInterval = wglGetSwapIntervalEXT(); - qCDebug(interfaceapp, "V-Sync is %s\n", (swapInterval > 0 ? "ON" : "OFF")); - }*/ -#endif + // Where the gpuContext is created and where the TRUE Backend is created and assigned + _gpuContext = std::make_shared(new gpu::GLBackend()); initDisplay(); qCDebug(interfaceapp, "Initialized Display."); @@ -876,8 +857,9 @@ void Application::paintGL() { _glWidget->makeCurrent(); auto lodManager = DependencyManager::get(); - gpu::Context context(new gpu::GLBackend()); - RenderArgs renderArgs(&context, nullptr, getViewFrustum(), lodManager->getOctreeSizeScale(), + + + RenderArgs renderArgs(_gpuContext, nullptr, getViewFrustum(), lodManager->getOctreeSizeScale(), lodManager->getBoundaryLevelAdjust(), RenderArgs::DEFAULT_RENDER_MODE, RenderArgs::MONO, RenderArgs::RENDER_DEBUG_NONE); @@ -893,6 +875,7 @@ void Application::paintGL() { PerformanceWarning warn(showWarnings, "Application::paintGL()"); resizeGL(); + { PerformanceTimer perfTimer("renderOverlay"); @@ -903,8 +886,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); Menu::getInstance()->setIsOptionChecked(MenuOption::ThirdPerson, !(_myAvatar->getBoomLength() <= MyAvatar::ZOOM_MIN)); @@ -955,7 +936,6 @@ void Application::paintGL() { } // Sync up the View Furstum with the camera - // FIXME: it's happening again in the updateSHadow and it shouldn't, this should be the place loadViewFrustum(_myCamera, _viewFrustum); @@ -994,7 +974,7 @@ void Application::paintGL() { displaySide(&renderArgs, _myCamera); - if (_myCamera.getMode() != CAMERA_MODE_MIRROR && Menu::getInstance()->isOptionChecked(MenuOption::Mirror)) { + if (Menu::getInstance()->isOptionChecked(MenuOption::Mirror)) { renderArgs._renderMode = RenderArgs::MIRROR_RENDER_MODE; renderRearViewMirror(&renderArgs, _mirrorViewRect); renderArgs._renderMode = RenderArgs::NORMAL_RENDER_MODE; @@ -3169,10 +3149,6 @@ namespace render { model::Skybox::render(batch, *(Application::getInstance()->getDisplayViewFrustum()), *skybox); } } - // FIX ME - If I don't call this renderBatch() here, then the atmosphere and skybox don't render, but it - // seems like these payloadRender() methods shouldn't be doing this. We need to investigate why the engine - // isn't rendering our batch - gpu::GLBackend::renderBatch(batch, true); } } @@ -3441,7 +3417,6 @@ void Application::renderRearViewMirror(RenderArgs* renderArgs, const QRect& regi bool updateViewFrustum = false; loadViewFrustum(_mirrorCamera, _viewFrustum); - // render rear mirror view displaySide(renderArgs, _mirrorCamera, true, billboard); diff --git a/interface/src/Application.h b/interface/src/Application.h index 2fc335eeac..3a07fb656d 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -68,6 +68,7 @@ #include "octree/OctreePacketProcessor.h" #include "UndoStackScriptingInterface.h" +#include "gpu/Context.h" #include "render/Engine.h" class QGLWidget; @@ -325,6 +326,8 @@ public: render::ScenePointer getMain3DScene() const { return _main3DScene; } + gpu::ContextPointer getGPUContext() const { return _gpuContext; } + signals: /// Fired when we're simulating; allows external parties to hook in. @@ -481,6 +484,7 @@ private: glm::vec3 getSunDirection(); void renderRearViewMirror(RenderArgs* renderArgs, const QRect& region, bool billboard = false); + void setMenuShortcutsEnabled(bool enabled); static void attachNewHeadToNode(Node *newNode); @@ -631,6 +635,7 @@ private: render::ScenePointer _main3DScene{ new render::Scene() }; render::EnginePointer _renderEngine{ new render::Engine() }; + gpu::ContextPointer _gpuContext; // initialized during window creation Overlays _overlays; ApplicationOverlay _applicationOverlay; diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 83804ab79d..4147d24b15 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -1532,8 +1532,8 @@ void MyAvatar::maybeUpdateBillboard() { return; } } - gpu::Context context(new gpu::GLBackend()); - RenderArgs renderArgs(&context); + + RenderArgs renderArgs(qApp->getGPUContext()); QImage image = qApp->renderAvatarBillboard(&renderArgs); _billboard.clear(); QBuffer buffer(&_billboard); diff --git a/interface/src/ui/ApplicationOverlay.h b/interface/src/ui/ApplicationOverlay.h index ae09aa0b10..532fea23dc 100644 --- a/interface/src/ui/ApplicationOverlay.h +++ b/interface/src/ui/ApplicationOverlay.h @@ -49,7 +49,6 @@ private: gpu::TexturePointer _overlayDepthTexture; gpu::TexturePointer _overlayColorTexture; gpu::FramebufferPointer _overlayFramebuffer; - }; #endif // hifi_ApplicationOverlay_h diff --git a/libraries/gpu/src/gpu/Context.h b/libraries/gpu/src/gpu/Context.h index 4eb0976e3c..484c772c71 100644 --- a/libraries/gpu/src/gpu/Context.h +++ b/libraries/gpu/src/gpu/Context.h @@ -134,7 +134,7 @@ protected: friend class Shader; }; - +typedef std::shared_ptr ContextPointer; }; diff --git a/libraries/gpu/src/gpu/GLBackend.cpp b/libraries/gpu/src/gpu/GLBackend.cpp index adebee2f20..721be0f402 100644 --- a/libraries/gpu/src/gpu/GLBackend.cpp +++ b/libraries/gpu/src/gpu/GLBackend.cpp @@ -8,6 +8,7 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include #include "GPULogging.h" #include "GLBackendShared.h" #include @@ -89,6 +90,36 @@ GLBackend::GLBackend() : _pipeline(), _output() { + static std::once_flag once; + std::call_once(once, [] { + qCDebug(gpulogging) << "GL Version: " << QString((const char*) glGetString(GL_VERSION)); + qCDebug(gpulogging) << "GL Shader Language Version: " << QString((const char*) glGetString(GL_SHADING_LANGUAGE_VERSION)); + qCDebug(gpulogging) << "GL Vendor: " << QString((const char*) glGetString(GL_VENDOR)); + qCDebug(gpulogging) << "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(gpulogging, "Error: %s\n", glewGetErrorString(err)); + } + qCDebug(gpulogging, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION)); + + if (wglewGetExtension("WGL_EXT_swap_control")) { + int swapInterval = wglGetSwapIntervalEXT(); + qCDebug(gpulogging, "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")) { + int swapInterval = wglGetSwapIntervalEXT(); + qCDebug(gpulogging, "V-Sync is %s\n", (swapInterval > 0 ? "ON" : "OFF")); + }*/ +#endif + }); + initInput(); initTransform(); } @@ -113,6 +144,7 @@ void GLBackend::render(Batch& batch) { } void GLBackend::renderBatch(Batch& batch, bool syncCache) { + qCDebug(gpulogging) << "GLBackend::renderBatch : Deprecated call, don;t do it!!!"; GLBackend backend; if (syncCache) { backend.syncCache(); @@ -166,6 +198,8 @@ void GLBackend::syncCache() { syncTransformStateCache(); syncPipelineStateCache(); syncInputStateCache(); + + glEnable(GL_LINE_SMOOTH); } void GLBackend::do_draw(Batch& batch, uint32 paramOffset) { diff --git a/libraries/gpu/src/gpu/GLBackend.h b/libraries/gpu/src/gpu/GLBackend.h index 60c01a815c..b3e905bf21 100644 --- a/libraries/gpu/src/gpu/GLBackend.h +++ b/libraries/gpu/src/gpu/GLBackend.h @@ -447,7 +447,6 @@ protected: typedef void (GLBackend::*CommandCall)(Batch&, uint32); static CommandCall _commandCalls[Batch::NUM_COMMANDS]; - }; diff --git a/libraries/render-utils/src/FramebufferCache.cpp b/libraries/render-utils/src/FramebufferCache.cpp index 8e16eeec62..c7cb6451f7 100644 --- a/libraries/render-utils/src/FramebufferCache.cpp +++ b/libraries/render-utils/src/FramebufferCache.cpp @@ -103,22 +103,6 @@ gpu::TexturePointer FramebufferCache::getPrimarySpecularTexture() { return _primarySpecularTexture; } -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()))); diff --git a/libraries/render-utils/src/FramebufferCache.h b/libraries/render-utils/src/FramebufferCache.h index 348c4818f9..ca01a470d9 100644 --- a/libraries/render-utils/src/FramebufferCache.h +++ b/libraries/render-utils/src/FramebufferCache.h @@ -39,9 +39,6 @@ public: /// 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 diff --git a/libraries/shared/src/RenderArgs.h b/libraries/shared/src/RenderArgs.h index 604cb46731..7a5daf7a17 100644 --- a/libraries/shared/src/RenderArgs.h +++ b/libraries/shared/src/RenderArgs.h @@ -80,7 +80,7 @@ public: RENDER_DEBUG_SIMULATION_OWNERSHIP = 2, }; - RenderArgs(gpu::Context* context = nullptr, + RenderArgs(std::shared_ptr context = nullptr, OctreeRenderer* renderer = nullptr, ViewFrustum* viewFrustum = nullptr, float sizeScale = 1.0f, @@ -102,7 +102,7 @@ public: _shouldRender(shouldRender) { } - gpu::Context* _context = nullptr; + std::shared_ptr _context = nullptr; OctreeRenderer* _renderer = nullptr; ViewFrustum* _viewFrustum = nullptr; glm::ivec4 _viewport{ 0, 0, 1, 1 };