mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-03 17:30:04 -05:00
Issue/525 (#593)
* Add initializeGL and deinitializeGL methods to OpenSpaceModule Call releaseAll from ProgramObjectManager in deinitializeGL to guard against errors when deinitializing assets * Change removeProgramObject function in RenderEngine to take a non-owning pointer instead of a reference to a unique pointer to make it compatible with the ProgramObjectManager Update Ghoul repository * Using ProgramObjectManager in more modules to reduce the number of programs compiled at startup
This commit is contained in:
+1
-1
Submodule ext/sgct updated: 0f689a49a8...52e2943cd7
@@ -61,12 +61,22 @@ public:
|
||||
*/
|
||||
void initialize(const ghoul::Dictionary& moduleConfigurations);
|
||||
|
||||
/**
|
||||
* Calls the initializeGL functions of all registered OpenSpaceModule%s.
|
||||
*/
|
||||
void initializeGL();
|
||||
|
||||
/**
|
||||
* Deinitializes all of the contained OpenSpaceModule%s by calling the
|
||||
* OpenSpaceModule::deinitialize methods.
|
||||
*/
|
||||
void deinitialize();
|
||||
|
||||
/**
|
||||
* Calls the deinitializeGL functions of all registered OpenSpaceModule%s.
|
||||
*/
|
||||
void deinitializeGL();
|
||||
|
||||
/**
|
||||
* Registers the passed \p module with this ModuleEngine. The OpenSpaceModule::create
|
||||
* method will be called on the \p module in the process.
|
||||
|
||||
@@ -120,8 +120,7 @@ public:
|
||||
std::string csPath,
|
||||
const ghoul::Dictionary& dictionary = ghoul::Dictionary());
|
||||
|
||||
void removeRenderProgram(
|
||||
const std::unique_ptr<ghoul::opengl::ProgramObject>& program);
|
||||
void removeRenderProgram(ghoul::opengl::ProgramObject* program);
|
||||
|
||||
/**
|
||||
* Set raycasting uniforms on the program object, and setup raycasting.
|
||||
|
||||
@@ -66,7 +66,13 @@ public:
|
||||
* internalInitialize method for further customization for each subclass.
|
||||
*/
|
||||
void initialize(const ModuleEngine* moduleEngine,
|
||||
const ghoul::Dictionary& configuration);
|
||||
const ghoul::Dictionary& configuration);
|
||||
|
||||
/**
|
||||
* This method calls the internalInitializeGL method for further customization for
|
||||
* each subclass.
|
||||
*/
|
||||
void initializeGL();
|
||||
|
||||
/**
|
||||
* Empty deinitialization method that will call the internalDeinitialize method for
|
||||
@@ -74,6 +80,11 @@ public:
|
||||
*/
|
||||
void deinitialize();
|
||||
|
||||
/**
|
||||
* This method will call the internalDeinitializeGL method for each subclass.
|
||||
*/
|
||||
void deinitializeGL();
|
||||
|
||||
/**
|
||||
* Returns a list of Documentation classes that are valid for this OpenSpaceModule.
|
||||
* \return A list of Documentation classes that are valid for this OpenSapceModule
|
||||
@@ -112,12 +123,26 @@ protected:
|
||||
*/
|
||||
virtual void internalInitialize(const ghoul::Dictionary& configuration);
|
||||
|
||||
/**
|
||||
* Customization point for each derived class. The internalInitializeGL method is
|
||||
* called by the initializeGL method at a time when a valid OpenGL state is
|
||||
* guaranteed.
|
||||
*/
|
||||
virtual void internalInitializeGL();
|
||||
|
||||
/**
|
||||
* Customization point for each derived class. The internalDeinitialize method is
|
||||
* called by the deinitialize method.
|
||||
*/
|
||||
virtual void internalDeinitialize();
|
||||
|
||||
/**
|
||||
* Customization point for each derived class. The internalDeinitializeGL method is
|
||||
* called by the deinitializeGL method at a time when a valid OpenGL state is
|
||||
* guaranteed.
|
||||
*/
|
||||
virtual void internalDeinitializeGL();
|
||||
|
||||
/**
|
||||
* Returns the path for this module, possibly containing ghoul::filesystem::FileSystem
|
||||
* path tokens.
|
||||
|
||||
@@ -66,6 +66,8 @@
|
||||
|
||||
namespace openspace {
|
||||
|
||||
ghoul::opengl::ProgramObjectManager BaseModule::ProgramObjectManager;
|
||||
|
||||
BaseModule::BaseModule() : OpenSpaceModule(BaseModule::Name) {}
|
||||
|
||||
void BaseModule::internalInitialize(const ghoul::Dictionary&) {
|
||||
@@ -137,6 +139,10 @@ void BaseModule::internalInitialize(const ghoul::Dictionary&) {
|
||||
fGeometry->registerClass<modelgeometry::MultiModelGeometry>("MultiModelGeometry");
|
||||
}
|
||||
|
||||
void BaseModule::internalDeinitializeGL() {
|
||||
ProgramObjectManager.releaseAll(ghoul::opengl::ProgramObjectManager::Warnings::Yes);
|
||||
}
|
||||
|
||||
std::vector<documentation::Documentation> BaseModule::documentations() const {
|
||||
return {
|
||||
DashboardItemDate::Documentation(),
|
||||
|
||||
@@ -27,6 +27,8 @@
|
||||
|
||||
#include <openspace/util/openspacemodule.h>
|
||||
|
||||
#include <ghoul/opengl/programobjectmanager.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class BaseModule : public OpenSpaceModule {
|
||||
@@ -39,8 +41,11 @@ public:
|
||||
std::vector<documentation::Documentation> documentations() const override;
|
||||
std::vector<scripting::LuaLibrary> luaLibraries() const override;
|
||||
|
||||
static ghoul::opengl::ProgramObjectManager ProgramObjectManager;
|
||||
|
||||
protected:
|
||||
void internalInitialize(const ghoul::Dictionary&) override;
|
||||
void internalDeinitializeGL() override;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -24,8 +24,8 @@
|
||||
|
||||
#include <modules/base/rendering/renderablemodel.h>
|
||||
|
||||
#include <modules/base/basemodule.h>
|
||||
#include <modules/base/rendering/modelgeometry.h>
|
||||
|
||||
#include <openspace/documentation/documentation.h>
|
||||
#include <openspace/documentation/verifier.h>
|
||||
#include <openspace/engine/configurationmanager.h>
|
||||
@@ -43,7 +43,8 @@
|
||||
#include <ghoul/opengl/textureunit.h>
|
||||
|
||||
namespace {
|
||||
const char* KeyGeometry = "Geometry";
|
||||
constexpr const char* ProgramName = "ModelProgram";
|
||||
constexpr const char* KeyGeometry = "Geometry";
|
||||
|
||||
static const openspace::properties::Property::PropertyInfo TextureInfo = {
|
||||
"ColorTexture",
|
||||
@@ -154,10 +155,15 @@ bool RenderableModel::isReady() const {
|
||||
}
|
||||
|
||||
void RenderableModel::initializeGL() {
|
||||
_programObject = OsEng.renderEngine().buildRenderProgram(
|
||||
"ModelProgram",
|
||||
absPath("${MODULE_BASE}/shaders/model_vs.glsl"),
|
||||
absPath("${MODULE_BASE}/shaders/model_fs.glsl")
|
||||
_programObject = BaseModule::ProgramObjectManager.requestProgramObject(
|
||||
ProgramName,
|
||||
[]() -> std::unique_ptr<ghoul::opengl::ProgramObject> {
|
||||
return OsEng.renderEngine().buildRenderProgram(
|
||||
ProgramName,
|
||||
absPath("${MODULE_BASE}/shaders/model_vs.glsl"),
|
||||
absPath("${MODULE_BASE}/shaders/model_fs.glsl")
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
_uniformCache.opacity = _programObject->uniformLocation("opacity");
|
||||
@@ -188,10 +194,13 @@ void RenderableModel::deinitializeGL() {
|
||||
}
|
||||
_texture = nullptr;
|
||||
|
||||
if (_programObject) {
|
||||
OsEng.renderEngine().removeRenderProgram(_programObject);
|
||||
_programObject = nullptr;
|
||||
}
|
||||
BaseModule::ProgramObjectManager.releaseProgramObject(
|
||||
ProgramName,
|
||||
[](ghoul::opengl::ProgramObject* p) {
|
||||
OsEng.renderEngine().removeRenderProgram(p);
|
||||
}
|
||||
);
|
||||
_programObject = nullptr;
|
||||
}
|
||||
|
||||
void RenderableModel::render(const RenderData& data, RendererTasks&) {
|
||||
|
||||
@@ -73,7 +73,7 @@ private:
|
||||
properties::BoolProperty _performShading;
|
||||
properties::Mat3Property _modelTransform;
|
||||
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _programObject;
|
||||
ghoul::opengl::ProgramObject* _programObject;
|
||||
UniformCache(opacity, directionToSunViewSpace, modelViewTransform,
|
||||
projectionTransform, performShading, texture) _uniformCache;
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
#include <modules/base/rendering/renderableplane.h>
|
||||
|
||||
#include <modules/base/basemodule.h>
|
||||
#include <openspace/documentation/documentation.h>
|
||||
#include <openspace/documentation/verifier.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
@@ -39,6 +40,8 @@
|
||||
#include <ghoul/opengl/textureunit.h>
|
||||
|
||||
namespace {
|
||||
constexpr const char* ProgramName = "Plane";
|
||||
|
||||
enum BlendMode {
|
||||
BlendModeNormal = 0,
|
||||
BlendModeAdditive
|
||||
@@ -164,11 +167,16 @@ void RenderablePlane::initializeGL() {
|
||||
glGenBuffers(1, &_vertexPositionBuffer); // generate buffer
|
||||
createPlane();
|
||||
|
||||
_shader = OsEng.renderEngine().buildRenderProgram(
|
||||
"PlaneProgram",
|
||||
absPath("${MODULE_BASE}/shaders/plane_vs.glsl"),
|
||||
absPath("${MODULE_BASE}/shaders/plane_fs.glsl")
|
||||
);
|
||||
_shader = BaseModule::ProgramObjectManager.requestProgramObject(
|
||||
ProgramName,
|
||||
[]() -> std::unique_ptr<ghoul::opengl::ProgramObject> {
|
||||
return OsEng.renderEngine().buildRenderProgram(
|
||||
ProgramName,
|
||||
absPath("${MODULE_BASE}/shaders/plane_vs.glsl"),
|
||||
absPath("${MODULE_BASE}/shaders/plane_fs.glsl")
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void RenderablePlane::deinitializeGL() {
|
||||
@@ -178,11 +186,13 @@ void RenderablePlane::deinitializeGL() {
|
||||
glDeleteBuffers(1, &_vertexPositionBuffer);
|
||||
_vertexPositionBuffer = 0;
|
||||
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
if (_shader) {
|
||||
renderEngine.removeRenderProgram(_shader);
|
||||
_shader = nullptr;
|
||||
}
|
||||
BaseModule::ProgramObjectManager.releaseProgramObject(
|
||||
ProgramName,
|
||||
[](ghoul::opengl::ProgramObject* p) {
|
||||
OsEng.renderEngine().removeRenderProgram(p);
|
||||
}
|
||||
);
|
||||
_shader = nullptr;
|
||||
}
|
||||
|
||||
void RenderablePlane::render(const RenderData& data, RendererTasks&) {
|
||||
|
||||
@@ -73,7 +73,7 @@ private:
|
||||
properties::FloatProperty _size;
|
||||
properties::OptionProperty _blendMode;
|
||||
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _shader;
|
||||
ghoul::opengl::ProgramObject* _shader;
|
||||
|
||||
GLuint _quad;
|
||||
GLuint _vertexPositionBuffer;
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
#include <modules/base/rendering/renderablesphere.h>
|
||||
|
||||
#include <modules/base/basemodule.h>
|
||||
#include <openspace/documentation/documentation.h>
|
||||
#include <openspace/documentation/verifier.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
@@ -39,6 +40,8 @@
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
|
||||
namespace {
|
||||
constexpr const char* ProgramName = "Sphere";
|
||||
|
||||
enum Orientation {
|
||||
Outside = 1,
|
||||
Inside = 2
|
||||
@@ -238,11 +241,15 @@ void RenderableSphere::initializeGL() {
|
||||
);
|
||||
_sphere->initialize();
|
||||
|
||||
// pscstandard
|
||||
_shader = OsEng.renderEngine().buildRenderProgram(
|
||||
"Sphere",
|
||||
absPath("${MODULE_BASE}/shaders/sphere_vs.glsl"),
|
||||
absPath("${MODULE_BASE}/shaders/sphere_fs.glsl")
|
||||
_shader = BaseModule::ProgramObjectManager.requestProgramObject(
|
||||
ProgramName,
|
||||
[]() -> std::unique_ptr<ghoul::opengl::ProgramObject> {
|
||||
return OsEng.renderEngine().buildRenderProgram(
|
||||
ProgramName,
|
||||
absPath("${MODULE_BASE}/shaders/sphere_vs.glsl"),
|
||||
absPath("${MODULE_BASE}/shaders/sphere_fs.glsl")
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
_uniformCache.opacity = _shader->uniformLocation("opacity");
|
||||
@@ -256,10 +263,13 @@ void RenderableSphere::initializeGL() {
|
||||
void RenderableSphere::deinitializeGL() {
|
||||
_texture = nullptr;
|
||||
|
||||
if (_shader) {
|
||||
OsEng.renderEngine().removeRenderProgram(_shader);
|
||||
_shader = nullptr;
|
||||
}
|
||||
BaseModule::ProgramObjectManager.releaseProgramObject(
|
||||
ProgramName,
|
||||
[](ghoul::opengl::ProgramObject* p) {
|
||||
OsEng.renderEngine().removeRenderProgram(p);
|
||||
}
|
||||
);
|
||||
_shader = nullptr;
|
||||
}
|
||||
|
||||
void RenderableSphere::render(const RenderData& data, RendererTasks&) {
|
||||
@@ -275,7 +285,7 @@ void RenderableSphere::render(const RenderData& data, RendererTasks&) {
|
||||
_shader->setUniform(_uniformCache.viewProjection, data.camera.viewProjectionMatrix());
|
||||
_shader->setUniform(_uniformCache.modelTransform, transform);
|
||||
|
||||
setPscUniforms(*_shader.get(), data.camera, data.position);
|
||||
setPscUniforms(*_shader, data.camera, data.position);
|
||||
|
||||
float adjustedTransparency = _opacity;
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ private:
|
||||
float _fadeOutThreshold;
|
||||
float _fadeInThreshold;
|
||||
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _shader;
|
||||
ghoul::opengl::ProgramObject* _shader;
|
||||
std::unique_ptr<ghoul::opengl::Texture> _texture;
|
||||
|
||||
std::unique_ptr<PowerScaledSphere> _sphere;
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
#include <modules/base/rendering/renderablesphericalgrid.h>
|
||||
|
||||
#include <modules/base/basemodule.h>
|
||||
#include <openspace/engine/configurationmanager.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
@@ -36,6 +37,8 @@
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
|
||||
namespace {
|
||||
constexpr const char* ProgramName = "GridProgram";
|
||||
|
||||
static const openspace::properties::Property::PropertyInfo GridColorInfo = {
|
||||
"GridColor",
|
||||
"Grid Color",
|
||||
@@ -182,10 +185,15 @@ bool RenderableSphericalGrid::isReady() const {
|
||||
}
|
||||
|
||||
void RenderableSphericalGrid::initializeGL() {
|
||||
_gridProgram = OsEng.renderEngine().buildRenderProgram(
|
||||
"GridProgram",
|
||||
absPath("${MODULE_BASE}/shaders/grid_vs.glsl"),
|
||||
absPath("${MODULE_BASE}/shaders/grid_fs.glsl")
|
||||
_gridProgram = BaseModule::ProgramObjectManager.requestProgramObject(
|
||||
ProgramName,
|
||||
[]() -> std::unique_ptr<ghoul::opengl::ProgramObject> {
|
||||
return OsEng.renderEngine().buildRenderProgram(
|
||||
ProgramName,
|
||||
absPath("${MODULE_BASE}/shaders/grid_vs.glsl"),
|
||||
absPath("${MODULE_BASE}/shaders/grid_fs.glsl")
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
glGenVertexArrays(1, &_vaoID);
|
||||
@@ -208,6 +216,14 @@ void RenderableSphericalGrid::deinitializeGL() {
|
||||
|
||||
glDeleteBuffers(1, &_iBufferID);
|
||||
_iBufferID = 0;
|
||||
|
||||
BaseModule::ProgramObjectManager.releaseProgramObject(
|
||||
ProgramName,
|
||||
[](ghoul::opengl::ProgramObject* p) {
|
||||
OsEng.renderEngine().removeRenderProgram(p);
|
||||
}
|
||||
);
|
||||
_gridProgram = nullptr;
|
||||
}
|
||||
|
||||
void RenderableSphericalGrid::render(const RenderData& data, RendererTasks&){
|
||||
|
||||
@@ -63,7 +63,7 @@ protected:
|
||||
float location[3];
|
||||
};
|
||||
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _gridProgram;
|
||||
ghoul::opengl::ProgramObject* _gridProgram;
|
||||
|
||||
properties::DMat4Property _gridMatrix;
|
||||
properties::Vec4Property _gridColor;
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
#include <modules/base/rendering/renderabletrail.h>
|
||||
|
||||
#include <modules/base/basemodule.h>
|
||||
#include <openspace/documentation/documentation.h>
|
||||
#include <openspace/documentation/verifier.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
@@ -35,7 +36,8 @@
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
|
||||
namespace {
|
||||
const char* KeyTranslation = "Translation";
|
||||
constexpr const char* ProgramName = "EphemerisProgram";
|
||||
constexpr const char* KeyTranslation = "Translation";
|
||||
|
||||
// The possible values for the _renderingModes property
|
||||
enum RenderingMode {
|
||||
@@ -222,11 +224,15 @@ RenderableTrail::RenderableTrail(const ghoul::Dictionary& dictionary)
|
||||
}
|
||||
|
||||
void RenderableTrail::initializeGL() {
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
_programObject = renderEngine.buildRenderProgram(
|
||||
"EphemerisProgram",
|
||||
absPath("${MODULE_BASE}/shaders/renderabletrail_vs.glsl"),
|
||||
absPath("${MODULE_BASE}/shaders/renderabletrail_fs.glsl")
|
||||
_programObject = BaseModule::ProgramObjectManager.requestProgramObject(
|
||||
ProgramName,
|
||||
[]() -> std::unique_ptr<ghoul::opengl::ProgramObject> {
|
||||
return OsEng.renderEngine().buildRenderProgram(
|
||||
ProgramName,
|
||||
absPath("${MODULE_BASE}/shaders/renderabletrail_vs.glsl"),
|
||||
absPath("${MODULE_BASE}/shaders/renderabletrail_fs.glsl")
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
_uniformCache.opacity = _programObject->uniformLocation("opacity");
|
||||
@@ -246,11 +252,13 @@ void RenderableTrail::initializeGL() {
|
||||
}
|
||||
|
||||
void RenderableTrail::deinitializeGL() {
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
if (_programObject) {
|
||||
renderEngine.removeRenderProgram(_programObject);
|
||||
_programObject = nullptr;
|
||||
}
|
||||
BaseModule::ProgramObjectManager.releaseProgramObject(
|
||||
ProgramName,
|
||||
[](ghoul::opengl::ProgramObject* p) {
|
||||
OsEng.renderEngine().removeRenderProgram(p);
|
||||
}
|
||||
);
|
||||
_programObject = nullptr;
|
||||
}
|
||||
|
||||
bool RenderableTrail::isReady() const {
|
||||
@@ -305,7 +313,7 @@ void RenderableTrail::render(const RenderData& data, RendererTasks&) {
|
||||
glEnable(GL_PROGRAM_POINT_SIZE);
|
||||
}
|
||||
|
||||
auto render = [renderLines, renderPoints, p = _programObject.get(), &data,
|
||||
auto render = [renderLines, renderPoints, p = _programObject, &data,
|
||||
&modelTransform, pointSize = _pointSize.value(), c = _uniformCache]
|
||||
(RenderInformation& info, int nVertices, int offset)
|
||||
{
|
||||
|
||||
@@ -158,7 +158,7 @@ private:
|
||||
properties::OptionProperty _renderingModes;
|
||||
|
||||
/// Program object used to render the data stored in RenderInformation
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _programObject;
|
||||
ghoul::opengl::ProgramObject* _programObject;
|
||||
|
||||
UniformCache(opacity, modelView, projection, color, useLineFade, lineFade,
|
||||
vertexSorting, idOffset, nVertices, stride, pointSize, renderPhase) _uniformCache;
|
||||
|
||||
@@ -213,7 +213,7 @@ void RenderableDebugPlane::deinitializeGL() {
|
||||
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
if (_shader) {
|
||||
renderEngine.removeRenderProgram(_shader);
|
||||
renderEngine.removeRenderProgram(_shader.get());
|
||||
_shader = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +40,8 @@
|
||||
|
||||
namespace openspace {
|
||||
|
||||
ghoul::opengl::ProgramObjectManager DigitalUniverseModule::ProgramObjectManager;
|
||||
|
||||
DigitalUniverseModule::DigitalUniverseModule()
|
||||
: OpenSpaceModule(DigitalUniverseModule::Name)
|
||||
{}
|
||||
@@ -54,6 +56,10 @@ void DigitalUniverseModule::internalInitialize(const ghoul::Dictionary&) {
|
||||
fRenderable->registerClass<RenderableDUMeshes>("RenderableDUMeshes");
|
||||
}
|
||||
|
||||
void DigitalUniverseModule::internalDeinitializeGL() {
|
||||
ProgramObjectManager.releaseAll(ghoul::opengl::ProgramObjectManager::Warnings::Yes);
|
||||
}
|
||||
|
||||
std::vector<documentation::Documentation> DigitalUniverseModule::documentations() const {
|
||||
return {
|
||||
RenderablePoints::Documentation(),
|
||||
|
||||
@@ -27,6 +27,8 @@
|
||||
|
||||
#include <openspace/util/openspacemodule.h>
|
||||
|
||||
#include <ghoul/opengl/programobjectmanager.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class DigitalUniverseModule : public OpenSpaceModule {
|
||||
@@ -37,8 +39,11 @@ public:
|
||||
virtual ~DigitalUniverseModule() = default;
|
||||
std::vector<documentation::Documentation> documentations() const override;
|
||||
|
||||
static ghoul::opengl::ProgramObjectManager ProgramObjectManager;
|
||||
|
||||
protected:
|
||||
void internalInitialize(const ghoul::Dictionary&) override;
|
||||
void internalDeinitializeGL() override;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -24,12 +24,12 @@
|
||||
|
||||
#include <modules/digitaluniverse/rendering/renderablebillboardscloud.h>
|
||||
|
||||
#include <modules/digitaluniverse/digitaluniversemodule.h>
|
||||
#include <openspace/documentation/documentation.h>
|
||||
#include <openspace/documentation/verifier.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
|
||||
#include <ghoul/filesystem/cachemanager.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/misc/templatefactory.h>
|
||||
@@ -39,10 +39,8 @@
|
||||
#include <ghoul/opengl/textureunit.h>
|
||||
#include <ghoul/font/fontmanager.h>
|
||||
#include <ghoul/font/fontrenderer.h>
|
||||
|
||||
#include <glm/gtx/string_cast.hpp>
|
||||
#include <ghoul/glm.h>
|
||||
|
||||
#include <array>
|
||||
#include <fstream>
|
||||
#include <stdint.h>
|
||||
@@ -51,6 +49,9 @@
|
||||
|
||||
namespace {
|
||||
constexpr const char* _loggerCat = "RenderableBillboardsCloud";
|
||||
constexpr const char* ProgramObjectName = "RenderableBillboardsCloud";
|
||||
constexpr const char* RenderToPolygonProgram = "RenderableBillboardsCloud_Polygon";
|
||||
|
||||
constexpr const char* KeyFile = "File";
|
||||
constexpr const char* keyColor = "Color";
|
||||
constexpr const char* keyUnit = "Unit";
|
||||
@@ -391,6 +392,7 @@ RenderableBillboardsCloud::RenderableBillboardsCloud(const ghoul::Dictionary& di
|
||||
, _polygonTexture(nullptr)
|
||||
, _spriteTexture(nullptr)
|
||||
, _program(nullptr)
|
||||
, _renderToPolygonProgram(nullptr)
|
||||
, _font(nullptr)
|
||||
, _speckFile("")
|
||||
, _colorMapFile("")
|
||||
@@ -623,15 +625,32 @@ void RenderableBillboardsCloud::initialize() {
|
||||
}
|
||||
|
||||
void RenderableBillboardsCloud::initializeGL() {
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
|
||||
_program = renderEngine.buildRenderProgram(
|
||||
"RenderableBillboardsCloud",
|
||||
absPath("${MODULE_DIGITALUNIVERSE}/shaders/billboard_vs.glsl"),
|
||||
absPath("${MODULE_DIGITALUNIVERSE}/shaders/billboard_fs.glsl"),
|
||||
absPath("${MODULE_DIGITALUNIVERSE}/shaders/billboard_gs.glsl")
|
||||
_program = DigitalUniverseModule::ProgramObjectManager.requestProgramObject(
|
||||
ProgramObjectName,
|
||||
[]() -> std::unique_ptr<ghoul::opengl::ProgramObject> {
|
||||
return OsEng.renderEngine().buildRenderProgram(
|
||||
ProgramObjectName,
|
||||
absPath("${MODULE_DIGITALUNIVERSE}/shaders/billboard_vs.glsl"),
|
||||
absPath("${MODULE_DIGITALUNIVERSE}/shaders/billboard_fs.glsl"),
|
||||
absPath("${MODULE_DIGITALUNIVERSE}/shaders/billboard_gs.glsl")
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
_renderToPolygonProgram =
|
||||
DigitalUniverseModule::ProgramObjectManager.requestProgramObject(
|
||||
RenderToPolygonProgram,
|
||||
[]() -> std::unique_ptr<ghoul::opengl::ProgramObject> {
|
||||
return ghoul::opengl::ProgramObject::Build(
|
||||
RenderToPolygonProgram,
|
||||
absPath("${MODULE_DIGITALUNIVERSE}/shaders/billboardpolygon_vs.glsl"),
|
||||
absPath("${MODULE_DIGITALUNIVERSE}/shaders/billboardpolygon_fs.glsl"),
|
||||
absPath("${MODULE_DIGITALUNIVERSE}/shaders/billboardpolygon_gs.glsl")
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
_uniformCache.modelViewProjection = _program->uniformLocation(
|
||||
"modelViewProjectionTransform"
|
||||
);
|
||||
@@ -678,11 +697,18 @@ void RenderableBillboardsCloud::deinitializeGL() {
|
||||
glDeleteVertexArrays(1, &_vao);
|
||||
_vao = 0;
|
||||
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
if (_program) {
|
||||
renderEngine.removeRenderProgram(_program);
|
||||
_program = nullptr;
|
||||
}
|
||||
DigitalUniverseModule::ProgramObjectManager.releaseProgramObject(
|
||||
ProgramObjectName,
|
||||
[](ghoul::opengl::ProgramObject* p) {
|
||||
OsEng.renderEngine().removeRenderProgram(p);
|
||||
}
|
||||
);
|
||||
_program = nullptr;
|
||||
|
||||
DigitalUniverseModule::ProgramObjectManager.releaseProgramObject(
|
||||
RenderToPolygonProgram
|
||||
);
|
||||
_renderToPolygonProgram = nullptr;
|
||||
|
||||
if (_hasSpriteTexture) {
|
||||
_spriteTexture = nullptr;
|
||||
@@ -1689,25 +1715,18 @@ void RenderableBillboardsCloud::loadPolygonGeometryForRendering() {
|
||||
}
|
||||
|
||||
void RenderableBillboardsCloud::renderPolygonGeometry(GLuint vao) {
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> program =
|
||||
ghoul::opengl::ProgramObject::Build("RenderableBillboardsCloud_Polygon",
|
||||
absPath("${MODULE_DIGITALUNIVERSE}/shaders/billboardpolygon_vs.glsl"),
|
||||
absPath("${MODULE_DIGITALUNIVERSE}/shaders/billboardpolygon_fs.glsl"),
|
||||
absPath("${MODULE_DIGITALUNIVERSE}/shaders/billboardpolygon_gs.glsl")
|
||||
);
|
||||
|
||||
program->activate();
|
||||
_renderToPolygonProgram->activate();
|
||||
static const float black[] = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
glClearBufferfv(GL_COLOR, 0, black);
|
||||
|
||||
program->setUniform("sides", _polygonSides);
|
||||
program->setUniform("polygonColor", _pointColor);
|
||||
_renderToPolygonProgram->setUniform("sides", _polygonSides);
|
||||
_renderToPolygonProgram->setUniform("polygonColor", _pointColor);
|
||||
|
||||
glBindVertexArray(vao);
|
||||
glDrawArrays(GL_POINTS, 0, 1);
|
||||
glBindVertexArray(0);
|
||||
|
||||
program->deactivate();
|
||||
_renderToPolygonProgram->deactivate();
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -141,7 +141,9 @@ private:
|
||||
std::unique_ptr<ghoul::opengl::Texture> _polygonTexture;
|
||||
std::unique_ptr<ghoul::opengl::Texture> _spriteTexture;
|
||||
std::unique_ptr<ghoul::filesystem::File> _spriteTextureFile;
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _program;
|
||||
ghoul::opengl::ProgramObject* _program;
|
||||
ghoul::opengl::ProgramObject* _renderToPolygonProgram;
|
||||
|
||||
UniformCache(modelViewProjection, cameraPos, cameraLookup,
|
||||
renderOption, centerSceenInWorldPos, minBillboardSize, maxBillboardSize,
|
||||
color, sides, alphaValue, scaleFactor, up, right, fadeInValue, screenSize,
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
#include <modules/digitaluniverse/rendering/renderabledumeshes.h>
|
||||
|
||||
#include <modules/digitaluniverse/digitaluniversemodule.h>
|
||||
#include <openspace/documentation/documentation.h>
|
||||
#include <openspace/documentation/verifier.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
@@ -48,6 +49,8 @@
|
||||
|
||||
namespace {
|
||||
constexpr const char* _loggerCat = "RenderableDUMeshes";
|
||||
constexpr const char* ProgramObjectName = "RenderableDUMeshes";
|
||||
|
||||
constexpr const char* KeyFile = "File";
|
||||
constexpr const char* keyColor = "Color";
|
||||
constexpr const char* keyUnit = "Unit";
|
||||
@@ -398,11 +401,15 @@ bool RenderableDUMeshes::isReady() const {
|
||||
}
|
||||
|
||||
void RenderableDUMeshes::initializeGL() {
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
_program = renderEngine.buildRenderProgram(
|
||||
"RenderableDUMeshes",
|
||||
absPath("${MODULE_DIGITALUNIVERSE}/shaders/dumesh_vs.glsl"),
|
||||
absPath("${MODULE_DIGITALUNIVERSE}/shaders/dumesh_fs.glsl")
|
||||
_program = DigitalUniverseModule::ProgramObjectManager.requestProgramObject(
|
||||
ProgramObjectName,
|
||||
[]() -> std::unique_ptr<ghoul::opengl::ProgramObject> {
|
||||
return OsEng.renderEngine().buildRenderProgram(
|
||||
"RenderableDUMeshes",
|
||||
absPath("${MODULE_DIGITALUNIVERSE}/shaders/dumesh_vs.glsl"),
|
||||
absPath("${MODULE_DIGITALUNIVERSE}/shaders/dumesh_fs.glsl")
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
_uniformCache.modelViewTransform = _program->uniformLocation("modelViewTransform");
|
||||
@@ -439,11 +446,12 @@ void RenderableDUMeshes::deinitializeGL() {
|
||||
}
|
||||
}
|
||||
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
if (_program) {
|
||||
renderEngine.removeRenderProgram(_program);
|
||||
_program = nullptr;
|
||||
}
|
||||
DigitalUniverseModule::ProgramObjectManager.releaseProgramObject(
|
||||
ProgramObjectName,
|
||||
[](ghoul::opengl::ProgramObject* p) {
|
||||
OsEng.renderEngine().removeRenderProgram(p);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void RenderableDUMeshes::renderMeshes(const RenderData&,
|
||||
|
||||
@@ -139,7 +139,7 @@ private:
|
||||
// DEBUG:
|
||||
properties::OptionProperty _renderOption;
|
||||
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _program;
|
||||
ghoul::opengl::ProgramObject* _program;
|
||||
UniformCache(modelViewTransform, projectionTransform, alphaValue,
|
||||
/*scaleFactor,*/ color) _uniformCache;
|
||||
std::shared_ptr<ghoul::fontrendering::Font> _font;
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
#include <modules/digitaluniverse/rendering/renderableplanescloud.h>
|
||||
|
||||
#include <modules/digitaluniverse/digitaluniversemodule.h>
|
||||
#include <openspace/documentation/documentation.h>
|
||||
#include <openspace/documentation/verifier.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
@@ -50,6 +51,9 @@
|
||||
|
||||
namespace {
|
||||
constexpr const char* _loggerCat = "RenderablePlanesCloud";
|
||||
constexpr const char* ProgramObjectName = "RenderablePlanesCloud";
|
||||
|
||||
|
||||
constexpr const char* KeyFile = "File";
|
||||
constexpr const char* keyUnit = "Unit";
|
||||
constexpr const char* MeterUnit = "m";
|
||||
@@ -517,12 +521,15 @@ void RenderablePlanesCloud::initialize() {
|
||||
}
|
||||
|
||||
void RenderablePlanesCloud::initializeGL() {
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
|
||||
_program = renderEngine.buildRenderProgram(
|
||||
"RenderablePlanesCloud",
|
||||
absPath("${MODULE_DIGITALUNIVERSE}/shaders/plane_vs.glsl"),
|
||||
absPath("${MODULE_DIGITALUNIVERSE}/shaders/plane_fs.glsl")
|
||||
_program = DigitalUniverseModule::ProgramObjectManager.requestProgramObject(
|
||||
ProgramObjectName,
|
||||
[]() -> std::unique_ptr<ghoul::opengl::ProgramObject> {
|
||||
return OsEng.renderEngine().buildRenderProgram(
|
||||
"RenderablePlanesCloud",
|
||||
absPath("${MODULE_DIGITALUNIVERSE}/shaders/plane_vs.glsl"),
|
||||
absPath("${MODULE_DIGITALUNIVERSE}/shaders/plane_fs.glsl")
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
_uniformCache.modelViewProjectionTransform = _program->uniformLocation(
|
||||
@@ -560,11 +567,12 @@ void RenderablePlanesCloud::deleteDataGPU() {
|
||||
void RenderablePlanesCloud::deinitializeGL() {
|
||||
deleteDataGPU();
|
||||
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
if (_program) {
|
||||
renderEngine.removeRenderProgram(_program);
|
||||
_program = nullptr;
|
||||
}
|
||||
DigitalUniverseModule::ProgramObjectManager.releaseProgramObject(
|
||||
ProgramObjectName,
|
||||
[](ghoul::opengl::ProgramObject* p) {
|
||||
OsEng.renderEngine().removeRenderProgram(p);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void RenderablePlanesCloud::renderPlanes(const RenderData&,
|
||||
|
||||
@@ -50,112 +50,113 @@ namespace ghoul::opengl {
|
||||
} // namespace ghoul::opengl
|
||||
|
||||
namespace openspace {
|
||||
// (x, y, z, w, s, t) * 6 = 36
|
||||
const int PLANES_VERTEX_DATA_SIZE = 36;
|
||||
|
||||
namespace documentation { struct Documentation; }
|
||||
// (x, y, z, w, s, t) * 6 = 36
|
||||
const int PLANES_VERTEX_DATA_SIZE = 36;
|
||||
|
||||
class RenderablePlanesCloud : public Renderable {
|
||||
public:
|
||||
explicit RenderablePlanesCloud(const ghoul::Dictionary& dictionary);
|
||||
~RenderablePlanesCloud() = default;
|
||||
namespace documentation { struct Documentation; }
|
||||
|
||||
void initialize() override;
|
||||
void initializeGL() override;
|
||||
void deinitializeGL() override;
|
||||
class RenderablePlanesCloud : public Renderable {
|
||||
public:
|
||||
explicit RenderablePlanesCloud(const ghoul::Dictionary& dictionary);
|
||||
~RenderablePlanesCloud() = default;
|
||||
|
||||
bool isReady() const override;
|
||||
void initialize() override;
|
||||
void initializeGL() override;
|
||||
void deinitializeGL() override;
|
||||
|
||||
void render(const RenderData& data, RendererTasks& rendererTask) override;
|
||||
void update(const UpdateData& data) override;
|
||||
bool isReady() const override;
|
||||
|
||||
static documentation::Documentation Documentation();
|
||||
void render(const RenderData& data, RendererTasks& rendererTask) override;
|
||||
void update(const UpdateData& data) override;
|
||||
|
||||
private:
|
||||
enum Unit {
|
||||
Meter = 0,
|
||||
Kilometer = 1,
|
||||
Parsec = 2,
|
||||
Kiloparsec = 3,
|
||||
Megaparsec = 4,
|
||||
Gigaparsec = 5,
|
||||
static documentation::Documentation Documentation();
|
||||
|
||||
GigalightYears = 6
|
||||
};
|
||||
private:
|
||||
enum Unit {
|
||||
Meter = 0,
|
||||
Kilometer = 1,
|
||||
Parsec = 2,
|
||||
Kiloparsec = 3,
|
||||
Megaparsec = 4,
|
||||
Gigaparsec = 5,
|
||||
|
||||
struct RenderingPlane {
|
||||
int planeIndex;
|
||||
GLuint vao;
|
||||
GLuint vbo;
|
||||
GLfloat vertexData[PLANES_VERTEX_DATA_SIZE];
|
||||
};
|
||||
|
||||
void deleteDataGPU();
|
||||
void createPlanes();
|
||||
void renderPlanes(const RenderData& data, const glm::dmat4& modelViewMatrix,
|
||||
const glm::dmat4& projectionMatrix, float fadeInVariable);
|
||||
void renderLabels(const RenderData& data,
|
||||
const glm::dmat4& modelViewProjectionMatrix, const glm::dvec3& orthoRight,
|
||||
const glm::dvec3& orthoUp, float fadeInVarible);
|
||||
|
||||
bool loadData();
|
||||
bool loadTextures();
|
||||
bool readSpeckFile();
|
||||
bool readLabelFile();
|
||||
bool loadCachedFile(const std::string& file);
|
||||
bool saveCachedFile(const std::string& file) const;
|
||||
|
||||
bool _hasSpeckFile;
|
||||
bool _dataIsDirty;
|
||||
bool _textColorIsDirty;
|
||||
bool _hasLabel;
|
||||
bool _labelDataIsDirty;
|
||||
|
||||
int _textMinSize;
|
||||
int _textMaxSize;
|
||||
int _planeStartingIndexPos;
|
||||
int _textureVariableIndex;
|
||||
|
||||
properties::FloatProperty _alphaValue;
|
||||
properties::FloatProperty _scaleFactor;
|
||||
properties::Vec4Property _textColor;
|
||||
properties::FloatProperty _textSize;
|
||||
properties::BoolProperty _drawElements;
|
||||
properties::OptionProperty _blendMode;
|
||||
properties::Vec2Property _fadeInDistance;
|
||||
properties::BoolProperty _disableFadeInDistance;
|
||||
properties::FloatProperty _planeMinSize;
|
||||
|
||||
// DEBUG:
|
||||
properties::OptionProperty _renderOption;
|
||||
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _program;
|
||||
UniformCache(modelViewProjectionTransform, alphaValue, scaleFactor, fadeInValue,
|
||||
galaxyTexture) _uniformCache;
|
||||
std::shared_ptr<ghoul::fontrendering::Font> _font;
|
||||
std::unordered_map<int, std::unique_ptr<ghoul::opengl::Texture>> _textureMap;
|
||||
std::unordered_map<int, std::string> _textureFileMap;
|
||||
|
||||
std::string _speckFile;
|
||||
std::string _labelFile;
|
||||
std::string _texturesPath;
|
||||
std::string _luminosityVar;
|
||||
|
||||
Unit _unit;
|
||||
|
||||
std::vector<float> _fullData;
|
||||
std::vector<std::pair<glm::vec3, std::string>> _labelData;
|
||||
std::unordered_map<std::string, int> _variableDataPositionMap;
|
||||
|
||||
int _nValuesPerAstronomicalObject;
|
||||
|
||||
float _sluminosity;
|
||||
|
||||
glm::dmat4 _transformationMatrix;
|
||||
|
||||
std::vector<RenderingPlane> _renderingPlanesArray;
|
||||
GigalightYears = 6
|
||||
};
|
||||
|
||||
struct RenderingPlane {
|
||||
int planeIndex;
|
||||
GLuint vao;
|
||||
GLuint vbo;
|
||||
GLfloat vertexData[PLANES_VERTEX_DATA_SIZE];
|
||||
};
|
||||
|
||||
void deleteDataGPU();
|
||||
void createPlanes();
|
||||
void renderPlanes(const RenderData& data, const glm::dmat4& modelViewMatrix,
|
||||
const glm::dmat4& projectionMatrix, float fadeInVariable);
|
||||
void renderLabels(const RenderData& data,
|
||||
const glm::dmat4& modelViewProjectionMatrix, const glm::dvec3& orthoRight,
|
||||
const glm::dvec3& orthoUp, float fadeInVarible);
|
||||
|
||||
bool loadData();
|
||||
bool loadTextures();
|
||||
bool readSpeckFile();
|
||||
bool readLabelFile();
|
||||
bool loadCachedFile(const std::string& file);
|
||||
bool saveCachedFile(const std::string& file) const;
|
||||
|
||||
bool _hasSpeckFile;
|
||||
bool _dataIsDirty;
|
||||
bool _textColorIsDirty;
|
||||
bool _hasLabel;
|
||||
bool _labelDataIsDirty;
|
||||
|
||||
int _textMinSize;
|
||||
int _textMaxSize;
|
||||
int _planeStartingIndexPos;
|
||||
int _textureVariableIndex;
|
||||
|
||||
properties::FloatProperty _alphaValue;
|
||||
properties::FloatProperty _scaleFactor;
|
||||
properties::Vec4Property _textColor;
|
||||
properties::FloatProperty _textSize;
|
||||
properties::BoolProperty _drawElements;
|
||||
properties::OptionProperty _blendMode;
|
||||
properties::Vec2Property _fadeInDistance;
|
||||
properties::BoolProperty _disableFadeInDistance;
|
||||
properties::FloatProperty _planeMinSize;
|
||||
|
||||
// DEBUG:
|
||||
properties::OptionProperty _renderOption;
|
||||
|
||||
ghoul::opengl::ProgramObject* _program;
|
||||
UniformCache(modelViewProjectionTransform, alphaValue, scaleFactor, fadeInValue,
|
||||
galaxyTexture) _uniformCache;
|
||||
std::shared_ptr<ghoul::fontrendering::Font> _font;
|
||||
std::unordered_map<int, std::unique_ptr<ghoul::opengl::Texture>> _textureMap;
|
||||
std::unordered_map<int, std::string> _textureFileMap;
|
||||
|
||||
std::string _speckFile;
|
||||
std::string _labelFile;
|
||||
std::string _texturesPath;
|
||||
std::string _luminosityVar;
|
||||
|
||||
Unit _unit;
|
||||
|
||||
std::vector<float> _fullData;
|
||||
std::vector<std::pair<glm::vec3, std::string>> _labelData;
|
||||
std::unordered_map<std::string, int> _variableDataPositionMap;
|
||||
|
||||
int _nValuesPerAstronomicalObject;
|
||||
|
||||
float _sluminosity;
|
||||
|
||||
glm::dmat4 _transformationMatrix;
|
||||
|
||||
std::vector<RenderingPlane> _renderingPlanesArray;
|
||||
};
|
||||
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
|
||||
@@ -24,12 +24,12 @@
|
||||
|
||||
#include <modules/digitaluniverse/rendering/renderablepoints.h>
|
||||
|
||||
#include <modules/digitaluniverse/digitaluniversemodule.h>
|
||||
#include <openspace/documentation/documentation.h>
|
||||
#include <openspace/documentation/verifier.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
|
||||
#include <ghoul/filesystem/cachemanager.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/misc/templatefactory.h>
|
||||
@@ -37,7 +37,6 @@
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
#include <ghoul/opengl/textureunit.h>
|
||||
|
||||
#include <array>
|
||||
#include <fstream>
|
||||
#include <stdint.h>
|
||||
@@ -46,6 +45,7 @@
|
||||
|
||||
namespace {
|
||||
constexpr const char* _loggerCat = "RenderablePoints";
|
||||
|
||||
constexpr const char* KeyFile = "File";
|
||||
constexpr const char* keyColor = "Color";
|
||||
constexpr const char* keyUnit = "Unit";
|
||||
@@ -267,12 +267,21 @@ void RenderablePoints::initialize() {
|
||||
}
|
||||
|
||||
void RenderablePoints::initializeGL() {
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
// OBS: The ProgramObject name is later used to release the program as well, so the
|
||||
// name parameter to requestProgramObject and the first parameter to
|
||||
// buildRenderProgram has to be the same or an assertion will be thrown at the
|
||||
// end of the program.
|
||||
|
||||
if (_hasSpriteTexture) {
|
||||
_program = renderEngine.buildRenderProgram(
|
||||
"RenderablePoints",
|
||||
absPath("${MODULE_DIGITALUNIVERSE}/shaders/points_vs.glsl"),
|
||||
absPath("${MODULE_DIGITALUNIVERSE}/shaders/points_sprite_fs.glsl")
|
||||
_program = DigitalUniverseModule::ProgramObjectManager.requestProgramObject(
|
||||
"RenderablePoints Sprite",
|
||||
[]() -> std::unique_ptr<ghoul::opengl::ProgramObject> {
|
||||
return OsEng.renderEngine().buildRenderProgram(
|
||||
"RenderablePoints Sprite",
|
||||
absPath("${MODULE_DIGITALUNIVERSE}/shaders/points_vs.glsl"),
|
||||
absPath("${MODULE_DIGITALUNIVERSE}/shaders/points_sprite_fs.glsl")
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
_uniformCache.modelViewProjectionTransform = _program->uniformLocation(
|
||||
@@ -286,10 +295,15 @@ void RenderablePoints::initializeGL() {
|
||||
_uniformCache.hasColorMap = _program->uniformLocation("hasColorMap");
|
||||
}
|
||||
else {
|
||||
_program = renderEngine.buildRenderProgram(
|
||||
_program = DigitalUniverseModule::ProgramObjectManager.requestProgramObject(
|
||||
"RenderablePoints",
|
||||
absPath("${MODULE_DIGITALUNIVERSE}/shaders/points_vs.glsl"),
|
||||
absPath("${MODULE_DIGITALUNIVERSE}/shaders/points_fs.glsl")
|
||||
[]() -> std::unique_ptr<ghoul::opengl::ProgramObject> {
|
||||
return OsEng.renderEngine().buildRenderProgram(
|
||||
"RenderablePoints",
|
||||
absPath("${MODULE_DIGITALUNIVERSE}/shaders/points_vs.glsl"),
|
||||
absPath("${MODULE_DIGITALUNIVERSE}/shaders/points_sprite_fs.glsl")
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
_uniformCache.modelViewProjectionTransform = _program->uniformLocation(
|
||||
@@ -309,11 +323,13 @@ void RenderablePoints::deinitializeGL() {
|
||||
glDeleteVertexArrays(1, &_vao);
|
||||
_vao = 0;
|
||||
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
if (_program) {
|
||||
renderEngine.removeRenderProgram(_program);
|
||||
_program = nullptr;
|
||||
}
|
||||
|
||||
DigitalUniverseModule::ProgramObjectManager.releaseProgramObject(
|
||||
_program->name(),
|
||||
[](ghoul::opengl::ProgramObject* p) {
|
||||
OsEng.renderEngine().removeRenderProgram(p);
|
||||
}
|
||||
);
|
||||
|
||||
if (_hasSpriteTexture) {
|
||||
_spriteTexture = nullptr;
|
||||
|
||||
@@ -98,7 +98,7 @@ namespace openspace {
|
||||
|
||||
std::unique_ptr<ghoul::opengl::Texture> _spriteTexture;
|
||||
std::unique_ptr<ghoul::filesystem::File> _spriteTextureFile;
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _program;
|
||||
ghoul::opengl::ProgramObject* _program;
|
||||
UniformCache(modelViewProjectionTransform, color, sides, alphaValue, scaleFactor,
|
||||
spriteTexture, hasColorMap) _uniformCache;
|
||||
|
||||
|
||||
@@ -248,7 +248,7 @@ void RenderableFieldlines::deinitializeGL() {
|
||||
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
if (_program) {
|
||||
renderEngine.removeRenderProgram(_program);
|
||||
renderEngine.removeRenderProgram(_program.get());
|
||||
_program = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1003,7 +1003,7 @@ void RenderableFieldlinesSequence::deinitializeGL() {
|
||||
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
if (_shaderProgram) {
|
||||
renderEngine.removeRenderProgram(_shaderProgram);
|
||||
renderEngine.removeRenderProgram(_shaderProgram.get());
|
||||
_shaderProgram = nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -144,7 +144,7 @@ LayerShaderManager::LayerShaderManager(const std::string& shaderName,
|
||||
LayerShaderManager::~LayerShaderManager() {
|
||||
if (_programObject) {
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
renderEngine.removeRenderProgram(_programObject);
|
||||
renderEngine.removeRenderProgram(_programObject.get());
|
||||
_programObject = nullptr;
|
||||
}
|
||||
}
|
||||
@@ -230,7 +230,7 @@ void LayerShaderManager::recompileShaderProgram(
|
||||
}
|
||||
|
||||
// Remove old program
|
||||
OsEng.renderEngine().removeRenderProgram(_programObject);
|
||||
OsEng.renderEngine().removeRenderProgram(_programObject.get());
|
||||
|
||||
_programObject = OsEng.renderEngine().buildRenderProgram(
|
||||
_shaderName,
|
||||
|
||||
@@ -241,7 +241,7 @@ void IswaCygnet::update(const UpdateData&) {
|
||||
bool IswaCygnet::destroyShader() {
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
if (_shader) {
|
||||
renderEngine.removeRenderProgram(_shader);
|
||||
renderEngine.removeRenderProgram(_shader.get());
|
||||
_shader = nullptr;
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -228,7 +228,7 @@ void RenderableConstellationBounds::deinitializeGL() {
|
||||
_vao = 0;
|
||||
|
||||
if (_program) {
|
||||
OsEng.renderEngine().removeRenderProgram(_program);
|
||||
OsEng.renderEngine().removeRenderProgram(_program.get());
|
||||
_program = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,24 +24,22 @@
|
||||
|
||||
#include <modules/space/rendering/renderableplanet.h>
|
||||
|
||||
#include <modules/space/spacemodule.h>
|
||||
#include <modules/space/rendering/planetgeometry.h>
|
||||
#include <openspace/documentation/documentation.h>
|
||||
#include <openspace/documentation/verifier.h>
|
||||
|
||||
#include <modules/space/rendering/planetgeometry.h>
|
||||
#include <openspace/util/time.h>
|
||||
#include <openspace/util/spicemanager.h>
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
#include <openspace/util/time.h>
|
||||
#include <openspace/util/spicemanager.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/misc/assert.h>
|
||||
#include <ghoul/io/texture/texturereader.h>
|
||||
#include <ghoul/misc/assert.h>
|
||||
#include <ghoul/misc/invariants.h>
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
#include <ghoul/opengl/textureunit.h>
|
||||
#include <ghoul/misc/invariants.h>
|
||||
|
||||
#include <memory>
|
||||
#include <fstream>
|
||||
|
||||
@@ -51,6 +49,11 @@
|
||||
#include <math.h>
|
||||
|
||||
namespace {
|
||||
constexpr const char* PlainProgramName = "PlanetProgram";
|
||||
constexpr const char* ShadowNightProgramName = "ShadowNightPlanetProgram";
|
||||
constexpr const char* NightProgramName = "NightPlanetProgram";
|
||||
constexpr const char* ShadowProgramName = "ShadowPlanetProgram";
|
||||
|
||||
constexpr const char* KeyBody = "Body";
|
||||
constexpr const char* KeyGeometry = "Geometry";
|
||||
constexpr const char* KeyRadius = "Radius";
|
||||
@@ -352,38 +355,57 @@ RenderablePlanet::RenderablePlanet(const ghoul::Dictionary& dictionary)
|
||||
}
|
||||
|
||||
void RenderablePlanet::initializeGL() {
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
// @FRAGILE: The shader deinitialization below relies on the name names for the
|
||||
// request and the parameters to buildRenderProgram. That way, we can use
|
||||
// the ProgramObject name in the releaseProgramObject method and release the
|
||||
// correct one.
|
||||
|
||||
if (_programObject == nullptr && _shadowEnabled && _hasNightTexture) {
|
||||
// shadow program
|
||||
_programObject = renderEngine.buildRenderProgram(
|
||||
"shadowNightProgram",
|
||||
absPath("${MODULE_SPACE}/shaders/shadow_nighttexture_vs.glsl"),
|
||||
absPath("${MODULE_SPACE}/shaders/shadow_nighttexture_fs.glsl")
|
||||
_programObject = SpaceModule::ProgramObjectManager.requestProgramObject(
|
||||
ShadowNightProgramName,
|
||||
[]() -> std::unique_ptr<ghoul::opengl::ProgramObject> {
|
||||
return OsEng.renderEngine().buildRenderProgram(
|
||||
ShadowNightProgramName,
|
||||
absPath("${MODULE_SPACE}/shaders/shadow_nighttexture_vs.glsl"),
|
||||
absPath("${MODULE_SPACE}/shaders/shadow_nighttexture_fs.glsl")
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
else if (_programObject == nullptr && _shadowEnabled) {
|
||||
// shadow program
|
||||
_programObject = renderEngine.buildRenderProgram(
|
||||
"shadowProgram",
|
||||
absPath("${MODULE_SPACE}/shaders/shadow_vs.glsl"),
|
||||
absPath("${MODULE_SPACE}/shaders/shadow_fs.glsl")
|
||||
_programObject = SpaceModule::ProgramObjectManager.requestProgramObject(
|
||||
ShadowProgramName,
|
||||
[]() -> std::unique_ptr<ghoul::opengl::ProgramObject> {
|
||||
return OsEng.renderEngine().buildRenderProgram(
|
||||
ShadowProgramName,
|
||||
absPath("${MODULE_SPACE}/shaders/shadow_vs.glsl"),
|
||||
absPath("${MODULE_SPACE}/shaders/shadow_fs.glsl")
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
else if (_programObject == nullptr && _hasNightTexture) {
|
||||
// Night texture program
|
||||
_programObject = renderEngine.buildRenderProgram(
|
||||
"nightTextureProgram",
|
||||
absPath("${MODULE_SPACE}/shaders/nighttexture_vs.glsl"),
|
||||
absPath("${MODULE_SPACE}/shaders/nighttexture_fs.glsl")
|
||||
_programObject = SpaceModule::ProgramObjectManager.requestProgramObject(
|
||||
NightProgramName,
|
||||
[]() -> std::unique_ptr<ghoul::opengl::ProgramObject> {
|
||||
return OsEng.renderEngine().buildRenderProgram(
|
||||
NightProgramName,
|
||||
absPath("${MODULE_SPACE}/shaders/nighttexture_vs.glsl"),
|
||||
absPath("${MODULE_SPACE}/shaders/nighttexture_fs.glsl")
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
else if (_programObject == nullptr) {
|
||||
// pscstandard
|
||||
_programObject = renderEngine.buildRenderProgram(
|
||||
"pscstandard",
|
||||
absPath("${MODULE_SPACE}/shaders/renderableplanet_vs.glsl"),
|
||||
absPath("${MODULE_SPACE}/shaders/renderableplanet_fs.glsl")
|
||||
_programObject = SpaceModule::ProgramObjectManager.requestProgramObject(
|
||||
PlainProgramName,
|
||||
[]() -> std::unique_ptr<ghoul::opengl::ProgramObject> {
|
||||
return OsEng.renderEngine().buildRenderProgram(
|
||||
PlainProgramName,
|
||||
absPath("${MODULE_SPACE}/shaders/renderableplanet_vs.glsl"),
|
||||
absPath("${MODULE_SPACE}/shaders/renderableplanet_fs.glsl")
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -405,11 +427,12 @@ void RenderablePlanet::deinitializeGL() {
|
||||
_geometry = nullptr;
|
||||
}
|
||||
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
if (_programObject) {
|
||||
renderEngine.removeRenderProgram(_programObject);
|
||||
_programObject = nullptr;
|
||||
}
|
||||
SpaceModule::ProgramObjectManager.releaseProgramObject(
|
||||
_programObject->name(),
|
||||
[](ghoul::opengl::ProgramObject* p) {
|
||||
OsEng.renderEngine().removeRenderProgram(p);
|
||||
}
|
||||
);
|
||||
|
||||
_geometry = nullptr;
|
||||
_texture = nullptr;
|
||||
@@ -482,7 +505,7 @@ void RenderablePlanet::render(const RenderData& data, RendererTasks&) {
|
||||
// glm::mat4 ModelViewTrans = data.camera.viewMatrix() * scaleCamTrans *
|
||||
// translateCamTrans * translateObjTrans * glm::mat4(modelTransform);
|
||||
|
||||
setPscUniforms(*_programObject.get(), data.camera, data.position);
|
||||
setPscUniforms(*_programObject, data.camera, data.position);
|
||||
|
||||
_programObject->setUniform("_performShading", _performShading);
|
||||
_programObject->setUniform("_hasHeightMap", _hasHeightTexture);
|
||||
|
||||
@@ -94,7 +94,7 @@ private:
|
||||
properties::StringProperty _nightTexturePath;
|
||||
properties::StringProperty _heightMapTexturePath;
|
||||
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _programObject;
|
||||
ghoul::opengl::ProgramObject* _programObject;
|
||||
|
||||
std::unique_ptr<ghoul::opengl::Texture> _texture;
|
||||
std::unique_ptr<ghoul::opengl::Texture> _nightTexture;
|
||||
|
||||
@@ -216,7 +216,7 @@ void RenderableRings::deinitializeGL() {
|
||||
_textureFile = nullptr;
|
||||
_texture = nullptr;
|
||||
|
||||
OsEng.renderEngine().removeRenderProgram(_shader);
|
||||
OsEng.renderEngine().removeRenderProgram(_shader.get());
|
||||
_shader = nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -323,7 +323,7 @@ void RenderableStars::deinitializeGL() {
|
||||
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
if (_program) {
|
||||
renderEngine.removeRenderProgram(_program);
|
||||
renderEngine.removeRenderProgram(_program.get());
|
||||
_program = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +45,8 @@
|
||||
|
||||
namespace openspace {
|
||||
|
||||
ghoul::opengl::ProgramObjectManager SpaceModule::ProgramObjectManager;
|
||||
|
||||
SpaceModule::SpaceModule() : OpenSpaceModule(Name) {}
|
||||
|
||||
void SpaceModule::internalInitialize(const ghoul::Dictionary&) {
|
||||
@@ -80,6 +82,10 @@ void SpaceModule::internalInitialize(const ghoul::Dictionary&) {
|
||||
fGeometry->registerClass<planetgeometry::SimpleSphereGeometry>("SimpleSphere");
|
||||
}
|
||||
|
||||
void SpaceModule::internalDeinitializeGL() {
|
||||
ProgramObjectManager.releaseAll(ghoul::opengl::ProgramObjectManager::Warnings::Yes);
|
||||
}
|
||||
|
||||
std::vector<documentation::Documentation> SpaceModule::documentations() const {
|
||||
return {
|
||||
RenderableConstellationBounds::Documentation(),
|
||||
|
||||
@@ -27,6 +27,8 @@
|
||||
|
||||
#include <openspace/util/openspacemodule.h>
|
||||
|
||||
#include <ghoul/opengl/programobjectmanager.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class SpaceModule : public OpenSpaceModule {
|
||||
@@ -37,8 +39,11 @@ public:
|
||||
virtual ~SpaceModule() = default;
|
||||
std::vector<documentation::Documentation> documentations() const override;
|
||||
|
||||
static ghoul::opengl::ProgramObjectManager ProgramObjectManager;
|
||||
|
||||
private:
|
||||
void internalInitialize(const ghoul::Dictionary&) override;
|
||||
void internalDeinitializeGL() override;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -175,7 +175,7 @@ void RenderableCrawlingLine::deinitializeGL() {
|
||||
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
if (_program) {
|
||||
renderEngine.removeRenderProgram(_program);
|
||||
renderEngine.removeRenderProgram(_program.get());
|
||||
_program = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,24 +24,23 @@
|
||||
|
||||
#include <modules/spacecraftinstruments/rendering/renderablefov.h>
|
||||
|
||||
#include <modules/spacecraftinstruments/spacecraftinstrumentsmodule.h>
|
||||
#include <modules/spacecraftinstruments/util/imagesequencer.h>
|
||||
|
||||
#include <openspace/documentation/documentation.h>
|
||||
#include <openspace/documentation/verifier.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
#include <ghoul/misc/defer.h>
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
|
||||
#include <glm/gtx/projection.hpp>
|
||||
|
||||
#include <openspace/performance/performancemeasurement.h>
|
||||
|
||||
namespace {
|
||||
constexpr const char* ProgramName = "FovProgram";
|
||||
constexpr const char* KeyBody = "Body";
|
||||
constexpr const char* KeyFrame = "Frame";
|
||||
// const char* KeyColor = "RGB";
|
||||
@@ -317,12 +316,17 @@ RenderableFov::RenderableFov(const ghoul::Dictionary& dictionary)
|
||||
}
|
||||
|
||||
void RenderableFov::initializeGL() {
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
_programObject = renderEngine.buildRenderProgram(
|
||||
"FovProgram",
|
||||
absPath("${MODULE_SPACECRAFTINSTRUMENTS}/shaders/fov_vs.glsl"),
|
||||
absPath("${MODULE_SPACECRAFTINSTRUMENTS}/shaders/fov_fs.glsl")
|
||||
);
|
||||
_programObject =
|
||||
SpacecraftInstrumentsModule::ProgramObjectManager.requestProgramObject(
|
||||
ProgramName,
|
||||
[]() -> std::unique_ptr<ghoul::opengl::ProgramObject> {
|
||||
return OsEng.renderEngine().buildRenderProgram(
|
||||
ProgramName,
|
||||
absPath("${MODULE_SPACECRAFTINSTRUMENTS}/shaders/fov_vs.glsl"),
|
||||
absPath("${MODULE_SPACECRAFTINSTRUMENTS}/shaders/fov_fs.glsl")
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
_uniformCache.modelViewProjection = _programObject->uniformLocation(
|
||||
"modelViewProjectionTransform"
|
||||
@@ -481,7 +485,12 @@ void RenderableFov::initializeGL() {
|
||||
}
|
||||
|
||||
void RenderableFov::deinitializeGL() {
|
||||
OsEng.renderEngine().removeRenderProgram(_programObject);
|
||||
SpacecraftInstrumentsModule::ProgramObjectManager.releaseProgramObject(
|
||||
ProgramName,
|
||||
[](ghoul::opengl::ProgramObject* p) {
|
||||
OsEng.renderEngine().removeRenderProgram(p);
|
||||
}
|
||||
);
|
||||
_programObject = nullptr;
|
||||
|
||||
glDeleteBuffers(1, &_orthogonalPlane.vbo);
|
||||
|
||||
@@ -92,7 +92,7 @@ private:
|
||||
properties::FloatProperty _lineWidth;
|
||||
properties::BoolProperty _drawSolid;
|
||||
properties::DoubleProperty _standOffDistance;
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _programObject;
|
||||
ghoul::opengl::ProgramObject* _programObject;
|
||||
UniformCache(modelViewProjection, defaultColorStart, defaultColorEnd, activeColor,
|
||||
targetInFieldOfViewColor, intersectionStartColor, intersectionEndColor,
|
||||
squareColor, interpolation) _uniformCache;
|
||||
|
||||
@@ -257,7 +257,7 @@ void RenderableModelProjection::deinitializeGL() {
|
||||
|
||||
_projectionComponent.deinitialize();
|
||||
|
||||
OsEng.renderEngine().removeRenderProgram(_programObject);
|
||||
OsEng.renderEngine().removeRenderProgram(_programObject.get());
|
||||
_programObject = nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -111,7 +111,7 @@ void RenderablePlaneProjection::initializeGL() {
|
||||
void RenderablePlaneProjection::deinitializeGL() {
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
if (_shader) {
|
||||
renderEngine.removeRenderProgram(_shader);
|
||||
renderEngine.removeRenderProgram(_shader.get());
|
||||
_shader = nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,35 +24,29 @@
|
||||
|
||||
#include <modules/spacecraftinstruments/rendering/renderableplanetprojection.h>
|
||||
|
||||
#include <modules/spacecraftinstruments/spacecraftinstrumentsmodule.h>
|
||||
#include <modules/space/rendering/planetgeometry.h>
|
||||
|
||||
#include <modules/spacecraftinstruments/util/imagesequencer.h>
|
||||
#include <openspace/documentation/documentation.h>
|
||||
#include <openspace/documentation/verifier.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/properties/triggerproperty.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
#include <openspace/util/factorymanager.h>
|
||||
|
||||
#include <openspace/util/updatestructures.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/io/texture/texturereader.h>
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
#include <ghoul/opengl/textureconversion.h>
|
||||
#include <ghoul/opengl/textureunit.h>
|
||||
|
||||
#include <modules/spacecraftinstruments/util/imagesequencer.h>
|
||||
|
||||
#include <openspace/documentation/documentation.h>
|
||||
#include <openspace/properties/triggerproperty.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
#ifdef WIN32
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
constexpr const char* _loggerCat = "RenderablePlanetProjection";
|
||||
constexpr const char* ProjectiveProgramName = "ProjectiveProgram";
|
||||
constexpr const char* FBOPassProgramName = "FBOPassProgram";
|
||||
|
||||
|
||||
constexpr const char* KeyGeometry = "Geometry";
|
||||
constexpr const char* KeyProjection = "Projection";
|
||||
@@ -327,11 +321,21 @@ RenderablePlanetProjection::RenderablePlanetProjection(const ghoul::Dictionary&
|
||||
RenderablePlanetProjection::~RenderablePlanetProjection() {}
|
||||
|
||||
void RenderablePlanetProjection::initializeGL() {
|
||||
_programObject = OsEng.renderEngine().buildRenderProgram(
|
||||
"projectiveProgram",
|
||||
absPath("${MODULE_SPACECRAFTINSTRUMENTS}/shaders/renderablePlanet_vs.glsl"),
|
||||
absPath("${MODULE_SPACECRAFTINSTRUMENTS}/shaders/renderablePlanet_fs.glsl")
|
||||
);
|
||||
_programObject =
|
||||
SpacecraftInstrumentsModule::ProgramObjectManager.requestProgramObject(
|
||||
ProjectiveProgramName,
|
||||
[]() -> std::unique_ptr<ghoul::opengl::ProgramObject> {
|
||||
return OsEng.renderEngine().buildRenderProgram(
|
||||
ProjectiveProgramName,
|
||||
absPath("${MODULE_SPACECRAFTINSTRUMENTS}/shaders/"
|
||||
"renderablePlanet_vs.glsl"
|
||||
),
|
||||
absPath("${MODULE_SPACECRAFTINSTRUMENTS}/shaders/"
|
||||
"renderablePlanet_fs.glsl"
|
||||
)
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
_mainUniformCache.sunPos = _programObject->uniformLocation("sun_pos");
|
||||
_mainUniformCache.modelTransform = _programObject->uniformLocation("modelTransform");
|
||||
@@ -356,15 +360,23 @@ void RenderablePlanetProjection::initializeGL() {
|
||||
);
|
||||
_mainUniformCache.heightTexture = _programObject->uniformLocation("heightTexture");
|
||||
|
||||
_fboProgramObject = ghoul::opengl::ProgramObject::Build(
|
||||
"fboPassProgram",
|
||||
absPath(
|
||||
"${MODULE_SPACECRAFTINSTRUMENTS}/shaders/renderablePlanetProjection_vs.glsl"
|
||||
),
|
||||
absPath(
|
||||
"${MODULE_SPACECRAFTINSTRUMENTS}/shaders/renderablePlanetProjection_fs.glsl"
|
||||
)
|
||||
);
|
||||
_fboProgramObject =
|
||||
SpacecraftInstrumentsModule::ProgramObjectManager.requestProgramObject(
|
||||
FBOPassProgramName,
|
||||
[]() -> std::unique_ptr<ghoul::opengl::ProgramObject> {
|
||||
return ghoul::opengl::ProgramObject::Build(
|
||||
FBOPassProgramName,
|
||||
absPath(
|
||||
"${MODULE_SPACECRAFTINSTRUMENTS}/shaders/"
|
||||
"renderablePlanetProjection_vs.glsl"
|
||||
),
|
||||
absPath(
|
||||
"${MODULE_SPACECRAFTINSTRUMENTS}/shaders/"
|
||||
"renderablePlanetProjection_fs.glsl"
|
||||
)
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
_fboUniformCache.projectionTexture = _fboProgramObject->uniformLocation(
|
||||
"projectionTexture"
|
||||
@@ -426,9 +438,17 @@ void RenderablePlanetProjection::deinitializeGL() {
|
||||
glDeleteVertexArrays(1, &_quad);
|
||||
glDeleteBuffers(1, &_vertexPositionBuffer);
|
||||
|
||||
OsEng.renderEngine().removeRenderProgram(_programObject);
|
||||
SpacecraftInstrumentsModule::ProgramObjectManager.releaseProgramObject(
|
||||
ProjectiveProgramName,
|
||||
[](ghoul::opengl::ProgramObject* p) {
|
||||
OsEng.renderEngine().removeRenderProgram(p);
|
||||
}
|
||||
);
|
||||
_programObject = nullptr;
|
||||
|
||||
SpacecraftInstrumentsModule::ProgramObjectManager.releaseProgramObject(
|
||||
FBOPassProgramName
|
||||
);
|
||||
_fboProgramObject = nullptr;
|
||||
}
|
||||
|
||||
@@ -487,12 +507,12 @@ void RenderablePlanetProjection::attitudeParameters(double time) {
|
||||
//90 deg rotation w.r.t spice req.
|
||||
glm::mat4 rot = glm::rotate(
|
||||
_transform,
|
||||
static_cast<float>(M_PI_2),
|
||||
glm::half_pi<float>(),
|
||||
glm::vec3(1, 0, 0)
|
||||
);
|
||||
glm::mat4 roty = glm::rotate(
|
||||
_transform,
|
||||
static_cast<float>(M_PI_2),
|
||||
glm::half_pi<float>(),
|
||||
glm::vec3(0, -1, 0)
|
||||
);
|
||||
|
||||
@@ -597,8 +617,16 @@ void RenderablePlanetProjection::render(const RenderData& data, RendererTasks&)
|
||||
// meridian and y completes the right handed coordinate system.
|
||||
// Doing this is part of changing from using the transforms defined by the
|
||||
// scenegraph node (data.modelTransform) to achieve higher precision rendering. //KB
|
||||
glm::dmat4 rot = glm::rotate(glm::dmat4(1.0), M_PI_2, glm::dvec3(1, 0, 0));
|
||||
glm::dmat4 roty = glm::rotate(glm::dmat4(1.0), M_PI_2, glm::dvec3(0, -1, 0));
|
||||
glm::dmat4 rot = glm::rotate(
|
||||
glm::dmat4(1.0),
|
||||
glm::half_pi<double>(),
|
||||
glm::dvec3(1.0, 0.0, 0.0)
|
||||
);
|
||||
glm::dmat4 roty = glm::rotate(
|
||||
glm::dmat4(1.0),
|
||||
glm::half_pi<double>(),
|
||||
glm::dvec3(0.0, -1.0, 0.0)
|
||||
);
|
||||
modelTransform = modelTransform * rot * roty;
|
||||
|
||||
glm::dmat4 modelViewTransform = data.camera.combinedViewMatrix() * modelTransform;
|
||||
|
||||
@@ -76,8 +76,8 @@ private:
|
||||
properties::StringProperty _addHeightMapTexturePath;
|
||||
bool _heightMapTextureDirty;
|
||||
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _programObject;
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _fboProgramObject;
|
||||
ghoul::opengl::ProgramObject* _programObject;
|
||||
ghoul::opengl::ProgramObject* _fboProgramObject;
|
||||
UniformCache(sunPos, modelTransform, modelViewProjectionTransform, hasBaseMap,
|
||||
hasHeightMap, heightExaggeration, meridianShift, ambientBrightness,
|
||||
projectionFading, baseTexture, projectionTexture, heightTexture)
|
||||
|
||||
@@ -24,18 +24,19 @@
|
||||
|
||||
#include <modules/spacecraftinstruments/rendering/renderableshadowcylinder.h>
|
||||
|
||||
#include <modules/spacecraftinstruments/spacecraftinstrumentsmodule.h>
|
||||
#include <openspace/documentation/verifier.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/util/powerscaledcoordinate.h>
|
||||
#include <openspace/util/spicemanager.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
|
||||
namespace {
|
||||
const char* MainFrame = "GALACTIC";
|
||||
constexpr const char* ProgramName = "ShadowCylinderProgram";
|
||||
constexpr const char* MainFrame = "GALACTIC";
|
||||
|
||||
static const openspace::properties::Property::PropertyInfo NumberPointsInfo = {
|
||||
"AmountOfPoints",
|
||||
@@ -265,11 +266,19 @@ void RenderableShadowCylinder::initializeGL() {
|
||||
glGenVertexArrays(1, &_vao);
|
||||
glGenBuffers(1, &_vbo);
|
||||
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
_shader = renderEngine.buildRenderProgram(
|
||||
"ShadowCylinderProgram",
|
||||
absPath("${MODULE_SPACECRAFTINSTRUMENTS}/shaders/terminatorshadow_vs.glsl"),
|
||||
absPath("${MODULE_SPACECRAFTINSTRUMENTS}/shaders/terminatorshadow_fs.glsl")
|
||||
_shader = SpacecraftInstrumentsModule::ProgramObjectManager.requestProgramObject(
|
||||
ProgramName,
|
||||
[]() -> std::unique_ptr<ghoul::opengl::ProgramObject> {
|
||||
return OsEng.renderEngine().buildRenderProgram(
|
||||
ProgramName,
|
||||
absPath(
|
||||
"${MODULE_SPACECRAFTINSTRUMENTS}/shaders/terminatorshadow_vs.glsl"
|
||||
),
|
||||
absPath(
|
||||
"${MODULE_SPACECRAFTINSTRUMENTS}/shaders/terminatorshadow_fs.glsl"
|
||||
)
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
_uniformCache.modelViewProjectionTransform = _shader->uniformLocation(
|
||||
@@ -281,12 +290,14 @@ void RenderableShadowCylinder::initializeGL() {
|
||||
}
|
||||
|
||||
void RenderableShadowCylinder::deinitializeGL() {
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
if (_shader) {
|
||||
renderEngine.removeRenderProgram(_shader);
|
||||
_shader = nullptr;
|
||||
}
|
||||
|
||||
SpacecraftInstrumentsModule::ProgramObjectManager.releaseProgramObject(
|
||||
ProgramName,
|
||||
[](ghoul::opengl::ProgramObject* p) {
|
||||
OsEng.renderEngine().removeRenderProgram(p);
|
||||
}
|
||||
);
|
||||
_shader = nullptr;
|
||||
|
||||
glDeleteVertexArrays(1, &_vao);
|
||||
_vao = 0;
|
||||
glDeleteBuffers(1, &_vbo);
|
||||
|
||||
@@ -78,7 +78,7 @@ private:
|
||||
properties::StringProperty _bodyFrame;
|
||||
properties::OptionProperty _aberration;
|
||||
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _shader;
|
||||
ghoul::opengl::ProgramObject* _shader;
|
||||
UniformCache(modelViewProjectionTransform, shadowColor) _uniformCache;
|
||||
|
||||
glm::dmat3 _stateMatrix;
|
||||
|
||||
@@ -45,6 +45,8 @@
|
||||
|
||||
namespace openspace {
|
||||
|
||||
ghoul::opengl::ProgramObjectManager SpacecraftInstrumentsModule::ProgramObjectManager;
|
||||
|
||||
SpacecraftInstrumentsModule::SpacecraftInstrumentsModule() : OpenSpaceModule(Name) {}
|
||||
|
||||
void SpacecraftInstrumentsModule::internalInitialize(const ghoul::Dictionary&) {
|
||||
@@ -79,6 +81,10 @@ void SpacecraftInstrumentsModule::internalDeinitialize() {
|
||||
ImageSequencer::deinitialize();
|
||||
}
|
||||
|
||||
void SpacecraftInstrumentsModule::internalDeinitializeGL() {
|
||||
ProgramObjectManager.releaseAll(ghoul::opengl::ProgramObjectManager::Warnings::Yes);
|
||||
}
|
||||
|
||||
std::vector<documentation::Documentation>
|
||||
SpacecraftInstrumentsModule::documentations() const
|
||||
{
|
||||
|
||||
@@ -27,6 +27,8 @@
|
||||
|
||||
#include <openspace/util/openspacemodule.h>
|
||||
|
||||
#include <ghoul/opengl/programobjectmanager.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class SpacecraftInstrumentsModule : public OpenSpaceModule {
|
||||
@@ -37,9 +39,12 @@ public:
|
||||
|
||||
std::vector<documentation::Documentation> documentations() const override;
|
||||
|
||||
static ghoul::opengl::ProgramObjectManager ProgramObjectManager;
|
||||
|
||||
protected:
|
||||
void internalInitialize(const ghoul::Dictionary&) override;
|
||||
void internalDeinitialize() override;
|
||||
void internalDeinitializeGL() override;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -113,7 +113,7 @@ void TouchMarker::deinitialize() {
|
||||
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
if (_shader) {
|
||||
renderEngine.removeRenderProgram(_shader);
|
||||
renderEngine.removeRenderProgram(_shader.get());
|
||||
_shader = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,6 +57,15 @@ void ModuleEngine::initialize(const ghoul::Dictionary& moduleConfigurations) {
|
||||
}
|
||||
}
|
||||
|
||||
void ModuleEngine::initializeGL() {
|
||||
LDEBUG("Initializing OpenGL of modules");
|
||||
for (std::unique_ptr<OpenSpaceModule>& m : _modules) {
|
||||
LDEBUG(fmt::format("Initializing OpenGL of module '{}'", m->identifier()));
|
||||
m->initializeGL();
|
||||
}
|
||||
LDEBUG("Finished initializing OpenGL of modules");
|
||||
}
|
||||
|
||||
void ModuleEngine::deinitialize() {
|
||||
LDEBUG("Deinitializing modules");
|
||||
for (std::unique_ptr<OpenSpaceModule>& m : _modules) {
|
||||
@@ -64,6 +73,8 @@ void ModuleEngine::deinitialize() {
|
||||
m->deinitialize();
|
||||
}
|
||||
|
||||
LDEBUG("Finished deinitializing modules");
|
||||
|
||||
for (std::unique_ptr<OpenSpaceModule>& m : _modules) {
|
||||
LDEBUG(fmt::format("Destroying module '{}'", m->identifier()));
|
||||
m = nullptr;
|
||||
@@ -73,6 +84,16 @@ void ModuleEngine::deinitialize() {
|
||||
_modules.clear();
|
||||
}
|
||||
|
||||
void ModuleEngine::deinitializeGL() {
|
||||
LDEBUG("Deinitializing OpenGL of modules");
|
||||
for (std::unique_ptr<OpenSpaceModule>& m : _modules) {
|
||||
LDEBUG(fmt::format("Deinitializing OpenGL of module '{}'", m->identifier()));
|
||||
m->deinitializeGL();
|
||||
|
||||
}
|
||||
LDEBUG("Finished deinitializing OpenGL of modules");
|
||||
}
|
||||
|
||||
void ModuleEngine::registerModule(std::unique_ptr<OpenSpaceModule> m,
|
||||
const ghoul::Dictionary& configuration)
|
||||
{
|
||||
|
||||
@@ -464,6 +464,7 @@ void OpenSpaceEngine::destroy() {
|
||||
|
||||
_engine->_renderEngine->deinitializeGL();
|
||||
|
||||
_engine->_moduleEngine->deinitializeGL();
|
||||
_engine->_moduleEngine->deinitialize();
|
||||
_engine->_console->deinitialize();
|
||||
|
||||
@@ -1228,6 +1229,8 @@ void OpenSpaceEngine::initializeGL() {
|
||||
LDEBUG("Initializing Rendering Engine");
|
||||
_renderEngine->initializeGL();
|
||||
|
||||
_moduleEngine->initializeGL();
|
||||
|
||||
for (const auto& func : _moduleCallbacks.initializeGL) {
|
||||
func();
|
||||
}
|
||||
|
||||
@@ -780,7 +780,6 @@ std::unique_ptr<ghoul::opengl::ProgramObject> RenderEngine::buildRenderProgram(
|
||||
std::string name, std::string vsPath,
|
||||
std::string fsPath, const ghoul::Dictionary& data)
|
||||
{
|
||||
|
||||
ghoul::Dictionary dict = data;
|
||||
|
||||
// set path to the current renderer's main fragment shader
|
||||
@@ -835,9 +834,7 @@ std::unique_ptr<ghoul::opengl::ProgramObject> RenderEngine::buildRenderProgram(
|
||||
return program;
|
||||
}
|
||||
|
||||
void RenderEngine::removeRenderProgram(
|
||||
const std::unique_ptr<ghoul::opengl::ProgramObject>& program)
|
||||
{
|
||||
void RenderEngine::removeRenderProgram(ghoul::opengl::ProgramObject* program) {
|
||||
if (!program) {
|
||||
return;
|
||||
}
|
||||
@@ -845,7 +842,7 @@ void RenderEngine::removeRenderProgram(
|
||||
auto it = std::find(
|
||||
_programs.begin(),
|
||||
_programs.end(),
|
||||
program.get()
|
||||
program
|
||||
);
|
||||
|
||||
if (it != _programs.end()) {
|
||||
|
||||
@@ -357,7 +357,7 @@ bool ScreenSpaceRenderable::deinitializeGL() {
|
||||
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
if (_shader) {
|
||||
renderEngine.removeRenderProgram(_shader);
|
||||
renderEngine.removeRenderProgram(_shader.get());
|
||||
_shader = nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -71,10 +71,18 @@ void OpenSpaceModule::initialize(const ModuleEngine* moduleEngine,
|
||||
internalInitialize(configuration);
|
||||
}
|
||||
|
||||
void OpenSpaceModule::initializeGL() {
|
||||
internalInitializeGL();
|
||||
}
|
||||
|
||||
void OpenSpaceModule::deinitialize() {
|
||||
internalDeinitialize();
|
||||
}
|
||||
|
||||
void OpenSpaceModule::deinitializeGL() {
|
||||
internalDeinitializeGL();
|
||||
}
|
||||
|
||||
std::vector<documentation::Documentation> OpenSpaceModule::documentations() const {
|
||||
return {};
|
||||
}
|
||||
@@ -126,6 +134,10 @@ const ModuleEngine* OpenSpaceModule::moduleEngine() const {
|
||||
|
||||
void OpenSpaceModule::internalInitialize(const ghoul::Dictionary&) {}
|
||||
|
||||
void OpenSpaceModule::internalInitializeGL() {}
|
||||
|
||||
void OpenSpaceModule::internalDeinitialize() {}
|
||||
|
||||
void OpenSpaceModule::internalDeinitializeGL() {}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
Reference in New Issue
Block a user