mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-07 04:00:37 -06:00
Create dataplane through dataSurfaceContainer moudle
This commit is contained in:
@@ -3,7 +3,7 @@ return {
|
||||
Name = "DataSurfaces",
|
||||
Parent = "Root",
|
||||
Renderable = {
|
||||
Type = "RenderableDataPlane"
|
||||
Type = "DataSurfaceContainer"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -87,18 +87,6 @@ return {
|
||||
Position = {0, 0, 0, 5}
|
||||
}
|
||||
}
|
||||
--,
|
||||
--{
|
||||
-- Name = "EarthPlane",
|
||||
-- Parent = "Earth",
|
||||
-- Renderable = {
|
||||
-- Type = "RenderableDataPlane"
|
||||
-- },
|
||||
-- Ephemeris = {
|
||||
-- Type = "Static",
|
||||
-- Position = {10, 0, 0, 1}
|
||||
-- }
|
||||
--}
|
||||
-- Plane
|
||||
-- {
|
||||
-- Name = "EarthPlane",
|
||||
|
||||
@@ -25,12 +25,16 @@
|
||||
include(${OPENSPACE_CMAKE_EXT_DIR}/module_definition.cmake)
|
||||
|
||||
set(HEADER_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderabledataplane.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/datasurfacecontainer.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/datasurface.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/dataplane.h
|
||||
)
|
||||
source_group("Header Files" FILES ${HEADER_FILES})
|
||||
|
||||
set(SOURCE_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderabledataplane.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/datasurfacecontainer.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/datasurface.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/dataplane.cpp
|
||||
|
||||
)
|
||||
source_group("Source Files" FILES ${SOURCE_FILES})
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
|
||||
#include <ghoul/misc/assert.h>
|
||||
|
||||
#include <modules/datasurface/rendering/renderabledataplane.h>
|
||||
#include <modules/datasurface/rendering/datasurfacecontainer.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
@@ -41,6 +41,6 @@
|
||||
auto fRenderable = FactoryManager::ref().factory<Renderable>();
|
||||
ghoul_assert(fRenderable, "No renderable factory existed");
|
||||
|
||||
fRenderable->registerClass<RenderableDataPlane>("RenderableDataPlane");
|
||||
fRenderable->registerClass<DataSurfaceContainer>("DataSurfaceContainer");
|
||||
}
|
||||
}
|
||||
189
modules/datasurface/rendering/dataplane.cpp
Normal file
189
modules/datasurface/rendering/dataplane.cpp
Normal file
@@ -0,0 +1,189 @@
|
||||
// /*****************************************************************************************
|
||||
// * *
|
||||
// * 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/datasurface/rendering/dataplane.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>
|
||||
|
||||
|
||||
namespace openspace {
|
||||
|
||||
DataPlane::DataPlane(std::shared_ptr<KameleonWrapper> kw, std::string path)
|
||||
:DataSurface(kw, path)
|
||||
,_texture(nullptr)
|
||||
, _quad(0)
|
||||
, _vertexPositionBuffer(0)
|
||||
{}
|
||||
|
||||
|
||||
DataPlane::~DataPlane(){}
|
||||
|
||||
|
||||
bool DataPlane::initialize(){
|
||||
DataSurface::initialize();
|
||||
|
||||
_dimensions = glm::size3_t(1000,1000,1);
|
||||
float zSlice = 0.5f;
|
||||
|
||||
_dataSlice = _kw->getUniformSliceValues(std::string("p"), _dimensions, zSlice);
|
||||
|
||||
glGenVertexArrays(1, &_quad); // generate array
|
||||
glGenBuffers(1, &_vertexPositionBuffer); // generate buffer
|
||||
createPlane();
|
||||
|
||||
if (_shader == nullptr) {
|
||||
// Plane Program
|
||||
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
_shader = renderEngine.buildRenderProgram("PlaneProgram",
|
||||
"${MODULE_DATASURFACE}/shaders/dataplane_vs.glsl",
|
||||
"${MODULE_DATASURFACE}/shaders/dataplane_fs.glsl"
|
||||
);
|
||||
if (!_shader)
|
||||
return false;
|
||||
}
|
||||
|
||||
loadTexture();
|
||||
|
||||
return isReady();
|
||||
}
|
||||
|
||||
bool DataPlane::deinitialize(){
|
||||
DataSurface::deinitialize();
|
||||
|
||||
glDeleteVertexArrays(1, &_quad);
|
||||
_quad = 0;
|
||||
|
||||
glDeleteBuffers(1, &_vertexPositionBuffer);
|
||||
_vertexPositionBuffer = 0;
|
||||
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
if (_shader) {
|
||||
renderEngine.removeRenderProgram(_shader);
|
||||
_shader = nullptr;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool DataPlane::isReady() const {
|
||||
bool ready = true;
|
||||
if (!_shader)
|
||||
ready &= false;
|
||||
if(!_texture)
|
||||
ready &= false;
|
||||
return ready;
|
||||
};
|
||||
|
||||
void DataPlane::render(){
|
||||
psc position = _parent->worldPosition();
|
||||
position += glm::vec4(-_pscOffset.x, _pscOffset.y, _pscOffset.z, _pscOffset.w);
|
||||
|
||||
glm::mat4 transform = glm::mat4(1.0);
|
||||
// transform = glm::rotate(transform, _roatation.value()[0], glm::vec3(1,0,0));
|
||||
// transform = glm::rotate(transform, _roatation.value()[1], glm::vec3(0,1,0));
|
||||
// transform = glm::rotate(transform, _roatation.value()[2], glm::vec3(0,0,1));
|
||||
|
||||
// Activate shader
|
||||
_shader->activate();
|
||||
glEnable(GL_ALPHA_TEST);
|
||||
glDisable(GL_CULL_FACE);
|
||||
|
||||
_shader->setUniform("ViewProjection", OsEng.renderEngine().camera()->viewProjectionMatrix());
|
||||
_shader->setUniform("ModelTransform", transform);
|
||||
setPscUniforms(_shader.get(), OsEng.renderEngine().camera(), position);
|
||||
|
||||
ghoul::opengl::TextureUnit unit;
|
||||
unit.activate();
|
||||
_texture->bind();
|
||||
_shader->setUniform("texture1", unit);
|
||||
|
||||
glBindVertexArray(_quad);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
glEnable(GL_CULL_FACE);
|
||||
_shader->deactivate();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void DataPlane::loadTexture() {
|
||||
|
||||
//std::unique_ptr<ghoul::opengl::Texture> texture = ghoul::io::TextureReader::ref().loadTexture(absPath(_texturePath));
|
||||
ghoul::opengl::Texture::FilterMode filtermode = ghoul::opengl::Texture::FilterMode::Linear;
|
||||
ghoul::opengl::Texture::WrappingMode wrappingmode = ghoul::opengl::Texture::WrappingMode::ClampToEdge;
|
||||
std::unique_ptr<ghoul::opengl::Texture> texture =
|
||||
std::make_unique<ghoul::opengl::Texture>(_dataSlice, _dimensions, ghoul::opengl::Texture::Format::Red, GL_RED, GL_FLOAT, filtermode, wrappingmode);
|
||||
if (texture) {
|
||||
// std::cout << "texture path: " << absPath(_texturePath) << std::endl;
|
||||
// LDEBUG("Loaded texture from '" << absPath(_texturePath) << "'");
|
||||
|
||||
texture->uploadTexture();
|
||||
|
||||
// Textures of planets looks much smoother with AnisotropicMipMap rather than linear
|
||||
texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
|
||||
|
||||
_texture = std::move(texture);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void DataPlane::createPlane() {
|
||||
// ============================
|
||||
// GEOMETRY (quad)
|
||||
// ============================
|
||||
const GLfloat x = _modelScale.x/2.0;
|
||||
const GLfloat y = _modelScale.y/2.0;
|
||||
const GLfloat w = _modelScale.w;
|
||||
const GLfloat vertex_data[] = { // square of two triangles (sigh)
|
||||
// x y z w s t
|
||||
-x, -y, 0.0f, w, 0, 1,
|
||||
x, y, 0.0f, w, 1, 0,
|
||||
-x, y, 0.0f, w, 0, 0,
|
||||
-x, -y, 0.0f, w, 0, 1,
|
||||
x, -y, 0.0f, w, 1, 1,
|
||||
x, y, 0.0f, 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));
|
||||
}
|
||||
|
||||
}// namespace openspace
|
||||
@@ -22,10 +22,11 @@
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef __RENDERABLEDATAPLANE_H__
|
||||
#define __RENDERABLEDATAPLANE_H__
|
||||
#ifndef __DATAPLANE_H__
|
||||
#define __DATAPLANE_H__
|
||||
|
||||
#include <openspace/rendering/renderable.h>
|
||||
// #include <openspace/rendering/renderable.h>
|
||||
#include <modules/datasurface/rendering/datasurface.h>
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
#include <openspace/properties/vectorproperty.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
@@ -34,40 +35,37 @@
|
||||
|
||||
namespace openspace{
|
||||
|
||||
class RenderableDataPlane : public Renderable {
|
||||
class DataPlane : public DataSurface {
|
||||
public:
|
||||
RenderableDataPlane(const ghoul::Dictionary& dictionary);
|
||||
~RenderableDataPlane();
|
||||
DataPlane(std::shared_ptr<KameleonWrapper> kw, std::string path);
|
||||
~DataPlane();
|
||||
|
||||
bool initialize() override;
|
||||
bool deinitialize() override;
|
||||
virtual bool initialize();
|
||||
virtual bool deinitialize();
|
||||
|
||||
bool isReady() const override;
|
||||
bool isReady() const;
|
||||
|
||||
virtual void render(const RenderData& data) override;
|
||||
virtual void update(const UpdateData& data) override;
|
||||
virtual void render();
|
||||
// virtual void update();
|
||||
|
||||
private:
|
||||
|
||||
void loadTexture();
|
||||
void createPlane();
|
||||
|
||||
properties::StringProperty _texturePath;
|
||||
properties::Vec3Property _roatation;
|
||||
// properties::StringProperty _texturePath;
|
||||
// properties::Vec3Property _roatation;
|
||||
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _shader;
|
||||
// std::unique_ptr<ghoul::opengl::ProgramObject> _shader;
|
||||
std::unique_ptr<ghoul::opengl::Texture> _texture;
|
||||
|
||||
float* _dataSlice;
|
||||
glm::size3_t _dimensions;
|
||||
glm::vec4 _pscOffset;
|
||||
glm::vec4 _modelScale;
|
||||
psc _parentPos;
|
||||
|
||||
GLuint _quad;
|
||||
GLuint _vertexPositionBuffer;
|
||||
|
||||
KameleonWrapper* _kw;
|
||||
bool _planeIsDirty;
|
||||
// bool _planeIsDirty;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
66
modules/datasurface/rendering/datasurface.cpp
Normal file
66
modules/datasurface/rendering/datasurface.cpp
Normal file
@@ -0,0 +1,66 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
#include <modules/datasurface/rendering/datasurface.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/scene/scene.h>
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
|
||||
namespace openspace{
|
||||
DataSurface::DataSurface(std::shared_ptr<KameleonWrapper> kw, std::string path)
|
||||
:_kw(kw)
|
||||
,_path("path", "Path", path)
|
||||
,_shader(nullptr)
|
||||
{}
|
||||
|
||||
DataSurface::~DataSurface(){}
|
||||
|
||||
bool DataSurface::initialize(){
|
||||
_parent = OsEng.renderEngine().scene()->sceneGraphNode("Earth");
|
||||
|
||||
_modelScale = _kw->getModelScaleScaled();
|
||||
_pscOffset = _kw->getModelBarycenterOffsetScaled();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DataSurface::deinitialize(){
|
||||
_parent = nullptr;
|
||||
}
|
||||
|
||||
void DataSurface::render(){
|
||||
|
||||
}
|
||||
|
||||
void DataSurface::setPscUniforms(
|
||||
ghoul::opengl::ProgramObject* program,
|
||||
const Camera* camera,
|
||||
const PowerScaledCoordinate& position)
|
||||
{
|
||||
program->setUniform("campos", camera->position().vec4());
|
||||
program->setUniform("objpos", position.vec4());
|
||||
program->setUniform("camrot", camera->viewRotationMatrix());
|
||||
program->setUniform("scaling", camera->scaling());
|
||||
}
|
||||
}//namespace openspac
|
||||
58
modules/datasurface/rendering/datasurface.h
Normal file
58
modules/datasurface/rendering/datasurface.h
Normal file
@@ -0,0 +1,58 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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 __DATASURFACE_H__
|
||||
#define __DATASURFACE_H__
|
||||
#include <openspace/properties/propertyowner.h>
|
||||
#include <memory>
|
||||
#include <modules/kameleon/include/kameleonwrapper.h>
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
|
||||
namespace openspace{
|
||||
class DataSurface : public properties::PropertyOwner{
|
||||
public:
|
||||
DataSurface(std::shared_ptr<KameleonWrapper> kw, std::string path);
|
||||
~DataSurface();
|
||||
|
||||
virtual bool initialize();
|
||||
virtual bool deinitialize();
|
||||
|
||||
virtual void render();
|
||||
// virtual void update();
|
||||
|
||||
protected:
|
||||
void setPscUniforms(ghoul::opengl::ProgramObject* program, const Camera* camera, const PowerScaledCoordinate& position);
|
||||
|
||||
std::shared_ptr<KameleonWrapper> _kw;
|
||||
properties::StringProperty _path;
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _shader;
|
||||
|
||||
glm::vec4 _pscOffset;
|
||||
glm::vec4 _modelScale;
|
||||
SceneGraphNode* _parent;
|
||||
};
|
||||
|
||||
}//namespace openspace
|
||||
#endif
|
||||
70
modules/datasurface/rendering/datasurfacecontainer.cpp
Normal file
70
modules/datasurface/rendering/datasurfacecontainer.cpp
Normal file
@@ -0,0 +1,70 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
#include <modules/datasurface/rendering/datasurfacecontainer.h>
|
||||
#include <modules/kameleon/include/kameleonwrapper.h>
|
||||
#include <ghoul/filesystem/filesystem>
|
||||
|
||||
#include <modules/datasurface/rendering/datasurface.h>
|
||||
#include <modules/datasurface/rendering/dataplane.h>
|
||||
|
||||
namespace openspace{
|
||||
DataSurfaceContainer::DataSurfaceContainer(const ghoul::Dictionary& dictionary)
|
||||
:Renderable(dictionary)
|
||||
{
|
||||
std::cout << "Created datasurface container" << std::endl;
|
||||
}
|
||||
|
||||
DataSurfaceContainer::~DataSurfaceContainer(){}
|
||||
|
||||
bool DataSurfaceContainer::initialize(){
|
||||
std::cout << "Initialized datasurface container" << std::endl;
|
||||
|
||||
addDataSurface("${OPENSPACE_DATA}/BATSRUS.cdf");
|
||||
}
|
||||
bool DataSurfaceContainer::deinitialize(){}
|
||||
bool DataSurfaceContainer::isReady() const {}
|
||||
|
||||
void DataSurfaceContainer::render(const RenderData& data){
|
||||
for(dataSurface : _dataSurfaces)
|
||||
dataSurface->render();
|
||||
}
|
||||
|
||||
void DataSurfaceContainer::update(const UpdateData& data){}
|
||||
|
||||
void DataSurfaceContainer::addDataSurface(std::string path){
|
||||
if(FileSys.fileExists(absPath(path))) {
|
||||
std::shared_ptr<DataSurface> ds;
|
||||
std::shared_ptr<KameleonWrapper> kw = std::make_shared<KameleonWrapper>(absPath(path));
|
||||
|
||||
//find out what class to create
|
||||
ds = std::make_shared<DataPlane>(kw, path);
|
||||
|
||||
|
||||
ds->initialize();
|
||||
_dataSurfaces.push_back(ds);
|
||||
}else{
|
||||
std::cout << "file does not exist";
|
||||
}
|
||||
}
|
||||
}
|
||||
53
modules/datasurface/rendering/datasurfacecontainer.h
Normal file
53
modules/datasurface/rendering/datasurfacecontainer.h
Normal file
@@ -0,0 +1,53 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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 __DATASURFACECONTAINER_H__
|
||||
#define __DATASURFACECONTAINER_H__
|
||||
#include <openspace/rendering/renderable.h>
|
||||
|
||||
namespace openspace{
|
||||
class DataSurface;
|
||||
|
||||
class DataSurfaceContainer : public Renderable {
|
||||
public:
|
||||
DataSurfaceContainer(const ghoul::Dictionary& dictionary);
|
||||
~DataSurfaceContainer();
|
||||
|
||||
bool initialize() override;
|
||||
bool deinitialize() override;
|
||||
|
||||
bool isReady() const override;
|
||||
|
||||
virtual void render(const RenderData& data) override;
|
||||
virtual void update(const UpdateData& data) override;
|
||||
|
||||
void addDataSurface(std::string path);
|
||||
|
||||
private:
|
||||
std::vector<std::shared_ptr<DataSurface>> _dataSurfaces;
|
||||
|
||||
};
|
||||
}//namespace openspace
|
||||
|
||||
#endif
|
||||
@@ -1,217 +0,0 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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/datasurface/rendering/renderabledataplane.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>
|
||||
|
||||
|
||||
namespace openspace {
|
||||
|
||||
RenderableDataPlane::RenderableDataPlane(const ghoul::Dictionary& dictionary)
|
||||
: Renderable(dictionary)
|
||||
,_texturePath("texture", "Texture", "${OPENSPACE_DATA}/test.png")
|
||||
,_roatation("rotation", "Roatation", glm::vec3(0), glm::vec3(0), glm::vec3(2*M_PI))
|
||||
, _shader(nullptr)
|
||||
, _texture(nullptr)
|
||||
, _quad(0)
|
||||
, _vertexPositionBuffer(0)
|
||||
{
|
||||
std::cout << "Creating RenderableDataPlane" << std::endl;
|
||||
|
||||
addProperty(_texturePath);
|
||||
addProperty(_roatation);
|
||||
|
||||
_texturePath.onChange(std::bind(&RenderableDataPlane::loadTexture, this));
|
||||
|
||||
}
|
||||
|
||||
|
||||
RenderableDataPlane::~RenderableDataPlane(){
|
||||
}
|
||||
|
||||
bool RenderableDataPlane::initialize() {
|
||||
|
||||
KameleonWrapper kw(absPath("${OPENSPACE_DATA}/BATSRUS.cdf"));
|
||||
|
||||
_dimensions = glm::size3_t(1000,1000,1);
|
||||
float zSlice = 0.5f;
|
||||
|
||||
_dataSlice = kw.getUniformSliceValues(std::string("p"), _dimensions, zSlice);
|
||||
|
||||
_modelScale = kw.getModelScaleScaled();
|
||||
_pscOffset = kw.getModelBarycenterOffsetScaled();
|
||||
|
||||
std::cout << "Scale: " << _modelScale.x << ", " << _modelScale.y << ", " << _modelScale.z << ", " << _modelScale.w << std::endl;
|
||||
std::cout << "Offset: " << _pscOffset.x << ", " << _pscOffset.y << ", " << _pscOffset.z << ", " << _pscOffset.w << std::endl;
|
||||
|
||||
|
||||
|
||||
glGenVertexArrays(1, &_quad); // generate array
|
||||
glGenBuffers(1, &_vertexPositionBuffer); // generate buffer
|
||||
createPlane();
|
||||
|
||||
if (_shader == nullptr) {
|
||||
// Plane Program
|
||||
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
_shader = renderEngine.buildRenderProgram("PlaneProgram",
|
||||
"${MODULE_DATASURFACE}/shaders/dataplane_vs.glsl",
|
||||
"${MODULE_DATASURFACE}/shaders/dataplane_fs.glsl"
|
||||
);
|
||||
if (!_shader)
|
||||
return false;
|
||||
}
|
||||
|
||||
loadTexture();
|
||||
|
||||
return isReady();
|
||||
};
|
||||
bool RenderableDataPlane::deinitialize() {
|
||||
glDeleteVertexArrays(1, &_quad);
|
||||
_quad = 0;
|
||||
|
||||
glDeleteBuffers(1, &_vertexPositionBuffer);
|
||||
_vertexPositionBuffer = 0;
|
||||
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
if (_shader) {
|
||||
renderEngine.removeRenderProgram(_shader);
|
||||
_shader = nullptr;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
bool RenderableDataPlane::isReady() const {
|
||||
bool ready = true;
|
||||
if (!_shader)
|
||||
ready &= false;
|
||||
if(!_texture)
|
||||
ready &= false;
|
||||
return ready;
|
||||
};
|
||||
|
||||
void RenderableDataPlane::render(const RenderData& data)
|
||||
{
|
||||
|
||||
auto parent = OsEng.renderEngine().scene()->sceneGraphNode("Earth");
|
||||
psc _parentPos = parent->worldPosition();
|
||||
glm::dvec4 pos = _parentPos.dvec4();
|
||||
// std::cout << pos.x << ", " << pos.y << ", " << pos.z << ", " << pos.w << std::endl;
|
||||
// std::cout << parent->name() << std::endl;
|
||||
|
||||
// float w = (float)_texture->width();
|
||||
// float h = (float)_texture->height();
|
||||
// float textureRatio = h/w;
|
||||
|
||||
glm::mat4 transform = glm::mat4(1.0);
|
||||
transform = glm::rotate(transform, _roatation.value()[0], glm::vec3(1,0,0));
|
||||
transform = glm::rotate(transform, _roatation.value()[1], glm::vec3(0,1,0));
|
||||
transform = glm::rotate(transform, _roatation.value()[2], glm::vec3(0,0,1));
|
||||
|
||||
// Activate shader
|
||||
_shader->activate();
|
||||
glEnable(GL_ALPHA_TEST);
|
||||
glDisable(GL_CULL_FACE);
|
||||
auto psc = _parentPos;
|
||||
glm::dvec4 dpc = psc.dvec4();
|
||||
psc += glm::vec4(-_pscOffset.x, _pscOffset.y, _pscOffset.z, _pscOffset.w);
|
||||
std::cout << dpc.x << ", " << dpc.y << ", " << dpc.z << ", " << dpc.w << std::endl;
|
||||
_shader->setUniform("ViewProjection", data.camera.viewProjectionMatrix());
|
||||
_shader->setUniform("ModelTransform", transform);
|
||||
setPscUniforms(_shader.get(), &data.camera, psc);
|
||||
|
||||
ghoul::opengl::TextureUnit unit;
|
||||
unit.activate();
|
||||
_texture->bind();
|
||||
_shader->setUniform("texture1", unit);
|
||||
|
||||
glBindVertexArray(_quad);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
glEnable(GL_CULL_FACE);
|
||||
_shader->deactivate();
|
||||
};
|
||||
void RenderableDataPlane::update(const UpdateData& data){
|
||||
if (_planeIsDirty)
|
||||
createPlane();
|
||||
};
|
||||
|
||||
|
||||
void RenderableDataPlane::loadTexture() {
|
||||
if (_texturePath.value() != "") {
|
||||
//std::unique_ptr<ghoul::opengl::Texture> texture = ghoul::io::TextureReader::ref().loadTexture(absPath(_texturePath));
|
||||
ghoul::opengl::Texture::FilterMode filtermode = ghoul::opengl::Texture::FilterMode::Linear;
|
||||
ghoul::opengl::Texture::WrappingMode wrappingmode = ghoul::opengl::Texture::WrappingMode::ClampToEdge;
|
||||
std::unique_ptr<ghoul::opengl::Texture> texture =
|
||||
std::make_unique<ghoul::opengl::Texture>(_dataSlice, _dimensions, ghoul::opengl::Texture::Format::Red, GL_RED, GL_FLOAT, filtermode, wrappingmode);
|
||||
if (texture) {
|
||||
std::cout << "texture path: " << absPath(_texturePath) << std::endl;
|
||||
// LDEBUG("Loaded texture from '" << absPath(_texturePath) << "'");
|
||||
|
||||
texture->uploadTexture();
|
||||
|
||||
// Textures of planets looks much smoother with AnisotropicMipMap rather than linear
|
||||
texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
|
||||
|
||||
_texture = std::move(texture);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RenderableDataPlane::createPlane() {
|
||||
// ============================
|
||||
// GEOMETRY (quad)
|
||||
// ============================
|
||||
const GLfloat x = _modelScale.x/2.0;
|
||||
const GLfloat y = _modelScale.y/2.0;
|
||||
const GLfloat w = _modelScale.w;
|
||||
const GLfloat vertex_data[] = { // square of two triangles (sigh)
|
||||
// x y z w s t
|
||||
-x, -y, 0.0f, w, 0, 1,
|
||||
x, y, 0.0f, w, 1, 0,
|
||||
-x, y, 0.0f, w, 0, 0,
|
||||
-x, -y, 0.0f, w, 0, 1,
|
||||
x, -y, 0.0f, w, 1, 1,
|
||||
x, y, 0.0f, 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));
|
||||
_planeIsDirty = false;
|
||||
}
|
||||
}// namespace openspace
|
||||
Reference in New Issue
Block a user