Mercurial > touhou
annotate pytouhou/ui/opengl/texture.pyx @ 792:11bc22bad1bf
python: Replace the image crate with png
We weren’t using any of its features anyway, so the png crate is exactly what
we need, without the many heavy dependencies of image.
https://github.com/image-rs/image-png/pull/670 will eventually make it even
faster to build.
| author | Link Mauve <linkmauve@linkmauve.fr> |
|---|---|
| date | Sat, 17 Jan 2026 22:22:25 +0100 |
| parents | 7e940ebeb5fd |
| children |
| rev | line source |
|---|---|
|
52
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
25
diff
changeset
|
1 # -*- encoding: utf-8 -*- |
|
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
25
diff
changeset
|
2 ## |
|
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
25
diff
changeset
|
3 ## Copyright (C) 2011 Thibaut Girka <thib@sitedethib.com> |
|
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
25
diff
changeset
|
4 ## |
|
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
25
diff
changeset
|
5 ## This program is free software; you can redistribute it and/or modify |
|
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
25
diff
changeset
|
6 ## it under the terms of the GNU General Public License as published |
|
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
25
diff
changeset
|
7 ## by the Free Software Foundation; version 3 only. |
|
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
25
diff
changeset
|
8 ## |
|
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
25
diff
changeset
|
9 ## This program is distributed in the hope that it will be useful, |
|
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
25
diff
changeset
|
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
25
diff
changeset
|
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
25
diff
changeset
|
12 ## GNU General Public License for more details. |
|
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
25
diff
changeset
|
13 ## |
|
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
25
diff
changeset
|
14 |
|
423
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
15 from pytouhou.lib.opengl cimport \ |
|
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
16 (glTexParameteri, GL_TEXTURE_MIN_FILTER, GL_TEXTURE_MAG_FILTER, |
|
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
17 GL_LINEAR, GL_BGRA, GL_RGBA, GL_RGB, GL_LUMINANCE, GL_UNSIGNED_BYTE, |
|
559
1be60813f7cb
Get OpenGL ES 2.0 to work thanks to libepoxy. PCB textures will need swizzle in the shaders since BGRA isn’t natively supported on GLES.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
525
diff
changeset
|
18 GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_UNSIGNED_SHORT_4_4_4_4, |
|
579
b8df946d394d
Add grouping for OpenGL calls, making traces much more readable.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
559
diff
changeset
|
19 glGenTextures, glBindTexture, glTexImage2D, GL_TEXTURE_2D, GLuint, |
|
b8df946d394d
Add grouping for OpenGL calls, making traces much more readable.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
559
diff
changeset
|
20 glPushDebugGroup, GL_DEBUG_SOURCE_APPLICATION, glPopDebugGroup) |
|
423
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
21 |
|
517
dec43940f092
Don’t crash if SDL2_ttf couldn’t render a specific string.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
515
diff
changeset
|
22 from pytouhou.lib.sdl import SDLError |
|
423
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
23 from pytouhou.formats.thtx import Texture #TODO: perhaps define that elsewhere? |
|
473
1c891c71cf22
Cythonize pytouhou.game.text.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
24 from pytouhou.game.text cimport NativeText |
| 14 | 25 |
|
582
6e79756b7f42
Don’t call gl*DebugGroup if it isn’t exposed by the driver.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
581
diff
changeset
|
26 from .backend cimport use_debug_group |
|
6e79756b7f42
Don’t call gl*DebugGroup if it isn’t exposed by the driver.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
581
diff
changeset
|
27 |
|
423
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
28 import os |
|
393
9e2cbb2c2c64
Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
392
diff
changeset
|
29 |
|
517
dec43940f092
Don’t crash if SDL2_ttf couldn’t render a specific string.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
515
diff
changeset
|
30 from pytouhou.utils.helpers import get_logger |
|
dec43940f092
Don’t crash if SDL2_ttf couldn’t render a specific string.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
515
diff
changeset
|
31 logger = get_logger(__name__) |
|
dec43940f092
Don’t crash if SDL2_ttf couldn’t render a specific string.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
515
diff
changeset
|
32 |
| 14 | 33 |
|
505
bfea9e9a6845
Manage the texture-specific indices in the Texture, and some more renderer optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
504
diff
changeset
|
34 cdef class TextureManager: |
|
bfea9e9a6845
Manage the texture-specific indices in the Texture, and some more renderer optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
504
diff
changeset
|
35 def __init__(self, loader=None, renderer=None, texture_class=None): |
|
bfea9e9a6845
Manage the texture-specific indices in the Texture, and some more renderer optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
504
diff
changeset
|
36 self.loader = loader |
|
bfea9e9a6845
Manage the texture-specific indices in the Texture, and some more renderer optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
504
diff
changeset
|
37 self.renderer = renderer |
|
bfea9e9a6845
Manage the texture-specific indices in the Texture, and some more renderer optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
504
diff
changeset
|
38 self.texture_class = texture_class |
|
16
66ce9bb440ac
Refactor in order to support multiple textures
Thibaut Girka <thib@sitedethib.com>
parents:
15
diff
changeset
|
39 |
| 158 | 40 |
|
617
a6af3ff86612
Change all “void except *” function into “bint except True”, to prevent PyErr_Occurred() from being called at each call.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
606
diff
changeset
|
41 cdef bint load(self, dict anms) except True: |
|
582
6e79756b7f42
Don’t call gl*DebugGroup if it isn’t exposed by the driver.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
581
diff
changeset
|
42 if use_debug_group: |
|
6e79756b7f42
Don’t call gl*DebugGroup if it isn’t exposed by the driver.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
581
diff
changeset
|
43 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Texture loading") |
|
6e79756b7f42
Don’t call gl*DebugGroup if it isn’t exposed by the driver.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
581
diff
changeset
|
44 |
|
505
bfea9e9a6845
Manage the texture-specific indices in the Texture, and some more renderer optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
504
diff
changeset
|
45 for anm in sorted(anms.values(), key=is_ascii): |
|
582
6e79756b7f42
Don’t call gl*DebugGroup if it isn’t exposed by the driver.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
581
diff
changeset
|
46 if use_debug_group: |
|
6e79756b7f42
Don’t call gl*DebugGroup if it isn’t exposed by the driver.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
581
diff
changeset
|
47 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Loading textures from ANM") |
|
6e79756b7f42
Don’t call gl*DebugGroup if it isn’t exposed by the driver.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
581
diff
changeset
|
48 |
|
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
426
diff
changeset
|
49 for entry in anm: |
|
525
43ecf0f98f4d
Precalculate the inverse of the texture size at ANM load, to not recalculate at every sprite change.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
517
diff
changeset
|
50 if entry.texture is None: |
|
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
426
diff
changeset
|
51 texture = decode_png(self.loader, entry.first_name, entry.secondary_name) |
|
505
bfea9e9a6845
Manage the texture-specific indices in the Texture, and some more renderer optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
504
diff
changeset
|
52 elif not isinstance(entry.texture, self.texture_class): |
|
bfea9e9a6845
Manage the texture-specific indices in the Texture, and some more renderer optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
504
diff
changeset
|
53 texture = entry.texture |
|
bfea9e9a6845
Manage the texture-specific indices in the Texture, and some more renderer optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
504
diff
changeset
|
54 entry.texture = self.texture_class(load_texture(texture), self.renderer) |
|
582
6e79756b7f42
Don’t call gl*DebugGroup if it isn’t exposed by the driver.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
581
diff
changeset
|
55 |
|
6e79756b7f42
Don’t call gl*DebugGroup if it isn’t exposed by the driver.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
581
diff
changeset
|
56 if use_debug_group: |
|
6e79756b7f42
Don’t call gl*DebugGroup if it isn’t exposed by the driver.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
581
diff
changeset
|
57 glPopDebugGroup() |
|
6e79756b7f42
Don’t call gl*DebugGroup if it isn’t exposed by the driver.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
581
diff
changeset
|
58 anms.clear() |
|
6e79756b7f42
Don’t call gl*DebugGroup if it isn’t exposed by the driver.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
581
diff
changeset
|
59 |
|
6e79756b7f42
Don’t call gl*DebugGroup if it isn’t exposed by the driver.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
581
diff
changeset
|
60 if use_debug_group: |
|
579
b8df946d394d
Add grouping for OpenGL calls, making traces much more readable.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
559
diff
changeset
|
61 glPopDebugGroup() |
|
25
cc864aadc733
Preload enemy and background textures
Thibaut Girka <thib@sitedethib.com>
parents:
16
diff
changeset
|
62 |
|
cc864aadc733
Preload enemy and background textures
Thibaut Girka <thib@sitedethib.com>
parents:
16
diff
changeset
|
63 |
|
505
bfea9e9a6845
Manage the texture-specific indices in the Texture, and some more renderer optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
504
diff
changeset
|
64 def is_ascii(anm): |
|
bfea9e9a6845
Manage the texture-specific indices in the Texture, and some more renderer optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
504
diff
changeset
|
65 return anm[0].first_name.endswith('ascii.png') |
|
bfea9e9a6845
Manage the texture-specific indices in the Texture, and some more renderer optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
504
diff
changeset
|
66 |
|
bfea9e9a6845
Manage the texture-specific indices in the Texture, and some more renderer optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
504
diff
changeset
|
67 |
|
456
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
455
diff
changeset
|
68 cdef class FontManager: |
|
505
bfea9e9a6845
Manage the texture-specific indices in the Texture, and some more renderer optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
504
diff
changeset
|
69 def __init__(self, fontname, fontsize=16, renderer=None, texture_class=None): |
|
456
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
455
diff
changeset
|
70 self.font = Font(fontname, fontsize) |
|
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
455
diff
changeset
|
71 self.renderer = renderer |
|
505
bfea9e9a6845
Manage the texture-specific indices in the Texture, and some more renderer optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
504
diff
changeset
|
72 self.texture_class = texture_class |
|
456
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
455
diff
changeset
|
73 |
|
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
455
diff
changeset
|
74 |
|
617
a6af3ff86612
Change all “void except *” function into “bint except True”, to prevent PyErr_Occurred() from being called at each call.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
606
diff
changeset
|
75 cdef bint load(self, dict labels) except True: |
|
473
1c891c71cf22
Cythonize pytouhou.game.text.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
76 cdef NativeText label |
|
1c891c71cf22
Cythonize pytouhou.game.text.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
77 |
|
582
6e79756b7f42
Don’t call gl*DebugGroup if it isn’t exposed by the driver.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
581
diff
changeset
|
78 if use_debug_group: |
|
6e79756b7f42
Don’t call gl*DebugGroup if it isn’t exposed by the driver.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
581
diff
changeset
|
79 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Text rendering") |
|
6e79756b7f42
Don’t call gl*DebugGroup if it isn’t exposed by the driver.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
581
diff
changeset
|
80 |
|
517
dec43940f092
Don’t crash if SDL2_ttf couldn’t render a specific string.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
515
diff
changeset
|
81 for i, label in labels.items(): |
|
473
1c891c71cf22
Cythonize pytouhou.game.text.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
82 if label.texture is None: |
|
517
dec43940f092
Don’t crash if SDL2_ttf couldn’t render a specific string.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
515
diff
changeset
|
83 try: |
|
dec43940f092
Don’t crash if SDL2_ttf couldn’t render a specific string.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
515
diff
changeset
|
84 surface = self.font.render(label.text) |
|
dec43940f092
Don’t crash if SDL2_ttf couldn’t render a specific string.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
515
diff
changeset
|
85 except SDLError as e: |
|
dec43940f092
Don’t crash if SDL2_ttf couldn’t render a specific string.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
515
diff
changeset
|
86 logger.error(u'Rendering of label “%s” failed: %s', label.text, e) |
|
dec43940f092
Don’t crash if SDL2_ttf couldn’t render a specific string.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
515
diff
changeset
|
87 del labels[i] # Prevents it from retrying to render. |
|
dec43940f092
Don’t crash if SDL2_ttf couldn’t render a specific string.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
515
diff
changeset
|
88 continue |
|
dec43940f092
Don’t crash if SDL2_ttf couldn’t render a specific string.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
515
diff
changeset
|
89 |
|
456
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
455
diff
changeset
|
90 label.width, label.height = surface.surface.w, surface.surface.h |
|
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
455
diff
changeset
|
91 |
|
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
455
diff
changeset
|
92 if label.align == 'center': |
|
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
455
diff
changeset
|
93 label.x -= label.width // 2 |
|
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
455
diff
changeset
|
94 elif label.align == 'right': |
|
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
455
diff
changeset
|
95 label.x -= label.width |
|
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
455
diff
changeset
|
96 else: |
|
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
455
diff
changeset
|
97 assert label.align == 'left' |
|
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
455
diff
changeset
|
98 |
|
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
455
diff
changeset
|
99 texture = Texture(label.width, label.height, -4, surface.pixels) |
|
505
bfea9e9a6845
Manage the texture-specific indices in the Texture, and some more renderer optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
504
diff
changeset
|
100 label.texture = self.texture_class(load_texture(texture), self.renderer) |
|
582
6e79756b7f42
Don’t call gl*DebugGroup if it isn’t exposed by the driver.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
581
diff
changeset
|
101 |
|
6e79756b7f42
Don’t call gl*DebugGroup if it isn’t exposed by the driver.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
581
diff
changeset
|
102 if use_debug_group: |
|
6e79756b7f42
Don’t call gl*DebugGroup if it isn’t exposed by the driver.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
581
diff
changeset
|
103 glPopDebugGroup() |
|
456
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
455
diff
changeset
|
104 |
|
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
455
diff
changeset
|
105 |
|
426
5d7bb2fd74f7
Never keep texture on the host when it has been uploaded, and prevent them from being decoded again.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
423
diff
changeset
|
106 cdef decode_png(loader, first_name, secondary_name): |
|
786
7e940ebeb5fd
Replace SDL2_image with the image crate
Link Mauve <linkmauve@linkmauve.fr>
parents:
617
diff
changeset
|
107 if secondary_name is not None: |
|
7e940ebeb5fd
Replace SDL2_image with the image crate
Link Mauve <linkmauve@linkmauve.fr>
parents:
617
diff
changeset
|
108 image = loader.get_image_with_alpha(first_name, secondary_name) |
|
7e940ebeb5fd
Replace SDL2_image with the image crate
Link Mauve <linkmauve@linkmauve.fr>
parents:
617
diff
changeset
|
109 else: |
|
7e940ebeb5fd
Replace SDL2_image with the image crate
Link Mauve <linkmauve@linkmauve.fr>
parents:
617
diff
changeset
|
110 image = loader.get_image(first_name) |
|
7e940ebeb5fd
Replace SDL2_image with the image crate
Link Mauve <linkmauve@linkmauve.fr>
parents:
617
diff
changeset
|
111 width, height = image.dimensions |
|
7e940ebeb5fd
Replace SDL2_image with the image crate
Link Mauve <linkmauve@linkmauve.fr>
parents:
617
diff
changeset
|
112 return Texture(width, height, -4, image.pixels) |
|
393
9e2cbb2c2c64
Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
392
diff
changeset
|
113 |
|
9e2cbb2c2c64
Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
392
diff
changeset
|
114 |
|
515
b3193b43a86c
Add an indirection layer for textures, to cope with drivers assigning them random names.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
513
diff
changeset
|
115 cdef GLuint load_texture(thtx) except? 65535: |
|
426
5d7bb2fd74f7
Never keep texture on the host when it has been uploaded, and prevent them from being decoded again.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
423
diff
changeset
|
116 cdef GLuint texture |
|
515
b3193b43a86c
Add an indirection layer for textures, to cope with drivers assigning them random names.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
513
diff
changeset
|
117 cdef long fmt = thtx.fmt |
| 15 | 118 |
|
515
b3193b43a86c
Add an indirection layer for textures, to cope with drivers assigning them random names.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
513
diff
changeset
|
119 if fmt == 1: |
|
559
1be60813f7cb
Get OpenGL ES 2.0 to work thanks to libepoxy. PCB textures will need swizzle in the shaders since BGRA isn’t natively supported on GLES.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
525
diff
changeset
|
120 #format_ = GL_BGRA |
|
1be60813f7cb
Get OpenGL ES 2.0 to work thanks to libepoxy. PCB textures will need swizzle in the shaders since BGRA isn’t natively supported on GLES.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
525
diff
changeset
|
121 format_ = GL_RGBA #XXX: should be GL_BGRA |
|
426
5d7bb2fd74f7
Never keep texture on the host when it has been uploaded, and prevent them from being decoded again.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
423
diff
changeset
|
122 type_ = GL_UNSIGNED_BYTE |
|
5d7bb2fd74f7
Never keep texture on the host when it has been uploaded, and prevent them from being decoded again.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
423
diff
changeset
|
123 composants = GL_RGBA |
|
515
b3193b43a86c
Add an indirection layer for textures, to cope with drivers assigning them random names.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
513
diff
changeset
|
124 elif fmt == 3: |
|
426
5d7bb2fd74f7
Never keep texture on the host when it has been uploaded, and prevent them from being decoded again.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
423
diff
changeset
|
125 format_ = GL_RGB |
|
5d7bb2fd74f7
Never keep texture on the host when it has been uploaded, and prevent them from being decoded again.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
423
diff
changeset
|
126 type_ = GL_UNSIGNED_SHORT_5_6_5 |
|
5d7bb2fd74f7
Never keep texture on the host when it has been uploaded, and prevent them from being decoded again.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
423
diff
changeset
|
127 composants = GL_RGB |
|
515
b3193b43a86c
Add an indirection layer for textures, to cope with drivers assigning them random names.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
513
diff
changeset
|
128 elif fmt == 5: |
|
559
1be60813f7cb
Get OpenGL ES 2.0 to work thanks to libepoxy. PCB textures will need swizzle in the shaders since BGRA isn’t natively supported on GLES.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
525
diff
changeset
|
129 #format_ = GL_BGRA |
|
1be60813f7cb
Get OpenGL ES 2.0 to work thanks to libepoxy. PCB textures will need swizzle in the shaders since BGRA isn’t natively supported on GLES.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
525
diff
changeset
|
130 format_ = GL_RGBA #XXX: should be GL_BGRA |
|
1be60813f7cb
Get OpenGL ES 2.0 to work thanks to libepoxy. PCB textures will need swizzle in the shaders since BGRA isn’t natively supported on GLES.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
525
diff
changeset
|
131 #type_ = GL_UNSIGNED_SHORT_4_4_4_4_REV |
|
1be60813f7cb
Get OpenGL ES 2.0 to work thanks to libepoxy. PCB textures will need swizzle in the shaders since BGRA isn’t natively supported on GLES.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
525
diff
changeset
|
132 type_ = GL_UNSIGNED_SHORT_4_4_4_4 #XXX: should be GL_UNSIGNED_SHORT_4_4_4_4_REV |
|
426
5d7bb2fd74f7
Never keep texture on the host when it has been uploaded, and prevent them from being decoded again.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
423
diff
changeset
|
133 composants = GL_RGBA |
|
515
b3193b43a86c
Add an indirection layer for textures, to cope with drivers assigning them random names.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
513
diff
changeset
|
134 elif fmt == 7: |
|
426
5d7bb2fd74f7
Never keep texture on the host when it has been uploaded, and prevent them from being decoded again.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
423
diff
changeset
|
135 format_ = GL_LUMINANCE |
|
5d7bb2fd74f7
Never keep texture on the host when it has been uploaded, and prevent them from being decoded again.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
423
diff
changeset
|
136 type_ = GL_UNSIGNED_BYTE |
|
5d7bb2fd74f7
Never keep texture on the host when it has been uploaded, and prevent them from being decoded again.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
423
diff
changeset
|
137 composants = GL_LUMINANCE |
|
515
b3193b43a86c
Add an indirection layer for textures, to cope with drivers assigning them random names.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
513
diff
changeset
|
138 elif fmt == -4: #XXX: non-standard |
|
426
5d7bb2fd74f7
Never keep texture on the host when it has been uploaded, and prevent them from being decoded again.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
423
diff
changeset
|
139 format_ = GL_RGBA |
|
5d7bb2fd74f7
Never keep texture on the host when it has been uploaded, and prevent them from being decoded again.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
423
diff
changeset
|
140 type_ = GL_UNSIGNED_BYTE |
|
5d7bb2fd74f7
Never keep texture on the host when it has been uploaded, and prevent them from being decoded again.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
423
diff
changeset
|
141 composants = GL_RGBA |
|
5d7bb2fd74f7
Never keep texture on the host when it has been uploaded, and prevent them from being decoded again.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
423
diff
changeset
|
142 else: |
|
5d7bb2fd74f7
Never keep texture on the host when it has been uploaded, and prevent them from being decoded again.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
423
diff
changeset
|
143 raise Exception('Unknown texture type') |
| 14 | 144 |
|
426
5d7bb2fd74f7
Never keep texture on the host when it has been uploaded, and prevent them from being decoded again.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
423
diff
changeset
|
145 glGenTextures(1, &texture) |
|
5d7bb2fd74f7
Never keep texture on the host when it has been uploaded, and prevent them from being decoded again.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
423
diff
changeset
|
146 glBindTexture(GL_TEXTURE_2D, texture) |
|
5d7bb2fd74f7
Never keep texture on the host when it has been uploaded, and prevent them from being decoded again.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
423
diff
changeset
|
147 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) |
|
5d7bb2fd74f7
Never keep texture on the host when it has been uploaded, and prevent them from being decoded again.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
423
diff
changeset
|
148 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) |
|
16
66ce9bb440ac
Refactor in order to support multiple textures
Thibaut Girka <thib@sitedethib.com>
parents:
15
diff
changeset
|
149 |
|
426
5d7bb2fd74f7
Never keep texture on the host when it has been uploaded, and prevent them from being decoded again.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
423
diff
changeset
|
150 glTexImage2D(GL_TEXTURE_2D, 0, |
|
5d7bb2fd74f7
Never keep texture on the host when it has been uploaded, and prevent them from being decoded again.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
423
diff
changeset
|
151 composants, |
|
5d7bb2fd74f7
Never keep texture on the host when it has been uploaded, and prevent them from being decoded again.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
423
diff
changeset
|
152 thtx.width, thtx.height, |
|
5d7bb2fd74f7
Never keep texture on the host when it has been uploaded, and prevent them from being decoded again.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
423
diff
changeset
|
153 0, |
|
5d7bb2fd74f7
Never keep texture on the host when it has been uploaded, and prevent them from being decoded again.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
423
diff
changeset
|
154 format_, type_, |
|
5d7bb2fd74f7
Never keep texture on the host when it has been uploaded, and prevent them from being decoded again.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
423
diff
changeset
|
155 <char*>thtx.data) |
|
393
9e2cbb2c2c64
Implement THTX, uncompressed textures stored inside ANM files, and use it instead of pyglet’s own wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
392
diff
changeset
|
156 |
|
505
bfea9e9a6845
Manage the texture-specific indices in the Texture, and some more renderer optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
504
diff
changeset
|
157 return texture |
