More code cleanup

This commit is contained in:
Alexander Bock
2017-05-15 14:39:25 -04:00
parent 2d5c292326
commit 302fa06067
30 changed files with 260 additions and 292 deletions

View File

@@ -28,7 +28,6 @@
#include <openspace/properties/propertyowner.h>
#include <openspace/properties/scalar/boolproperty.h>
#include <openspace/util/updatestructures.h>
#include <ghoul/opengl/programobject.h>
@@ -42,6 +41,10 @@ namespace ghoul {
namespace openspace {
struct RenderData;
struct UpdateData;
struct RendererTasks;
namespace documentation { struct Documentation; }
// Forward declare to minimize dependencies

View File

@@ -25,20 +25,24 @@
#include <modules/base/rendering/modelgeometry.h>
#include <openspace/documentation/verifier.h>
#include <openspace/rendering/renderable.h>
#include <openspace/util/factorymanager.h>
#include <ghoul/filesystem/cachemanager.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/misc/dictionary.h>
#include <ghoul/misc/invariants.h>
#include <fstream>
namespace {
const char* _loggerCat = "ModelGeometry";
const char* keyGeomModelFile = "GeometryFile";
const char* KeyName = "Name";
const char* KeyType = "Type";
const char* KeyGeomModelFile = "GeometryFile";
const int8_t CurrentCacheVersion = 3;
const char* keyType = "Type";
const char* keyName = "Name";
}
} // namespace
namespace openspace {
namespace modelgeometry {
@@ -50,13 +54,13 @@ documentation:: Documentation ModelGeometry::Documentation() {
"base_geometry_model",
{
{
keyType,
KeyType,
new StringVerifier,
"The type of the Model Geometry that should be generated",
Optional::No
},
{
keyGeomModelFile,
KeyGeomModelFile,
new StringVerifier,
"The file that should be loaded in this ModelGeometry. The file can "
"contain filesystem tokens or can be specified relatively to the "
@@ -71,25 +75,18 @@ documentation:: Documentation ModelGeometry::Documentation() {
std::unique_ptr<ModelGeometry> ModelGeometry::createFromDictionary(
const ghoul::Dictionary& dictionary)
{
if (!dictionary.hasKeyAndValue<std::string>(keyType)) {
if (!dictionary.hasKeyAndValue<std::string>(KeyType)) {
throw ghoul::RuntimeError("Dictionary did not contain a key 'Type'");
}
std::string geometryType = dictionary.value<std::string>(keyType);
const std::string geometryType = dictionary.value<std::string>(KeyType);
auto factory = FactoryManager::ref().factory<ModelGeometry>();
std::unique_ptr<ModelGeometry> result = factory->create(geometryType, dictionary);
if (result == nullptr) {
throw ghoul::RuntimeError(
"Failed to create a ModelGeometry object of type '" + geometryType + "'"
);
}
return result;
return factory->create(geometryType, dictionary);;
}
ModelGeometry::ModelGeometry(const ghoul::Dictionary& dictionary)
: properties::PropertyOwner("ModelGeometry")
, _parent(nullptr)
, _mode(GL_TRIANGLES)
{
documentation::testSpecificationAndThrow(
@@ -98,11 +95,7 @@ ModelGeometry::ModelGeometry(const ghoul::Dictionary& dictionary)
"ModelGeometry"
);
std::string name;
bool success = dictionary.getValue(keyName, name);
ghoul_assert(success, "Name tag was not present");
_file = absPath(dictionary.value<std::string>(keyGeomModelFile));
_file = absPath(dictionary.value<std::string>(KeyGeomModelFile));
}
double ModelGeometry::boundingRadius() const {
@@ -119,10 +112,6 @@ double ModelGeometry::boundingRadius() const {
return maxDist;
}
ModelGeometry::~ModelGeometry() {
}
void ModelGeometry::render() {
glBindVertexArray(_vaoID);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _ibo);
@@ -135,39 +124,67 @@ void ModelGeometry::changeRenderMode(const GLenum mode) {
}
bool ModelGeometry::initialize(Renderable* parent) {
_parent = parent;
float maximumDistanceSquared = 0;
for (auto v: _vertices)
{
for (const Vertex& v : _vertices) {
maximumDistanceSquared = glm::max(
glm::pow(v.location[0], 2.f) +
glm::pow(v.location[1], 2.f) +
glm::pow(v.location[2], 2.f), maximumDistanceSquared);
}
_parent->setBoundingSphere(glm::sqrt(maximumDistanceSquared));
parent->setBoundingSphere(glm::sqrt(maximumDistanceSquared));
if (_vertices.empty())
if (_vertices.empty()) {
return false;
}
glGenVertexArrays(1, &_vaoID);
glGenBuffers(1, &_vbo);
glGenBuffers(1, &_ibo);
glBindVertexArray(_vaoID);
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
glBufferData(GL_ARRAY_BUFFER, _vertices.size() * sizeof(Vertex), _vertices.data(), GL_STATIC_DRAW);
glBufferData(
GL_ARRAY_BUFFER,
_vertices.size() * sizeof(Vertex),
_vertices.data(),
GL_STATIC_DRAW
);
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glEnableVertexAttribArray(2);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex),
reinterpret_cast<const GLvoid*>(offsetof(Vertex, location)));
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex),
reinterpret_cast<const GLvoid*>(offsetof(Vertex, tex)));
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex),
reinterpret_cast<const GLvoid*>(offsetof(Vertex, normal)));
glVertexAttribPointer(
0,
4,
GL_FLOAT,
GL_FALSE,
sizeof(Vertex),
reinterpret_cast<const GLvoid*>(offsetof(Vertex, location))
);
glVertexAttribPointer(
1,
2,
GL_FLOAT,
GL_FALSE,
sizeof(Vertex),
reinterpret_cast<const GLvoid*>(offsetof(Vertex, tex))
);
glVertexAttribPointer(
2,
3,
GL_FLOAT,
GL_FALSE,
sizeof(Vertex),
reinterpret_cast<const GLvoid*>(offsetof(Vertex, normal))
);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _ibo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, _indices.size() * sizeof(int), _indices.data(), GL_STATIC_DRAW);
glBufferData(
GL_ELEMENT_ARRAY_BUFFER,
_indices.size() * sizeof(int),
_indices.data(),
GL_STATIC_DRAW
);
glBindVertexArray(0);
@@ -181,37 +198,42 @@ void ModelGeometry::deinitialize() {
}
bool ModelGeometry::loadObj(const std::string& filename) {
std::string cachedFile = FileSys.cacheManager()->cachedFilename(
const std::string cachedFile = FileSys.cacheManager()->cachedFilename(
filename,
ghoul::filesystem::CacheManager::Persistent::Yes
);
);
bool hasCachedFile = FileSys.fileExists(cachedFile);
const bool hasCachedFile = FileSys.fileExists(cachedFile);
if (hasCachedFile) {
LINFO("Cached file '" << cachedFile << "' used for Model file '" << filename << "'");
LINFO("Cached file '" << cachedFile << "' used for file '" << filename << "'");
bool success = loadCachedFile(cachedFile);
if (success)
const bool success = loadCachedFile(cachedFile);
if (success) {
return true;
else
}
else {
FileSys.cacheManager()->removeCacheFile(filename);
}
// Intentional fall-through to the 'else' computation to generate the cache
// file for the next run
}
else {
LINFO("Cached file '" << cachedFile << "' used for Model file '" << filename << "' not found");
LINFO(
"Cached file '" << cachedFile << "' for file '" << filename << "' not found"
);
}
LINFO("Loading Model file '" << filename << "'");
bool success = loadModel(filename);
const bool modelSuccess = loadModel(filename);
if (!success)
if (!modelSuccess) {
return false;
}
LINFO("Saving cache");
success = saveCachedFile(cachedFile);
const bool cacheSuccess = saveCachedFile(cachedFile);
return success;
return cacheSuccess;
}
bool ModelGeometry::saveCachedFile(const std::string& filename) {
@@ -271,22 +293,6 @@ bool ModelGeometry::loadCachedFile(const std::string& filename) {
}
}
bool ModelGeometry::getVertices(std::vector<Vertex>* vertexList) {
vertexList->clear();
for (auto v : _vertices)
vertexList->push_back(v);
return !(vertexList->empty());
}
bool ModelGeometry::getIndices(std::vector<int>* indexList) {
indexList->clear();
for (auto i : _indices)
indexList->push_back(i);
return !(indexList->empty());
}
void ModelGeometry::setUniforms(ghoul::opengl::ProgramObject&) {}
} // namespace modelgeometry

View File

@@ -27,36 +27,46 @@
#include <openspace/properties/propertyowner.h>
#include <modules/base/rendering/renderablemodel.h>
#include <ghoul/opengl/ghoul_gl.h>
namespace ghoul { class Dictionary; }
#include <memory>
namespace ghoul {
class Dictionary;
namespace opengl { class ProgramObject; }
} // namespace ghoul
namespace openspace {
namespace documentation { struct Documentation; }
class Renderable;
namespace documentation { struct Documentation; }
namespace modelgeometry {
class ModelGeometry : public properties::PropertyOwner {
public:
static std::unique_ptr<ModelGeometry> createFromDictionary(
const ghoul::Dictionary& dictionary
);
struct Vertex {
GLfloat location[4];
GLfloat tex[2];
GLfloat normal[3];
};
static std::unique_ptr<ModelGeometry> createFromDictionary(
const ghoul::Dictionary& dictionary
);
ModelGeometry(const ghoul::Dictionary& dictionary);
virtual ~ModelGeometry();
virtual ~ModelGeometry() = default;
virtual bool initialize(Renderable* parent);
virtual void deinitialize();
void render();
virtual bool loadModel(const std::string& filename) = 0;
void changeRenderMode(const GLenum mode);
bool getVertices(std::vector<Vertex>* vertexList);
bool getIndices(std::vector<int>* indexList);
//bool getVertices(std::vector<Vertex>* vertexList);
//bool getIndices(std::vector<int>* indexList);
double boundingRadius() const;
@@ -65,8 +75,6 @@ public:
static documentation::Documentation Documentation();
protected:
Renderable* _parent;
bool loadObj(const std::string& filename);
bool loadCachedFile(const std::string& filename);
bool saveCachedFile(const std::string& filename);

View File

@@ -24,15 +24,7 @@
#include <modules/base/rendering/multimodelgeometry.h>
#include "ghoul/logging/logmanager.h"
#include "ghoul/io/model/modelreadermultiformat.h"
#include "ghoul/opengl/vertexbufferobject.h"
#include <openspace/util/powerscaledcoordinate.h>
namespace {
const std::string _loggerCat = "MultiModelGeometry";
}
namespace openspace {
namespace modelgeometry {
@@ -43,25 +35,13 @@ MultiModelGeometry::MultiModelGeometry(const ghoul::Dictionary& dictionary)
loadObj(_file);
}
bool MultiModelGeometry::initialize(Renderable* parent) {
bool success = ModelGeometry::initialize(parent);
return success;
}
void MultiModelGeometry::deinitialize() {
ModelGeometry::deinitialize();
}
bool MultiModelGeometry::loadModel(const std::string& filename) {
ghoul::io::ModelReaderMultiFormat modelReader;
std::vector<ghoul::io::ModelReaderBase::Vertex> vertices;
std::vector<int> indices;
modelReader.loadModel(filename, vertices, indices);
ghoul::io::ModelReaderMultiFormat().loadModel(filename, vertices, indices);
_vertices.reserve(vertices.size());
for (const auto & v : vertices) {
for (const ghoul::io::ModelReaderBase::Vertex& v : vertices) {
Vertex vv;
memcpy(vv.location, v.location, sizeof(GLfloat) * 3);
vv.location[3] = 1.0;

View File

@@ -38,9 +38,6 @@ class MultiModelGeometry : public ModelGeometry {
public:
MultiModelGeometry(const ghoul::Dictionary& dictionary);
bool initialize(Renderable* parent) override;
void deinitialize() override;
private:
bool loadModel(const std::string& filename);
};

View File

@@ -24,38 +24,33 @@
#include <modules/base/rendering/renderablemodel.h>
#include <modules/base/rendering/modelgeometry.h>
#include <openspace/documentation/documentation.h>
#include <openspace/documentation/verifier.h>
#include <openspace/rendering/renderengine.h>
#include <modules/base/rendering/modelgeometry.h>
#include <openspace/engine/configurationmanager.h>
#include <ghoul/io/texture/texturereader.h>
#include <ghoul/opengl/textureunit.h>
#include <ghoul/filesystem/filesystem.h>
#include <openspace/scene/scenegraphnode.h>
#include <openspace/util/time.h>
#include <ghoul/misc/invariants.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/scene/scenegraphnode.h>
#include <openspace/util/time.h>
#include <openspace/util/updatestructures.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/io/texture/texturereader.h>
#include <ghoul/misc/invariants.h>
#include <ghoul/opengl/programobject.h>
#include <ghoul/opengl/texture.h>
#include <ghoul/opengl/textureunit.h>
namespace {
const std::string _loggerCat = "RenderableModel";
const char* KeyGeometry = "Geometry";
const char* KeyTexture = "Textures.Color";
const char* KeyModelTransform = "Rotation.ModelTransform";
const char* KeyFading = "Shading.Fadeable";
const char* keyBody = "Body";
const char* keyStart = "StartTime";
const char* keyEnd = "EndTime";
const char* keyFading = "Shading.Fadeable";
const char* keyModelTransform = "Rotation.ModelTransform";
} // namespace
namespace openspace {
@@ -75,9 +70,23 @@ documentation::Documentation RenderableModel::Documentation() {
{
KeyTexture,
new StringVerifier,
"A color texture that can be applied to the model specified bny the "
"A color texture that can be applied to the model specified by the "
"Geometry.",
Optional::Yes
},
{
KeyModelTransform,
new DoubleMatrix3Verifier,
"Specifies a distinct transformation matrix that is applied to the "
"model. If it is not specified, it is equal to the Identity matrix.",
Optional::Yes
},
{
KeyFading,
new BoolVerifier,
"Specifies whether the model should be periodically fading in and out. "
"If this value is not specified, it will not fade.",
Optional::Yes
}
}
};
@@ -85,16 +94,14 @@ documentation::Documentation RenderableModel::Documentation() {
RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary)
: Renderable(dictionary)
, _geometry(nullptr)
, _colorTexturePath("colorTexture", "Color Texture")
, _performFade("performFading", "Perform Fading", false)
, _performShading("performShading", "Perform Shading", true)
, _fading("fading", "Fade", 0)
, _debugModelRotation("modelrotation", "Model Rotation", glm::vec3(0.f), glm::vec3(0.f), glm::vec3(360.f))
, _programObject(nullptr)
, _texture(nullptr)
, _geometry(nullptr)
, _alpha(1.f)
, _performShading("performShading", "Perform Shading", true)
, _frameCount(0)
, _modelTransform(1.0)
{
ghoul_precondition(
dictionary.hasKeyAndValue<std::string>(SceneGraphNode::KeyName),
@@ -107,7 +114,6 @@ RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary)
"RenderableModel"
);
if (dictionary.hasKey(KeyGeometry)) {
std::string name = dictionary.value<std::string>(SceneGraphNode::KeyName);
ghoul::Dictionary dict = dictionary.value<ghoul::Dictionary>(KeyGeometry);
@@ -119,57 +125,39 @@ RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary)
_colorTexturePath = absPath(dictionary.value<std::string>(KeyTexture));
}
if (dictionary.hasKey(KeyModelTransform)) {
_modelTransform = dictionary.value<glm::dmat3>(KeyModelTransform);
}
if (dictionary.hasKey(KeyFading)) {
_performFade = dictionary.value<bool>(KeyFading);
}
addPropertySubOwner(_geometry.get());
addProperty(_colorTexturePath);
_colorTexturePath.onChange(std::bind(&RenderableModel::loadTexture, this));
addProperty(_debugModelRotation);
if (dictionary.hasKeyAndValue<glm::dmat3>(keyModelTransform)) {
dictionary.getValue(keyModelTransform, _modelTransform);
}
else {
_modelTransform = glm::dmat3(1.f);
}
addProperty(_performShading);
if (dictionary.hasKeyAndValue<bool>(keyFading)) {
bool fading;
dictionary.getValue(keyFading, fading);
_performFade = fading;
}
addProperty(_performFade);
}
bool RenderableModel::isReady() const {
bool ready = true;
ready &= (_programObject != nullptr);
ready &= (_texture != nullptr);
return ready;
return _programObject && _texture;
}
bool RenderableModel::initialize() {
bool completeSuccess = true;
if (_programObject == nullptr) {
// NH shader
RenderEngine& renderEngine = OsEng.renderEngine();
_programObject = renderEngine.buildRenderProgram("ModelProgram",
"${MODULE_BASE}/shaders/model_vs.glsl",
"${MODULE_BASE}/shaders/model_fs.glsl");
if (!_programObject)
return false;
}
_programObject = OsEng.renderEngine().buildRenderProgram(
"ModelProgram",
"${MODULE_BASE}/shaders/model_vs.glsl",
"${MODULE_BASE}/shaders/model_fs.glsl"
);
loadTexture();
bool completeSuccess = true;
completeSuccess &= (_texture != nullptr);
completeSuccess &= _geometry->initialize(this);
//completeSuccess &= !_source.empty();
//completeSuccess &= !_destination.empty();
return completeSuccess;
}
@@ -180,10 +168,8 @@ bool RenderableModel::deinitialize() {
}
_texture = nullptr;
RenderEngine& renderEngine = OsEng.renderEngine();
if (_programObject) {
renderEngine.removeRenderProgram(_programObject);
OsEng.renderEngine().removeRenderProgram(_programObject);
_programObject = nullptr;
}
@@ -199,30 +185,18 @@ void RenderableModel::render(const RenderData& data) {
}
else if (!_performFade && _fading < 1.f) {
_fading = _fading + 0.01f;
}
// debug rotation controlled from GUI
glm::mat4 unitMat4(1);
glm::vec3 debugEulerRot = glm::radians(_debugModelRotation.value());
glm::mat4 rotX = glm::rotate(unitMat4, debugEulerRot.x, glm::vec3(1, 0, 0));
glm::mat4 rotY = glm::rotate(unitMat4, debugEulerRot.y, glm::vec3(0, 1, 0));
glm::mat4 rotZ = glm::rotate(unitMat4, debugEulerRot.z, glm::vec3(0, 0, 1));
glm::dmat4 debugModelRotation = rotX * rotY * rotZ;
// Model transform and view transform needs to be in double precision
glm::dmat4 modelTransform =
glm::translate(glm::dmat4(1.0), data.modelTransform.translation) * // Translation
glm::dmat4(data.modelTransform.rotation) * // Spice rotation
glm::dmat4(glm::scale(glm::dmat4(_modelTransform), glm::dvec3(data.modelTransform.scale)));
debugModelRotation; // debug model rotation controlled from GUI
glm::dmat4 modelViewTransform = data.camera.combinedViewMatrix() * modelTransform;
glm::vec3 directionToSun = glm::normalize(_sunPos - data.modelTransform.translation);
glm::vec3 directionToSunViewSpace = glm::mat3(data.camera.combinedViewMatrix()) * directionToSun;
_programObject->setUniform("transparency", _alpha);
_programObject->setUniform("directionToSunViewSpace", directionToSunViewSpace);
_programObject->setUniform("modelViewTransform", glm::mat4(modelViewTransform));
_programObject->setUniform("projectionTransform", data.camera.projectionMatrix());
@@ -239,7 +213,6 @@ void RenderableModel::render(const RenderData& data) {
_geometry->render();
// disable shader
_programObject->deactivate();
}
@@ -247,23 +220,6 @@ void RenderableModel::update(const UpdateData& data) {
if (_programObject->isDirty()) {
_programObject->rebuildFromFile();
}
// double _time = data.time;
//if (_isGhost){
// futureTime = openspace::ImageSequencer::ref().getNextCaptureTime();
// double remaining = openspace::ImageSequencer::ref().getNextCaptureTime() - data.time;
// double interval = openspace::ImageSequencer::ref().getIntervalLength();
// double t = 1.f - remaining / openspace::ImageSequencer::ref().getIntervalLength();
// if (interval > 60) {
// if (t < 0.8)
// _fading = static_cast<float>(t);
// else if (t >= 0.95)
// _fading = _fading - 0.5f;
// }
// else
// _fading = 0.f;
// _time = futureTime;
//}
_sunPos = OsEng.renderEngine().scene()->sceneGraphNode("Sun")->worldPosition();
}
@@ -273,7 +229,10 @@ void RenderableModel::loadTexture() {
if (_colorTexturePath.value() != "") {
_texture = ghoul::io::TextureReader::ref().loadTexture(absPath(_colorTexturePath));
if (_texture) {
LDEBUG("Loaded texture from '" << absPath(_colorTexturePath) << "'");
LDEBUGC(
"RenderableModel",
"Loaded texture from '" << absPath(_colorTexturePath) << "'"
);
_texture->uploadTexture();
_texture->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap);
}

View File

@@ -31,15 +31,21 @@
#include <openspace/properties/scalar/boolproperty.h>
#include <openspace/properties/scalar/floatproperty.h>
#include <openspace/properties/vector/vec3property.h>
#include <openspace/util/updatestructures.h>
#include <ghoul/opengl/programobject.h>
#include <ghoul/opengl/texture.h>
#include <memory>
namespace ghoul {
namespace opengl {
class ProgramObject;
class Texture;
} // namespace opengl
} // namespace ghoul
namespace openspace {
struct RenderData;
struct UpdateData;
namespace documentation { struct Documentation; }
namespace modelgeometry {
@@ -64,24 +70,18 @@ protected:
void loadTexture();
private:
std::unique_ptr<modelgeometry::ModelGeometry> _geometry;
properties::StringProperty _colorTexturePath;
properties::BoolProperty _performFade;
properties::BoolProperty _performShading;
properties::FloatProperty _fading;
std::unique_ptr<ghoul::opengl::ProgramObject> _programObject;
std::unique_ptr<ghoul::opengl::Texture> _texture;
std::unique_ptr<modelgeometry::ModelGeometry> _geometry;
glm::dmat3 _modelTransform;
float _alpha;
int _frameCount;
glm::dvec3 _sunPos;
properties::BoolProperty _performShading;
properties::Vec3Property _debugModelRotation;
};
} // namespace openspace

View File

@@ -26,13 +26,10 @@
#include <openspace/documentation/documentation.h>
#include <openspace/documentation/verifier.h>
#include <openspace/engine/configurationmanager.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/util/powerscaledcoordinate.h>
#include <openspace/scene/scenegraphnode.h>
#include <openspace/rendering/renderengine.h>
#include <modules/newhorizons/rendering/renderableplanetprojection.h>
#include <openspace/scene/scenegraphnode.h>
#include <openspace/util/updatestructures.h>
#include <ghoul/filesystem/filesystem>
#include <ghoul/io/texture/texturereader.h>
@@ -45,14 +42,6 @@ namespace {
const char* KeyBillboard = "Billboard";
const char* KeyBlendMode = "BlendMode";
const char* KeyTexture = "Texture";
const char* keyFieldlines = "Fieldlines";
const char* keyFilename = "File";
const char* keyHints = "Hints";
const char* keyShaders = "Shaders";
const char* keyVertexShader = "VertexShader";
const char* keyFragmentShader = "FragmentShader";
} // namespace
namespace openspace {
@@ -102,11 +91,12 @@ RenderablePlane::RenderablePlane(const ghoul::Dictionary& dictionary)
, _billboard("billboard", "Billboard", false)
, _size("size", "Size", 10, 0, std::pow(10, 25))
, _shader(nullptr)
, _textureIsDirty(false)
, _texture(nullptr)
, _blendMode(BlendMode::Normal)
, _quad(0)
, _vertexPositionBuffer(0)
, _planeIsDirty(false)
, _textureIsDirty(false)
{
documentation::testSpecificationAndThrow(
Documentation(),
@@ -131,7 +121,7 @@ RenderablePlane::RenderablePlane(const ghoul::Dictionary& dictionary)
}
}
_texturePath = absPath(dictionary.value<std::string>(KeyTexture));
_textureFile = new ghoul::filesystem::File(_texturePath);
_textureFile = std::make_unique<ghoul::filesystem::File>(_texturePath);
addProperty(_billboard);
addProperty(_texturePath);
@@ -146,11 +136,6 @@ RenderablePlane::RenderablePlane(const ghoul::Dictionary& dictionary)
setBoundingSphere(_size);
}
RenderablePlane::~RenderablePlane() {
delete _textureFile;
_textureFile = nullptr;
}
bool RenderablePlane::isReady() const {
return _shader && _texture;
}
@@ -177,7 +162,6 @@ bool RenderablePlane::deinitialize() {
glDeleteBuffers(1, &_vertexPositionBuffer);
_vertexPositionBuffer = 0;
delete _textureFile;
_textureFile = nullptr;
RenderEngine& renderEngine = OsEng.renderEngine();
@@ -190,9 +174,6 @@ bool RenderablePlane::deinitialize() {
}
void RenderablePlane::render(const RenderData& data) {
glm::mat4 scaleTransform = glm::mat4(1.0);
// Activate shader
_shader->activate();
//if (_projectionListener){
// //get parent node-texture and set with correct dimensions
@@ -208,28 +189,20 @@ void RenderablePlane::render(const RenderData& data) {
//}
// Model transform and view transform needs to be in double precision
glm::dmat4 rotationTransform;
if (_billboard) {
rotationTransform = glm::inverse(glm::dmat4(data.camera.viewRotationMatrix()));
}
else {
rotationTransform = glm::dmat4(data.modelTransform.rotation);
}
const glm::dmat4 rotationTransform = _billboard ?
glm::inverse(glm::dmat4(data.camera.viewRotationMatrix())) :
glm::dmat4(data.modelTransform.rotation);
glm::dmat4 modelTransform =
const glm::dmat4 modelTransform =
glm::translate(glm::dmat4(1.0), data.modelTransform.translation) *
rotationTransform *
glm::dmat4(glm::scale(glm::dmat4(1.0), glm::dvec3(data.modelTransform.scale))) *
glm::dmat4(scaleTransform);
glm::dmat4 modelViewTransform = data.camera.combinedViewMatrix() * modelTransform;
glm::dmat4(1.0);
const glm::dmat4 modelViewTransform = data.camera.combinedViewMatrix() * modelTransform;
_shader->setUniform("modelViewProjectionTransform",
data.camera.projectionMatrix() * glm::mat4(modelViewTransform));
//_shader->setUniform("ViewProjection", data.camera.viewProjectionMatrix());
//_shader->setUniform("ModelTransform", transform);
//setPscUniforms(*_shader.get(), data.camera, data.position);
ghoul::opengl::TextureUnit unit;
unit.activate();
_texture->bind();
@@ -292,19 +265,15 @@ void RenderablePlane::loadTexture() {
_texture = std::move(texture);
delete _textureFile;
_textureFile = new ghoul::filesystem::File(_texturePath);
_textureFile = std::make_unique<ghoul::filesystem::File>(_texturePath);
_textureFile->setCallback([&](const ghoul::filesystem::File&) { _textureIsDirty = true; });
}
}
}
void RenderablePlane::createPlane() {
// ============================
// GEOMETRY (quad)
// ============================
const GLfloat size = _size;
const GLfloat vertex_data[] = {
const GLfloat vertexData[] = {
// x y z w s t
-size, -size, 0.f, 0.f, 0.f, 0.f,
size, size, 0.f, 0.f, 1.f, 1.f,
@@ -314,13 +283,28 @@ void RenderablePlane::createPlane() {
size, size, 0.f, 0.f, 1.f, 1.f,
};
glBindVertexArray(_quad); // bind array
glBindBuffer(GL_ARRAY_BUFFER, _vertexPositionBuffer); // bind buffer
glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_data), vertex_data, GL_STATIC_DRAW);
glBindVertexArray(_quad);
glBindBuffer(GL_ARRAY_BUFFER, _vertexPositionBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertexData), vertexData, GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 6, reinterpret_cast<void*>(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));
glVertexAttribPointer(
1,
2,
GL_FLOAT,
GL_FALSE,
sizeof(GLfloat) * 6,
reinterpret_cast<void*>(sizeof(GLfloat) * 4)
);
}
} // namespace openspace

View File

@@ -29,34 +29,29 @@
#include <openspace/properties/stringproperty.h>
#include <openspace/properties/scalar/boolproperty.h>
#include <openspace/util/updatestructures.h>
#include <openspace/properties/scalar/floatproperty.h>
namespace ghoul {
namespace filesystem {
class File;
}
namespace opengl {
class ProgramObject;
class Texture;
}
namespace filesystem { class File; }
namespace opengl {
class ProgramObject;
class Texture;
}
} // namespace ghoul
namespace openspace {
struct RenderData;
struct UpdateData;
namespace documentation { struct Documentation; }
struct LinePoint;
class RenderablePlane : public Renderable {
public:
enum class BlendMode : int {
Normal = 0,
Additive
};
RenderablePlane(const ghoul::Dictionary& dictionary);
~RenderablePlane();
bool initialize() override;
bool deinitialize() override;
@@ -69,6 +64,11 @@ public:
static documentation::Documentation Documentation();
private:
enum class BlendMode : int {
Normal = 0,
Additive
};
void loadTexture();
void createPlane();
@@ -76,15 +76,17 @@ private:
properties::BoolProperty _billboard;
properties::FloatProperty _size;
bool _planeIsDirty;
std::unique_ptr<ghoul::opengl::ProgramObject> _shader;
bool _textureIsDirty;
std::unique_ptr<ghoul::opengl::Texture> _texture;
std::unique_ptr<ghoul::filesystem::File> _textureFile;
BlendMode _blendMode;
ghoul::filesystem::File* _textureFile;
GLuint _quad;
GLuint _vertexPositionBuffer;
bool _planeIsDirty;
bool _textureIsDirty;
};
} // namespace openspace

View File

@@ -26,12 +26,16 @@
#include <openspace/documentation/documentation.h>
#include <openspace/documentation/verifier.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/rendering/renderengine.h>
#include <ghoul/io/texture/texturereader.h>
#include <ghoul/opengl/textureunit.h>
#include <openspace/util/powerscaledsphere.h>
#include <openspace/util/updatestructures.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/io/texture/texturereader.h>
#include <ghoul/opengl/texture.h>
#include <ghoul/opengl/textureunit.h>
#include <ghoul/opengl/programobject.h>
#define _USE_MATH_DEFINES
#include <math.h>
@@ -42,8 +46,6 @@ namespace {
const char* KeyTexture = "Texture";
const char* KeyOrientation = "Orientation";
enum Orientation {
Outside = 1,
Inside = 2

View File

@@ -26,19 +26,25 @@
#define __OPENSPACE_MODULE_BASE___RENDERABLESPHERE___H__
#include <openspace/rendering/renderable.h>
#include <openspace/util/updatestructures.h>
#include <openspace/properties/stringproperty.h>
#include <openspace/properties/optionproperty.h>
#include <openspace/properties/scalar/intproperty.h>
#include <openspace/properties/scalar/floatproperty.h>
#include <openspace/properties/vector/vec2property.h>
#include <ghoul/opengl/programobject.h>
#include <ghoul/opengl/texture.h>
#include <openspace/util/powerscaledsphere.h>
namespace ghoul {
namespace opengl {
class ProgramObject;
class Texture;
}
} // namespace ghoul
namespace openspace {
class PowerScaledSphere;
struct RenderData;
struct UpdateData;
namespace documentation { struct Documentation; }
class RenderableSphere : public Renderable {

View File

@@ -27,6 +27,7 @@
#include <openspace/engine/configurationmanager.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/util/spicemanager.h>
#include <openspace/util/updatestructures.h>
#include <ghoul/glm.h>
#define _USE_MATH_DEFINES

View File

@@ -32,6 +32,7 @@
#include <ghoul/opengl/texture.h>
namespace openspace {
class RenderableSphericalGrid : public Renderable{
public:
RenderableSphericalGrid(const ghoul::Dictionary& dictionary);

View File

@@ -29,6 +29,7 @@
#include <openspace/engine/openspaceengine.h>
#include <openspace/rendering/renderengine.h>
#include <openspace/scene/translation.h>
#include <openspace/util/updatestructures.h>
namespace {
const char* KeyTranslation = "Translation";

View File

@@ -27,6 +27,7 @@
#include <openspace/documentation/documentation.h>
#include <openspace/documentation/verifier.h>
#include <openspace/scene/translation.h>
#include <openspace/util/updatestructures.h>
#include <numeric>

View File

@@ -28,6 +28,7 @@
#include <openspace/documentation/verifier.h>
#include <openspace/scene/translation.h>
#include <openspace/util/spicemanager.h>
#include <openspace/util/updatestructures.h>
// This class creates the entire trajectory at once and keeps it in memory the entire
// time. This means that there is no need for updating the trail at runtime, but also that

View File

@@ -30,6 +30,7 @@
#include <modules/globebrowsing/tile/tileselector.h>
#include <modules/globebrowsing/tile/tilemetadata.h>
#include <modules/globebrowsing/rendering/layer/layergroup.h>
#include <openspace/util/updatestructures.h>
namespace openspace {

View File

@@ -29,6 +29,7 @@
#include <modules/globebrowsing/globes/renderableglobe.h>
#include <modules/globebrowsing/rendering/layer/layermanager.h>
#include <modules/globebrowsing/tile/tileprovider/tileprovider.h>
#include <openspace/util/updatestructures.h>
namespace openspace {
namespace globebrowsing {

View File

@@ -29,6 +29,7 @@
#include <modules/globebrowsing/globes/renderableglobe.h>
#include <modules/globebrowsing/rendering/layer/layermanager.h>
#include <modules/globebrowsing/tile/tileprovider/tileprovider.h>
#include <openspace/util/updatestructures.h>
namespace openspace {
namespace globebrowsing {

View File

@@ -26,6 +26,7 @@
#include <modules/globebrowsing/chunk/chunk.h>
#include <modules/globebrowsing/globes/renderableglobe.h>
#include <openspace/util/updatestructures.h>
namespace openspace {
namespace globebrowsing {

View File

@@ -26,6 +26,7 @@
#include <modules/globebrowsing/chunk/chunk.h>
#include <modules/globebrowsing/globes/renderableglobe.h>
#include <openspace/util/updatestructures.h>
namespace openspace {
namespace globebrowsing {

View File

@@ -29,6 +29,7 @@
#include <openspace/engine/openspaceengine.h>
#include <openspace/engine/wrapper/windowwrapper.h>
#include <openspace/rendering/renderengine.h>
#include <openspace/util/updatestructures.h>
namespace openspace {
namespace globebrowsing {

View File

@@ -24,6 +24,7 @@
#include <modules/globebrowsing/other/distanceswitch.h>
#include <openspace/rendering/renderable.h>
#include <openspace/util/updatestructures.h>
namespace openspace {
namespace globebrowsing {

View File

@@ -31,6 +31,7 @@
#include <modules/globebrowsing/rendering/gpu/gpulayermanager.h>
#include <modules/globebrowsing/rendering/layer/layergroup.h>
#include <modules/globebrowsing/tile/rawtiledatareader/rawtiledatareader.h>
#include <openspace/util/updatestructures.h>
namespace {
const char* keyFrame = "Frame";

View File

@@ -28,6 +28,8 @@
#include <openspace/util/time.h>
#include <openspace/util/transformationmanager.h>
#include <modules/iswa/rendering/iswabasegroup.h>
#include <openspace/util/powerscaledcoordinate.h>
#include <openspace/util/updatestructures.h>
namespace {
const std::string _loggerCat = "IswaCygnet";

View File

@@ -50,7 +50,7 @@ namespace ghoul {
namespace openspace {
struct RenderData;
class RaycastData;
struct RaycastData;
class KameleonVolumeRaycaster : public VolumeRaycaster {
public:

View File

@@ -24,12 +24,15 @@
#include <modules/newhorizons/rendering/renderablecrawlingline.h>
#include <modules/newhorizons/util/imagesequencer.h>
#include <openspace/documentation/documentation.h>
#include <openspace/documentation/verifier.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/rendering/renderengine.h>
#include <openspace/util/spicemanager.h>
#include <modules/newhorizons/util/imagesequencer.h>
#include <openspace/util/updatestructures.h>
#include <ghoul/glm.h>
namespace {
const char* KeySource = "Source";

View File

@@ -30,6 +30,7 @@
#include <openspace/documentation/verifier.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/rendering/renderengine.h>
#include <openspace/util/updatestructures.h>
#include <ghoul/opengl/programobject.h>

View File

@@ -34,6 +34,8 @@
#include <openspace/properties/stringproperty.h>
#include <openspace/properties/vector/vec3property.h>
#include <openspace/util/powerscaledcoordinate.h>
namespace ghoul {
namespace opengl {
class ProgramObject;

View File

@@ -42,7 +42,7 @@ namespace ghoul {
namespace openspace {
struct RenderData;
class RaycastData;
struct RaycastData;
class ToyVolumeRaycaster : public VolumeRaycaster {
public: