Mercurial > touhou
comparison pytouhou/ui/opengl/renderer.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 |
---|---|
31 GL_LINEAR, GL_TEXTURE_MAG_FILTER, GL_RGBA, GL_RENDERBUFFER, | 31 GL_LINEAR, GL_TEXTURE_MAG_FILTER, GL_RGBA, GL_RENDERBUFFER, |
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) | 36 glDeleteVertexArrays, glBindVertexArray, glPushDebugGroup, |
37 GL_DEBUG_SOURCE_APPLICATION, glPopDebugGroup) | |
37 | 38 |
38 from pytouhou.lib.sdl import SDLError | 39 from pytouhou.lib.sdl import SDLError |
39 | 40 |
40 from pytouhou.game.element cimport Element | 41 from pytouhou.game.element cimport Element |
41 from .sprite cimport get_sprite_rendering_data | 42 from .sprite cimport get_sprite_rendering_data |
115 logger.error('Font file ā%sā not found, disabling text rendering altogether.', font_name) | 116 logger.error('Font file ā%sā not found, disabling text rendering altogether.', font_name) |
116 | 117 |
117 if not is_legacy: | 118 if not is_legacy: |
118 framebuffer_indices[:] = [0, 1, 2, 2, 3, 0] | 119 framebuffer_indices[:] = [0, 1, 2, 2, 3, 0] |
119 | 120 |
121 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Renderer creation") | |
120 glGenBuffers(1, &self.vbo) | 122 glGenBuffers(1, &self.vbo) |
121 glGenBuffers(1, &self.framebuffer_vbo) | 123 glGenBuffers(1, &self.framebuffer_vbo) |
122 glGenBuffers(1, &self.framebuffer_ibo) | 124 glGenBuffers(1, &self.framebuffer_ibo) |
123 | 125 |
124 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, self.framebuffer_ibo) | 126 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, self.framebuffer_ibo) |
132 | 134 |
133 glGenVertexArrays(1, &self.framebuffer_vao) | 135 glGenVertexArrays(1, &self.framebuffer_vao) |
134 glBindVertexArray(self.framebuffer_vao) | 136 glBindVertexArray(self.framebuffer_vao) |
135 self.set_framebuffer_state() | 137 self.set_framebuffer_state() |
136 glBindVertexArray(0) | 138 glBindVertexArray(0) |
139 glPopDebugGroup() | |
137 | 140 |
138 | 141 |
139 cdef void set_state(self) nogil: | 142 cdef void set_state(self) nogil: |
140 glBindBuffer(GL_ARRAY_BUFFER, self.vbo) | 143 glBindBuffer(GL_ARRAY_BUFFER, self.vbo) |
141 | 144 |
202 rec[next_indice+5] = nb_vertices | 205 rec[next_indice+5] = nb_vertices |
203 self.last_indices[key] += 6 | 206 self.last_indices[key] += 6 |
204 | 207 |
205 nb_vertices += 4 | 208 nb_vertices += 4 |
206 | 209 |
210 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Elements drawing") | |
207 if is_legacy: | 211 if is_legacy: |
208 glVertexPointer(3, GL_SHORT, sizeof(Vertex), &self.vertex_buffer[0].x) | 212 glVertexPointer(3, GL_SHORT, sizeof(Vertex), &self.vertex_buffer[0].x) |
209 glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), &self.vertex_buffer[0].u) | 213 glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), &self.vertex_buffer[0].u) |
210 glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex), &self.vertex_buffer[0].r) | 214 glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex), &self.vertex_buffer[0].r) |
211 else: | 215 else: |
241 | 245 |
242 glBindTexture(GL_TEXTURE_2D, 0) | 246 glBindTexture(GL_TEXTURE_2D, 0) |
243 | 247 |
244 if not is_legacy and use_vao: | 248 if not is_legacy and use_vao: |
245 glBindVertexArray(0) | 249 glBindVertexArray(0) |
250 glPopDebugGroup() | |
246 | 251 |
247 | 252 |
248 cdef void render_quads(self, rects, colors, GLuint texture): | 253 cdef void render_quads(self, rects, colors, GLuint texture): |
249 # There is nothing that batch more than two quads on the same texture, currently. | 254 # There is nothing that batch more than two quads on the same texture, currently. |
250 cdef Vertex buf[8] | 255 cdef Vertex buf[8] |
260 buf[4*i] = Vertex(r.x, r.y, 0, 0, 0, 0, c1.r, c1.g, c1.b, c1.a) | 265 buf[4*i] = Vertex(r.x, r.y, 0, 0, 0, 0, c1.r, c1.g, c1.b, c1.a) |
261 buf[4*i+1] = Vertex(r.x + r.w, r.y, 0, 0, 1, 0, c2.r, c2.g, c2.b, c2.a) | 266 buf[4*i+1] = Vertex(r.x + r.w, r.y, 0, 0, 1, 0, c2.r, c2.g, c2.b, c2.a) |
262 buf[4*i+2] = Vertex(r.x + r.w, r.y + r.h, 0, 0, 1, 1, c3.r, c3.g, c3.b, c3.a) | 267 buf[4*i+2] = Vertex(r.x + r.w, r.y + r.h, 0, 0, 1, 1, c3.r, c3.g, c3.b, c3.a) |
263 buf[4*i+3] = Vertex(r.x, r.y + r.h, 0, 0, 0, 1, c4.r, c4.g, c4.b, c4.a) | 268 buf[4*i+3] = Vertex(r.x, r.y + r.h, 0, 0, 0, 1, c4.r, c4.g, c4.b, c4.a) |
264 | 269 |
270 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Quads drawing") | |
265 if is_legacy: | 271 if is_legacy: |
266 glVertexPointer(3, GL_SHORT, sizeof(Vertex), &buf[0].x) | 272 glVertexPointer(3, GL_SHORT, sizeof(Vertex), &buf[0].x) |
267 glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), &buf[0].u) | 273 glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), &buf[0].u) |
268 glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex), &buf[0].r) | 274 glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex), &buf[0].r) |
269 else: | 275 else: |
277 self.set_state() | 283 self.set_state() |
278 | 284 |
279 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) | 285 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) |
280 glBindTexture(GL_TEXTURE_2D, texture) | 286 glBindTexture(GL_TEXTURE_2D, texture) |
281 glDrawElements(GL_TRIANGLES, 6 * length, GL_UNSIGNED_SHORT, indices) | 287 glDrawElements(GL_TRIANGLES, 6 * length, GL_UNSIGNED_SHORT, indices) |
288 glPopDebugGroup() | |
282 | 289 |
283 | 290 |
284 cdef void render_framebuffer(self, Framebuffer fb): | 291 cdef void render_framebuffer(self, Framebuffer fb): |
285 cdef PassthroughVertex[4] buf | 292 cdef PassthroughVertex[4] buf |
286 | 293 |
287 assert not is_legacy | 294 assert not is_legacy |
295 | |
296 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Framebuffer drawing") | |
288 | 297 |
289 glBindFramebuffer(GL_FRAMEBUFFER, 0) | 298 glBindFramebuffer(GL_FRAMEBUFFER, 0) |
290 glViewport(self.x, self.y, self.width, self.height) | 299 glViewport(self.x, self.y, self.width, self.height) |
291 glBlendFunc(GL_ONE, GL_ZERO) | 300 glBlendFunc(GL_ONE, GL_ZERO) |
292 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) | 301 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) |
311 | 320 |
312 if use_vao: | 321 if use_vao: |
313 glBindVertexArray(0) | 322 glBindVertexArray(0) |
314 else: | 323 else: |
315 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0) | 324 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0) |
325 glPopDebugGroup() | |
316 | 326 |
317 | 327 |
318 cdef class Framebuffer: | 328 cdef class Framebuffer: |
319 def __init__(self, int x, int y, int width, int height): | 329 def __init__(self, int x, int y, int width, int height): |
320 self.x = x | 330 self.x = x |
321 self.y = y | 331 self.y = y |
322 self.width = width | 332 self.width = width |
323 self.height = height | 333 self.height = height |
334 | |
335 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Framebuffer creation") | |
324 | 336 |
325 glGenTextures(1, &self.texture) | 337 glGenTextures(1, &self.texture) |
326 glBindTexture(GL_TEXTURE_2D, self.texture) | 338 glBindTexture(GL_TEXTURE_2D, self.texture) |
327 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) | 339 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) |
328 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) | 340 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) |
344 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, self.texture, 0) | 356 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, self.texture, 0) |
345 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, self.rbo) | 357 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, self.rbo) |
346 assert glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE | 358 assert glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE |
347 glBindFramebuffer(GL_FRAMEBUFFER, 0) | 359 glBindFramebuffer(GL_FRAMEBUFFER, 0) |
348 | 360 |
361 glPopDebugGroup() | |
362 | |
349 cpdef bind(self): | 363 cpdef bind(self): |
350 glBindFramebuffer(GL_FRAMEBUFFER, self.fbo) | 364 glBindFramebuffer(GL_FRAMEBUFFER, self.fbo) |