Commit d4b50516 authored by Jan Möbius's avatar Jan Möbius

Merge branch 'ACG_update' into 'master'

Acg update

- The renderer can track which node created a renderObject now.
- fix memory crash in UniformPool: crash on destructor of UniformPool that was previously initialized with the assignment operator

See merge request !160
parents f3691620 41b9fcb4
Pipeline #3504 passed with stage
in 58 minutes and 23 seconds
......@@ -446,6 +446,9 @@ class ScenegraphTraversalStackEl {
void IRenderer::traverseRenderableNodes( ACG::GLState* _glState, ACG::SceneGraph::DrawModes::DrawMode _drawMode, ACG::SceneGraph::BaseNode &_node, const ACG::SceneGraph::Material &_mat )
{
renderObjectSource_.clear();
overlayObjectSource_.clear();
if (_node.status() == ACG::SceneGraph::BaseNode::HideSubtree)
return;
......@@ -478,6 +481,10 @@ void IRenderer::traverseRenderableNodes( ACG::GLState* _glState, ACG::SceneGraph
if (cur.node->status() != ACG::SceneGraph::BaseNode::HideNode)
cur.node->getRenderObjects(this, *_glState, nodeDM, cur.material);
// keep track of which node added objects
size_t numAddedObjects = renderObjects_.size() - renderObjectSource_.size();
renderObjectSource_.insert(renderObjectSource_.end(), numAddedObjects, cur.node);
// Process children?
if (cur.node->status() != ACG::SceneGraph::BaseNode::HideChildren) {
// Process all children which are second pass
......@@ -565,11 +572,21 @@ void IRenderer::prepareRenderingPipeline(ACG::GLState* _glState, ACG::SceneGraph
lineGL42Objects_.clear();
lineGL42Objects_.reserve(numLineObjects);
sortListObjects_.clear();
sortListObjects_.reserve(numRenderObjects);
sortListOverlays_.clear();
sortListOverlays_.reserve(numOverlayObjects);
// init sorted objects array
for (size_t i = 0; i < renderObjects_.size(); ++i)
{
if (renderObjects_[i].overlay)
{
overlayObjects_.push_back(&renderObjects_[i]);
sortListOverlays_.push_back(i);
}
else if (enableLineThicknessGL42_ && numLineObjects && renderObjects_[i].isDefaultLineObject())
{
renderObjects_[i].shaderDesc.geometryTemplateFile = "Wireframe/gl42/geometry.tpl";
......@@ -582,7 +599,10 @@ void IRenderer::prepareRenderingPipeline(ACG::GLState* _glState, ACG::SceneGraph
lineGL42Objects_.push_back(&renderObjects_[i]);
}
else
{
sortedObjects_.push_back(&renderObjects_[i]);
sortListObjects_.push_back(i);
}
}
sortRenderObjects();
......@@ -790,16 +810,50 @@ void IRenderer::clearInputFbo( const ACG::Vec4f& clearColor )
namespace {
struct RenderObjectComparator {
bool operator() (ACG::RenderObject *a, ACG::RenderObject * b) {
return (a->priority < b->priority);
RenderObjectComparator(const std::vector<ACG::RenderObject>& _vec) : vec_(_vec) {
}
bool operator() (int a, int b) {
return (vec_[a].priority < vec_[b].priority);
}
const std::vector<ACG::RenderObject>& vec_;
};
}
void IRenderer::sortRenderObjects()
{
std::sort(sortedObjects_.begin(), sortedObjects_.end(), RenderObjectComparator());
std::sort(overlayObjects_.begin(), overlayObjects_.end(), RenderObjectComparator());
size_t numObjs = sortListObjects_.size();
size_t numOverlays = sortListOverlays_.size();
RenderObjectComparator cmpOp(renderObjects_);
std::sort(sortListObjects_.begin(), sortListObjects_.end(), cmpOp);
std::sort(sortListOverlays_.begin(), sortListOverlays_.end(), cmpOp);
// apply sorting list
std::vector<ACG::SceneGraph::BaseNode*> temp;
renderObjectSource_.swap(temp);
renderObjectSource_.resize(numObjs, 0);
overlayObjectSource_.resize(numOverlays, 0);
for (size_t i = 0; i < numObjs; ++i)
{
int objID = sortListObjects_[i];
sortedObjects_[i] = &renderObjects_[objID];
renderObjectSource_[i] = temp[objID];
}
for (size_t i = 0; i < numOverlays; ++i)
{
int objID = sortListOverlays_[i];
overlayObjects_[i] = &renderObjects_[objID];
overlayObjectSource_[i] = temp[objID];
}
}
......@@ -1148,6 +1202,18 @@ ACG::RenderObject* IRenderer::getOverlayRenderObject( int i )
return overlayObjects_[i];
}
ACG::SceneGraph::BaseNode* IRenderer::getRenderObjectNode( int i )
{
return renderObjectSource_[i];
}
ACG::SceneGraph::BaseNode* IRenderer::getOverlayRenderObjectNode( int i )
{
return overlayObjectSource_[i];
}
ACG::RenderObject* IRenderer::getLineGL42RenderObject( int i )
{
if (lineGL42Objects_.empty())
......
......@@ -446,6 +446,14 @@ protected:
const ACG::Vec3f& getGlobalAmbientScale() const {return globalLightModelAmbient_;}
/// Get node that emitted the render object in the sorted list by index (not including overlay objects)
ACG::SceneGraph::BaseNode* getRenderObjectNode(int i);
/// Get node that emitted the render object in the sorted list by index (only overlay objects)
ACG::SceneGraph::BaseNode* getOverlayRenderObjectNode(int i);
/** Enable/disable line thickness rendering with opengl4.2
*
* Instead of quad extrusion in a geometry shader, thick lines are manually rasterized in a load/store image.
......@@ -498,6 +506,10 @@ protected:
/// array of renderobjects, filled by addRenderObject()
std::vector<ACG::RenderObject> renderObjects_;
/// map sortedID -> original renderObjectID
std::vector<int> sortListObjects_;
/// map sortedID -> original renderObjectID
std::vector<int> sortListOverlays_;
/// sorted list of renderobjects without overlay objects (sorted in rendering order)
std::vector<ACG::RenderObject*> sortedObjects_;
......@@ -508,6 +520,12 @@ protected:
/// active render object modifiers
std::vector<ACG::RenderObjectModifier*> renderObjectModifiers_;
/// source node that added the render object (map renderObjectID -> scenegraph node)
std::vector<ACG::SceneGraph::BaseNode*> renderObjectSource_;
/// source node that added the overlay render object (map renderObjectID -> scenegraph node)
std::vector<ACG::SceneGraph::BaseNode*> overlayObjectSource_;
/**
* Stores fbo containing a depth map for each viewport.
* The depth map is computed in a z-prepass if at least one RenderObject makes use of the scene depth map.
......
......@@ -183,7 +183,7 @@ public:
/** \brief get the internal mesh
*/
const Mesh& mesh() const { return mesh_; }
const Mesh& mesh() const { return mesh_; }
private:
/// The mesh this node works on
......
......@@ -83,6 +83,11 @@ namespace GLSL {
clear();
}
void UniformPool::operator =(const UniformPool& _other) {
addPool(_other);
}
void UniformPool::clear() {
// Delete the uniforms in that pool
for (UniformListIt it = pool_.begin(); it != pool_.end(); ++it)
......@@ -311,7 +316,6 @@ namespace GLSL {
checkGLError2(id.c_str());
}
/** \brief Creates a copy of input data
*/
UniformPool::UniformBuf::UniformBuf()
......
......@@ -121,6 +121,11 @@ namespace GLSL {
*/
bool empty() const;
/** \brief copy
*
*/
void operator =(const UniformPool& _other);
private:
struct UniformBase {
std::string id;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment