Mercurial > touhou
comparison pytouhou/ui/opengl/renderer.pyx @ 585:e0166cda75d5
Use primitive-restart to lower the size of our ibo, if supported.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Wed, 08 Oct 2014 14:28:37 +0200 |
parents | 6e79756b7f42 |
children | 4b0593da29d5 |
comparison
equal
deleted
inserted
replaced
584:538b52aafbca | 585:e0166cda75d5 |
---|---|
32 GL_DEPTH_COMPONENT16, GL_COLOR_ATTACHMENT0, GL_DEPTH_ATTACHMENT, | 32 GL_DEPTH_COMPONENT16, GL_COLOR_ATTACHMENT0, GL_DEPTH_ATTACHMENT, |
33 GL_FRAMEBUFFER_COMPLETE, glClear, GL_COLOR_BUFFER_BIT, | 33 GL_FRAMEBUFFER_COMPLETE, glClear, GL_COLOR_BUFFER_BIT, |
34 GL_DEPTH_BUFFER_BIT, GLuint, glDeleteTextures, | 34 GL_DEPTH_BUFFER_BIT, GLuint, glDeleteTextures, |
35 GL_ELEMENT_ARRAY_BUFFER, GL_STATIC_DRAW, glGenVertexArrays, | 35 GL_ELEMENT_ARRAY_BUFFER, GL_STATIC_DRAW, glGenVertexArrays, |
36 glDeleteVertexArrays, glBindVertexArray, glPushDebugGroup, | 36 glDeleteVertexArrays, glBindVertexArray, glPushDebugGroup, |
37 GL_DEBUG_SOURCE_APPLICATION, glPopDebugGroup) | 37 GL_DEBUG_SOURCE_APPLICATION, glPopDebugGroup, GL_TRIANGLE_STRIP) |
38 | 38 |
39 from pytouhou.lib.sdl import SDLError | 39 from pytouhou.lib.sdl import SDLError |
40 | 40 |
41 from pytouhou.game.element cimport Element | 41 from pytouhou.game.element cimport Element |
42 from .sprite cimport get_sprite_rendering_data | 42 from .sprite cimport get_sprite_rendering_data |
43 from .backend cimport is_legacy, use_debug_group, use_vao | 43 from .backend cimport is_legacy, use_debug_group, use_vao, use_primitive_restart |
44 | 44 |
45 from pytouhou.utils.helpers import get_logger | 45 from pytouhou.utils.helpers import get_logger |
46 | 46 |
47 logger = get_logger(__name__) | 47 logger = get_logger(__name__) |
48 | 48 |
195 # Pack data in buffer | 195 # Pack data in buffer |
196 x1, x2, x3, x4, y1, y2, y3, y4, z1, z2, z3, z4 = <short>data.pos[0], <short>data.pos[1], <short>data.pos[2], <short>data.pos[3], <short>data.pos[4], <short>data.pos[5], <short>data.pos[6], <short>data.pos[7], <short>data.pos[8], <short>data.pos[9], <short>data.pos[10], <short>data.pos[11] | 196 x1, x2, x3, x4, y1, y2, y3, y4, z1, z2, z3, z4 = <short>data.pos[0], <short>data.pos[1], <short>data.pos[2], <short>data.pos[3], <short>data.pos[4], <short>data.pos[5], <short>data.pos[6], <short>data.pos[7], <short>data.pos[8], <short>data.pos[9], <short>data.pos[10], <short>data.pos[11] |
197 r, g, b, a = data.color[0], data.color[1], data.color[2], data.color[3] | 197 r, g, b, a = data.color[0], data.color[1], data.color[2], data.color[3] |
198 self.vertex_buffer[nb_vertices] = Vertex(x1 + ox, y1 + oy, z1, 0, data.left, data.bottom, r, g, b, a) | 198 self.vertex_buffer[nb_vertices] = Vertex(x1 + ox, y1 + oy, z1, 0, data.left, data.bottom, r, g, b, a) |
199 self.vertex_buffer[nb_vertices+1] = Vertex(x2 + ox, y2 + oy, z2, 0, data.right, data.bottom, r, g, b, a) | 199 self.vertex_buffer[nb_vertices+1] = Vertex(x2 + ox, y2 + oy, z2, 0, data.right, data.bottom, r, g, b, a) |
200 self.vertex_buffer[nb_vertices+2] = Vertex(x3 + ox, y3 + oy, z3, 0, data.right, data.top, r, g, b, a) | 200 self.vertex_buffer[nb_vertices+2] = Vertex(x4 + ox, y4 + oy, z4, 0, data.left, data.top, r, g, b, a) |
201 self.vertex_buffer[nb_vertices+3] = Vertex(x4 + ox, y4 + oy, z4, 0, data.left, data.top, r, g, b, a) | 201 self.vertex_buffer[nb_vertices+3] = Vertex(x3 + ox, y3 + oy, z3, 0, data.right, data.top, r, g, b, a) |
202 | 202 |
203 # Add indices | 203 # Add indices |
204 rec[next_indice] = nb_vertices | 204 if use_primitive_restart: |
205 rec[next_indice+1] = nb_vertices + 1 | 205 rec[next_indice] = nb_vertices |
206 rec[next_indice+2] = nb_vertices + 2 | 206 rec[next_indice+1] = nb_vertices + 1 |
207 rec[next_indice+3] = nb_vertices + 2 | 207 rec[next_indice+2] = nb_vertices + 2 |
208 rec[next_indice+4] = nb_vertices + 3 | 208 rec[next_indice+3] = nb_vertices + 3 |
209 rec[next_indice+5] = nb_vertices | 209 rec[next_indice+4] = 0xFFFF |
210 self.last_indices[key] += 6 | 210 self.last_indices[key] += 5 |
211 else: | |
212 rec[next_indice] = nb_vertices | |
213 rec[next_indice+1] = nb_vertices + 1 | |
214 rec[next_indice+2] = nb_vertices + 2 | |
215 rec[next_indice+3] = nb_vertices + 1 | |
216 rec[next_indice+4] = nb_vertices + 2 | |
217 rec[next_indice+5] = nb_vertices + 3 | |
218 self.last_indices[key] += 6 | |
211 | 219 |
212 nb_vertices += 4 | 220 nb_vertices += 4 |
213 | 221 |
214 if use_debug_group: | 222 if use_debug_group: |
215 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Elements drawing") | 223 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Elements drawing") |
242 | 250 |
243 if blendfunc != previous_blendfunc: | 251 if blendfunc != previous_blendfunc: |
244 glBlendFunc(GL_SRC_ALPHA, (GL_ONE_MINUS_SRC_ALPHA, GL_ONE)[blendfunc]) | 252 glBlendFunc(GL_SRC_ALPHA, (GL_ONE_MINUS_SRC_ALPHA, GL_ONE)[blendfunc]) |
245 if texture != previous_texture: | 253 if texture != previous_texture: |
246 glBindTexture(GL_TEXTURE_2D, self.textures[texture]) | 254 glBindTexture(GL_TEXTURE_2D, self.textures[texture]) |
247 glDrawElements(GL_TRIANGLES, nb_indices, GL_UNSIGNED_SHORT, self.indices[texture][blendfunc]) | 255 glDrawElements(GL_TRIANGLE_STRIP if use_primitive_restart else GL_TRIANGLES, nb_indices, GL_UNSIGNED_SHORT, self.indices[texture][blendfunc]) |
248 | 256 |
249 previous_blendfunc = blendfunc | 257 previous_blendfunc = blendfunc |
250 previous_texture = texture | 258 previous_texture = texture |
251 | 259 |
252 glBindTexture(GL_TEXTURE_2D, 0) | 260 glBindTexture(GL_TEXTURE_2D, 0) |