From 9d73059ad04f9bc8f5a8f8c63c831c8d0f043b94 Mon Sep 17 00:00:00 2001 From: Quantum Date: Tue, 28 Aug 2018 03:42:18 -0400 Subject: [PATCH] Sky cubemap loading progress. --- punyverse/entity.py | 4 ++-- punyverse/texture.py | 8 +++++--- punyverse/world.py | 5 +++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/punyverse/entity.py b/punyverse/entity.py index 59abb27..98e44b1 100644 --- a/punyverse/entity.py +++ b/punyverse/entity.py @@ -121,14 +121,14 @@ class Belt(Entity): class Sky(Entity): background = True - def __init__(self, world, info): + def __init__(self, world, info, callback=None): pitch = world.evaluate(info.get('pitch', 0)) yaw = world.evaluate(info.get('yaw', 0)) roll = world.evaluate(info.get('roll', 0)) super(Sky, self).__init__(world, 'Sky', (0, 0, 0), [pitch, yaw, roll]) - self.texture = get_best_texture(info['texture'], loader=get_cube_map) + self.texture = get_best_texture(info['texture'], loader=get_cube_map, callback=callback) self.constellation = get_cube_map(info['constellation']) self.cube = Cube() diff --git a/punyverse/texture.py b/punyverse/texture.py index d4f8c4a..2f106c6 100644 --- a/punyverse/texture.py +++ b/punyverse/texture.py @@ -260,8 +260,9 @@ def load_clouds(file): return id -def get_cube_map(files): +def get_cube_map(files, callback=None): assert len(files) == 6 + callback = callback or (lambda index, file: None) buffer = GLuint() glGenTextures(1, byref(buffer)) @@ -270,16 +271,17 @@ def get_cube_map(files): glBindTexture(GL_TEXTURE_CUBE_MAP, id) glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, 0) glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_LEVEL, 0) - for file, part in zip(files, [ + for index, (file, part) in enumerate(zip(files, [ GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, - ]): + ])): try: path, file = get_file_path(file) + callback(index, file) path, width, height, depth, mode, texture = load_image(file, path) except Exception: glDeleteTextures(1, byref(buffer)) diff --git a/punyverse/world.py b/punyverse/world.py index 8a1efd1..6ec665c 100644 --- a/punyverse/world.py +++ b/punyverse/world.py @@ -122,8 +122,9 @@ class World(object): self.tracker.append(Belt(name, self, info)) if 'sky' in root: - self.callback('Loading sky...', 'Loading sky.', 0) - self.tracker.append(Sky(self, root['sky'])) + def callback(index, file): + self.callback('Loading sky...', 'Loading %s.' % file, index / 6) + self.tracker.append(Sky(self, root['sky'], callback)) if 'asteroids' in root: asteroids = root['asteroids']