comparison pytouhou/ui/opengl/background.pyx @ 579:b8df946d394d

Add grouping for OpenGL calls, making traces much more readable.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sun, 17 Aug 2014 16:16:58 +0200
parents c759b97f4f81
children 6e79756b7f42
comparison
equal deleted inserted replaced
578:00f228b57840 579:b8df946d394d
20 glBindTexture, glBindBuffer, glBufferData, GL_ARRAY_BUFFER, 20 glBindTexture, glBindBuffer, glBufferData, GL_ARRAY_BUFFER,
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 27
27 from .sprite cimport get_sprite_rendering_data 28 from .sprite cimport get_sprite_rendering_data
28 from .backend cimport is_legacy, use_vao 29 from .backend cimport is_legacy, use_vao
29 30
30 31
43 glDeleteVertexArrays(1, &self.vao) 44 glDeleteVertexArrays(1, &self.vao)
44 45
45 46
46 def __init__(self): 47 def __init__(self):
47 if not is_legacy: 48 if not is_legacy:
49 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Background creation")
48 glGenBuffers(1, &self.vbo) 50 glGenBuffers(1, &self.vbo)
49 glGenBuffers(1, &self.ibo) 51 glGenBuffers(1, &self.ibo)
50 52
51 if use_vao: 53 if use_vao:
52 glGenVertexArrays(1, &self.vao) 54 glGenVertexArrays(1, &self.vao)
53
54 glBindVertexArray(self.vao) 55 glBindVertexArray(self.vao)
55 self.set_state() 56 self.set_state()
56 glBindVertexArray(0) 57 glBindVertexArray(0)
58 glPopDebugGroup()
57 59
58 60
59 cdef void set_state(self) nogil: 61 cdef void set_state(self) nogil:
60 glBindBuffer(GL_ARRAY_BUFFER, self.vbo) 62 glBindBuffer(GL_ARRAY_BUFFER, self.vbo)
61 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, self.ibo) 63 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, self.ibo)
68 glVertexAttribPointer(2, 4, GL_UNSIGNED_BYTE, True, sizeof(Vertex), <void*>20) 70 glVertexAttribPointer(2, 4, GL_UNSIGNED_BYTE, True, sizeof(Vertex), <void*>20)
69 glEnableVertexAttribArray(2) 71 glEnableVertexAttribArray(2)
70 72
71 73
72 cdef void render_background(self): 74 cdef void render_background(self):
75 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Background drawing")
73 if is_legacy: 76 if is_legacy:
74 indices = self.indices 77 indices = self.indices
75 glVertexPointer(3, GL_FLOAT, sizeof(Vertex), &self.vertex_buffer[0].x) 78 glVertexPointer(3, GL_FLOAT, sizeof(Vertex), &self.vertex_buffer[0].x)
76 glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), &self.vertex_buffer[0].u) 79 glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), &self.vertex_buffer[0].u)
77 glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex), &self.vertex_buffer[0].r) 80 glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex), &self.vertex_buffer[0].r)
92 if use_vao: 95 if use_vao:
93 glBindVertexArray(0) 96 glBindVertexArray(0)
94 else: 97 else:
95 glBindBuffer(GL_ARRAY_BUFFER, 0) 98 glBindBuffer(GL_ARRAY_BUFFER, 0)
96 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0) 99 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)
100 glPopDebugGroup()
97 101
98 102
99 cdef void load(self, background, Renderer renderer): 103 cdef void load(self, background, Renderer renderer):
100 cdef float ox, oy, oz, ox2, oy2, oz2 104 cdef float ox, oy, oz, ox2, oy2, oz2
101 cdef GLsizei nb_vertices = 0, nb_indices = 0 105 cdef GLsizei nb_vertices = 0, nb_indices = 0
138 142
139 if is_legacy: 143 if is_legacy:
140 self.vertex_buffer = <Vertex*> realloc(vertex_buffer, nb_vertices * sizeof(Vertex)) 144 self.vertex_buffer = <Vertex*> realloc(vertex_buffer, nb_vertices * sizeof(Vertex))
141 self.indices = <GLushort*> realloc(indices, nb_indices * sizeof(GLushort)) 145 self.indices = <GLushort*> realloc(indices, nb_indices * sizeof(GLushort))
142 else: 146 else:
147 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Background uploading")
143 glBindBuffer(GL_ARRAY_BUFFER, self.vbo) 148 glBindBuffer(GL_ARRAY_BUFFER, self.vbo)
144 glBufferData(GL_ARRAY_BUFFER, nb_vertices * sizeof(Vertex), vertex_buffer, GL_STATIC_DRAW) 149 glBufferData(GL_ARRAY_BUFFER, nb_vertices * sizeof(Vertex), vertex_buffer, GL_STATIC_DRAW)
145 glBindBuffer(GL_ARRAY_BUFFER, 0) 150 glBindBuffer(GL_ARRAY_BUFFER, 0)
146 151
147 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, self.ibo) 152 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, self.ibo)
148 glBufferData(GL_ELEMENT_ARRAY_BUFFER, nb_indices * sizeof(GLushort), indices, GL_STATIC_DRAW) 153 glBufferData(GL_ELEMENT_ARRAY_BUFFER, nb_indices * sizeof(GLushort), indices, GL_STATIC_DRAW)
149 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0) 154 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)
155 glPopDebugGroup()