diff --git a/src/shimatta-opengl-colored-triangle.c b/src/shimatta-opengl-colored-triangle.c index 7660c62..b965662 100644 --- a/src/shimatta-opengl-colored-triangle.c +++ b/src/shimatta-opengl-colored-triangle.c @@ -69,14 +69,41 @@ static void draw_with_model_matrix(ShimattaOpenglGraphics *self, mat4 m, mat4 n) draw(self); } +static void shimatta_opengl_colored_triangle_dispose(GObject *obj) +{ + ShimattaOpenglColoredTriangle *self; + ShimattaOpenglColoredTrianglePrivate *priv; + + self = SHIMATTA_OPENGL_COLORED_TRIANGLE(obj); + priv = shimatta_opengl_colored_triangle_get_instance_private(self); + + if (priv->vao) { + glDeleteVertexArrays(1, &priv->vao); + priv->vao = 0; + } + + if (priv->vbo) { + glDeleteBuffers(1, &priv->vbo); + priv->vbo = 0; + } + + g_clear_object(&priv->prog); + + G_OBJECT_CLASS(shimatta_opengl_colored_triangle_parent_class)->dispose(obj); +} + void shimatta_opengl_colored_triangle_class_init(ShimattaOpenglColoredTriangleClass *klass) { ShimattaOpenglGraphicsClass *gclass; + GObjectClass *oclass; + gclass = SHIMATTA_OPENGL_GRAPHICS_CLASS(klass); + oclass = G_OBJECT_CLASS(klass); gclass->draw = draw; gclass->realize = realize; gclass->draw_with_model_matrix = draw_with_model_matrix; + oclass->dispose = shimatta_opengl_colored_triangle_dispose; } void shimatta_opengl_colored_triangle_init(ShimattaOpenglColoredTriangle *self)