diff --git a/modules/debugging/rendering/debugrenderer.cpp b/modules/debugging/rendering/debugrenderer.cpp index 13d4c34b7e..f889d29a43 100644 --- a/modules/debugging/rendering/debugrenderer.cpp +++ b/modules/debugging/rendering/debugrenderer.cpp @@ -41,33 +41,37 @@ namespace { namespace openspace { - std::shared_ptr DebugRenderer::_reference = nullptr; - + DebugRenderer* DebugRenderer::_reference = nullptr; DebugRenderer::DebugRenderer() { - _programObject = std::shared_ptr(OsEng.renderEngine().buildRenderProgram( + _programObject = OsEng.renderEngine().buildRenderProgram( "BasicDebugShader", "${MODULE_DEBUGGING}/rendering/debugshader_vs.glsl", "${MODULE_DEBUGGING}/rendering/debugshader_fs.glsl" - )); + ); } - DebugRenderer::DebugRenderer(std::shared_ptr programObject) - : _programObject(programObject) + DebugRenderer::DebugRenderer(std::unique_ptr programObject) + : _programObject(std::move(programObject)) { // nothing to do } - std::shared_ptr DebugRenderer::ref() { + DebugRenderer::~DebugRenderer() + { + + } + + const DebugRenderer& DebugRenderer::ref() { if (_reference == nullptr) { try { - _reference = std::make_shared(); + _reference = new DebugRenderer(); } catch (const ShaderObject::ShaderCompileError& e) { LERROR(e.what()); } } - return _reference; + return *_reference; } void DebugRenderer::renderVertices(const Vertices& clippingSpacePoints, GLenum mode, RGBA rgba) const { @@ -163,17 +167,17 @@ namespace openspace { lineVertices.push_back(V[1]); lineVertices.push_back(V[3]); lineVertices.push_back(V[4]); lineVertices.push_back(V[6]); lineVertices.push_back(V[5]); lineVertices.push_back(V[7]); - DebugRenderer::ref()->renderVertices(lineVertices, GL_LINES, rgba); + DebugRenderer::ref().renderVertices(lineVertices, GL_LINES, rgba); } void DebugRenderer::renderNiceBox(const Vertices& clippingSpaceBoxCorners, RGBA rgba) const { renderBoxFaces(clippingSpaceBoxCorners, rgba); glLineWidth(4.0f); - DebugRenderer::ref()->renderBoxEdges(clippingSpaceBoxCorners, rgba); + DebugRenderer::ref().renderBoxEdges(clippingSpaceBoxCorners, rgba); glPointSize(10.0f); - DebugRenderer::ref()->renderVertices(clippingSpaceBoxCorners, GL_POINTS, rgba); + DebugRenderer::ref().renderVertices(clippingSpaceBoxCorners, GL_POINTS, rgba); } void DebugRenderer::renderCameraFrustum(const RenderData& data, const Camera& otherCamera, RGBA rgba) const { diff --git a/modules/debugging/rendering/debugrenderer.h b/modules/debugging/rendering/debugrenderer.h index 8699e828fa..82889f708f 100644 --- a/modules/debugging/rendering/debugrenderer.h +++ b/modules/debugging/rendering/debugrenderer.h @@ -43,7 +43,6 @@ namespace openspace { using namespace ghoul::opengl; - /** A helper class for quick rendering of vertices IN clipping space. @@ -54,11 +53,9 @@ namespace openspace { */ class DebugRenderer { public: - typedef std::vector Vertices; typedef glm::vec4 RGBA; - /** * Consider using ref() before creating a new default instance! */ @@ -67,15 +64,13 @@ namespace openspace { /** * Instantiate a new DebugRenderer with a custom shader program */ - DebugRenderer(std::shared_ptr programObject); + DebugRenderer(std::unique_ptr programObject); + ~DebugRenderer(); /** * Access the static reference */ - static std::shared_ptr ref(); - - - + static const DebugRenderer& ref(); /** * Render the vector of clipping space points in the specified mode and color. @@ -127,8 +122,6 @@ namespace openspace { */ void renderNiceBox(const Vertices& clippingSpaceBoxCorners, RGBA rgba = { 1, 0, 0, 0.3 }) const; - - /** * Input arguments: * 1. const RenderData& data: defines position and camera that we will see the @@ -143,7 +136,6 @@ namespace openspace { */ void renderAABB2(const AABB2& screenSpaceAABB, RGBA rgba = { 1, 1, 1, 0.3 }) const; - /** * Takes a AABB3 in screen space and returns vertices representing the corner points * of the AABB. The ordering of the corner points is compatible with the box rendering @@ -151,17 +143,13 @@ namespace openspace { */ const Vertices verticesFor(const AABB3& screenSpaceAABB) const; - protected: + std::unique_ptr _programObject; - std::shared_ptr _programObject; - static std::shared_ptr _reference; + // A raw pointer for the reason that it should not be deleted by the static + // destructor and the normal destructor. This class has ownership + static DebugRenderer* _reference; }; - - } // namespace openspace - - - #endif // __DEBUG_RENDERER_H__ diff --git a/modules/globebrowsing/chunk/chunkedlodglobe.cpp b/modules/globebrowsing/chunk/chunkedlodglobe.cpp index f94d5507f6..b4aa5b5843 100644 --- a/modules/globebrowsing/chunk/chunkedlodglobe.cpp +++ b/modules/globebrowsing/chunk/chunkedlodglobe.cpp @@ -202,7 +202,7 @@ namespace openspace { if (_savedCamera != nullptr) { - DebugRenderer::ref()->renderCameraFrustum(data, *_savedCamera); + DebugRenderer::ref().renderCameraFrustum(data, *_savedCamera); } @@ -234,12 +234,12 @@ namespace openspace { vec4 color = vec4(colorBits & 1, colorBits & 2, colorBits & 4, 0.3); if (debugOptions.showChunkBounds) { - DebugRenderer::ref()->renderNiceBox(clippingSpaceCorners, color); + DebugRenderer::ref().renderNiceBox(clippingSpaceCorners, color); } if (debugOptions.showChunkAABB) { - auto& screenSpacePoints = DebugRenderer::ref()->verticesFor(screenSpaceBounds); - DebugRenderer::ref()->renderNiceBox(screenSpacePoints, color); + auto& screenSpacePoints = DebugRenderer::ref().verticesFor(screenSpaceBounds); + DebugRenderer::ref().renderNiceBox(screenSpacePoints, color); } } } diff --git a/modules/globebrowsing/chunk/chunkedlodglobe.h b/modules/globebrowsing/chunk/chunkedlodglobe.h index 56e8d2e39c..a5f89c9112 100644 --- a/modules/globebrowsing/chunk/chunkedlodglobe.h +++ b/modules/globebrowsing/chunk/chunkedlodglobe.h @@ -37,7 +37,6 @@ #include #include - #include #include @@ -149,7 +148,6 @@ namespace openspace { std::shared_ptr _savedCamera; std::shared_ptr _tileProviderManager; - }; } // namespace openspace