General cleanup

Adapt to changes in Ghoul
Make use of TextureManager
Jenkins compile fix
This commit is contained in:
Alexander Bock
2018-07-19 14:43:53 -04:00
parent dbdc5dfd28
commit 0774348fc2
26 changed files with 142 additions and 138 deletions
@@ -33,6 +33,7 @@
#include <openspace/rendering/renderengine.h>
#include <ghoul/filesystem/cachemanager.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/misc/crc32.h>
#include <ghoul/misc/templatefactory.h>
#include <ghoul/io/texture/texturereader.h>
#include <ghoul/logging/logmanager.h>
@@ -51,19 +52,19 @@
#include <string>
namespace {
constexpr const char* _loggerCat = "RenderableBillboardsCloud";
constexpr const char* ProgramObjectName = "RenderableBillboardsCloud";
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";
constexpr const char* MeterUnit = "m";
constexpr const char* KilometerUnit = "Km";
constexpr const char* ParsecUnit = "pc";
constexpr const char* KiloparsecUnit = "Kpc";
constexpr const char* MegaparsecUnit = "Mpc";
constexpr const char* GigaparsecUnit = "Gpc";
constexpr const char* KeyFile = "File";
constexpr const char* keyColor = "Color";
constexpr const char* keyUnit = "Unit";
constexpr const char* MeterUnit = "m";
constexpr const char* KilometerUnit = "Km";
constexpr const char* ParsecUnit = "pc";
constexpr const char* KiloparsecUnit = "Kpc";
constexpr const char* MegaparsecUnit = "Mpc";
constexpr const char* GigaparsecUnit = "Gpc";
constexpr const char* GigalightyearUnit = "Gly";
constexpr int8_t CurrentCacheVersion = 1;
@@ -480,14 +481,8 @@ RenderableBillboardsCloud::RenderableBillboardsCloud(const ghoul::Dictionary& di
_spriteTexturePath = absPath(dictionary.value<std::string>(
SpriteTextureInfo.identifier
));
_spriteTextureFile = std::make_unique<ghoul::filesystem::File>(
_spriteTexturePath
);
_spriteTexturePath.onChange([&] { _spriteTextureIsDirty = true; });
_spriteTextureFile->setCallback(
[&](const ghoul::filesystem::File&) { _spriteTextureIsDirty = true; }
);
_spriteTexturePath.onChange([&]() { _spriteTextureIsDirty = true; });
addProperty(_spriteTexturePath);
_hasSpriteTexture = true;
@@ -658,29 +653,28 @@ void RenderableBillboardsCloud::initialize() {
}
void RenderableBillboardsCloud::initializeGL() {
_program = DigitalUniverseModule::ProgramObjectManager.requestProgramObject(
_program = DigitalUniverseModule::ProgramObjectManager.request(
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")
);
}
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")
);
}
_renderToPolygonProgram = DigitalUniverseModule::ProgramObjectManager.request(
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.cameraViewProjectionMatrix = _program->uniformLocation(
@@ -738,22 +732,19 @@ void RenderableBillboardsCloud::deinitializeGL() {
glDeleteVertexArrays(1, &_vao);
_vao = 0;
DigitalUniverseModule::ProgramObjectManager.releaseProgramObject(
DigitalUniverseModule::ProgramObjectManager.release(
ProgramObjectName,
[](ghoul::opengl::ProgramObject* p) {
OsEng.renderEngine().removeRenderProgram(p);
}
OsEng.renderEngine().removeRenderProgram(p);
}
);
_program = nullptr;
DigitalUniverseModule::ProgramObjectManager.releaseProgramObject(
RenderToPolygonProgram
);
DigitalUniverseModule::ProgramObjectManager.release(RenderToPolygonProgram);
_renderToPolygonProgram = nullptr;
if (_hasSpriteTexture) {
_spriteTexture = nullptr;
}
DigitalUniverseModule::TextureManager.release(_spriteTexture);
_spriteTexture = nullptr;
if (_hasPolygon) {
_polygonTexture = nullptr;
@@ -1077,37 +1068,30 @@ void RenderableBillboardsCloud::update(const UpdateData&) {
_dataIsDirty = false;
}
if (_hasSpriteTexture && _spriteTextureIsDirty) {
LDEBUG("Reloading Sprite Texture");
_spriteTexture = nullptr;
if (_spriteTexturePath.value() != "") {
_spriteTexture = ghoul::io::TextureReader::ref().loadTexture(
absPath(_spriteTexturePath)
);
if (_spriteTexture) {
LINFO(fmt::format(
"Loaded texture from '{}'",
absPath(_spriteTexturePath)
));
_spriteTexture->uploadTexture();
if (_hasSpriteTexture && _spriteTextureIsDirty && !_spriteTexturePath.value().empty())
{
ghoul::opengl::Texture* t = _spriteTexture;
unsigned int hash = ghoul::hashCRC32File(_spriteTexturePath);
_spriteTexture = DigitalUniverseModule::TextureManager.request(
std::to_string(hash),
[path = _spriteTexturePath]() -> std::unique_ptr<ghoul::opengl::Texture> {
LINFO(fmt::format("Loaded texture from '{}'", absPath(path)));
std::unique_ptr<ghoul::opengl::Texture> t =
ghoul::io::TextureReader::ref().loadTexture(
absPath(path)
);
t->uploadTexture();
t->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap);
return t;
}
_spriteTexture->setFilter(
ghoul::opengl::Texture::FilterMode::AnisotropicMipMap
);
);
_spriteTextureFile = std::make_unique<ghoul::filesystem::File>(
_spriteTexturePath);
_spriteTextureFile->setCallback(
[&](const ghoul::filesystem::File&) { _spriteTextureIsDirty = true; }
);
}
DigitalUniverseModule::TextureManager.release(t);
_spriteTextureIsDirty = false;
}
if (_hasLabel && _labelDataIsDirty) {
_labelDataIsDirty = false;
}
}
bool RenderableBillboardsCloud::loadData() {