Merge fix

This commit is contained in:
Sebastian Piwell
2016-06-01 12:09:58 -04:00
22 changed files with 411 additions and 201 deletions

View File

@@ -30,20 +30,21 @@ function postInitialization()
openspace.printInfo("Done setting default values")
--openspace.iswa.addCygnet(-4,"Data");
openspace.iswa.addCygnet(-4,"Data","Ion");
--openspace.iswa.addCygnet(-1,"Data");
--openspace.iswa.addCygnet(-2,"Data");
--openspace.iswa.addCygnet(-3,"Data");
openspace.iswa.addCygnet(-3,"Data","GM");
--openspace.iswa.addCygnet(-1,"Texture");
--openspace.iswa.addCygnet(-2,"Texture");
--openspace.iswa.addCygnet(-3,"Texture");
--openspace.iswa.addCygnet(-3,"Data","GM");
--openspace.iswa.addCygnet(-2,"Data","GM");
--openspace.iswa.addCygnet(-1,"Data","GM");
--openspace.iswa.addCygnet(-3,"Texture","GM");
openspace.iswa.addCygnet(-2,"Texture","GM");
--openspace.iswa.addCygnet(-1,"Texture","GM");
openspace.iswa.addCdfFiles("${OPENSPACE_DATA}/cdflist.json");
--[[

View File

@@ -4,6 +4,8 @@ local file3 = '${OPENSPACE_DATA}/scene/fieldlines/bats_seeds/BATS_R_US_open_sout
local file4 = '${OPENSPACE_DATA}/scene/fieldlines/bats_seeds/BATS_R_US_solar_wind_all.txt';
local file5 = '${OPENSPACE_DATA}/scene/fieldlines/bats_seeds/BATS_R_US_separatrix_seeds_all.txt';
local volumeFile = '${OPENSPACE_DATA}/batsrus.cdf';
return {
{
Name = "Fieldlines1",
@@ -16,7 +18,7 @@ return {
Type = "RenderableFieldlines",
VectorField = {
Type = "VolumeKameleon",
File = "${OPENSPACE_DATA}/BATSRUS.cdf",
File = volumeFile,
Model = "BATSRUS",
Variables = {"bx", "by", "bz"}
},
@@ -42,7 +44,7 @@ return {
Type = "RenderableFieldlines",
VectorField = {
Type = "VolumeKameleon",
File = "${OPENSPACE_DATA}/BATSRUS.cdf",
File = volumeFile,
Model = "BATSRUS",
Variables = {"bx", "by", "bz"}
},
@@ -68,7 +70,7 @@ return {
Type = "RenderableFieldlines",
VectorField = {
Type = "VolumeKameleon",
File = "${OPENSPACE_DATA}/BATSRUS.cdf",
File = volumeFile,
Model = "BATSRUS",
Variables = {"bx", "by", "bz"}
},
@@ -94,7 +96,7 @@ return {
Type = "RenderableFieldlines",
VectorField = {
Type = "VolumeKameleon",
File = "${OPENSPACE_DATA}/BATSRUS.cdf",
File = volumeFile,
Model = "BATSRUS",
Variables = {"bx", "by", "bz"}
},
@@ -120,7 +122,7 @@ return {
Type = "RenderableFieldlines",
VectorField = {
Type = "VolumeKameleon",
File = "${OPENSPACE_DATA}/BATSRUS.cdf",
File = volumeFile,
Model = "BATSRUS",
Variables = {"bx", "by", "bz"}
},

View File

@@ -2,7 +2,7 @@
# #
# OpenSpace #
# #
# Copyright (c) 2014-2015 #
# Copyright (c) 2014-2016 #
# #
# Permission is hereby granted, free of charge, to any person obtaining a copy of this #
# software and associated documentation files (the "Software"), to deal in the Software #
@@ -39,6 +39,7 @@ set(HEADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/rendering/datasphere.h
${CMAKE_CURRENT_SOURCE_DIR}/rendering/screenspacecygnet.h
${CMAKE_CURRENT_SOURCE_DIR}/rendering/iswagroup.h
${CMAKE_CURRENT_SOURCE_DIR}/rendering/texturecygnet.h
)
source_group("Header Files" FILES ${HEADER_FILES})
@@ -57,6 +58,7 @@ set(SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/rendering/datasphere.cpp
${CMAKE_CURRENT_SOURCE_DIR}/rendering/screenspacecygnet.cpp
${CMAKE_CURRENT_SOURCE_DIR}/rendering/iswagroup.cpp
${CMAKE_CURRENT_SOURCE_DIR}/rendering/texturecygnet.cpp
)
source_group("Source Files" FILES ${SOURCE_FILES})

View File

@@ -77,7 +77,7 @@ bool CygnetPlane::destroyGeometry(){
return true;
}
void CygnetPlane::renderGeometry(){
void CygnetPlane::renderGeometry() const {
glBindVertexArray(_quad);
glDrawArrays(GL_TRIANGLES, 0, 6);
}

View File

@@ -38,7 +38,7 @@ public:
protected:
virtual bool createGeometry() override;
virtual bool destroyGeometry() override;
virtual void renderGeometry() override;
virtual void renderGeometry() const override;
GLuint _quad;
GLuint _vertexPositionBuffer;

View File

@@ -54,7 +54,7 @@ bool CygnetSphere::destroyGeometry(){
return true;
}
void CygnetSphere::renderGeometry(){
void CygnetSphere::renderGeometry() const {
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
_sphere->render();

View File

@@ -2,7 +2,7 @@
* *
* OpenSpace *
* *
* Copyright (c) 2014-2015 *
* Copyright (c) 2014-2016 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
@@ -44,7 +44,7 @@ protected:
private:
virtual bool createGeometry() override;
virtual bool destroyGeometry() override;
virtual void renderGeometry() override;
virtual void renderGeometry() const override;
float _radius;
};

View File

@@ -0,0 +1,39 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2016 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include <modules/iswa/rendering/datacygnet.h>
namespace {
const std::string _loggerCat = "DataCygnet";
}
namespace openspace{
DataCygnet::DataCygnet(const ghoul::Dictionary& dictionary)
:IswaCygnet(dictionary)
{}
DataCygnet::~DataCygnet(){}
} //namespace openspace

View File

@@ -0,0 +1,40 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2016 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __DATACYGNET_H__
#define __DATACYGNET_H__
#include <modules/iswa/rendering/iswacygnet.h>
namespace openspace{
class DataCygnet : public IswaCygnet {
public:
DataCygnet(const ghoul::Dictionary& dictionary);
~DataCygnet();
protected:
};
} //namespace openspace
#endif //__DATACYGNET_H__

View File

@@ -67,6 +67,10 @@ DataPlane::DataPlane(const ghoul::Dictionary& dictionary)
addProperty(_backgroundValues);
addProperty(_transferFunctionsFile);
addProperty(_dataOptions);
_programName = "DataPlaneProgram";
_vsPath = "${MODULE_ISWA}/shaders/dataplane_vs.glsl";
_fsPath = "${MODULE_ISWA}/shaders/dataplane_fs.glsl";
}
DataPlane::~DataPlane(){}
@@ -254,7 +258,7 @@ bool DataPlane::updateTexture(){
return false;
}
bool DataPlane::readyToRender(){
bool DataPlane::readyToRender() const {
return (!_textures.empty());
}
@@ -322,18 +326,6 @@ void DataPlane::setUniformAndTextures(){
_shader->setUniform("transparency", _alpha.value());
}
bool DataPlane::createShader(){
if (_shader == nullptr) {
// DatePlane Program
RenderEngine& renderEngine = OsEng.renderEngine();
_shader = renderEngine.buildRenderProgram("DataPlaneProgram",
"${MODULE_ISWA}/shaders/dataplane_vs.glsl",
"${MODULE_ISWA}/shaders/dataplane_fs.glsl"
);
if (!_shader) return false;
}
}
void DataPlane::setTransferFunctions(std::string tfPath){
std::string line;
std::ifstream tfFile(absPath(tfPath));

View File

@@ -2,7 +2,7 @@
* *
* OpenSpace *
* *
* Copyright (c) 2014-2015 *
* Copyright (c) 2014-2016 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
@@ -46,9 +46,8 @@ friend class IswaGroup;
virtual bool loadTexture() override;
virtual bool updateTexture() override;
virtual bool readyToRender() override;
virtual bool readyToRender() const override;
virtual void setUniformAndTextures() override;
virtual bool createShader() override;
void setTransferFunctions(std::string tfPath);
void fillOptions();

View File

@@ -2,7 +2,7 @@
* *
* OpenSpace *
* *
* Copyright (c) 2014-2015 *
* Copyright (c) 2014-2016 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
@@ -61,6 +61,10 @@ DataSphere::DataSphere(const ghoul::Dictionary& dictionary)
addProperty(_backgroundValues);
addProperty(_transferFunctionsFile);
addProperty(_dataOptions);
_programName = "DataSphereProgram";
_vsPath = "${MODULE_ISWA}/shaders/datasphere_vs.glsl";
_fsPath = "${MODULE_ISWA}/shaders/datasphere_fs.glsl";
}
DataSphere::~DataSphere(){}
@@ -72,7 +76,6 @@ bool DataSphere::initialize(){
_dataProcessor = _group->dataProcessor();
auto groupEvent = _group->groupEvent();
groupEvent->subscribe(name(), "useLogChanged", [&](const ghoul::Dictionary& dict){
LDEBUG(name() + " Event useLogChanged");
_useLog.setValue(dict.value<bool>("useLog"));
@@ -250,7 +253,7 @@ bool DataSphere::updateTexture(){
}
bool DataSphere::readyToRender(){
bool DataSphere::readyToRender() const {
return (!_textures.empty());
bool ready = isReady();
@@ -326,19 +329,19 @@ void DataSphere::setUniformAndTextures(){
}
bool DataSphere::createShader(){
if (_shader == nullptr) {
// Plane Program
RenderEngine& renderEngine = OsEng.renderEngine();
_shader = renderEngine.buildRenderProgram(
"DataSphereProgram",
"${MODULE_ISWA}/shaders/datasphere_vs.glsl",
"${MODULE_ISWA}/shaders/datasphere_fs.glsl");
if (!_shader)
return false;
}
return true;
}
// bool DataSphere::createShader(){
// if (_shader == nullptr) {
// // Plane Program
// RenderEngine& renderEngine = OsEng.renderEngine();
// _shader = renderEngine.buildRenderProgram(
// "DataSphereProgram",
// "${MODULE_ISWA}/shaders/datasphere_vs.glsl",
// "${MODULE_ISWA}/shaders/datasphere_fs.glsl");
// if (!_shader)
// return false;
// }
// return true;
// }
void DataSphere::setTransferFunctions(std::string tfPath){
std::string line;

View File

@@ -40,22 +40,13 @@ public:
~DataSphere();
bool initialize() override;
protected:
// virtual void useLog(bool useLog) override;
// virtual void normValues(glm::vec2 normValues) override;
// virtual void useHistogram(bool useHistogram) override;
// virtual void dataOptions(std::vector<int> options) override;
// virtual void transferFunctionsFile(std::string tfPath) override;
// virtual void backgroundValues(glm::vec2 backgroundValues) override;
private:
virtual bool loadTexture() override;
virtual bool updateTexture() override;
virtual bool readyToRender() override;
virtual bool readyToRender() const override;
virtual void setUniformAndTextures() override;
virtual bool createShader() override;
void setTransferFunctions(std::string tfPath);
void fillOptions();

View File

@@ -243,6 +243,19 @@ void IswaCygnet::initializeTime(){
_minRealTimeUpdateInterval = 100;
}
bool IswaCygnet::createShader(){
if (_shader == nullptr) {
// Plane Program
RenderEngine& renderEngine = OsEng.renderEngine();
_shader = renderEngine.buildRenderProgram(_programName,
_vsPath,
_fsPath
);
if (!_shader) return false;
}
return true;
}
void IswaCygnet::initializeGroup(){
// _groupEvent = IswaManager::ref().groupEvent(_data->groupName, _type);
_group = IswaManager::ref().iswaGroup(_data->groupName);

View File

@@ -75,11 +75,11 @@ public:
IswaCygnet(const ghoul::Dictionary& dictionary);
~IswaCygnet();
virtual bool initialize() override;
virtual bool deinitialize() override;
virtual bool isReady() const override;
void render(const RenderData& data) override;
void update(const UpdateData& data) override;
virtual bool initialize();
virtual bool deinitialize();
virtual bool isReady() const;
void render(const RenderData& data);
void update(const UpdateData& data);
protected:
@@ -90,16 +90,16 @@ protected:
void initializeTime();
void initializeGroup();
bool destroyShader();
bool createShader();
virtual bool createGeometry() = 0;
virtual bool destroyGeometry() = 0;
virtual void renderGeometry() = 0;
virtual void renderGeometry() const = 0;
virtual bool loadTexture() = 0;
virtual bool updateTexture() = 0;
virtual bool readyToRender() = 0;
virtual bool readyToRender() const = 0;
virtual void setUniformAndTextures() = 0;
virtual bool createShader() = 0;
properties::FloatProperty _alpha;
properties::TriggerProperty _delete;
@@ -125,6 +125,10 @@ protected:
// IswaManager::CygnetType _type;
bool _textureDirty;
std::string _vsPath;
std::string _fsPath;
std::string _programName;
};
}//namespace openspace

View File

@@ -109,6 +109,10 @@ KameleonPlane::KameleonPlane(const ghoul::Dictionary& dictionary)
_slice.setValue((_data->offset.z - _data->gridMin.z)/_scale);
}
_programName = "DataPlaneProgram";
_vsPath = "${MODULE_ISWA}/shaders/dataplane_vs.glsl";
_fsPath = "${MODULE_ISWA}/shaders/dataplane_fs.glsl";
}
KameleonPlane::~KameleonPlane(){}
@@ -116,7 +120,7 @@ KameleonPlane::~KameleonPlane(){}
bool KameleonPlane::deinitialize(){
IswaCygnet::deinitialize();
_fieldlines.set(std::vector<int>());
// _kw = nullptr;
return true;
}
bool KameleonPlane::initialize(){
@@ -336,7 +340,7 @@ bool KameleonPlane::updateTexture(){
}
bool KameleonPlane::readyToRender(){
bool KameleonPlane::readyToRender() const {
return (!_textures.empty() && !_transferFunctions.empty());
}
@@ -399,18 +403,6 @@ void KameleonPlane::setUniformAndTextures(){
_shader->setUniform("transparency", _alpha.value());
}
bool KameleonPlane::createShader(){
if (_shader == nullptr) {
// DatePlane Program
RenderEngine& renderEngine = OsEng.renderEngine();
_shader = renderEngine.buildRenderProgram("DataPlaneProgram",
"${MODULE_ISWA}/shaders/dataplane_vs.glsl",
"${MODULE_ISWA}/shaders/dataplane_fs.glsl"
);
if (!_shader) return false;
}
}
void KameleonPlane::setTransferFunctions(std::string tfPath){
std::string line;
std::ifstream tfFile(absPath(tfPath));

View File

@@ -1,26 +1,26 @@
// ****************************************************************************************
// * *
// * OpenSpace *
// * *
// * Copyright (c) 2014-2015 *
// * *
// * Permission is hereby granted, free of charge, to any person obtaining a copy of this *
// * software and associated documentation files (the "Software"), to deal in the Software *
// * without restriction, including without limitation the rights to use, copy, modify, *
// * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
// * permit persons to whom the Software is furnished to do so, subject to the following *
// * conditions: *
// * *
// * The above copyright notice and this permission notice shall be included in all copies *
// * or substantial portions of the Software. *
// * *
// * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
// * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
// * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
// * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
// * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
// * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
// ***************************************************************************************
/****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2015 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __KAMELEONPLANE_H__
#define __KAMELEONPLANE_H__
@@ -46,9 +46,8 @@
virtual bool loadTexture() override;
virtual bool updateTexture() override;
virtual bool readyToRender() override;
virtual bool readyToRender() const override;
virtual void setUniformAndTextures() override;
virtual bool createShader() override;
/**
* Given a path to the json index of seedpoints file, this

View File

@@ -0,0 +1,95 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2016 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include <modules/iswa/rendering/texturecygnet.h>
#include <ghoul/io/texture/texturereader.h>
namespace {
const std::string _loggerCat = "TextureCygnet";
}
namespace openspace{
TextureCygnet::TextureCygnet(const ghoul::Dictionary& dictionary)
:IswaCygnet(dictionary)
{}
TextureCygnet::~TextureCygnet(){}
bool TextureCygnet::loadTexture() {
// if The future is done then get the new imageFile
DownloadManager::MemoryFile imageFile;
if(_futureObject.valid() && DownloadManager::futureReady(_futureObject)){
imageFile = _futureObject.get();
} else {
return false;
}
if(imageFile.corrupted)
return false;
std::unique_ptr<ghoul::opengl::Texture> texture = ghoul::io::TextureReader::ref().loadTexture(
(void*) imageFile.buffer,
imageFile.size,
imageFile.format);
if (texture) {
LDEBUG("Loaded texture from image iswa cygnet with id: '" << _data->id << "'");
texture->uploadTexture();
// Textures of planets looks much smoother with AnisotropicMipMap rather than linear
texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
_textures[0] = std::move(texture);
}
return false;
}
bool TextureCygnet::updateTexture(){
if(_textures.empty())
_textures.push_back(nullptr);
if(_futureObject.valid())
return false;
std::future<DownloadManager::MemoryFile> future = IswaManager::ref().fetchImageCygnet(_data->id);
if(future.valid()){
_futureObject = std::move(future);
return true;
}
return false;
}
bool TextureCygnet::readyToRender() const {
return (isReady() && ((!_textures.empty()) && (_textures[0] != nullptr)));
}
} //namespace openspace

View File

@@ -0,0 +1,57 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2016 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __TEXTURECYGNET_H__
#define __TEXTURECYGNET_H__
#include <modules/iswa/rendering/iswacygnet.h>
namespace openspace{
/**
* This class exist tp abstract away the loading of images
* from iSWA and updating of the textures for child geometries.
* The class specifies the minimum interface that child classes
* needs to implement.
*/
class TextureCygnet : public IswaCygnet {
public:
TextureCygnet(const ghoul::Dictionary& dictionary);
~TextureCygnet();
protected:
bool loadTexture() override;
bool updateTexture() override;
bool readyToRender() const override;
// Interface for concrete subclasses
virtual void setUniformAndTextures() = 0;
virtual bool createGeometry() = 0;
virtual bool destroyGeometry() = 0;
virtual void renderGeometry() const = 0;
};
} //namespace openspace
#endif //__TEXTURECYGNET_H__

View File

@@ -23,91 +23,31 @@
****************************************************************************************/
#include <modules/iswa/rendering/textureplane.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/rendering/renderengine.h>
//#include <ghoul/filesystem/filesystem>
#include <ghoul/io/texture/texturereader.h>
#include <ghoul/opengl/programobject.h>
#include <ghoul/opengl/texture.h>
#include <ghoul/opengl/textureunit.h>
#include <modules/kameleon/include/kameleonwrapper.h>
#include <openspace/scene/scene.h>
#include <openspace/scene/scenegraphnode.h>
#include <openspace/util/spicemanager.h>
namespace {
const std::string _loggerCat = "TexutePlane";
const std::string _loggerCat = "TexturePlane";
}
namespace openspace {
TexturePlane::TexturePlane(const ghoul::Dictionary& dictionary)
:CygnetPlane(dictionary)
:TextureCygnet(dictionary)
,_quad(0)
,_vertexPositionBuffer(0)
{
std::string name;
dictionary.getValue("Name", name);
setName(name);
registerProperties();
}
_programName = "PlaneProgram";
_vsPath = "${MODULE_ISWA}/shaders/cygnetplane_vs.glsl";
_fsPath = "${MODULE_ISWA}/shaders/cygnetplane_fs.glsl";
}
TexturePlane::~TexturePlane(){}
bool TexturePlane::loadTexture() {
// if The future is done then get the new imageFile
DownloadManager::MemoryFile imageFile;
if(_futureObject.valid() && DownloadManager::futureReady(_futureObject)){
imageFile = _futureObject.get();
}
else {
return false;
}
if(imageFile.corrupted)
return false;
std::unique_ptr<ghoul::opengl::Texture> texture = ghoul::io::TextureReader::ref().loadTexture(
(void*) imageFile.buffer,
imageFile.size,
imageFile.format);
if (texture) {
LDEBUG("Loaded texture from image iswa cygnet with id: '" << _data->id << "'");
texture->uploadTexture();
// Textures of planets looks much smoother with AnisotropicMipMap rather than linear
texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
_textures[0] = std::move(texture);
}
return false;
}
bool TexturePlane::updateTexture(){
if(_textures.empty())
_textures.push_back(nullptr);
if(_futureObject.valid())
return false;
std::future<DownloadManager::MemoryFile> future = IswaManager::ref().fetchImageCygnet(_data->id);
if(future.valid()){
_futureObject = std::move(future);
return true;
}
return false;
}
bool TexturePlane::readyToRender(){
return (isReady() && ((!_textures.empty()) && (_textures[0] != nullptr)));
}
void TexturePlane::setUniformAndTextures(){
ghoul::opengl::TextureUnit unit;
@@ -117,18 +57,54 @@ void TexturePlane::setUniformAndTextures(){
_shader->setUniform("transparency", _alpha.value());
}
bool TexturePlane::createGeometry() {
glGenVertexArrays(1, &_quad); // generate array
glGenBuffers(1, &_vertexPositionBuffer); // generate buffer
// ============================
// GEOMETRY (quad)
// ============================
float s = _data->spatialScale.x;
const GLfloat x = s*_data->scale.x/2.0;
const GLfloat y = s*_data->scale.y/2.0;
const GLfloat z = s*_data->scale.z/2.0;
const GLfloat w = _data->spatialScale.w;
const GLfloat vertex_data[] = { // square of two triangles (sigh)
// x y z w s t
-x, -y, -z, w, 0, 1,
x, y, z, w, 1, 0,
-x, ((x>0)?y:-y), z, w, 0, 0,
-x, -y, -z, w, 0, 1,
x, ((x>0)?-y:y), -z, w, 1, 1,
x, y, z, w, 1, 0,
};
glBindVertexArray(_quad); // bind array
glBindBuffer(GL_ARRAY_BUFFER, _vertexPositionBuffer); // bind buffer
glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_data), vertex_data, GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 6, reinterpret_cast<void*>(0));
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 6, reinterpret_cast<void*>(sizeof(GLfloat) * 4));
bool TexturePlane::createShader(){
if (_shader == nullptr) {
// Plane Program
RenderEngine& renderEngine = OsEng.renderEngine();
_shader = renderEngine.buildRenderProgram("PlaneProgram",
"${MODULE_ISWA}/shaders/cygnetplane_vs.glsl",
"${MODULE_ISWA}/shaders/cygnetplane_fs.glsl"
);
if (!_shader) return false;
}
return true;
}
bool TexturePlane::destroyGeometry(){
glDeleteVertexArrays(1, &_quad);
_quad = 0;
glDeleteBuffers(1, &_vertexPositionBuffer);
_vertexPositionBuffer = 0;
return true;
}
void TexturePlane::renderGeometry() const {
glBindVertexArray(_quad);
glDrawArrays(GL_TRIANGLES, 0, 6);
}
}// namespace openspace

View File

@@ -2,7 +2,7 @@
* *
* OpenSpace *
* *
* Copyright (c) 2014-2015 *
* Copyright (c) 2014-2016 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
@@ -25,25 +25,29 @@
#ifndef __TEXTUREPLANE_H__
#define __TEXTUREPLANE_H__
#include <modules/iswa/rendering/cygnetplane.h>
#include <ghoul/opengl/texture.h>
#include <openspace/engine/downloadmanager.h>
#include <modules/iswa/rendering/texturecygnet.h>
namespace openspace{
class TexturePlane : public CygnetPlane{
public:
TexturePlane(const ghoul::Dictionary& dictionary);
~TexturePlane();
namespace openspace{
private:
virtual bool loadTexture() override;
virtual bool updateTexture() override;
/**
* TexturePlane is a "concrete" IswaCygnet. It handles the creation,
* destruction and rendering of a plane geometry. It also specifies
* which shaders to use and the uniforms that it needs.
*/
class TexturePlane : public TextureCygnet{
public:
TexturePlane(const ghoul::Dictionary& dictionary);
~TexturePlane();
virtual bool readyToRender() override;
virtual void setUniformAndTextures() override;
virtual bool createShader() override;
};
private:
bool createGeometry() override;
void setUniformAndTextures() override;
bool destroyGeometry() override;
void renderGeometry() const override;
GLuint _quad;
GLuint _vertexPositionBuffer;
};
} // namespace openspace

View File

@@ -470,6 +470,7 @@ void IswaManager::createSphere(std::shared_ptr<MetadataFuture> data){
if(!data->group.empty()){
std::string type = typeid(DataSphere).name();
registerGroup(data->group, type);
auto it = _groups.find(data->group);
if(it == _groups.end() || (*it).second->isType(type)){