Cleanup and

This commit is contained in:
brunoherbelin
2020-06-14 20:21:09 +02:00
parent 709d379bc7
commit bfdeb0b52f
10 changed files with 129 additions and 78 deletions

View File

@@ -13,30 +13,45 @@
Frame::Frame(Type type) : Node(), type_(type), side_(nullptr), top_(nullptr), shadow_(nullptr), square_(nullptr) Frame::Frame(Type type) : Node(), type_(type), side_(nullptr), top_(nullptr), shadow_(nullptr), square_(nullptr)
{ {
static Mesh *shadows[3] = {nullptr};
if (shadows[0] == nullptr) {
shadows[0] = new Mesh("mesh/glow.ply", "images/glow.dds");
shadows[1] = new Mesh("mesh/shadow.ply", "images/shadow.dds");
shadows[2] = new Mesh("mesh/shadow_perspective.ply", "images/shadow_perspective.dds");
}
static Mesh *frames[4] = {nullptr};
if (frames[0] == nullptr) {
frames[0] = new Mesh("mesh/border_round.ply");
frames[1] = new Mesh("mesh/border_top.ply");
frames[2] = new Mesh("mesh/border_large_round.ply");
frames[3] = new Mesh("mesh/border_large_top.ply");
}
static LineSquare *sharpframe = new LineSquare( 3 );
color = glm::vec4( 1.f, 1.f, 1.f, 1.f); color = glm::vec4( 1.f, 1.f, 1.f, 1.f);
switch (type) { switch (type) {
case SHARP_LARGE: case SHARP_LARGE:
square_ = new LineSquare( 3 ); square_ = sharpframe;
shadow_ = new Mesh("mesh/glow.ply", "images/glow.dds"); shadow_ = shadows[0];
break; break;
case SHARP_THIN: case SHARP_THIN:
square_ = new LineSquare( 3 ); square_ = sharpframe;
break; break;
case ROUND_LARGE: case ROUND_LARGE:
side_ = new Mesh("mesh/border_large_round.ply"); side_ = frames[2];
top_ = new Mesh("mesh/border_large_top.ply"); top_ = frames[3];
shadow_ = new Mesh("mesh/shadow.ply", "images/shadow.dds"); shadow_ = shadows[1];
break; break;
default: default:
case ROUND_THIN: case ROUND_THIN:
side_ = new Mesh("mesh/border_round.ply"); side_ = frames[0];
top_ = new Mesh("mesh/border_top.ply"); top_ = frames[1];
shadow_ = new Mesh("mesh/shadow.ply", "images/shadow.dds"); shadow_ = shadows[1];
break; break;
case ROUND_SHADOW: case ROUND_SHADOW:
side_ = new Mesh("mesh/border_round.ply"); side_ = frames[0];
top_ = new Mesh("mesh/border_top.ply"); top_ = frames[1];
shadow_ = new Mesh("mesh/shadow_perspective.ply", "images/shadow_perspective.dds"); shadow_ = shadows[2];
break; break;
} }
@@ -44,9 +59,7 @@ Frame::Frame(Type type) : Node(), type_(type), side_(nullptr), top_(nullptr), sh
Frame::~Frame() Frame::~Frame()
{ {
if(side_) delete side_;
if(top_) delete top_;
if(shadow_) delete shadow_;
} }
void Frame::update( float dt ) void Frame::update( float dt )
@@ -58,14 +71,21 @@ void Frame::update( float dt )
side_->update(dt); side_->update(dt);
if(shadow_) if(shadow_)
shadow_->update(dt); shadow_->update(dt);
if(square_)
square_->update(dt);
} }
void Frame::draw(glm::mat4 modelview, glm::mat4 projection) void Frame::draw(glm::mat4 modelview, glm::mat4 projection)
{ {
if ( !initialized() ) { if ( !initialized() ) {
if(side_) side_->init(); if(side_ && !side_->initialized())
if(top_) top_->init(); side_->init();
if(shadow_) shadow_->init(); if(top_ && !top_->initialized())
top_->init();
if(shadow_ && !shadow_->initialized())
shadow_->init();
if(square_ && !square_->initialized())
square_->init();
init(); init();
} }
@@ -127,21 +147,21 @@ void Frame::accept(Visitor& v)
Handles::Handles(Type type) : Node(), type_(type) Handles::Handles(Type type) : Node(), type_(type)
{ {
color = glm::vec4( 1.f, 1.f, 0.f, 1.f); static Mesh *handle_rotation_ = new Mesh("mesh/border_handles_rotation.ply");
static Mesh *handle_corner = new Mesh("mesh/border_handles_overlay.ply");
color = glm::vec4( 1.f, 1.f, 0.f, 1.f);
if ( type_ == ROTATE ) { if ( type_ == ROTATE ) {
handle_ = new Mesh("mesh/border_handles_rotation.ply"); handle_ = handle_rotation_;
} }
else { else {
// handle_ = new LineSquare(color, int ( 2.1f * Rendering::manager().DPIScale()) ); handle_ = handle_corner;
handle_ = new Mesh("mesh/border_handles_overlay.ply");
} }
} }
Handles::~Handles() Handles::~Handles()
{ {
if(handle_) delete handle_;
} }
void Handles::update( float dt ) void Handles::update( float dt )
@@ -153,7 +173,8 @@ void Handles::update( float dt )
void Handles::draw(glm::mat4 modelview, glm::mat4 projection) void Handles::draw(glm::mat4 modelview, glm::mat4 projection)
{ {
if ( !initialized() ) { if ( !initialized() ) {
if(handle_) handle_->init(); if(handle_ && !handle_->initialized())
handle_->init();
init(); init();
} }
@@ -248,45 +269,33 @@ void Handles::accept(Visitor& v)
Icon::Icon(Type style, glm::vec3 pos) : Node() Icon::Icon(Type style, glm::vec3 pos) : Node()
{ {
color = glm::vec4( 1.f, 1.f, 1.f, 1.f); static Mesh *icons[7] = {nullptr};
translation_ = pos; if (icons[0] == nullptr) {
icons[IMAGE] = new Mesh("mesh/icon_image.ply");
switch (style) { icons[VIDEO] = new Mesh("mesh/icon_video.ply");
case IMAGE: icons[SESSION] = new Mesh("mesh/icon_vimix.ply");
icon_ = new Mesh("mesh/icon_image.ply"); icons[CLONE] = new Mesh("mesh/icon_clone.ply");
break; icons[RENDER] = new Mesh("mesh/icon_render.ply");
case VIDEO: icons[EMPTY] = new Mesh("mesh/icon_empty.ply");
icon_ = new Mesh("mesh/icon_video.ply"); icons[GENERIC] = new Mesh("mesh/point.ply");
break;
case SESSION:
icon_ = new Mesh("mesh/icon_vimix.ply");
break;
case CLONE:
icon_ = new Mesh("mesh/icon_clone.ply");
break;
case RENDER:
icon_ = new Mesh("mesh/icon_render.ply");
break;
case EMPTY:
icon_ = new Mesh("mesh/icon_empty.ply");
break;
default:
case GENERIC:
icon_ = new Mesh("mesh/point.ply");
break;
} }
icon_ = icons[style];
translation_ = pos;
color = glm::vec4( 1.f, 1.f, 1.f, 1.f);
} }
Icon::~Icon() Icon::~Icon()
{ {
if(icon_) delete icon_;
} }
void Icon::draw(glm::mat4 modelview, glm::mat4 projection) void Icon::draw(glm::mat4 modelview, glm::mat4 projection)
{ {
if ( !initialized() ) { if ( !initialized() ) {
if(icon_) icon_->init(); if(icon_ && !icon_->initialized())
icon_->init();
init(); init();
} }

View File

@@ -87,7 +87,4 @@ protected:
}; };
// TODO Shadow mesh with unique vao
#endif // DECORATIONS_H #endif // DECORATIONS_H

View File

@@ -38,7 +38,7 @@ void ImageShader::use()
program_->setUniform("stipple", stipple); program_->setUniform("stipple", stipple);
glActiveTexture(GL_TEXTURE1); glActiveTexture(GL_TEXTURE1);
if ( mask < 9 ) { if ( mask < 10 ) {
glBindTexture(GL_TEXTURE_2D, mask_presets[mask]); glBindTexture(GL_TEXTURE_2D, mask_presets[mask]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

2
Mesh.h
View File

@@ -26,7 +26,7 @@ public:
inline std::string meshPath() const { return mesh_resource_; } inline std::string meshPath() const { return mesh_resource_; }
inline std::string texturePath() const { return texture_resource_; } inline std::string texturePath() const { return texture_resource_; }
protected: //protected:
std::string mesh_resource_; std::string mesh_resource_;
std::string texture_resource_; std::string texture_resource_;
uint textureindex_; uint textureindex_;

View File

@@ -209,7 +209,7 @@ Points::Points(std::vector<glm::vec3> points, glm::vec4 color, uint pointsize) :
indices_.push_back ( i ); indices_.push_back ( i );
} }
drawMode_ = GL_POINTS; drawMode_ = GL_POINTS; // TODO implement drawing of points as Mesh
pointsize_ = pointsize; pointsize_ = pointsize;
} }

View File

@@ -64,7 +64,9 @@ void Node::accept(Visitor& v)
v.visit(*this); v.visit(*this);
} }
//
// Primitive // Primitive
//
Primitive::~Primitive() Primitive::~Primitive()
{ {
@@ -181,8 +183,10 @@ void Primitive::replaceShader( Shader *newshader )
} }
} }
//
// Group // Group
//
Group::~Group() Group::~Group()
{ {
clear(); clear();
@@ -292,11 +296,34 @@ Node *Group::back()
return nullptr; return nullptr;
} }
uint Group::numChildren() const //
// Switch node
//
Switch::~Switch()
{ {
return children_.size(); clear();
} }
void Switch::clear()
{
for(std::vector<Node *>::iterator it = children_.begin(); it != children_.end(); ) {
// one less ref to this node
(*it)->refcount_--;
// if this group was the only remaining parent
if ( (*it)->refcount_ < 1 ) {
// delete
delete (*it);
}
// erase this iterator from the list
it = children_.erase(it);
}
// reset active
active_ = 0;
}
void Switch::update( float dt ) void Switch::update( float dt )
{ {
Node::update(dt); Node::update(dt);
@@ -341,14 +368,20 @@ Node *Switch::child(uint index) const
uint Switch::attach(Node *child) uint Switch::attach(Node *child)
{ {
children_.push_back(child); children_.push_back(child);
child->refcount_++;
// make new child active
active_ = children_.size() - 1; active_ = children_.size() - 1;
return active_; return active_;
} }
void Switch::detatch(Node *child) void Switch::detatch(Node *child)
{ {
// if removing the active child, it cannot be active anymore
if ( children_.at(active_) == child )
active_ = 0;
// find the node with this id, and erase it out of the list of children // find the node with this id, and erase it out of the list of children
// NB: do NOT delete with remove : this takes all nodes with same depth (i.e. equal depth in set)
std::vector<Node *>::iterator it = std::find_if(children_.begin(), children_.end(), hasId(child->id())); std::vector<Node *>::iterator it = std::find_if(children_.begin(), children_.end(), hasId(child->id()));
if ( it != children_.end()) { if ( it != children_.end()) {
// detatch child from group parent // detatch child from group parent
@@ -357,6 +390,9 @@ void Switch::detatch(Node *child)
} }
} }
//
// Scene
//
Scene::Scene() Scene::Scene()
{ {

22
Scene.h
View File

@@ -165,20 +165,23 @@ public:
Group() : Node() {} Group() : Node() {}
virtual ~Group(); virtual ~Group();
// Node interface
virtual void update (float dt) override; virtual void update (float dt) override;
virtual void accept (Visitor& v) override; virtual void accept (Visitor& v) override;
virtual void draw (glm::mat4 modelview, glm::mat4 projection) override; virtual void draw (glm::mat4 modelview, glm::mat4 projection) override;
// container
void clear(); void clear();
void attach (Node *child); void attach (Node *child);
void detatch (Node *child); void detatch (Node *child);
void sort(); inline uint numChildren () const { return children_.size(); }
// Group specific access to its Nodes
void sort();
NodeSet::iterator begin(); NodeSet::iterator begin();
NodeSet::iterator end(); NodeSet::iterator end();
Node *front(); Node *front();
Node *back(); Node *back();
uint numChildren() const;
protected: protected:
NodeSet children_; NodeSet children_;
@@ -186,7 +189,7 @@ protected:
}; };
/** /**
* @brief The Switch class is a Group to selectively update & draw ONE selected child * @brief The Switch class selectively updates & draws ONE selected child
* *
* update() will update only the active child * update() will update only the active child
* draw() will draw only the active child * draw() will draw only the active child
@@ -196,18 +199,23 @@ class Switch : public Node {
public: public:
Switch() : Node(), active_(0) {} Switch() : Node(), active_(0) {}
virtual ~Switch();
// Node interface
virtual void update (float dt) override; virtual void update (float dt) override;
virtual void accept (Visitor& v) override; virtual void accept (Visitor& v) override;
virtual void draw (glm::mat4 modelview, glm::mat4 projection) override; virtual void draw (glm::mat4 modelview, glm::mat4 projection) override;
// container
void clear();
uint attach (Node *child); uint attach (Node *child);
void detatch (Node *child); void detatch (Node *child);
void setActive (uint index); inline uint numChildren () const { return children_.size(); }
uint active () const { return active_; } // Switch specific access to its Nodes
void setActive (uint index);
uint active () const { return active_; }
Node *activeChild () const { return child(active_); } Node *activeChild () const { return child(active_); }
uint numChildren () const { return children_.size(); }
Node *child (uint index) const; Node *child (uint index) const;
protected: protected:

View File

@@ -130,6 +130,7 @@ Source::~Source()
delete groups_[View::LAYER]; delete groups_[View::LAYER];
groups_.clear(); groups_.clear();
frames_.clear();
overlays_.clear(); overlays_.clear();
for (auto it = clones_.begin(); it != clones_.end(); it++) for (auto it = clones_.begin(); it != clones_.end(); it++)

View File

@@ -111,12 +111,12 @@ std::pair<Node *, glm::vec2> View::pick(glm::vec3 point)
void GeometryView::select(glm::vec2 A, glm::vec2 B) void GeometryView::select(glm::vec2 A, glm::vec2 B)
{ {
for(auto it = scene.ws()->begin(); it != scene.ws()->end(); it++) { // for(auto it = scene.ws()->begin(); it != scene.ws()->end(); it++) {
if ( *it != selection_box_) // if ( *it != selection_box_)
selection_box_->attach(*it); // selection_box_->attach(*it);
} // }
selection_box_->visible_ = true; // selection_box_->visible_ = true;
} }
@@ -319,9 +319,9 @@ GeometryView::GeometryView() : View(GEOMETRY)
scene.fg()->attach(border); scene.fg()->attach(border);
// selection box // selection box
selection_box_ = new Box; // selection_box_ = new Box;
selection_box_->visible_ = false; // selection_box_->visible_ = false;
scene.ws()->attach(selection_box_); // scene.ws()->attach(selection_box_);
} }
void GeometryView::update(float dt) void GeometryView::update(float dt)

2
View.h
View File

@@ -119,7 +119,7 @@ public:
Cursor over (glm::vec2, Source*, std::pair<Node *, glm::vec2>) override; Cursor over (glm::vec2, Source*, std::pair<Node *, glm::vec2>) override;
void select(glm::vec2, glm::vec2) override; void select(glm::vec2, glm::vec2) override;
class Box *selection_box_; // class Box *selection_box_;
}; };
class LayerView : public View class LayerView : public View