mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-11 18:34:58 +01:00
Fixed init of Group (actually should NOT init its children nodes).
Ensure Nodes deletetion is done.
This commit is contained in:
@@ -242,6 +242,10 @@ set(VMIX_RSC_FILES
|
||||
./rsc/mesh/disk.ply
|
||||
./rsc/mesh/shadow.ply
|
||||
./rsc/mesh/shadow.png
|
||||
./rsc/mesh/target.ply
|
||||
./rsc/mesh/border.ply
|
||||
./rsc/mesh/icon_video.ply
|
||||
./rsc/mesh/icon_image.ply
|
||||
)
|
||||
|
||||
add_executable(${VMIX_BINARY}
|
||||
|
||||
7
Mesh.cpp
7
Mesh.cpp
@@ -336,7 +336,7 @@ Mesh::Mesh(const std::string& path, const std::string& texture) : Primitive(), r
|
||||
|
||||
Mesh::~Mesh()
|
||||
{
|
||||
|
||||
delete shader_;
|
||||
}
|
||||
|
||||
void Mesh::init()
|
||||
@@ -373,3 +373,8 @@ void Mesh::accept(Visitor& v)
|
||||
Primitive::accept(v);
|
||||
v.visit(*this);
|
||||
}
|
||||
|
||||
//void Mesh::update( float dt )
|
||||
//{
|
||||
// scale_.x = scale_.y;
|
||||
//}
|
||||
|
||||
1
Mesh.h
1
Mesh.h
@@ -22,6 +22,7 @@ public:
|
||||
void init () override;
|
||||
void draw (glm::mat4 modelview, glm::mat4 projection) override;
|
||||
void accept (Visitor& v) override;
|
||||
// void update (float dt) override;
|
||||
|
||||
inline std::string getResource() const { return resource_; }
|
||||
inline std::string getTexture() const { return texturefilename_; }
|
||||
|
||||
@@ -41,6 +41,11 @@ ImageSurface::ImageSurface(const std::string& path) : Primitive(), resource_(pat
|
||||
drawMode_ = GL_TRIANGLE_STRIP;
|
||||
}
|
||||
|
||||
ImageSurface::~ImageSurface()
|
||||
{
|
||||
if (shader_)
|
||||
delete shader_;
|
||||
}
|
||||
|
||||
void ImageSurface::init()
|
||||
{
|
||||
@@ -166,6 +171,12 @@ Points::Points(std::vector<glm::vec3> points, glm::vec4 color, uint pointsize) :
|
||||
pointsize_ = pointsize;
|
||||
}
|
||||
|
||||
Points::~Points()
|
||||
{
|
||||
if (shader_)
|
||||
delete shader_;
|
||||
}
|
||||
|
||||
void Points::init()
|
||||
{
|
||||
Primitive::init();
|
||||
@@ -200,6 +211,12 @@ LineStrip::LineStrip(std::vector<glm::vec3> points, glm::vec4 color, uint linewi
|
||||
drawMode_ = GL_LINE_STRIP;
|
||||
}
|
||||
|
||||
LineStrip::~LineStrip()
|
||||
{
|
||||
if (shader_)
|
||||
delete shader_;
|
||||
}
|
||||
|
||||
void LineStrip::init()
|
||||
{
|
||||
Primitive::init();
|
||||
|
||||
@@ -12,6 +12,7 @@ class ImageSurface : public Primitive {
|
||||
|
||||
public:
|
||||
ImageSurface(const std::string& path = "" );
|
||||
~ImageSurface();
|
||||
|
||||
void init () override;
|
||||
void draw (glm::mat4 modelview, glm::mat4 projection) override;
|
||||
@@ -25,7 +26,7 @@ protected:
|
||||
};
|
||||
|
||||
|
||||
// Draw a Rectangle (triangle strip) with a media as animated texture
|
||||
// Draw a Rectangle with a media as animated texture
|
||||
class MediaPlayer;
|
||||
|
||||
class MediaSurface : public ImageSurface {
|
||||
@@ -66,6 +67,7 @@ class Points : public Primitive {
|
||||
|
||||
public:
|
||||
Points(std::vector<glm::vec3> points, glm::vec4 color, uint pointsize = 10);
|
||||
~Points();
|
||||
|
||||
virtual void init() override;
|
||||
virtual void draw(glm::mat4 modelview, glm::mat4 projection) override;
|
||||
@@ -85,6 +87,7 @@ class LineStrip : public Primitive {
|
||||
|
||||
public:
|
||||
LineStrip(std::vector<glm::vec3> points, glm::vec4 color, uint linewidth = 1);
|
||||
~LineStrip();
|
||||
|
||||
virtual void init() override;
|
||||
virtual void draw(glm::mat4 modelview, glm::mat4 projection) override;
|
||||
@@ -97,6 +100,7 @@ public:
|
||||
inline uint getLineWidth() const { return linewidth_; }
|
||||
};
|
||||
|
||||
|
||||
class LineSquare : public LineStrip {
|
||||
|
||||
void deleteGLBuffers_() override {}
|
||||
@@ -108,6 +112,7 @@ public:
|
||||
void accept(Visitor& v) override;
|
||||
};
|
||||
|
||||
|
||||
class LineCircle : public LineStrip {
|
||||
|
||||
void deleteGLBuffers_() override {}
|
||||
|
||||
27
Scene.cpp
27
Scene.cpp
@@ -51,7 +51,6 @@ void Node::update( float dt )
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Node::accept(Visitor& v)
|
||||
{
|
||||
v.visit(*this);
|
||||
@@ -62,12 +61,6 @@ void Node::accept(Visitor& v)
|
||||
Primitive::~Primitive()
|
||||
{
|
||||
deleteGLBuffers_();
|
||||
|
||||
// points_.clear();
|
||||
// colors_.clear();
|
||||
// texCoords_.clear();
|
||||
// indices_.clear();
|
||||
|
||||
}
|
||||
|
||||
void Primitive::init()
|
||||
@@ -119,8 +112,12 @@ void Primitive::init()
|
||||
drawCount_ = indices_.size();
|
||||
|
||||
// delete temporary buffers
|
||||
if ( arrayBuffer_ ) glDeleteBuffers ( 1, &arrayBuffer_);
|
||||
if ( elementBuffer_ ) glDeleteBuffers ( 1, &elementBuffer_);
|
||||
if ( arrayBuffer_ )
|
||||
glDeleteBuffers ( 1, &arrayBuffer_);
|
||||
if ( elementBuffer_ )
|
||||
glDeleteBuffers ( 1, &elementBuffer_);
|
||||
|
||||
// arrays of vertices are not needed anymore (STATIC DRAW of vertex object)
|
||||
points_.clear();
|
||||
colors_.clear();
|
||||
texCoords_.clear();
|
||||
@@ -146,7 +143,7 @@ void Primitive::draw(glm::mat4 modelview, glm::mat4 projection)
|
||||
//
|
||||
// draw vertex array object
|
||||
//
|
||||
if (drawMode_) {
|
||||
if (vao_) {
|
||||
glBindVertexArray( vao_ );
|
||||
glDrawElements( drawMode_, drawCount_, GL_UNSIGNED_INT, 0 );
|
||||
glBindVertexArray(0);
|
||||
@@ -174,16 +171,6 @@ Group::~Group()
|
||||
children_.clear();
|
||||
}
|
||||
|
||||
void Group::init()
|
||||
{
|
||||
for (NodeSet::iterator node = children_.begin();
|
||||
node != children_.end(); node++) {
|
||||
(*node)->init();
|
||||
}
|
||||
|
||||
Node::init();
|
||||
}
|
||||
|
||||
void Group::update( float dt )
|
||||
{
|
||||
Node::update(dt);
|
||||
|
||||
1
Scene.h
1
Scene.h
@@ -104,7 +104,6 @@ public:
|
||||
Group() : Node() {}
|
||||
virtual ~Group();
|
||||
|
||||
virtual void init () override;
|
||||
virtual void update (float dt) override;
|
||||
virtual void accept (Visitor& v) override;
|
||||
virtual void draw (glm::mat4 modelview, glm::mat4 projection) override;
|
||||
|
||||
16
main.cpp
16
main.cpp
@@ -263,38 +263,40 @@ int main(int, char**)
|
||||
|
||||
glm::vec4 color( 0.8f, 0.8f, 0.f, 1.f);
|
||||
LineSquare border(color, 5);
|
||||
// ObjModel shadow("models/square_border.obj");
|
||||
Mesh shadow("mesh/shadow.ply", "mesh/shadow.png");
|
||||
|
||||
Group g1;
|
||||
g1.translation_ = glm::vec3(1.f, 1.f, 0.2f);
|
||||
g1.scale_ = glm::vec3(1.2f, 1.2f, 1.f);
|
||||
g1.scale_ = glm::vec3(0.8f, 0.8f, 1.f);
|
||||
|
||||
Group g2;
|
||||
g2.translation_ = glm::vec3(-1.f, -1.f, 0.4f);
|
||||
|
||||
Animation A;
|
||||
A.speed_ = 0.08f;
|
||||
A.speed_ = 0.05f;
|
||||
A.axis_ = glm::vec3(1.f, 1.f, 1.f);
|
||||
|
||||
// std::vector<glm::vec3> pts = std::vector<glm::vec3> { glm::vec3( 0.f, 0.f, 0.f ) };
|
||||
// Points P(pts, pink);
|
||||
// P.setPointSize(60);
|
||||
Mesh P("mesh/point.ply");
|
||||
P.scale_ = glm::vec3(0.05f);
|
||||
Mesh P("mesh/target.ply");
|
||||
P.scale_ = glm::vec3(0.5f);
|
||||
|
||||
Mesh meshicon("mesh/icon_video.ply");
|
||||
|
||||
// build tree
|
||||
scene.root_.addChild(&disk);
|
||||
scene.root_.addChild(&circle);
|
||||
|
||||
g1.addChild(&shadow);
|
||||
g1.addChild(&testnode3);
|
||||
g1.addChild(&border);
|
||||
g1.addChild(&shadow);
|
||||
scene.root_.addChild(&g1);
|
||||
|
||||
g2.addChild(&shadow);
|
||||
g2.addChild(&testnode1);
|
||||
g2.addChild(&border);
|
||||
g2.addChild(&shadow);
|
||||
g2.addChild(&meshicon);
|
||||
scene.root_.addChild(&g2);
|
||||
|
||||
A.addChild(&P);
|
||||
|
||||
Reference in New Issue
Block a user