comparison pytouhou/ui/opengl/texture.pyx @ 579:b8df946d394d

Add grouping for OpenGL calls, making traces much more readable.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sun, 17 Aug 2014 16:16:58 +0200
parents 1be60813f7cb
children cb8a443bc046
comparison
equal deleted inserted replaced
578:00f228b57840 579:b8df946d394d
14 14
15 from pytouhou.lib.opengl cimport \ 15 from pytouhou.lib.opengl cimport \
16 (glTexParameteri, GL_TEXTURE_MIN_FILTER, GL_TEXTURE_MAG_FILTER, 16 (glTexParameteri, GL_TEXTURE_MIN_FILTER, GL_TEXTURE_MAG_FILTER,
17 GL_LINEAR, GL_BGRA, GL_RGBA, GL_RGB, GL_LUMINANCE, GL_UNSIGNED_BYTE, 17 GL_LINEAR, GL_BGRA, GL_RGBA, GL_RGB, GL_LUMINANCE, GL_UNSIGNED_BYTE,
18 GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_UNSIGNED_SHORT_4_4_4_4, 18 GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_UNSIGNED_SHORT_4_4_4_4,
19 glGenTextures, glBindTexture, glTexImage2D, GL_TEXTURE_2D, GLuint) 19 glGenTextures, glBindTexture, glTexImage2D, GL_TEXTURE_2D, GLuint,
20 glPushDebugGroup, GL_DEBUG_SOURCE_APPLICATION, glPopDebugGroup)
20 21
21 from pytouhou.lib.sdl cimport load_png, create_rgb_surface 22 from pytouhou.lib.sdl cimport load_png, create_rgb_surface
22 from pytouhou.lib.sdl import SDLError 23 from pytouhou.lib.sdl import SDLError
23 from pytouhou.formats.thtx import Texture #TODO: perhaps define that elsewhere? 24 from pytouhou.formats.thtx import Texture #TODO: perhaps define that elsewhere?
24 from pytouhou.game.text cimport NativeText 25 from pytouhou.game.text cimport NativeText
35 self.renderer = renderer 36 self.renderer = renderer
36 self.texture_class = texture_class 37 self.texture_class = texture_class
37 38
38 39
39 cdef void load(self, dict anms): 40 cdef void load(self, dict anms):
41 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Texture loading")
40 for anm in sorted(anms.values(), key=is_ascii): 42 for anm in sorted(anms.values(), key=is_ascii):
43 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Loading textures from ANM %s" % anm)
41 for entry in anm: 44 for entry in anm:
42 if entry.texture is None: 45 if entry.texture is None:
43 texture = decode_png(self.loader, entry.first_name, entry.secondary_name) 46 texture = decode_png(self.loader, entry.first_name, entry.secondary_name)
44 elif not isinstance(entry.texture, self.texture_class): 47 elif not isinstance(entry.texture, self.texture_class):
45 texture = entry.texture 48 texture = entry.texture
46 entry.texture = self.texture_class(load_texture(texture), self.renderer) 49 entry.texture = self.texture_class(load_texture(texture), self.renderer)
50 glPopDebugGroup()
51 glPopDebugGroup()
47 anms.clear() 52 anms.clear()
48 53
49 54
50 def is_ascii(anm): 55 def is_ascii(anm):
51 return anm[0].first_name.endswith('ascii.png') 56 return anm[0].first_name.endswith('ascii.png')
59 64
60 65
61 cdef void load(self, dict labels): 66 cdef void load(self, dict labels):
62 cdef NativeText label 67 cdef NativeText label
63 68
69 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Text rendering")
64 for i, label in labels.items(): 70 for i, label in labels.items():
65 if label.texture is None: 71 if label.texture is None:
66 try: 72 try:
67 surface = self.font.render(label.text) 73 surface = self.font.render(label.text)
68 except SDLError as e: 74 except SDLError as e:
79 else: 85 else:
80 assert label.align == 'left' 86 assert label.align == 'left'
81 87
82 texture = Texture(label.width, label.height, -4, surface.pixels) 88 texture = Texture(label.width, label.height, -4, surface.pixels)
83 label.texture = self.texture_class(load_texture(texture), self.renderer) 89 label.texture = self.texture_class(load_texture(texture), self.renderer)
90 glPopDebugGroup()
84 91
85 92
86 cdef decode_png(loader, first_name, secondary_name): 93 cdef decode_png(loader, first_name, secondary_name):
87 image_file = load_png(loader.get_file(os.path.basename(first_name))) 94 image_file = load_png(loader.get_file(os.path.basename(first_name)))
88 width, height = image_file.surface.w, image_file.surface.h 95 width, height = image_file.surface.w, image_file.surface.h