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/disk.ply
|
||||||
./rsc/mesh/shadow.ply
|
./rsc/mesh/shadow.ply
|
||||||
./rsc/mesh/shadow.png
|
./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}
|
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()
|
Mesh::~Mesh()
|
||||||
{
|
{
|
||||||
|
delete shader_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mesh::init()
|
void Mesh::init()
|
||||||
@@ -373,3 +373,8 @@ void Mesh::accept(Visitor& v)
|
|||||||
Primitive::accept(v);
|
Primitive::accept(v);
|
||||||
v.visit(*this);
|
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 init () override;
|
||||||
void draw (glm::mat4 modelview, glm::mat4 projection) override;
|
void draw (glm::mat4 modelview, glm::mat4 projection) override;
|
||||||
void accept (Visitor& v) override;
|
void accept (Visitor& v) override;
|
||||||
|
// void update (float dt) override;
|
||||||
|
|
||||||
inline std::string getResource() const { return resource_; }
|
inline std::string getResource() const { return resource_; }
|
||||||
inline std::string getTexture() const { return texturefilename_; }
|
inline std::string getTexture() const { return texturefilename_; }
|
||||||
|
|||||||
@@ -41,6 +41,11 @@ ImageSurface::ImageSurface(const std::string& path) : Primitive(), resource_(pat
|
|||||||
drawMode_ = GL_TRIANGLE_STRIP;
|
drawMode_ = GL_TRIANGLE_STRIP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ImageSurface::~ImageSurface()
|
||||||
|
{
|
||||||
|
if (shader_)
|
||||||
|
delete shader_;
|
||||||
|
}
|
||||||
|
|
||||||
void ImageSurface::init()
|
void ImageSurface::init()
|
||||||
{
|
{
|
||||||
@@ -166,6 +171,12 @@ Points::Points(std::vector<glm::vec3> points, glm::vec4 color, uint pointsize) :
|
|||||||
pointsize_ = pointsize;
|
pointsize_ = pointsize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Points::~Points()
|
||||||
|
{
|
||||||
|
if (shader_)
|
||||||
|
delete shader_;
|
||||||
|
}
|
||||||
|
|
||||||
void Points::init()
|
void Points::init()
|
||||||
{
|
{
|
||||||
Primitive::init();
|
Primitive::init();
|
||||||
@@ -200,6 +211,12 @@ LineStrip::LineStrip(std::vector<glm::vec3> points, glm::vec4 color, uint linewi
|
|||||||
drawMode_ = GL_LINE_STRIP;
|
drawMode_ = GL_LINE_STRIP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LineStrip::~LineStrip()
|
||||||
|
{
|
||||||
|
if (shader_)
|
||||||
|
delete shader_;
|
||||||
|
}
|
||||||
|
|
||||||
void LineStrip::init()
|
void LineStrip::init()
|
||||||
{
|
{
|
||||||
Primitive::init();
|
Primitive::init();
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ class ImageSurface : public Primitive {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
ImageSurface(const std::string& path = "" );
|
ImageSurface(const std::string& path = "" );
|
||||||
|
~ImageSurface();
|
||||||
|
|
||||||
void init () override;
|
void init () override;
|
||||||
void draw (glm::mat4 modelview, glm::mat4 projection) 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 MediaPlayer;
|
||||||
|
|
||||||
class MediaSurface : public ImageSurface {
|
class MediaSurface : public ImageSurface {
|
||||||
@@ -66,6 +67,7 @@ class Points : public Primitive {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
Points(std::vector<glm::vec3> points, glm::vec4 color, uint pointsize = 10);
|
Points(std::vector<glm::vec3> points, glm::vec4 color, uint pointsize = 10);
|
||||||
|
~Points();
|
||||||
|
|
||||||
virtual void init() override;
|
virtual void init() override;
|
||||||
virtual void draw(glm::mat4 modelview, glm::mat4 projection) override;
|
virtual void draw(glm::mat4 modelview, glm::mat4 projection) override;
|
||||||
@@ -85,6 +87,7 @@ class LineStrip : public Primitive {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
LineStrip(std::vector<glm::vec3> points, glm::vec4 color, uint linewidth = 1);
|
LineStrip(std::vector<glm::vec3> points, glm::vec4 color, uint linewidth = 1);
|
||||||
|
~LineStrip();
|
||||||
|
|
||||||
virtual void init() override;
|
virtual void init() override;
|
||||||
virtual void draw(glm::mat4 modelview, glm::mat4 projection) override;
|
virtual void draw(glm::mat4 modelview, glm::mat4 projection) override;
|
||||||
@@ -97,6 +100,7 @@ public:
|
|||||||
inline uint getLineWidth() const { return linewidth_; }
|
inline uint getLineWidth() const { return linewidth_; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class LineSquare : public LineStrip {
|
class LineSquare : public LineStrip {
|
||||||
|
|
||||||
void deleteGLBuffers_() override {}
|
void deleteGLBuffers_() override {}
|
||||||
@@ -108,6 +112,7 @@ public:
|
|||||||
void accept(Visitor& v) override;
|
void accept(Visitor& v) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class LineCircle : public LineStrip {
|
class LineCircle : public LineStrip {
|
||||||
|
|
||||||
void deleteGLBuffers_() override {}
|
void deleteGLBuffers_() override {}
|
||||||
|
|||||||
27
Scene.cpp
27
Scene.cpp
@@ -51,7 +51,6 @@ void Node::update( float dt )
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Node::accept(Visitor& v)
|
void Node::accept(Visitor& v)
|
||||||
{
|
{
|
||||||
v.visit(*this);
|
v.visit(*this);
|
||||||
@@ -62,12 +61,6 @@ void Node::accept(Visitor& v)
|
|||||||
Primitive::~Primitive()
|
Primitive::~Primitive()
|
||||||
{
|
{
|
||||||
deleteGLBuffers_();
|
deleteGLBuffers_();
|
||||||
|
|
||||||
// points_.clear();
|
|
||||||
// colors_.clear();
|
|
||||||
// texCoords_.clear();
|
|
||||||
// indices_.clear();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Primitive::init()
|
void Primitive::init()
|
||||||
@@ -119,8 +112,12 @@ void Primitive::init()
|
|||||||
drawCount_ = indices_.size();
|
drawCount_ = indices_.size();
|
||||||
|
|
||||||
// delete temporary buffers
|
// delete temporary buffers
|
||||||
if ( arrayBuffer_ ) glDeleteBuffers ( 1, &arrayBuffer_);
|
if ( arrayBuffer_ )
|
||||||
if ( elementBuffer_ ) glDeleteBuffers ( 1, &elementBuffer_);
|
glDeleteBuffers ( 1, &arrayBuffer_);
|
||||||
|
if ( elementBuffer_ )
|
||||||
|
glDeleteBuffers ( 1, &elementBuffer_);
|
||||||
|
|
||||||
|
// arrays of vertices are not needed anymore (STATIC DRAW of vertex object)
|
||||||
points_.clear();
|
points_.clear();
|
||||||
colors_.clear();
|
colors_.clear();
|
||||||
texCoords_.clear();
|
texCoords_.clear();
|
||||||
@@ -146,7 +143,7 @@ void Primitive::draw(glm::mat4 modelview, glm::mat4 projection)
|
|||||||
//
|
//
|
||||||
// draw vertex array object
|
// draw vertex array object
|
||||||
//
|
//
|
||||||
if (drawMode_) {
|
if (vao_) {
|
||||||
glBindVertexArray( vao_ );
|
glBindVertexArray( vao_ );
|
||||||
glDrawElements( drawMode_, drawCount_, GL_UNSIGNED_INT, 0 );
|
glDrawElements( drawMode_, drawCount_, GL_UNSIGNED_INT, 0 );
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
@@ -174,16 +171,6 @@ Group::~Group()
|
|||||||
children_.clear();
|
children_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Group::init()
|
|
||||||
{
|
|
||||||
for (NodeSet::iterator node = children_.begin();
|
|
||||||
node != children_.end(); node++) {
|
|
||||||
(*node)->init();
|
|
||||||
}
|
|
||||||
|
|
||||||
Node::init();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Group::update( float dt )
|
void Group::update( float dt )
|
||||||
{
|
{
|
||||||
Node::update(dt);
|
Node::update(dt);
|
||||||
|
|||||||
1
Scene.h
1
Scene.h
@@ -104,7 +104,6 @@ public:
|
|||||||
Group() : Node() {}
|
Group() : Node() {}
|
||||||
virtual ~Group();
|
virtual ~Group();
|
||||||
|
|
||||||
virtual void init () override;
|
|
||||||
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;
|
||||||
|
|||||||
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);
|
glm::vec4 color( 0.8f, 0.8f, 0.f, 1.f);
|
||||||
LineSquare border(color, 5);
|
LineSquare border(color, 5);
|
||||||
// ObjModel shadow("models/square_border.obj");
|
|
||||||
Mesh shadow("mesh/shadow.ply", "mesh/shadow.png");
|
Mesh shadow("mesh/shadow.ply", "mesh/shadow.png");
|
||||||
|
|
||||||
Group g1;
|
Group g1;
|
||||||
g1.translation_ = glm::vec3(1.f, 1.f, 0.2f);
|
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;
|
Group g2;
|
||||||
g2.translation_ = glm::vec3(-1.f, -1.f, 0.4f);
|
g2.translation_ = glm::vec3(-1.f, -1.f, 0.4f);
|
||||||
|
|
||||||
Animation A;
|
Animation A;
|
||||||
A.speed_ = 0.08f;
|
A.speed_ = 0.05f;
|
||||||
A.axis_ = glm::vec3(1.f, 1.f, 1.f);
|
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 ) };
|
// std::vector<glm::vec3> pts = std::vector<glm::vec3> { glm::vec3( 0.f, 0.f, 0.f ) };
|
||||||
// Points P(pts, pink);
|
// Points P(pts, pink);
|
||||||
// P.setPointSize(60);
|
// P.setPointSize(60);
|
||||||
Mesh P("mesh/point.ply");
|
Mesh P("mesh/target.ply");
|
||||||
P.scale_ = glm::vec3(0.05f);
|
P.scale_ = glm::vec3(0.5f);
|
||||||
|
|
||||||
|
Mesh meshicon("mesh/icon_video.ply");
|
||||||
|
|
||||||
// build tree
|
// build tree
|
||||||
scene.root_.addChild(&disk);
|
scene.root_.addChild(&disk);
|
||||||
scene.root_.addChild(&circle);
|
scene.root_.addChild(&circle);
|
||||||
|
|
||||||
g1.addChild(&shadow);
|
|
||||||
g1.addChild(&testnode3);
|
g1.addChild(&testnode3);
|
||||||
g1.addChild(&border);
|
g1.addChild(&border);
|
||||||
|
g1.addChild(&shadow);
|
||||||
scene.root_.addChild(&g1);
|
scene.root_.addChild(&g1);
|
||||||
|
|
||||||
g2.addChild(&shadow);
|
|
||||||
g2.addChild(&testnode1);
|
g2.addChild(&testnode1);
|
||||||
g2.addChild(&border);
|
g2.addChild(&border);
|
||||||
|
g2.addChild(&shadow);
|
||||||
|
g2.addChild(&meshicon);
|
||||||
scene.root_.addChild(&g2);
|
scene.root_.addChild(&g2);
|
||||||
|
|
||||||
A.addChild(&P);
|
A.addChild(&P);
|
||||||
|
|||||||
Reference in New Issue
Block a user