#StackBounty: #2d #sprites #python #resource-management #pyglet Why are pyglet.image and texture so heavy?

Bounty: 100

Envrionment:

  • python: 3.6.6
  • pyglet: 1.3.2

Here is my code and results:

import pyglet

images = []
textures = []

with_textures = True
count = 10
for x in range(count):
    image = pyglet.image.load("big.png")  # 2.1 Mb source 2400*2400px
    images.append(image)
    if with_textures:
        texture_grid = pyglet.image.ImageGrid(image, 10, 10).get_texture_sequence()
        textures.append(texture_grid)

# RES in htop result without textures
# count = 10 - 300Mb
# count = 20 - 553Mb
# count = 30 - 753Mb
# count = 40 - 973Mb
# ~23Mb just for each Image

# RES in htop result with textures
# count = 10 - 996Mb
# count = 20 - 1878Mb
# count = 30 - 2716Mb
# count = 40 - 3597Mb
# ~86Mb for Image and prepared grid


input("Press enter to exit")

Questions:

  1. Why each 2.1Mb file leads to 23Mb of memory usage with pyglet.image.AbstractImage?
    • If ImageGrid is used for creating sprite sheet -> it leads to additional ~60Mb
  2. How to deal with it? Because if game contains 50+ big sprites it would be not real to dedicate such many memory only for textures.
  3. Maybe there is some other approach in creating games which is used sprites? Or I should change my stack technology(pyglet as main library, also was trying with pygame) for client side?

PS: First time I’ve rewritten my application from pygame to pyglet, because I didn’t consider some aspects of event loop in pygame, and now I hadn’t test resource usage of pyglet library for my use-cases.

Update/clarification:

I’m using ImageGrid as for 3d part in vertices as for 2d part in pyglet.sprite.Sprite


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.