Skip to content

Commit

Permalink
Optimize VertexList region cache
Browse files Browse the repository at this point in the history
  • Loading branch information
cspotcode committed Aug 3, 2023
1 parent c8ee652 commit 7d721bf
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions pyglet/graphics/vertexdomain.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def __init__(self, domain, start, count):
self.start = start
self.count = count
self._caches = {}
self._cache_versions = {}
self._cache_version = None

def draw(self, mode):
"""Draw this vertex list in the given OpenGL mode.
Expand Down Expand Up @@ -261,8 +261,7 @@ def resize(self, count, index_count=None):
self.start = new_start
self.count = count

for version in self._cache_versions:
self._cache_versions[version] = None
self._cache_version = None

def delete(self):
"""Delete this group."""
Expand Down Expand Up @@ -292,6 +291,7 @@ def migrate(self, domain):
self.domain.allocator.dealloc(self.start, self.count)
self.domain = domain
self.start = new_start
self._cache_version = None

for version in self._cache_versions:
self._cache_versions[version] = None
Expand All @@ -304,12 +304,15 @@ def __getattr__(self, name):
"""dynamic access to vertex attributes, for backwards compatibility.
"""
domain = self.domain
if self._cache_versions.get(name, None) != domain.version:
version = domain.version
_caches = self._caches
if self._cache_version != version:
_caches.clear()
self._cache_version = version
region = _caches.get(name, None)
if region is None:
attribute = domain.attribute_names[name]
self._caches[name] = attribute.get_region(attribute.buffer, self.start, self.count)
self._cache_versions[name] = domain.version

region = self._caches[name]
region = _caches[name] = attribute.get_region(attribute.buffer, self.start, self.count)
region.invalidate()
return region.array

Expand Down

0 comments on commit 7d721bf

Please sign in to comment.