comparison pytouhou/ui/opengl/texture.pyx @ 582:6e79756b7f42

Don’t call gl*DebugGroup if it isn’t exposed by the driver.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sun, 05 Oct 2014 17:46:51 +0200
parents cb8a443bc046
children 3c2f96f1d715
comparison
equal deleted inserted replaced
581:cb8a443bc046 582:6e79756b7f42
22 from pytouhou.lib.sdl cimport load_png, create_rgb_surface 22 from pytouhou.lib.sdl cimport load_png, create_rgb_surface
23 from pytouhou.lib.sdl import SDLError 23 from pytouhou.lib.sdl import SDLError
24 from pytouhou.formats.thtx import Texture #TODO: perhaps define that elsewhere? 24 from pytouhou.formats.thtx import Texture #TODO: perhaps define that elsewhere?
25 from pytouhou.game.text cimport NativeText 25 from pytouhou.game.text cimport NativeText
26 26
27 from .backend cimport use_debug_group
28
27 import os 29 import os
28 30
29 from pytouhou.utils.helpers import get_logger 31 from pytouhou.utils.helpers import get_logger
30 logger = get_logger(__name__) 32 logger = get_logger(__name__)
31 33
36 self.renderer = renderer 38 self.renderer = renderer
37 self.texture_class = texture_class 39 self.texture_class = texture_class
38 40
39 41
40 cdef void load(self, dict anms): 42 cdef void load(self, dict anms):
41 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Texture loading") 43 if use_debug_group:
44 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Texture loading")
45
42 for anm in sorted(anms.values(), key=is_ascii): 46 for anm in sorted(anms.values(), key=is_ascii):
43 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Loading textures from ANM") 47 if use_debug_group:
48 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Loading textures from ANM")
49
44 for entry in anm: 50 for entry in anm:
45 if entry.texture is None: 51 if entry.texture is None:
46 texture = decode_png(self.loader, entry.first_name, entry.secondary_name) 52 texture = decode_png(self.loader, entry.first_name, entry.secondary_name)
47 elif not isinstance(entry.texture, self.texture_class): 53 elif not isinstance(entry.texture, self.texture_class):
48 texture = entry.texture 54 texture = entry.texture
49 entry.texture = self.texture_class(load_texture(texture), self.renderer) 55 entry.texture = self.texture_class(load_texture(texture), self.renderer)
56
57 if use_debug_group:
58 glPopDebugGroup()
59 anms.clear()
60
61 if use_debug_group:
50 glPopDebugGroup() 62 glPopDebugGroup()
51 glPopDebugGroup()
52 anms.clear()
53 63
54 64
55 def is_ascii(anm): 65 def is_ascii(anm):
56 return anm[0].first_name.endswith('ascii.png') 66 return anm[0].first_name.endswith('ascii.png')
57 67
64 74
65 75
66 cdef void load(self, dict labels): 76 cdef void load(self, dict labels):
67 cdef NativeText label 77 cdef NativeText label
68 78
69 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Text rendering") 79 if use_debug_group:
80 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Text rendering")
81
70 for i, label in labels.items(): 82 for i, label in labels.items():
71 if label.texture is None: 83 if label.texture is None:
72 try: 84 try:
73 surface = self.font.render(label.text) 85 surface = self.font.render(label.text)
74 except SDLError as e: 86 except SDLError as e:
85 else: 97 else:
86 assert label.align == 'left' 98 assert label.align == 'left'
87 99
88 texture = Texture(label.width, label.height, -4, surface.pixels) 100 texture = Texture(label.width, label.height, -4, surface.pixels)
89 label.texture = self.texture_class(load_texture(texture), self.renderer) 101 label.texture = self.texture_class(load_texture(texture), self.renderer)
90 glPopDebugGroup() 102
103 if use_debug_group:
104 glPopDebugGroup()
91 105
92 106
93 cdef decode_png(loader, first_name, secondary_name): 107 cdef decode_png(loader, first_name, secondary_name):
94 image_file = load_png(loader.get_file(os.path.basename(first_name))) 108 image_file = load_png(loader.get_file(os.path.basename(first_name)))
95 width, height = image_file.surface.w, image_file.surface.h 109 width, height = image_file.surface.w, image_file.surface.h