From 42d573372ef07915585d386281b2fe463ca732af Mon Sep 17 00:00:00 2001 From: faiface <faiface@ksp.sk> Date: Sat, 3 Dec 2016 16:33:56 +0100 Subject: [PATCH] add Deleter and DrawDeleter interfaces --- graphics.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/graphics.go b/graphics.go index 3807964..c328976 100644 --- a/graphics.go +++ b/graphics.go @@ -10,7 +10,7 @@ import ( // Drawer is anything that can be drawn. It's by no means a drawer inside your table. // -// Drawer consists of a single method: Draw. Draw methods takes any number of Transform arguments. It applies these +// Drawer consists of a single methods: Draw. Draw methods takes any number of Transform arguments. It applies these // transforms in the reverse order and finally draws something transformed by these transforms. // // Example: @@ -23,6 +23,19 @@ type Drawer interface { Draw(t ...Transform) } +// Deleter is anything that can be deleted. All graphics objects that have some associated video memory +// are deleters. It is necessary to call Delete when you're done with an object, otherwise you're going +// to have video memory leaks. +type Deleter interface { + Delete() +} + +// DrawDeleter combines Drawer and Deleter interfaces. +type DrawDeleter interface { + Drawer + Deleter +} + // PolygonColor is a polygon shape filled with a single color. type PolygonColor struct { parent pixelgl.Doer @@ -108,3 +121,8 @@ func (pc *PolygonColor) Draw(t ...Transform) { pc.va.Draw() } + +// Delete destroys a polygon shape and releases it's video memory. Do not use this shape after calling Delete. +func (pc *PolygonColor) Delete() { + pc.va.Delete() +} -- GitLab