Use global memory block for the models

This commit is contained in:
Alexander Bock
2020-08-19 10:27:21 +02:00
parent 7603edf906
commit 89af15126b
5 changed files with 25 additions and 27 deletions
+10 -3
View File
@@ -25,8 +25,10 @@
#include <modules/base/rendering/modelgeometry.h>
#include <openspace/documentation/verifier.h>
#include <openspace/engine/globals.h>
#include <openspace/rendering/renderable.h>
#include <openspace/util/factorymanager.h>
#include <openspace/util/memorymanager.h>
#include <ghoul/filesystem/cachemanager.h>
#include <ghoul/filesystem/file.h>
#include <ghoul/filesystem/filesystem.h>
@@ -80,7 +82,8 @@ documentation:: Documentation ModelGeometry::Documentation() {
};
}
std::unique_ptr<ModelGeometry> ModelGeometry::createFromDictionary(
// Create with ghoul::mm_unique_ptr
ghoul::mm_unique_ptr<ModelGeometry> ModelGeometry::createFromDictionary(
const ghoul::Dictionary& dictionary)
{
if (!dictionary.hasKeyAndValue<std::string>(KeyType)) {
@@ -90,8 +93,12 @@ std::unique_ptr<ModelGeometry> ModelGeometry::createFromDictionary(
const std::string& geometryType = dictionary.value<std::string>(KeyType);
auto factory = FactoryManager::ref().factory<ModelGeometry>();
ModelGeometry* geometry = factory->create(geometryType, dictionary);
return std::unique_ptr<ModelGeometry>(geometry);
ModelGeometry* geometry = factory->create(
geometryType,
dictionary,
&global::memoryManager.PersistentMemory
);
return ghoul::mm_unique_ptr<ModelGeometry>(geometry);
}
ModelGeometry::ModelGeometry(const ghoul::Dictionary& dictionary) {
+2 -1
View File
@@ -25,6 +25,7 @@
#ifndef __OPENSPACE_MODULE_BASE___MODELGEOMETRY___H__
#define __OPENSPACE_MODULE_BASE___MODELGEOMETRY___H__
#include <ghoul/misc/managedmemoryuniqueptr.h>
#include <ghoul/opengl/ghoul_gl.h>
#include <ghoul/opengl/texture.h>
#include <memory>
@@ -45,7 +46,7 @@ public:
GLfloat normal[3];
};
static std::unique_ptr<ModelGeometry> createFromDictionary(
static ghoul::mm_unique_ptr<ModelGeometry> createFromDictionary(
const ghoul::Dictionary& dictionary
);
+7 -19
View File
@@ -301,13 +301,13 @@ void RenderableModel::initializeGL() {
ghoul::opengl::updateUniformLocations(*_program, _uniformCache, UniformNames);
for (const std::unique_ptr<modelgeometry::ModelGeometry>& geom : _geometry) {
for (const ghoul::mm_unique_ptr<modelgeometry::ModelGeometry>& geom : _geometry) {
geom->initialize(this);
}
}
void RenderableModel::deinitializeGL() {
for (const std::unique_ptr<modelgeometry::ModelGeometry>& geom : _geometry) {
for (const ghoul::mm_unique_ptr<modelgeometry::ModelGeometry>& geom : _geometry) {
geom->deinitialize();
}
_geometry.clear();
@@ -382,22 +382,10 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) {
_uniformCache.projectionTransform,
data.camera.projectionMatrix()
);
_program->setUniform(
_uniformCache.ambientIntensity,
_ambientIntensity
);
_program->setUniform(
_uniformCache.diffuseIntensity,
_diffuseIntensity
);
_program->setUniform(
_uniformCache.specularIntensity,
_specularIntensity
);
_program->setUniform(
_uniformCache.performShading,
_performShading
);
_program->setUniform(_uniformCache.ambientIntensity, _ambientIntensity);
_program->setUniform(_uniformCache.diffuseIntensity, _diffuseIntensity);
_program->setUniform(_uniformCache.specularIntensity, _specularIntensity);
_program->setUniform(_uniformCache.performShading, _performShading);
if (_disableFaceCulling) {
glDisable(GL_CULL_FACE);
@@ -406,7 +394,7 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) {
ghoul::opengl::TextureUnit unit;
unit.activate();
_program->setUniform(_uniformCache.texture, unit);
for (const std::unique_ptr<modelgeometry::ModelGeometry>& geom : _geometry) {
for (const ghoul::mm_unique_ptr<modelgeometry::ModelGeometry>& geom : _geometry) {
geom->setUniforms(*_program);
geom->bindTexture();
geom->render();
+4 -3
View File
@@ -27,13 +27,14 @@
#include <openspace/rendering/renderable.h>
#include <openspace/properties/matrix/dmat4property.h>
#include <openspace/properties/matrix/mat3property.h>
#include <openspace/properties/scalar/boolproperty.h>
#include <openspace/properties/scalar/floatproperty.h>
#include <openspace/properties/vector/vec3property.h>
#include <ghoul/misc/managedmemoryuniqueptr.h>
#include <ghoul/opengl/uniformcache.h>
#include <memory>
#include <openspace/properties/matrix/dmat4property.h>
#include <openspace/properties/vector/vec3property.h>
namespace ghoul::opengl {
class ProgramObject;
@@ -66,7 +67,7 @@ public:
static documentation::Documentation Documentation();
private:
std::vector<std::unique_ptr<modelgeometry::ModelGeometry>> _geometry;
std::vector<ghoul::mm_unique_ptr<modelgeometry::ModelGeometry>> _geometry;
properties::FloatProperty _ambientIntensity;