group = pyglet.sprite.DepthSpriteGroup(2048, 2048) #the size of the texture atlas
#load some image as img
my_sprites = [pyglet.sprite.DepthSprite(img, group, x=i*10) for i in range(10)]
window = pyglet.window.Window(500, 500)
@window.event
def on_draw():
window.clear()
group.draw()
solid = pyglet.graphics.OrderedGroup(0)
translucent = pyglet.graphics.OrderedGroup(1)
pyglet_image = pyglet.image.load("examples/pyglet.png")
spritea = pyglet.sprite.Sprite(img=pyglet_image, x=120, y=150, z=3, batch=batch, group=translucent)
spriteb = pyglet.sprite.Sprite(img=pyglet_image, x=140, y=170, z=2, batch=batch, group=translucent)
spritec = pyglet.sprite.Sprite(img=pyglet_image, x=160, y=190, z=1, batch=batch, group=solid)
sprited = pyglet.sprite.Sprite(img=pyglet_image, x=180, y=210, z=0, batch=batch, group=solid)
spritea.opacity = 200
spriteb.opacity = 200
I accidentally left a *print("new domain")* in there, which illustrates the consolidation that happens when the Sprites share the same TextureAtlas.
There is a bit more work to do in OrderedVertexDomain, such as the migration code. Also, deleting vertex_lists probably won't work because of the *OrderedVertexDomain._vertex_lists*.
Also, I think the cleanest way to fix the garbage collection issue caused by the OrderedVertexDomain._vertex_lists is probably by subclassing VertexList. A custom delete method can remove itself from the list, and the order attribute can be added so that OrderedVertexDomain.create can be neater.
I'm curious just how slow this will be. I guess it all comes down to the sitting time, and glDrawArrays VS glDrawElements.
There are only two things left, which are:
1. Migration. The code is there, but I don't think it's accurate.
2. Handling of drawing OrderedVertexDomains with a primsize that is not equal to 1.
Number 2 is important, since drawing breaks if you delete vertex lists from the middle (or migrated, if that worked). I haven't had time to figure out glMultiDrawElements yet, which is what we need to use I think. Maybe a different type of index list is needed.
Feedback is appreciated. I'm thinking that maybe it would be a good idea to benchmark this implementation before spending time finishing it up.
Sounds like y'all are tackling the same issue I did when I wanted to do vectorized translations on vertex lists. I tried to use pyglets architecture but it was so tied to domains being dumb and not keeping track of what was in what they had allocated. This is for obvious performance reasons, but my idea didn't mesh at all.
I made a defragmenting buffer that keeps track of each allocated entity, and an allocator that places new entities accordingly, rearranging the buffer as necessary. Everything (with a common gl state) is rendered with one glDrawArrays call.
Sorry for the terse description. I'm on my phone. Let me know if I can help. I'd love if pyglet had native support for ordered, contiguous buffers that could interface with my entity component system. Maybe you can use some code from the allocator. Here's the project:
https://github.com/Permafacture/data-oriented-pyglet
Elliot
--
You received this message because you are subscribed to the Google Groups "pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyglet-users+unsubscribe@googlegroups.com.
To post to this group, send email to pyglet...@googlegroups.com.
Visit this group at https://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.
That sounds pretty nice. The null triangles idea makes sense. I guess it would be considered wasteful, but would be insignificant waste with even semi-modern GPU memory.
I find the numpy stuff fascinating. I also love pyglet for being "pure Python", as in only needing the standard library. I feel like there is a need for pyglet in the Python world, but certainly a need for more focused libraries like yours.
If you poke around my branch, you'll see it's fairly simple. It uses the default vertex lists and allocator, so there is fragmentation when deleting/migrating lists. I'm relying on the gl*Elements functions to draw things out of the order in which they're allocated.
The sort method is just a simple sort with lambda depth. The sort is only called when a vertex lists depth attribute is changed, so it should perform well if there aren't many changes. I hear the Python sort function is fairly fast, but I've not benchmarked it.
starts = [vert_list.start for vert_list in self._vertex_lists]
sizes = [vert_list.get_size() for vert_list in self._vertex_lists]
primcount = len(starts)
starts = (GLint * primcount)(*starts)
sizes = (GLsizei * primcount)(*sizes)
glMultiDrawArrays(mode, starts, sizes, primcount)
tileGroup = pyglet.graphics.OrderedGroup(0)objectGroup = pyglet.graphics.OrderedGroup(1)sprites = []
for i in xrange(50):
for j in xrange(50):
sprites.append(pyglet.sprite.Sprite(tileImg, x=i*32, y=j*32, batch=batch, group=tileGroup))
for i in xrange(50):
for j in xrange(50):
sprites.append(pyglet.sprite.Sprite(objectImg, x=i*32, y=j*32, batch=batch, group=tileGroup))
tileGroup = pyglet.graphics.OrderedGroup(0)objectGroup = pyglet.graphics.OrderedGroup(1)
sprites = []
for i in xrange(50):
for j in xrange(50):
sprites.append(pyglet.sprite.Sprite(tileImg, x=i*32, y=j*32, batch=batch, group=tileGroup))
for i in xrange(50):
for j in xrange(50):
sprites.append(pyglet.sprite.Sprite(objectImg, x=i*32, y=j*32, batch=batch, group=objectGroup))
tileGroup = pyglet.graphics.OrderedGroup(0)objectGroup = pyglet.graphics.OrderedGroup(1)
sprites = []for i in xrange(50): for j in xrange(50): sprites.append(pyglet.sprite.Sprite(tileImg, x=i*32, y=j*32, batch=batch, group=tileGroup))
for i in xrange(50): for j in xrange(50): sprites.append(pyglet.sprite.Sprite(objectImg, x=i*32, y=j*32, order=j*32, batch=batch, group=objectGroup))
playerSprite = pyglet.sprite.Sprite(playerImg, x=0, y=0, group=objectGroup, batch=batch)
def moveChar(dt, axis, val): if axis == "x": playerSprite.update(x=playerSprite.x+val) else: playerSprite.update(y=playerSprite.y+val) playerSprite.order = playerSprite.y