Added visible property to groups to reduce rendering calls when not in use.
Also batches property for additional Group information.
@@ -159,6 +159,7 @@ video drivers, and requires indexed vertex lists.
"""
import ctypes
+import weakref
import pyglet
from pyglet.gl import *
@@ -469,6 +470,8 @@ class Batch:
if group.parent not in self.group_children:
self.group_children[group.parent] = []
self.group_children[group.parent].append(group)
+
+ group._assigned_batches.add(self)
self._draw_list_dirty = True
def _update_draw_list(self):
@@ -494,6 +497,7 @@ class Batch:
if children:
children.sort()
for child in list(children):
+ if child.visible:
draw_list.extend(visit(child))
if children or domain_map:
@@ -501,6 +505,7 @@ class Batch:
else:
# Remove unused group from batch
del self.group_map[group]
+ group._assigned_batches.remove(self)
if group.parent:
self.group_children[group.parent].remove(group)
try:
@@ -511,12 +516,14 @@ class Batch:
self.top_groups.remove(group)
except ValueError:
pass
+
return []
self._draw_list = []
self.top_groups.sort()
for group in list(self.top_groups):
+ if group.visible:
self._draw_list.extend(visit(group))
self._draw_list_dirty = False
@@ -588,12 +595,14 @@ class Batch:
if children:
children.sort()
for child in children:
+ if child.visible:
visit(child)
group.unset_state()
self.top_groups.sort()
for group in self.top_groups:
+ if group.visible:
visit(group)
@@ -613,9 +622,29 @@ class Group:
`parent` : `~pyglet.graphics.Group`
Group to contain this group; its state will be set before this
state's.
-
+ `visible` : bool
+ Determines whether this group is visible in any of the batches it is assigned to.
+ `batches` : list
+ Read Only. A list of which batches this group is a part of.
"""
self.parent = parent
+ self._visible = True
+ self._assigned_batches = weakref.WeakSet()
+
+ @property
+ def visible(self):
+ return self._visible
+
+ @visible.setter
+ def visible(self, value):
+ self._visible = value
+
+ for batch in self._assigned_batches:
+ batch.invalidate()
+
+ @property
+ def batches(self):
+ return [batch for batch in self._assigned_batches]
def __lt__(self, other):
return hash(self) < hash(other)
