mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-24 21:39:02 -05:00
Track down the rendering problem for geometry and remove test classes.
This commit is contained in:
@@ -25,14 +25,9 @@ return {
|
||||
Name = "Earth",
|
||||
Parent = "EarthBarycenter",
|
||||
Renderable = {
|
||||
Type = "RenderableTestPlanet",
|
||||
Type = "Planet",
|
||||
Frame = "IAU_EARTH",
|
||||
Body = "EARTH",
|
||||
Geometry = {
|
||||
Type = "SimpleSphereTest",
|
||||
Radius = { 6.371, 6 },
|
||||
Segments = 100
|
||||
},
|
||||
Textures = {
|
||||
Type = "simple",
|
||||
Color = "textures/earth_bluemarble.jpg",
|
||||
|
||||
@@ -27,18 +27,12 @@ include(${OPENSPACE_CMAKE_EXT_DIR}/module_definition.cmake)
|
||||
set(HEADER_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/planet.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/geometry.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderabletestplanet.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/planettestgeometry.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/simplespheretestgeometry.h
|
||||
)
|
||||
source_group("Header Files" FILES ${HEADER_FILES})
|
||||
|
||||
set(SOURCE_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/planet.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/geometry.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderabletestplanet.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/planettestgeometry.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/simplespheretestgeometry.cpp
|
||||
)
|
||||
source_group("Source Files" FILES ${SOURCE_FILES})
|
||||
|
||||
|
||||
@@ -25,9 +25,6 @@
|
||||
#include <modules/planetbrowsing/planetbrowsingmodule.h>
|
||||
|
||||
#include <modules/planetbrowsing/rendering/planet.h>
|
||||
#include <modules/planetbrowsing/rendering/renderabletestplanet.h>
|
||||
#include <modules/planetbrowsing/rendering/planettestgeometry.h>
|
||||
#include <modules/planetbrowsing/rendering/simplespheretestgeometry.h>
|
||||
|
||||
#include <openspace/rendering/renderable.h>
|
||||
#include <openspace/util/factorymanager.h>
|
||||
@@ -60,17 +57,10 @@ void PlanetBrowsingModule::internalInitialize() {
|
||||
|
||||
|
||||
|
||||
FactoryManager::ref().addFactory(std::make_unique<ghoul::TemplateFactory<planettestgeometry::PlanetTestGeometry>>());
|
||||
|
||||
auto fRenderable = FactoryManager::ref().factory<Renderable>();
|
||||
ghoul_assert(fRenderable, "Renderable factory was not created");
|
||||
|
||||
fRenderable->registerClass<RenderableTestPlanet>("RenderableTestPlanet");
|
||||
|
||||
|
||||
auto fPlanetGeometry = FactoryManager::ref().factory<planettestgeometry::PlanetTestGeometry>();
|
||||
ghoul_assert(fPlanetGeometry, "Planet test geometry factory was not created");
|
||||
fPlanetGeometry->registerClass<planettestgeometry::SimpleSphereTestGeometry>("SimpleSphereTest");
|
||||
fRenderable->registerClass<Planet>("Planet");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -95,8 +95,8 @@ bool Geometry::initialize() {
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vertexBufferID);
|
||||
glBufferData(
|
||||
GL_ARRAY_BUFFER,
|
||||
_elementData.size() * sizeof(Vertex),
|
||||
&_elementData[0],
|
||||
_vertexData.size() * sizeof(Vertex),
|
||||
&_vertexData[0],
|
||||
GL_STATIC_DRAW);
|
||||
|
||||
// Positions at location 0
|
||||
|
||||
@@ -23,131 +23,258 @@
|
||||
****************************************************************************************/
|
||||
|
||||
// open space includes
|
||||
#include <modules/planetbrowsing/rendering/Planet.h>
|
||||
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/engine/configurationmanager.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <modules/planetbrowsing/rendering/planet.h>
|
||||
#include <openspace/util/time.h>
|
||||
#include <openspace/util/spicemanager.h>
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
|
||||
#include <modules/base/rendering/planetgeometry.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/misc/assert.h>
|
||||
#include <ghoul/io/texture/texturereader.h>
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
#include <ghoul/opengl/textureunit.h>
|
||||
|
||||
|
||||
#include <vector>
|
||||
#include <glm/glm.hpp>
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "Planet";
|
||||
const std::string keyGeometry = "Geometry";
|
||||
|
||||
const std::string keyFrame = "Frame";
|
||||
const std::string keyGeometry = "Geometry";
|
||||
const std::string keyShading = "PerformShading";
|
||||
|
||||
const std::string keyBody = "Body";
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
|
||||
Planet::Planet(const ghoul::Dictionary& dictionary) :
|
||||
Renderable(dictionary),
|
||||
_geometry(nullptr),
|
||||
_testProgramObject(nullptr)
|
||||
{
|
||||
std::string name;
|
||||
bool success = dictionary.getValue(SceneGraphNode::KeyName, name);
|
||||
LDEBUG(name);
|
||||
Planet::Planet(const ghoul::Dictionary& dictionary)
|
||||
: Renderable(dictionary)
|
||||
, _colorTexturePath("colorTexture", "Color Texture")
|
||||
, _programObject(nullptr)
|
||||
, _texture(nullptr)
|
||||
, _nightTexture(nullptr)
|
||||
, _performShading("performShading", "Perform Shading", true)
|
||||
, _rotation("rotation", "Rotation", 0, 0, 360)
|
||||
, _alpha(1.f)
|
||||
, _nightTexturePath("")
|
||||
, _hasNightTexture(false)
|
||||
{
|
||||
std::string name;
|
||||
bool success = dictionary.getValue(SceneGraphNode::KeyName, name);
|
||||
ghoul_assert(success,
|
||||
"RenderablePlanet need the '" << SceneGraphNode::KeyName << "' be specified");
|
||||
|
||||
ghoul_assert(success,
|
||||
"Planet need the '" << SceneGraphNode::KeyName << "' be specified");
|
||||
//std::string path;
|
||||
//success = dictionary.getValue(constants::scenegraph::keyPathModule, path);
|
||||
//ghoul_assert(success,
|
||||
// "RenderablePlanet need the '"<<constants::scenegraph::keyPathModule<<"' be specified");
|
||||
|
||||
dictionary.getValue(keyFrame, _frame);
|
||||
dictionary.getValue(keyBody, _target);
|
||||
if (_target != "")
|
||||
setBody(_target);
|
||||
|
||||
// TODO: textures need to be replaced by a good system similar to the geometry as soon
|
||||
// as the requirements are fixed (ab)
|
||||
std::string texturePath = "";
|
||||
success = dictionary.getValue("Textures.Color", texturePath);
|
||||
if (success)
|
||||
_colorTexturePath = absPath(texturePath);
|
||||
|
||||
std::string nightTexturePath = "";
|
||||
dictionary.getValue("Textures.Night", nightTexturePath);
|
||||
|
||||
if (nightTexturePath != "") {
|
||||
_hasNightTexture = true;
|
||||
_nightTexturePath = absPath(nightTexturePath);
|
||||
}
|
||||
|
||||
addProperty(_colorTexturePath);
|
||||
_colorTexturePath.onChange(std::bind(&Planet::loadTexture, this));
|
||||
|
||||
if (dictionary.hasKeyAndValue<bool>(keyShading)) {
|
||||
bool shading;
|
||||
dictionary.getValue(keyShading, shading);
|
||||
_performShading = shading;
|
||||
}
|
||||
|
||||
addProperty(_performShading);
|
||||
// Mainly for debugging purposes @AA
|
||||
addProperty(_rotation);
|
||||
|
||||
|
||||
ghoul::Dictionary geometryDictionary;
|
||||
success = dictionary.getValue(keyGeometry, geometryDictionary);
|
||||
if (success) {
|
||||
geometryDictionary.setValue(SceneGraphNode::KeyName, name);
|
||||
//geometryDictionary.setValue(constants::scenegraph::keyPathModule, path);
|
||||
_geometry = planetgeometry::PlanetGeometry::createFromDictionary(geometryDictionary);
|
||||
// Create a simple triangle for testing the geometry
|
||||
std::vector<unsigned int> triangleElements;
|
||||
std::vector<glm::vec4> trianglePositions;
|
||||
|
||||
trianglePositions.push_back(glm::vec4(0, 0, 0, 1));
|
||||
trianglePositions.push_back(glm::vec4(10000000, 0, 0, 1));
|
||||
trianglePositions.push_back(glm::vec4(10000000, 10000000, 0, 1));
|
||||
|
||||
triangleElements.push_back(0);
|
||||
triangleElements.push_back(1);
|
||||
triangleElements.push_back(2);
|
||||
|
||||
_testGeometry = std::unique_ptr<Geometry>(new Geometry(
|
||||
triangleElements,
|
||||
Geometry::Positions::Yes,
|
||||
Geometry::Textures::No,
|
||||
Geometry::Normals::No));
|
||||
|
||||
_testGeometry->setPositionData(trianglePositions);
|
||||
_testGeometry->initialize();
|
||||
|
||||
}
|
||||
|
||||
addPropertySubOwner(_geometry);
|
||||
|
||||
/*
|
||||
// Create a simple triangle for testing the geometry
|
||||
std::vector<unsigned int> triangleElements;
|
||||
std::vector<glm::vec4> trianglePositions;
|
||||
|
||||
trianglePositions.push_back(glm::vec4(0, 0, -0.5, 1));
|
||||
trianglePositions.push_back(glm::vec4(1, 0, -0.5, 1));
|
||||
trianglePositions.push_back(glm::vec4(1, 1, -0.5, 1));
|
||||
|
||||
triangleElements.push_back(0);
|
||||
triangleElements.push_back(1);
|
||||
triangleElements.push_back(2);
|
||||
|
||||
_testGeometry = std::unique_ptr<Geometry>(new Geometry(
|
||||
triangleElements,
|
||||
Geometry::Positions::Yes,
|
||||
Geometry::Textures::No,
|
||||
Geometry::Normals::No));
|
||||
|
||||
_testGeometry->setPositionData(trianglePositions);
|
||||
_testGeometry->initialize();
|
||||
*/
|
||||
// Create a test shader program object
|
||||
|
||||
}
|
||||
|
||||
Planet::~Planet() {
|
||||
|
||||
}
|
||||
|
||||
bool Planet::initialize() {
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
if (_testProgramObject == nullptr) {
|
||||
_testProgramObject = renderEngine.buildRenderProgram(
|
||||
"simpleTestProgram",
|
||||
"${MODULE_PLANETBROWSING}/shaders/simple_vs.glsl",
|
||||
"${MODULE_PLANETBROWSING}/shaders/simple_fs.glsl");
|
||||
if (!_testProgramObject) return false;
|
||||
Planet::~Planet() {
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
bool Planet::initialize() {
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
if (_programObject == nullptr && _hasNightTexture) {
|
||||
// Night texture program
|
||||
_programObject = renderEngine.buildRenderProgram(
|
||||
"simpleTextureProgram",
|
||||
"${MODULE_PLANETBROWSING}/shaders/simple_vs.glsl",
|
||||
"${MODULE_PLANETBROWSING}/shaders/simple_fs.glsl");
|
||||
if (!_programObject) return false;
|
||||
}
|
||||
else if (_programObject == nullptr) {
|
||||
// pscstandard
|
||||
_programObject = renderEngine.buildRenderProgram(
|
||||
"pscstandard",
|
||||
"${SHADERS}/pscstandard_vs.glsl",
|
||||
"${SHADERS}/pscstandard_fs.glsl");
|
||||
if (!_programObject) return false;
|
||||
|
||||
bool Planet::deinitialize() {
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
if (_testProgramObject) {
|
||||
renderEngine.removeRenderProgram(_testProgramObject);
|
||||
_testProgramObject = nullptr;
|
||||
}
|
||||
using IgnoreError = ghoul::opengl::ProgramObject::IgnoreError;
|
||||
_programObject->setIgnoreSubroutineUniformLocationError(IgnoreError::Yes);
|
||||
|
||||
loadTexture();
|
||||
|
||||
return isReady();
|
||||
}
|
||||
|
||||
if (_geometry) {
|
||||
_geometry->deinitialize();
|
||||
delete _geometry;
|
||||
|
||||
bool Planet::deinitialize() {
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
if (_programObject) {
|
||||
renderEngine.removeRenderProgram(_programObject);
|
||||
_programObject = nullptr;
|
||||
}
|
||||
|
||||
_texture = nullptr;
|
||||
_nightTexture = nullptr;
|
||||
return true;
|
||||
}
|
||||
_geometry = nullptr;
|
||||
|
||||
return true;
|
||||
}
|
||||
bool Planet::isReady() const {
|
||||
bool ready = true;
|
||||
ready &= (_programObject != nullptr);
|
||||
ready &= (_texture != nullptr);
|
||||
return ready;
|
||||
}
|
||||
|
||||
bool Planet::isReady() const {
|
||||
bool ready = true;
|
||||
ready &= (_testProgramObject != nullptr);
|
||||
ready &= (_geometry != nullptr);
|
||||
void Planet::render(const RenderData& data)
|
||||
{
|
||||
// activate shader
|
||||
_programObject->activate();
|
||||
|
||||
return ready;
|
||||
}
|
||||
// scale the planet to appropriate size since the planet is a unit sphere
|
||||
glm::mat4 transform = glm::mat4(1);
|
||||
|
||||
void Planet::render(const RenderData& data) {
|
||||
// activate shader
|
||||
_testProgramObject->activate();
|
||||
//earth needs to be rotated for that to work.
|
||||
glm::mat4 rot = glm::rotate(transform, static_cast<float>(M_PI_2), glm::vec3(1, 0, 0));
|
||||
glm::mat4 roty = glm::rotate(transform, static_cast<float>(M_PI_2), glm::vec3(0, -1, 0));
|
||||
glm::mat4 rotProp = glm::rotate(transform, glm::radians(static_cast<float>(_rotation)), glm::vec3(0, 1, 0));
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
for (int j = 0; j < 3; j++) {
|
||||
transform[i][j] = static_cast<float>(_stateMatrix[i][j]);
|
||||
}
|
||||
}
|
||||
transform = transform * rot * roty * rotProp;
|
||||
|
||||
//glm::mat4 modelview = data.camera.viewMatrix()*data.camera.modelMatrix();
|
||||
//glm::vec3 camSpaceEye = (-(modelview*data.position.vec4())).xyz;
|
||||
|
||||
|
||||
//_testGeometry->render();
|
||||
_geometry->render();
|
||||
double lt;
|
||||
glm::dvec3 p =
|
||||
SpiceManager::ref().targetPosition("SUN", _target, "GALACTIC", {}, _time, lt);
|
||||
psc sun_pos = PowerScaledCoordinate::CreatePowerScaledCoordinate(p.x, p.y, p.z);
|
||||
|
||||
// setup the data to the shader
|
||||
// _programObject->setUniform("camdir", camSpaceEye);
|
||||
_programObject->setUniform("transparency", _alpha);
|
||||
_programObject->setUniform("ViewProjection", data.camera.viewProjectionMatrix());
|
||||
_programObject->setUniform("ModelTransform", transform);
|
||||
setPscUniforms(_programObject.get(), &data.camera, data.position);
|
||||
|
||||
// disable shader
|
||||
_testProgramObject->deactivate();
|
||||
}
|
||||
_programObject->setUniform("_performShading", _performShading);
|
||||
|
||||
void Planet::update(const UpdateData& data) {
|
||||
|
||||
}
|
||||
// Bind texture
|
||||
ghoul::opengl::TextureUnit dayUnit;
|
||||
dayUnit.activate();
|
||||
_texture->bind();
|
||||
_programObject->setUniform("texture1", dayUnit);
|
||||
|
||||
// Bind possible night texture
|
||||
if (_hasNightTexture) {
|
||||
ghoul::opengl::TextureUnit nightUnit;
|
||||
nightUnit.activate();
|
||||
_nightTexture->bind();
|
||||
_programObject->setUniform("nightTex", nightUnit);
|
||||
}
|
||||
|
||||
glEnable(GL_CULL_FACE);
|
||||
glCullFace(GL_BACK);
|
||||
|
||||
// render
|
||||
_testGeometry->render();
|
||||
|
||||
// disable shader
|
||||
_programObject->deactivate();
|
||||
}
|
||||
|
||||
void Planet::update(const UpdateData& data) {
|
||||
// set spice-orientation in accordance to timestamp
|
||||
_stateMatrix = SpiceManager::ref().positionTransformMatrix(_frame, "GALACTIC", data.time);
|
||||
_time = data.time;
|
||||
}
|
||||
|
||||
void Planet::loadTexture() {
|
||||
_texture = nullptr;
|
||||
if (_colorTexturePath.value() != "") {
|
||||
_texture = std::move(ghoul::io::TextureReader::ref().loadTexture(absPath(_colorTexturePath)));
|
||||
if (_texture) {
|
||||
LDEBUG("Loaded texture from '" << _colorTexturePath << "'");
|
||||
_texture->uploadTexture();
|
||||
|
||||
// Textures of planets looks much smoother with AnisotropicMipMap rather than linear
|
||||
// TODO: AnisotropicMipMap crashes on ATI cards ---abock
|
||||
//_texture->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap);
|
||||
_texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
|
||||
}
|
||||
}
|
||||
if (_hasNightTexture) {
|
||||
_nightTexture = nullptr;
|
||||
if (_nightTexturePath != "") {
|
||||
_nightTexture = std::move(ghoul::io::TextureReader::ref().loadTexture(absPath(_nightTexturePath)));
|
||||
if (_nightTexture) {
|
||||
LDEBUG("Loaded texture from '" << _nightTexturePath << "'");
|
||||
_nightTexture->uploadTexture();
|
||||
_nightTexture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
|
||||
//_nightTexture->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -28,34 +28,55 @@
|
||||
// open space includes
|
||||
#include <openspace/rendering/renderable.h>
|
||||
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
|
||||
#include <modules/planetbrowsing/rendering/geometry.h>
|
||||
|
||||
#include <memory>
|
||||
// ghoul includes
|
||||
namespace ghoul {
|
||||
namespace opengl {
|
||||
class ProgramObject;
|
||||
class Texture;
|
||||
}
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
|
||||
namespace planetgeometry {
|
||||
class PlanetGeometry;
|
||||
}
|
||||
class Planet : public Renderable {
|
||||
public:
|
||||
Planet(const ghoul::Dictionary& dictionary);
|
||||
~Planet();
|
||||
|
||||
class Planet : public Renderable {
|
||||
public:
|
||||
Planet(const ghoul::Dictionary& dictionary);
|
||||
~Planet();
|
||||
bool initialize() override;
|
||||
bool deinitialize() override;
|
||||
bool isReady() const override;
|
||||
|
||||
bool initialize() override;
|
||||
bool deinitialize() override;
|
||||
bool isReady() const override;
|
||||
void render(const RenderData& data) override;
|
||||
void update(const UpdateData& data) override;
|
||||
|
||||
void render(const RenderData& data) override;
|
||||
void update(const UpdateData& data) override;
|
||||
protected:
|
||||
void loadTexture();
|
||||
|
||||
private:
|
||||
// std::unique_ptr<Geometry> _testGeometry;
|
||||
planetgeometry::PlanetGeometry* _geometry;
|
||||
private:
|
||||
properties::StringProperty _colorTexturePath;
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _programObject;
|
||||
std::unique_ptr<ghoul::opengl::Texture> _texture;
|
||||
std::unique_ptr<ghoul::opengl::Texture> _nightTexture;
|
||||
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _testProgramObject;
|
||||
};
|
||||
std::unique_ptr<Geometry> _testGeometry;
|
||||
|
||||
properties::BoolProperty _performShading;
|
||||
properties::IntProperty _rotation;
|
||||
float _alpha;
|
||||
|
||||
glm::dmat3 _stateMatrix;
|
||||
std::string _nightTexturePath;
|
||||
std::string _frame;
|
||||
std::string _target;
|
||||
bool _hasNightTexture;
|
||||
double _time;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
|
||||
@@ -1,78 +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/planetbrowsing/rendering/planettestgeometry.h>
|
||||
#include <modules/planetbrowsing/rendering/renderabletestplanet.h>
|
||||
#include <openspace/util/factorymanager.h>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "PlanetTestGeometry";
|
||||
const std::string KeyType = "Type";
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
namespace planettestgeometry {
|
||||
|
||||
PlanetTestGeometry* PlanetTestGeometry::createFromDictionary(const ghoul::Dictionary& dictionary) {
|
||||
std::string geometryType;
|
||||
const bool success = dictionary.getValue(KeyType, geometryType);
|
||||
if (!success) {
|
||||
LERROR("PlanetTestGeometry did not contain a correct value of the key '"
|
||||
<< KeyType << "'");
|
||||
return nullptr;
|
||||
}
|
||||
ghoul::TemplateFactory<PlanetTestGeometry>* factory
|
||||
= FactoryManager::ref().factory<PlanetTestGeometry>();
|
||||
|
||||
PlanetTestGeometry* result = factory->create(geometryType, dictionary);
|
||||
if (result == nullptr) {
|
||||
LERROR("Failed to create a PlanetTestGeometry object of type '" << geometryType
|
||||
<< "'");
|
||||
return nullptr;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
PlanetTestGeometry::PlanetTestGeometry()
|
||||
: _parent(nullptr)
|
||||
{
|
||||
setName("PlanetTestGeometry");
|
||||
}
|
||||
|
||||
PlanetTestGeometry::~PlanetTestGeometry()
|
||||
{
|
||||
}
|
||||
|
||||
bool PlanetTestGeometry::initialize(RenderableTestPlanet* parent)
|
||||
{
|
||||
_parent = parent;
|
||||
return true;
|
||||
}
|
||||
|
||||
void PlanetTestGeometry::deinitialize()
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace planettestgeometry
|
||||
} // namespace openspace
|
||||
@@ -1,53 +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. *
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef __PLANETTESTGEOMETRY_H__
|
||||
#define __PLANETTESTGEOMETRY_H__
|
||||
|
||||
#include <openspace/properties/propertyowner.h>
|
||||
#include <modules/planetbrowsing/rendering/renderabletestplanet.h>
|
||||
#include <ghoul/misc/dictionary.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
namespace planettestgeometry {
|
||||
|
||||
class PlanetTestGeometry : public properties::PropertyOwner {
|
||||
public:
|
||||
static PlanetTestGeometry* createFromDictionary(const ghoul::Dictionary& dictionary);
|
||||
|
||||
PlanetTestGeometry();
|
||||
virtual ~PlanetTestGeometry();
|
||||
virtual bool initialize(RenderableTestPlanet* parent);
|
||||
virtual void deinitialize();
|
||||
virtual void render() = 0;
|
||||
|
||||
protected:
|
||||
RenderableTestPlanet* _parent;
|
||||
};
|
||||
|
||||
} // namespace planettestgeometry
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __PLANETTESTGEOMETRY_H__
|
||||
@@ -1,279 +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. *
|
||||
****************************************************************************************/
|
||||
|
||||
// open space includes
|
||||
#include <modules/planetbrowsing/rendering/renderabletestplanet.h>
|
||||
#include <modules/planetbrowsing/rendering/planettestgeometry.h>
|
||||
|
||||
#include <openspace/engine/configurationmanager.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <modules/base/rendering/planetgeometry.h>
|
||||
#include <openspace/util/time.h>
|
||||
#include <openspace/util/spicemanager.h>
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/misc/assert.h>
|
||||
#include <ghoul/io/texture/texturereader.h>
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
#include <ghoul/opengl/textureunit.h>
|
||||
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "RenderableTestPlanet";
|
||||
|
||||
const std::string keyFrame = "Frame";
|
||||
const std::string keyGeometry = "Geometry";
|
||||
const std::string keyShading = "PerformShading";
|
||||
|
||||
const std::string keyBody = "Body";
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
|
||||
RenderableTestPlanet::RenderableTestPlanet(const ghoul::Dictionary& dictionary)
|
||||
: Renderable(dictionary)
|
||||
, _colorTexturePath("colorTexture", "Color Texture")
|
||||
, _programObject(nullptr)
|
||||
, _texture(nullptr)
|
||||
, _nightTexture(nullptr)
|
||||
, _geometry(nullptr)
|
||||
, _performShading("performShading", "Perform Shading", true)
|
||||
, _rotation("rotation", "Rotation", 0, 0, 360)
|
||||
, _alpha(1.f)
|
||||
, _nightTexturePath("")
|
||||
, _hasNightTexture(false)
|
||||
{
|
||||
std::string name;
|
||||
bool success = dictionary.getValue(SceneGraphNode::KeyName, name);
|
||||
ghoul_assert(success,
|
||||
"RenderablePlanet need the '" << SceneGraphNode::KeyName<<"' be specified");
|
||||
|
||||
//std::string path;
|
||||
//success = dictionary.getValue(constants::scenegraph::keyPathModule, path);
|
||||
//ghoul_assert(success,
|
||||
// "RenderablePlanet need the '"<<constants::scenegraph::keyPathModule<<"' be specified");
|
||||
|
||||
ghoul::Dictionary geometryDictionary;
|
||||
success = dictionary.getValue(keyGeometry, geometryDictionary);
|
||||
if (success) {
|
||||
geometryDictionary.setValue(SceneGraphNode::KeyName, name);
|
||||
//geometryDictionary.setValue(constants::scenegraph::keyPathModule, path);
|
||||
_geometry = planettestgeometry::PlanetTestGeometry::createFromDictionary(geometryDictionary);
|
||||
}
|
||||
|
||||
dictionary.getValue(keyFrame, _frame);
|
||||
dictionary.getValue(keyBody, _target);
|
||||
if (_target != "")
|
||||
setBody(_target);
|
||||
|
||||
// TODO: textures need to be replaced by a good system similar to the geometry as soon
|
||||
// as the requirements are fixed (ab)
|
||||
std::string texturePath = "";
|
||||
success = dictionary.getValue("Textures.Color", texturePath);
|
||||
if (success)
|
||||
_colorTexturePath = absPath(texturePath);
|
||||
|
||||
std::string nightTexturePath = "";
|
||||
dictionary.getValue("Textures.Night", nightTexturePath);
|
||||
|
||||
if (nightTexturePath != ""){
|
||||
_hasNightTexture = true;
|
||||
_nightTexturePath = absPath(nightTexturePath);
|
||||
}
|
||||
|
||||
addPropertySubOwner(_geometry);
|
||||
|
||||
addProperty(_colorTexturePath);
|
||||
_colorTexturePath.onChange(std::bind(&RenderableTestPlanet::loadTexture, this));
|
||||
|
||||
if (dictionary.hasKeyAndValue<bool>(keyShading)) {
|
||||
bool shading;
|
||||
dictionary.getValue(keyShading, shading);
|
||||
_performShading = shading;
|
||||
}
|
||||
|
||||
addProperty(_performShading);
|
||||
// Mainly for debugging purposes @AA
|
||||
addProperty(_rotation);
|
||||
}
|
||||
|
||||
RenderableTestPlanet::~RenderableTestPlanet() {
|
||||
}
|
||||
|
||||
bool RenderableTestPlanet::initialize() {
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
if (_programObject == nullptr && _hasNightTexture) {
|
||||
// Night texture program
|
||||
_programObject = renderEngine.buildRenderProgram(
|
||||
"nightTextureProgram",
|
||||
"${SHADERS}/nighttexture_vs.glsl",
|
||||
"${SHADERS}/nighttexture_fs.glsl");
|
||||
if (!_programObject) return false;
|
||||
}
|
||||
else if (_programObject == nullptr) {
|
||||
// pscstandard
|
||||
_programObject = renderEngine.buildRenderProgram(
|
||||
"pscstandard",
|
||||
"${SHADERS}/pscstandard_vs.glsl",
|
||||
"${SHADERS}/pscstandard_fs.glsl");
|
||||
if (!_programObject) return false;
|
||||
|
||||
}
|
||||
using IgnoreError = ghoul::opengl::ProgramObject::IgnoreError;
|
||||
_programObject->setIgnoreSubroutineUniformLocationError(IgnoreError::Yes);
|
||||
|
||||
loadTexture();
|
||||
_geometry->initialize(this);
|
||||
|
||||
return isReady();
|
||||
}
|
||||
|
||||
bool RenderableTestPlanet::deinitialize() {
|
||||
if(_geometry) {
|
||||
_geometry->deinitialize();
|
||||
delete _geometry;
|
||||
}
|
||||
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
if (_programObject) {
|
||||
renderEngine.removeRenderProgram(_programObject);
|
||||
_programObject = nullptr;
|
||||
}
|
||||
|
||||
_geometry = nullptr;
|
||||
_texture = nullptr;
|
||||
_nightTexture = nullptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RenderableTestPlanet::isReady() const {
|
||||
bool ready = true;
|
||||
ready &= (_programObject != nullptr);
|
||||
ready &= (_texture != nullptr);
|
||||
ready &= (_geometry != nullptr);
|
||||
return ready;
|
||||
}
|
||||
|
||||
void RenderableTestPlanet::render(const RenderData& data)
|
||||
{
|
||||
// activate shader
|
||||
_programObject->activate();
|
||||
|
||||
// scale the planet to appropriate size since the planet is a unit sphere
|
||||
glm::mat4 transform = glm::mat4(1);
|
||||
|
||||
//earth needs to be rotated for that to work.
|
||||
glm::mat4 rot = glm::rotate(transform, static_cast<float>(M_PI_2), glm::vec3(1, 0, 0));
|
||||
glm::mat4 roty = glm::rotate(transform, static_cast<float>(M_PI_2), glm::vec3(0, -1, 0));
|
||||
glm::mat4 rotProp = glm::rotate(transform, glm::radians(static_cast<float>(_rotation)), glm::vec3(0, 1, 0));
|
||||
|
||||
for (int i = 0; i < 3; i++){
|
||||
for (int j = 0; j < 3; j++){
|
||||
transform[i][j] = static_cast<float>(_stateMatrix[i][j]);
|
||||
}
|
||||
}
|
||||
transform = transform * rot * roty * rotProp;
|
||||
|
||||
//glm::mat4 modelview = data.camera.viewMatrix()*data.camera.modelMatrix();
|
||||
//glm::vec3 camSpaceEye = (-(modelview*data.position.vec4())).xyz;
|
||||
|
||||
|
||||
double lt;
|
||||
glm::dvec3 p =
|
||||
SpiceManager::ref().targetPosition("SUN", _target, "GALACTIC", {}, _time, lt);
|
||||
psc sun_pos = PowerScaledCoordinate::CreatePowerScaledCoordinate(p.x, p.y, p.z);
|
||||
|
||||
// setup the data to the shader
|
||||
// _programObject->setUniform("camdir", camSpaceEye);
|
||||
_programObject->setUniform("transparency", _alpha);
|
||||
_programObject->setUniform("ViewProjection", data.camera.viewProjectionMatrix());
|
||||
_programObject->setUniform("ModelTransform", transform);
|
||||
setPscUniforms(_programObject.get(), &data.camera, data.position);
|
||||
|
||||
_programObject->setUniform("_performShading", _performShading);
|
||||
|
||||
// Bind texture
|
||||
ghoul::opengl::TextureUnit dayUnit;
|
||||
dayUnit.activate();
|
||||
_texture->bind();
|
||||
_programObject->setUniform("texture1", dayUnit);
|
||||
|
||||
// Bind possible night texture
|
||||
if (_hasNightTexture) {
|
||||
ghoul::opengl::TextureUnit nightUnit;
|
||||
nightUnit.activate();
|
||||
_nightTexture->bind();
|
||||
_programObject->setUniform("nightTex", nightUnit);
|
||||
}
|
||||
|
||||
glEnable(GL_CULL_FACE);
|
||||
glCullFace(GL_BACK);
|
||||
|
||||
// render
|
||||
_geometry->render();
|
||||
|
||||
// disable shader
|
||||
_programObject->deactivate();
|
||||
}
|
||||
|
||||
void RenderableTestPlanet::update(const UpdateData& data){
|
||||
// set spice-orientation in accordance to timestamp
|
||||
_stateMatrix = SpiceManager::ref().positionTransformMatrix(_frame, "GALACTIC", data.time);
|
||||
_time = data.time;
|
||||
}
|
||||
|
||||
void RenderableTestPlanet::loadTexture() {
|
||||
_texture = nullptr;
|
||||
if (_colorTexturePath.value() != "") {
|
||||
_texture = std::move(ghoul::io::TextureReader::ref().loadTexture(absPath(_colorTexturePath)));
|
||||
if (_texture) {
|
||||
LDEBUG("Loaded texture from '" << _colorTexturePath << "'");
|
||||
_texture->uploadTexture();
|
||||
|
||||
// Textures of planets looks much smoother with AnisotropicMipMap rather than linear
|
||||
// TODO: AnisotropicMipMap crashes on ATI cards ---abock
|
||||
//_texture->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap);
|
||||
_texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
|
||||
}
|
||||
}
|
||||
if (_hasNightTexture) {
|
||||
_nightTexture = nullptr;
|
||||
if (_nightTexturePath != "") {
|
||||
_nightTexture = std::move(ghoul::io::TextureReader::ref().loadTexture(absPath(_nightTexturePath)));
|
||||
if (_nightTexture) {
|
||||
LDEBUG("Loaded texture from '" << _nightTexturePath << "'");
|
||||
_nightTexture->uploadTexture();
|
||||
_nightTexture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
|
||||
//_nightTexture->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
@@ -1,83 +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. *
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef __RENDERABLETESTPLANET_H__
|
||||
#define __RENDERABLETESTPLANET_H__
|
||||
|
||||
// open space includes
|
||||
#include <openspace/rendering/renderable.h>
|
||||
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
|
||||
// ghoul includes
|
||||
namespace ghoul {
|
||||
namespace opengl {
|
||||
class ProgramObject;
|
||||
class Texture;
|
||||
}
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
|
||||
namespace planettestgeometry {
|
||||
class PlanetTestGeometry;
|
||||
}
|
||||
|
||||
class RenderableTestPlanet : public Renderable {
|
||||
public:
|
||||
RenderableTestPlanet(const ghoul::Dictionary& dictionary);
|
||||
~RenderableTestPlanet();
|
||||
|
||||
bool initialize() override;
|
||||
bool deinitialize() override;
|
||||
bool isReady() const override;
|
||||
|
||||
void render(const RenderData& data) override;
|
||||
void update(const UpdateData& data) override;
|
||||
|
||||
protected:
|
||||
void loadTexture();
|
||||
|
||||
private:
|
||||
properties::StringProperty _colorTexturePath;
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _programObject;
|
||||
std::unique_ptr<ghoul::opengl::Texture> _texture;
|
||||
std::unique_ptr<ghoul::opengl::Texture> _nightTexture;
|
||||
planettestgeometry::PlanetTestGeometry* _geometry;
|
||||
properties::BoolProperty _performShading;
|
||||
properties::IntProperty _rotation;
|
||||
float _alpha;
|
||||
|
||||
glm::dmat3 _stateMatrix;
|
||||
std::string _nightTexturePath;
|
||||
std::string _frame;
|
||||
std::string _target;
|
||||
bool _hasNightTexture;
|
||||
double _time;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __RENDERABLETESTPLANET_H__
|
||||
@@ -1,127 +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/planetbrowsing/rendering/simplespheretestgeometry.h>
|
||||
#include <openspace/util/powerscaledsphere.h>
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "SimpleSphereTestGeometry";
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
|
||||
namespace constants {
|
||||
namespace simplespheretestgeometry {
|
||||
const std::string keyRadius = "Radius";
|
||||
const std::string keySegments = "Segments";
|
||||
} // namespace simplespheretestgeometry
|
||||
}
|
||||
|
||||
namespace planettestgeometry {
|
||||
|
||||
SimpleSphereTestGeometry::SimpleSphereTestGeometry(const ghoul::Dictionary& dictionary)
|
||||
: PlanetTestGeometry()
|
||||
, _realRadius("radius", "Radius", glm::vec4(1.f, 1.f, 1.f, 0.f), glm::vec4(-10.f, -10.f, -10.f, -20.f),
|
||||
glm::vec4(10.f, 10.f, 10.f, 20.f))
|
||||
, _segments("segments", "Segments", 20, 1, 50)
|
||||
, _sphere(nullptr)
|
||||
{
|
||||
using constants::simplespheretestgeometry::keyRadius;
|
||||
using constants::simplespheretestgeometry::keySegments;
|
||||
|
||||
// The name is passed down from the SceneGraphNode
|
||||
bool success = dictionary.getValue(SceneGraphNode::KeyName, _name);
|
||||
assert(success);
|
||||
|
||||
glm::vec4 radius;
|
||||
success = dictionary.getValue(keyRadius, _modRadius);
|
||||
if (!success) {
|
||||
LERROR("SimpleSphereTestGeometry of '" << _name << "' did not provide a key '"
|
||||
<< keyRadius << "'");
|
||||
}
|
||||
else {
|
||||
radius[0] = _modRadius[0];
|
||||
radius[1] = _modRadius[0];
|
||||
radius[2] = _modRadius[0];
|
||||
radius[3] = _modRadius[1];
|
||||
_realRadius = radius; // In case the kernels does not supply a real
|
||||
}
|
||||
|
||||
double segments;
|
||||
success = dictionary.getValue(keySegments, segments);
|
||||
if (!success) {
|
||||
LERROR("SimpleSphereTestGeometry of '" << _name << "' did not provide a key '"
|
||||
<< keySegments << "'");
|
||||
}
|
||||
else
|
||||
_segments = static_cast<int>(segments);
|
||||
|
||||
// The shader need the radii values but they are not changeable runtime
|
||||
// TODO: Possibly add a scaling property @AA
|
||||
addProperty(_realRadius);
|
||||
// Changing the radius/scaling should affect the shader but not the geometry? @AA
|
||||
//_radius.onChange(std::bind(&SimpleSphereTestGeometry::createSphere, this));
|
||||
addProperty(_segments);
|
||||
_segments.onChange(std::bind(&SimpleSphereTestGeometry::createSphere, this));
|
||||
}
|
||||
|
||||
SimpleSphereTestGeometry::~SimpleSphereTestGeometry()
|
||||
{
|
||||
}
|
||||
|
||||
bool SimpleSphereTestGeometry::initialize(RenderableTestPlanet* parent)
|
||||
{
|
||||
bool success = PlanetTestGeometry::initialize(parent);
|
||||
createSphere();
|
||||
return success;
|
||||
}
|
||||
|
||||
void SimpleSphereTestGeometry::deinitialize()
|
||||
{
|
||||
if (_sphere)
|
||||
delete _sphere;
|
||||
_sphere = nullptr;
|
||||
}
|
||||
|
||||
void SimpleSphereTestGeometry::render()
|
||||
{
|
||||
_sphere->render();
|
||||
}
|
||||
|
||||
void SimpleSphereTestGeometry::createSphere() {
|
||||
//create the power scaled scalar
|
||||
|
||||
PowerScaledScalar planetSize(_modRadius);
|
||||
_parent->setBoundingSphere(planetSize);
|
||||
|
||||
if (_sphere)
|
||||
delete _sphere;
|
||||
//_sphere = new PowerScaledSphere(planetSize, _segments);
|
||||
_sphere = new PowerScaledSphere(_realRadius, _segments, _name);
|
||||
_sphere->initialize();
|
||||
}
|
||||
|
||||
} // namespace planetgeometry
|
||||
} // namespace openspace
|
||||
@@ -1,64 +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. *
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef __SIMPLESPHERETESTGEOMETRY_H__
|
||||
#define __SIMPLESPHERETESTGEOMETRY_H__
|
||||
|
||||
#include <modules/planetbrowsing/rendering/planettestgeometry.h>
|
||||
#include <openspace/properties/vectorproperty.h>
|
||||
#include <openspace/properties/scalarproperty.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class RenderablePlanet;
|
||||
class PowerScaledSphere;
|
||||
|
||||
namespace planettestgeometry {
|
||||
|
||||
class SimpleSphereTestGeometry : public PlanetTestGeometry {
|
||||
public:
|
||||
SimpleSphereTestGeometry(const ghoul::Dictionary& dictionary);
|
||||
~SimpleSphereTestGeometry();
|
||||
|
||||
|
||||
bool initialize(RenderableTestPlanet* parent) override;
|
||||
void deinitialize() override;
|
||||
void render() override;
|
||||
PowerScaledSphere* _planet;
|
||||
|
||||
private:
|
||||
void createSphere();
|
||||
|
||||
glm::vec2 _modRadius;
|
||||
properties::Vec4Property _realRadius;
|
||||
properties::IntProperty _segments;
|
||||
std::string _name;
|
||||
|
||||
PowerScaledSphere* _sphere;
|
||||
};
|
||||
|
||||
} // namespace planetgeometry
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __SIMPLESPHERETESTGEOMETRY_H__
|
||||
@@ -22,6 +22,18 @@
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
uniform vec4 campos;
|
||||
uniform vec4 objpos;
|
||||
|
||||
uniform vec3 sun_pos;
|
||||
|
||||
uniform bool _performShading = true;
|
||||
uniform float transparency;
|
||||
uniform int shadows;
|
||||
|
||||
uniform float time;
|
||||
uniform sampler2D texture1;
|
||||
uniform sampler2D nightTex;
|
||||
|
||||
in vec4 vs_position;
|
||||
|
||||
@@ -29,12 +41,10 @@ in vec4 vs_position;
|
||||
#include "fragment.glsl"
|
||||
|
||||
Fragment getFragment() {
|
||||
vec4 position = vs_position;
|
||||
|
||||
Fragment frag;
|
||||
|
||||
|
||||
frag.color = vec4(1,1,1,1);
|
||||
frag.depth = 0;
|
||||
frag.depth = pscDepth(vs_position);
|
||||
|
||||
return frag;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,9 @@
|
||||
|
||||
#version __CONTEXT__
|
||||
|
||||
uniform mat4 ViewProjection;
|
||||
uniform mat4 ModelTransform;
|
||||
|
||||
layout(location = 0) in vec4 in_position;
|
||||
|
||||
out vec4 vs_position;
|
||||
@@ -34,6 +37,10 @@ void main()
|
||||
{
|
||||
// set variables
|
||||
vs_position = in_position;
|
||||
vec4 tmp = in_position;
|
||||
|
||||
gl_Position = in_position;
|
||||
vec4 position = pscTransform(tmp, ModelTransform);
|
||||
vs_position = tmp;
|
||||
position = ViewProjection * position;
|
||||
gl_Position = z_normalization(position);
|
||||
}
|
||||
Reference in New Issue
Block a user