comparison pytouhou/ui/opengl/background.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
21 GL_STATIC_DRAW, GL_UNSIGNED_BYTE, GL_FLOAT, GL_SRC_ALPHA, 21 GL_STATIC_DRAW, GL_UNSIGNED_BYTE, GL_FLOAT, GL_SRC_ALPHA,
22 GL_ONE_MINUS_SRC_ALPHA, GL_TEXTURE_2D, glGenBuffers, glEnable, 22 GL_ONE_MINUS_SRC_ALPHA, GL_TEXTURE_2D, glGenBuffers, glEnable,
23 glDisable, GL_DEPTH_TEST, glDrawElements, GL_TRIANGLES, 23 glDisable, GL_DEPTH_TEST, glDrawElements, GL_TRIANGLES,
24 GL_UNSIGNED_SHORT, GL_ELEMENT_ARRAY_BUFFER, glDeleteBuffers, 24 GL_UNSIGNED_SHORT, GL_ELEMENT_ARRAY_BUFFER, glDeleteBuffers,
25 glGenVertexArrays, glDeleteVertexArrays, glBindVertexArray, 25 glGenVertexArrays, glDeleteVertexArrays, glBindVertexArray,
26 glPushDebugGroup, GL_DEBUG_SOURCE_APPLICATION, glPopDebugGroup) 26 glPushDebugGroup, GL_DEBUG_SOURCE_APPLICATION, glPopDebugGroup,
27 GL_TRIANGLE_STRIP)
27 28
28 from .sprite cimport get_sprite_rendering_data 29 from .sprite cimport get_sprite_rendering_data
29 from .backend cimport is_legacy, use_debug_group, use_vao 30 from .backend cimport is_legacy, use_debug_group, use_vao, use_primitive_restart
30 31
31 32
32 cdef class BackgroundRenderer: 33 cdef class BackgroundRenderer:
33 def __dealloc__(self): 34 def __dealloc__(self):
34 if is_legacy: 35 if is_legacy:
92 self.set_state() 93 self.set_state()
93 94
94 glEnable(GL_DEPTH_TEST) 95 glEnable(GL_DEPTH_TEST)
95 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) 96 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
96 glBindTexture(GL_TEXTURE_2D, self.texture) 97 glBindTexture(GL_TEXTURE_2D, self.texture)
97 glDrawElements(GL_TRIANGLES, self.nb_indices, GL_UNSIGNED_SHORT, indices) 98 glDrawElements(GL_TRIANGLE_STRIP if use_primitive_restart else GL_TRIANGLES, self.nb_indices, GL_UNSIGNED_SHORT, indices)
98 glDisable(GL_DEPTH_TEST) 99 glDisable(GL_DEPTH_TEST)
99 100
100 if not is_legacy: 101 if not is_legacy:
101 if use_vao: 102 if use_vao:
102 glBindVertexArray(0) 103 glBindVertexArray(0)
125 r, g, b, a = data.color[0], data.color[1], data.color[2], data.color[3] 126 r, g, b, a = data.color[0], data.color[1], data.color[2], data.color[3]
126 127
127 # Pack data 128 # Pack data
128 vertex_buffer[nb_vertices] = Vertex(x1 + ox + ox2, y1 + oy + oy2, z1 + oz + oz2, data.left, data.bottom, r, g, b, a) 129 vertex_buffer[nb_vertices] = Vertex(x1 + ox + ox2, y1 + oy + oy2, z1 + oz + oz2, data.left, data.bottom, r, g, b, a)
129 vertex_buffer[nb_vertices+1] = Vertex(x2 + ox + ox2, y2 + oy + oy2, z2 + oz + oz2, data.right, data.bottom, r, g, b, a) 130 vertex_buffer[nb_vertices+1] = Vertex(x2 + ox + ox2, y2 + oy + oy2, z2 + oz + oz2, data.right, data.bottom, r, g, b, a)
130 vertex_buffer[nb_vertices+2] = Vertex(x3 + ox + ox2, y3 + oy + oy2, z3 + oz + oz2, data.right, data.top, r, g, b, a) 131 vertex_buffer[nb_vertices+2] = Vertex(x4 + ox + ox2, y4 + oy + oy2, z4 + oz + oz2, data.left, data.top, r, g, b, a)
131 vertex_buffer[nb_vertices+3] = Vertex(x4 + ox + ox2, y4 + oy + oy2, z4 + oz + oz2, data.left, data.top, r, g, b, a) 132 vertex_buffer[nb_vertices+3] = Vertex(x3 + ox + ox2, y3 + oy + oy2, z3 + oz + oz2, data.right, data.top, r, g, b, a)
132 133
133 # Add indices 134 # Add indices
134 indices[nb_indices] = nb_vertices 135 if use_primitive_restart:
135 indices[nb_indices+1] = nb_vertices + 1 136 indices[nb_indices] = nb_vertices
136 indices[nb_indices+2] = nb_vertices + 2 137 indices[nb_indices+1] = nb_vertices + 1
137 indices[nb_indices+3] = nb_vertices + 2 138 indices[nb_indices+2] = nb_vertices + 2
138 indices[nb_indices+4] = nb_vertices + 3 139 indices[nb_indices+3] = nb_vertices + 3
139 indices[nb_indices+5] = nb_vertices 140 indices[nb_indices+4] = 0xFFFF
141 else:
142 indices[nb_indices] = nb_vertices
143 indices[nb_indices+1] = nb_vertices + 1
144 indices[nb_indices+2] = nb_vertices + 2
145 indices[nb_indices+3] = nb_vertices + 1
146 indices[nb_indices+4] = nb_vertices + 2
147 indices[nb_indices+5] = nb_vertices + 3
140 148
141 nb_vertices += 4 149 nb_vertices += 4
142 nb_indices += 6 150 nb_indices += 5 if use_primitive_restart else 6
143 151
144 # We only need to keep the rendered vertices and indices in memory, 152 # We only need to keep the rendered vertices and indices in memory,
145 # either in RAM or in VRAM, they will never change until we implement 153 # either in RAM or in VRAM, they will never change until we implement
146 # background animation. 154 # background animation.
147 155