|
9 | 9 | from .sprite import Sprite2D |
10 | 10 | from .texture import Texture |
11 | 11 | from .atlas import AtlasTexture |
12 | | -from . import _rot2d_vertices_rectangle_ |
| 12 | +from . import _rot2d_vertices_rectangle_, _render_sprite_batch_2d_, _render_atlas_texture_batch_2d_ |
13 | 13 | from ..math import * |
14 | 14 | from ..utils import * |
15 | 15 |
|
@@ -38,8 +38,8 @@ def draw(self, |
38 | 38 | sprite: Sprite2D | Texture, |
39 | 39 | x: float, |
40 | 40 | y: float, |
41 | | - width: int, |
42 | | - height: int, |
| 41 | + width: float, |
| 42 | + height: float, |
43 | 43 | angle: float = 0.0, |
44 | 44 | cull_sprites: bool = False |
45 | 45 | ) -> "SpriteBatch2D": |
@@ -95,21 +95,8 @@ def render(self, color: list = None, clear_batch: bool = True) -> "SpriteBatch2D |
95 | 95 |
|
96 | 96 | gl.glColor(*[1, 1, 1] if color is None else color) |
97 | 97 |
|
98 | | - gl.glEnable(gl.GL_TEXTURE_2D) |
99 | | - gl.glEnableClientState(gl.GL_VERTEX_ARRAY) |
100 | | - gl.glEnableClientState(gl.GL_TEXTURE_COORD_ARRAY) |
101 | | - |
102 | | - # Пройдитесь по каждой текстуре и отрендерьте все квадраты с этой текстурой: |
103 | | - for texture, vertices in self.texture_batches.items(): |
104 | | - gl.glBindTexture(gl.GL_TEXTURE_2D, texture) |
105 | | - gl.glVertexPointer(2, gl.GL_DOUBLE, 0, numpy.array(vertices)) |
106 | | - gl.glTexCoordPointer(2, gl.GL_DOUBLE, 0, numpy.array([0, 1, 1, 1, 1, 0, 0, 0] * (len(vertices) // 8))) |
107 | | - gl.glDrawArrays(gl.GL_QUADS, 0, len(vertices) // 2) |
108 | | - gl.glBindTexture(gl.GL_TEXTURE_2D, 0) |
109 | | - |
110 | | - gl.glDisableClientState(gl.GL_TEXTURE_COORD_ARRAY) |
111 | | - gl.glDisableClientState(gl.GL_VERTEX_ARRAY) |
112 | | - gl.glDisable(gl.GL_TEXTURE_2D) |
| 98 | + # Рисуем пакет спрайтов через ускоренную функцию Cython: |
| 99 | + _render_sprite_batch_2d_(self.texture_batches) |
113 | 100 |
|
114 | 101 | if clear_batch: self.texture_batches.clear() |
115 | 102 |
|
@@ -197,21 +184,8 @@ def render(self, color: list = None, clear_batch: bool = True) -> "AtlasTextureB |
197 | 184 |
|
198 | 185 | gl.glColor(*[1, 1, 1] if color is None else color) |
199 | 186 |
|
200 | | - gl.glEnable(gl.GL_TEXTURE_2D) |
201 | | - gl.glEnableClientState(gl.GL_VERTEX_ARRAY) |
202 | | - gl.glEnableClientState(gl.GL_TEXTURE_COORD_ARRAY) |
203 | | - |
204 | | - # Пройдитесь по каждой текстуре и отрендерьте все квадраты с этой текстурой: |
205 | | - for texture, (vertices, texcoords) in self.texture_batches.items(): |
206 | | - gl.glBindTexture(gl.GL_TEXTURE_2D, texture) |
207 | | - gl.glVertexPointer(2, gl.GL_DOUBLE, 0, numpy.array(vertices)) |
208 | | - gl.glTexCoordPointer(2, gl.GL_DOUBLE, 0, numpy.array(texcoords)) |
209 | | - gl.glDrawArrays(gl.GL_QUADS, 0, len(vertices) // 2) |
210 | | - gl.glBindTexture(gl.GL_TEXTURE_2D, 0) |
211 | | - |
212 | | - gl.glDisableClientState(gl.GL_TEXTURE_COORD_ARRAY) |
213 | | - gl.glDisableClientState(gl.GL_VERTEX_ARRAY) |
214 | | - gl.glDisable(gl.GL_TEXTURE_2D) |
| 187 | + # Рисуем пакет спрайтов через ускоренную функцию Cython: |
| 188 | + _render_atlas_texture_batch_2d_(self.texture_batches) |
215 | 189 |
|
216 | 190 | if clear_batch: self.texture_batches.clear() |
217 | 191 |
|
|
0 commit comments