Applied changes in texture reading io classes to OpenSpace

This commit is contained in:
Alexander Bock
2015-11-24 18:15:23 -05:00
parent 31db5c1603
commit 383c7028a8
20 changed files with 50 additions and 92 deletions

View File

@@ -149,7 +149,6 @@ bool RenderableModel::deinitialize() {
delete _geometry;
_geometry = nullptr;
}
delete _texture;
_texture = nullptr;
delete _programObject;
@@ -253,10 +252,9 @@ void RenderableModel::update(const UpdateData& data) {
}
void RenderableModel::loadTexture() {
delete _texture;
_texture = nullptr;
if (_colorTexturePath.value() != "") {
_texture = ghoul::io::TextureReader::ref().loadTexture(absPath(_colorTexturePath));
_texture = std::move(ghoul::io::TextureReader::ref().loadTexture(absPath(_colorTexturePath)));
if (_texture) {
LDEBUG("Loaded texture from '" << absPath(_colorTexturePath) << "'");
_texture->uploadTexture();

View File

@@ -60,7 +60,7 @@ private:
properties::BoolProperty _performFade;
properties::FloatProperty _fading;
ghoul::opengl::ProgramObject* _programObject;
ghoul::opengl::Texture* _texture;
std::unique_ptr<ghoul::opengl::Texture> _texture;
modelgeometry::ModelGeometry* _geometry;

View File

@@ -166,7 +166,6 @@ bool RenderablePlane::deinitialize() {
if (!_projectionListener){
// its parents job to kill texture
// iff projectionlistener
delete _texture;
_texture = nullptr;
}
@@ -190,8 +189,8 @@ void RenderablePlane::render(const RenderData& data) {
//get parent node-texture and set with correct dimensions
SceneGraphNode* textureNode = OsEng.renderEngine()->scene()->sceneGraphNode(_nodeName)->parent();
if (textureNode != nullptr){
RenderablePlanetProjection *t = static_cast<RenderablePlanetProjection*>(textureNode->renderable());
_texture = t->baseTexture();
RenderablePlanetProjection* t = static_cast<RenderablePlanetProjection*>(textureNode->renderable());
_texture = std::unique_ptr<ghoul::opengl::Texture>(t->baseTexture());
float h = _texture->height();
float w = _texture->width();
float scale = h / w;
@@ -229,7 +228,7 @@ void RenderablePlane::update(const UpdateData& data) {
void RenderablePlane::loadTexture() {
if (_texturePath.value() != "") {
ghoul::opengl::Texture* texture = ghoul::io::TextureReader::ref().loadTexture(absPath(_texturePath));
std::unique_ptr<ghoul::opengl::Texture> texture = ghoul::io::TextureReader::ref().loadTexture(absPath(_texturePath));
if (texture) {
LDEBUG("Loaded texture from '" << absPath(_texturePath) << "'");
texture->uploadTexture();
@@ -237,9 +236,7 @@ void RenderablePlane::loadTexture() {
// Textures of planets looks much smoother with AnisotropicMipMap rather than linear
texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
if (_texture)
delete _texture;
_texture = texture;
_texture = std::move(texture);
delete _textureFile;
_textureFile = new ghoul::filesystem::File(_texturePath);

View File

@@ -78,7 +78,7 @@ private:
ghoul::opengl::ProgramObject* _shader;
bool _textureIsDirty;
ghoul::opengl::Texture* _texture;
std::unique_ptr<ghoul::opengl::Texture> _texture;
ghoul::filesystem::File* _textureFile;
GLuint _quad;
GLuint _vertexPositionBuffer;

View File

@@ -138,10 +138,6 @@ bool RenderablePlanet::deinitialize() {
_geometry->deinitialize();
delete _geometry;
}
if (_texture)
delete _texture;
if (_nightTexture)
delete _nightTexture;
_geometry = nullptr;
_texture = nullptr;
@@ -222,10 +218,9 @@ void RenderablePlanet::update(const UpdateData& data){
}
void RenderablePlanet::loadTexture() {
delete _texture;
_texture = nullptr;
if (_colorTexturePath.value() != "") {
_texture = ghoul::io::TextureReader::ref().loadTexture(absPath(_colorTexturePath));
_texture = std::move(ghoul::io::TextureReader::ref().loadTexture(absPath(_colorTexturePath)));
if (_texture) {
LDEBUG("Loaded texture from '" << _colorTexturePath << "'");
_texture->uploadTexture();
@@ -237,10 +232,9 @@ void RenderablePlanet::loadTexture() {
}
}
if (_hasNightTexture) {
delete _nightTexture;
_nightTexture = nullptr;
if (_nightTexturePath != "") {
_nightTexture = ghoul::io::TextureReader::ref().loadTexture(absPath(_nightTexturePath));
_nightTexture = std::move(ghoul::io::TextureReader::ref().loadTexture(absPath(_nightTexturePath)));
if (_nightTexture) {
LDEBUG("Loaded texture from '" << _nightTexturePath << "'");
_nightTexture->uploadTexture();

View File

@@ -63,8 +63,8 @@ protected:
private:
properties::StringProperty _colorTexturePath;
ghoul::opengl::ProgramObject* _programObject;
ghoul::opengl::Texture* _texture;
ghoul::opengl::Texture* _nightTexture;
std::unique_ptr<ghoul::opengl::Texture> _texture;
std::unique_ptr<ghoul::opengl::Texture> _nightTexture;
planetgeometry::PlanetGeometry* _geometry;
properties::BoolProperty _performShading;
properties::IntProperty _rotation;

View File

@@ -131,7 +131,6 @@ bool RenderableSphere::deinitialize() {
delete _sphere;
_sphere = nullptr;
delete _texture;
_texture = nullptr;
delete _shader;
@@ -182,7 +181,7 @@ void RenderableSphere::update(const UpdateData& data) {
void RenderableSphere::loadTexture() {
if (_texturePath.value() != "") {
ghoul::opengl::Texture* texture = ghoul::io::TextureReader::ref().loadTexture(_texturePath);
std::unique_ptr<ghoul::opengl::Texture> texture = ghoul::io::TextureReader::ref().loadTexture(_texturePath);
if (texture) {
LDEBUG("Loaded texture from '" << absPath(_texturePath) << "'");
texture->uploadTexture();
@@ -192,9 +191,7 @@ void RenderableSphere::loadTexture() {
//texture->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap);
texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
if (_texture)
delete _texture;
_texture = texture;
_texture = std::move(texture);
}
}
}

View File

@@ -62,7 +62,7 @@ private:
properties::FloatProperty _transparency;
ghoul::opengl::ProgramObject* _shader;
ghoul::opengl::Texture* _texture;
std::unique_ptr<ghoul::opengl::Texture> _texture;
PowerScaledSphere* _sphere;

View File

@@ -137,7 +137,6 @@ RenderableStars::RenderableStars(const ghoul::Dictionary& dictionary)
RenderableStars::~RenderableStars() {
delete _psfTextureFile;
delete _colorTextureFile;
delete _colorTexture;
}
bool RenderableStars::isReady() const {
@@ -165,11 +164,10 @@ bool RenderableStars::deinitialize() {
glDeleteVertexArrays(1, &_vao);
_vao = 0;
delete _pointSpreadFunctionTexture;
_pointSpreadFunctionTexture = nullptr;
_colorTexture = nullptr;
if(_program)
delete _program;
delete _program;
_program = nullptr;
return true;
}
@@ -312,10 +310,9 @@ void RenderableStars::update(const UpdateData& data) {
if (_pointSpreadFunctionTextureIsDirty) {
LDEBUG("Reloading Point Spread Function texture");
delete _pointSpreadFunctionTexture;
_pointSpreadFunctionTexture = nullptr;
if (_pointSpreadFunctionTexturePath.value() != "") {
_pointSpreadFunctionTexture = ghoul::io::TextureReader::ref().loadTexture(absPath(_pointSpreadFunctionTexturePath));
_pointSpreadFunctionTexture = std::move(ghoul::io::TextureReader::ref().loadTexture(absPath(_pointSpreadFunctionTexturePath)));
if (_pointSpreadFunctionTexture) {
LDEBUG("Loaded texture from '" << absPath(_pointSpreadFunctionTexturePath) << "'");
_pointSpreadFunctionTexture->uploadTexture();
@@ -330,10 +327,9 @@ void RenderableStars::update(const UpdateData& data) {
if (_colorTextureIsDirty) {
LDEBUG("Reloading Color Texture");
delete _colorTexture;
_colorTexture = nullptr;
if (_colorTexturePath.value() != "") {
_colorTexture = ghoul::io::TextureReader::ref().loadTexture(absPath(_colorTexturePath));
_colorTexture = std::move(ghoul::io::TextureReader::ref().loadTexture(absPath(_colorTexturePath)));
if (_colorTexture) {
LDEBUG("Loaded texture from '" << absPath(_colorTexturePath) << "'");
_colorTexture->uploadTexture();

View File

@@ -63,11 +63,11 @@ private:
bool saveCachedFile(const std::string& file) const;
properties::StringProperty _pointSpreadFunctionTexturePath;
ghoul::opengl::Texture* _pointSpreadFunctionTexture;
std::unique_ptr<ghoul::opengl::Texture> _pointSpreadFunctionTexture;
bool _pointSpreadFunctionTextureIsDirty;
properties::StringProperty _colorTexturePath;
ghoul::opengl::Texture* _colorTexture;
std::unique_ptr<ghoul::opengl::Texture> _colorTexture;
bool _colorTextureIsDirty;
properties::OptionProperty _colorOption;

View File

@@ -44,7 +44,6 @@
#include <modules/newhorizons/util/imagesequencer.h>
namespace openspace {
NewHorizonsModule::NewHorizonsModule()
@@ -58,7 +57,6 @@ bool NewHorizonsModule::create() {
ImageSequencer2::initialize();
FactoryManager::ref().addFactory(new ghoul::TemplateFactory<planetgeometryprojection::PlanetGeometryProjection>);
FactoryManager::ref().addFactory(new ghoul::TemplateFactory<Decoder>);

View File

@@ -274,15 +274,6 @@ bool RenderableModelProjection::deinitialize() {
delete _geometry;
}
if (_texture)
delete _texture;
if (_textureProj)
delete _textureProj;
if (_textureOriginal)
delete _textureOriginal;
if (_textureWhiteSquare)
delete _textureWhiteSquare;
_geometry = nullptr;
_texture = nullptr;
_textureProj = nullptr;
@@ -488,30 +479,27 @@ void RenderableModelProjection::project() {
}
void RenderableModelProjection::loadTexture() {
delete _texture;
_texture = nullptr;
if (_colorTexturePath.value() != "") {
_texture = ghoul::io::TextureReader::ref().loadTexture(absPath(_colorTexturePath));
_texture = std::move(ghoul::io::TextureReader::ref().loadTexture(absPath(_colorTexturePath)));
if (_texture) {
LDEBUG("Loaded texture from '" << absPath(_colorTexturePath) << "'");
_texture->uploadTexture();
_texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
}
}
delete _textureOriginal;
_textureOriginal = nullptr;
if (_colorTexturePath.value() != "") {
_textureOriginal = ghoul::io::TextureReader::ref().loadTexture(absPath(_colorTexturePath));
_textureOriginal = std::move(ghoul::io::TextureReader::ref().loadTexture(absPath(_colorTexturePath)));
if (_textureOriginal) {
LDEBUG("Loaded texture from '" << absPath(_colorTexturePath) << "'");
_textureOriginal->uploadTexture();
_textureOriginal->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
}
}
delete _textureWhiteSquare;
_textureWhiteSquare = nullptr;
if (_defaultProjImage != "") {
_textureWhiteSquare = ghoul::io::TextureReader::ref().loadTexture(absPath(_defaultProjImage));
_textureWhiteSquare = std::move(ghoul::io::TextureReader::ref().loadTexture(absPath(_defaultProjImage)));
if (_textureWhiteSquare) {
_textureWhiteSquare->uploadTexture();
_textureWhiteSquare->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
@@ -520,10 +508,9 @@ void RenderableModelProjection::loadTexture() {
}
void RenderableModelProjection::loadProjectionTexture() {
delete _textureProj;
_textureProj = nullptr;
if (_projectionTexturePath.value() != "") {
_textureProj = ghoul::io::TextureReader::ref().loadTexture(absPath(_projectionTexturePath));
_textureProj = std::move(ghoul::io::TextureReader::ref().loadTexture(absPath(_projectionTexturePath)));
if (_textureProj) {
_textureProj->uploadTexture();
_textureProj->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap);

View File

@@ -80,10 +80,10 @@ namespace openspace {
ghoul::opengl::ProgramObject* _programObject;
ghoul::opengl::ProgramObject* _fboProgramObject;
ghoul::opengl::Texture* _texture;
ghoul::opengl::Texture* _textureOriginal;
ghoul::opengl::Texture* _textureProj;
ghoul::opengl::Texture* _textureWhiteSquare;
std::unique_ptr<ghoul::opengl::Texture> _texture;
std::unique_ptr<ghoul::opengl::Texture> _textureOriginal;
std::unique_ptr<ghoul::opengl::Texture> _textureProj;
std::unique_ptr<ghoul::opengl::Texture> _textureWhiteSquare;
modelgeometry::ModelGeometry* _geometry;

View File

@@ -119,7 +119,7 @@ bool RenderablePlaneProjection::deinitialize() {
_quad = 0;
glDeleteBuffers(1, &_vertexPositionBuffer);
_vertexPositionBuffer = 0;
delete _texture;
_texture = nullptr;
return true;
}
@@ -190,15 +190,13 @@ void RenderablePlaneProjection::update(const UpdateData& data) {
void RenderablePlaneProjection::loadTexture() {
if (_texturePath != "") {
ghoul::opengl::Texture* texture = ghoul::io::TextureReader::ref().loadTexture(absPath(_texturePath));
std::unique_ptr<ghoul::opengl::Texture> texture = ghoul::io::TextureReader::ref().loadTexture(absPath(_texturePath));
if (texture) {
texture->uploadTexture();
// TODO: AnisotropicMipMap crashes on ATI cards ---abock
//texture->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap);
texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
if (_texture)
delete _texture;
_texture = texture;
_texture = std::move(texture);
delete _textureFile;
_textureFile = new ghoul::filesystem::File(_texturePath);

View File

@@ -32,6 +32,8 @@
#include <openspace/properties/vectorproperty.h>
#include <openspace/util/updatestructures.h>
#include <memory>
namespace ghoul {
namespace filesystem {
class File;
@@ -52,12 +54,10 @@ struct target {
};
class RenderablePlaneProjection : public Renderable {
public:
RenderablePlaneProjection(const ghoul::Dictionary& dictionary);
~RenderablePlaneProjection();
bool initialize() override;
bool deinitialize() override;
@@ -81,7 +81,8 @@ private:
ghoul::opengl::ProgramObject* _shader;
bool _textureIsDirty;
ghoul::opengl::Texture* _texture;
std::unique_ptr<ghoul::opengl::Texture> _texture = nullptr;
// ghoul::opengl::Texture* _texture;
ghoul::filesystem::File* _textureFile;
GLuint _quad;
GLuint _vertexPositionBuffer;

View File

@@ -305,13 +305,9 @@ bool RenderablePlanetProjection::auxiliaryRendertarget(){
}
bool RenderablePlanetProjection::deinitialize(){
delete _texture;
_texture = nullptr;
delete _textureProj;
_textureProj = nullptr;
delete _textureOriginal;
_textureOriginal = nullptr;
delete _textureWhiteSquare;
_textureWhiteSquare = nullptr;
delete _geometry;
_geometry = nullptr;
@@ -561,10 +557,9 @@ void RenderablePlanetProjection::update(const UpdateData& data){
}
void RenderablePlanetProjection::loadProjectionTexture() {
delete _textureProj;
_textureProj = nullptr;
if (_colorTexturePath.value() != "") {
_textureProj = ghoul::io::TextureReader::ref().loadTexture(absPath(_projectionTexturePath));
_textureProj = std::move(ghoul::io::TextureReader::ref().loadTexture(absPath(_projectionTexturePath)));
if (_textureProj) {
_textureProj->uploadTexture();
// TODO: AnisotropicMipMap crashes on ATI cards ---abock
@@ -576,28 +571,25 @@ void RenderablePlanetProjection::loadProjectionTexture() {
}
void RenderablePlanetProjection::loadTexture() {
delete _texture;
_texture = nullptr;
if (_colorTexturePath.value() != "") {
_texture = ghoul::io::TextureReader::ref().loadTexture(_colorTexturePath);
_texture = std::move(ghoul::io::TextureReader::ref().loadTexture(_colorTexturePath));
if (_texture) {
_texture->uploadTexture();
_texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
}
}
delete _textureOriginal;
_textureOriginal = nullptr;
if (_colorTexturePath.value() != "") {
_textureOriginal = ghoul::io::TextureReader::ref().loadTexture(_colorTexturePath);
_textureOriginal = std::move(ghoul::io::TextureReader::ref().loadTexture(_colorTexturePath));
if (_textureOriginal) {
_textureOriginal->uploadTexture();
_textureOriginal->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
}
}
delete _textureWhiteSquare;
_textureWhiteSquare = nullptr;
if (_colorTexturePath.value() != "") {
_textureWhiteSquare = ghoul::io::TextureReader::ref().loadTexture(_defaultProjImage);
_textureWhiteSquare = std::move(ghoul::io::TextureReader::ref().loadTexture(_defaultProjImage));
if (_textureWhiteSquare) {
_textureWhiteSquare->uploadTexture();
_textureWhiteSquare->setFilter(ghoul::opengl::Texture::FilterMode::Linear);

View File

@@ -70,7 +70,7 @@ public:
void render(const RenderData& data) override;
void update(const UpdateData& data) override;
ghoul::opengl::Texture* baseTexture() { return _texture; };
ghoul::opengl::Texture* baseTexture() { return _texture.get(); };
protected:
@@ -98,10 +98,10 @@ private:
ghoul::opengl::ProgramObject* _programObject;
ghoul::opengl::ProgramObject* _fboProgramObject;
ghoul::opengl::Texture* _texture;
ghoul::opengl::Texture* _textureOriginal;
ghoul::opengl::Texture* _textureProj;
ghoul::opengl::Texture* _textureWhiteSquare;
std::unique_ptr<ghoul::opengl::Texture> _texture;
std::unique_ptr<ghoul::opengl::Texture> _textureOriginal;
std::unique_ptr<ghoul::opengl::Texture> _textureProj;
std::unique_ptr<ghoul::opengl::Texture> _textureWhiteSquare;
planetgeometryprojection::PlanetGeometryProjection* _geometry;
glm::vec2 _camScaling;

View File

@@ -296,7 +296,7 @@ ghoul::opengl::Texture* RenderableVolume::loadTransferFunction(const std::string
// check if not a txt based texture
if ( ! hasExtension(filepath, "txt")) {
ghoul::opengl::Texture* t = ghoul::io::TextureReader::ref().loadTexture(f);
ghoul::opengl::Texture* t = ghoul::io::TextureReader::ref().loadTexture(f).get();
t->setWrapping(wrappingmode);
return t;
}

View File

@@ -182,13 +182,13 @@ bool RenderEngine::initialize() {
OsEng.interactionHandler()->setCamera(_mainCamera);
#ifdef GHOUL_USE_DEVIL
ghoul::io::TextureReader::ref().addReader(new ghoul::io::impl::TextureReaderDevIL);
ghoul::io::TextureReader::ref().addReader(std::make_shared<ghoul::io::TextureReaderDevIL>());
#endif // GHOUL_USE_DEVIL
#ifdef GHOUL_USE_FREEIMAGE
ghoul::io::TextureReader::ref().addReader(new ghoul::io::impl::TextureReaderFreeImage);
ghoul::io::TextureReader::ref().addReader(std::make_shared<ghoul::io::TextureReaderFreeImage>());
#endif // GHOUL_USE_FREEIMAGE
ghoul::io::TextureReader::ref().addReader(new ghoul::io::impl::TextureReaderCMAP);
ghoul::io::TextureReader::ref().addReader(std::make_shared<ghoul::io::TextureReaderCMAP>());
return true;