Mercurial > touhou
comparison pytouhou/ui/opengl/renderer.pyx @ 582:6e79756b7f42
Don’t call gl*DebugGroup if it isn’t exposed by the driver.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sun, 05 Oct 2014 17:46:51 +0200 |
parents | b8df946d394d |
children | e0166cda75d5 |
comparison
equal
deleted
inserted
replaced
581:cb8a443bc046 | 582:6e79756b7f42 |
---|---|
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_vao | 43 from .backend cimport is_legacy, use_debug_group, use_vao |
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 |
116 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) |
117 | 117 |
118 if not is_legacy: | 118 if not is_legacy: |
119 framebuffer_indices[:] = [0, 1, 2, 2, 3, 0] | 119 framebuffer_indices[:] = [0, 1, 2, 2, 3, 0] |
120 | 120 |
121 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Renderer creation") | 121 if use_debug_group: |
122 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Renderer creation") | |
123 | |
122 glGenBuffers(1, &self.vbo) | 124 glGenBuffers(1, &self.vbo) |
123 glGenBuffers(1, &self.framebuffer_vbo) | 125 glGenBuffers(1, &self.framebuffer_vbo) |
124 glGenBuffers(1, &self.framebuffer_ibo) | 126 glGenBuffers(1, &self.framebuffer_ibo) |
125 | 127 |
126 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, self.framebuffer_ibo) | 128 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, self.framebuffer_ibo) |
134 | 136 |
135 glGenVertexArrays(1, &self.framebuffer_vao) | 137 glGenVertexArrays(1, &self.framebuffer_vao) |
136 glBindVertexArray(self.framebuffer_vao) | 138 glBindVertexArray(self.framebuffer_vao) |
137 self.set_framebuffer_state() | 139 self.set_framebuffer_state() |
138 glBindVertexArray(0) | 140 glBindVertexArray(0) |
139 glPopDebugGroup() | 141 |
142 if use_debug_group: | |
143 glPopDebugGroup() | |
140 | 144 |
141 | 145 |
142 cdef void set_state(self) nogil: | 146 cdef void set_state(self) nogil: |
143 glBindBuffer(GL_ARRAY_BUFFER, self.vbo) | 147 glBindBuffer(GL_ARRAY_BUFFER, self.vbo) |
144 | 148 |
205 rec[next_indice+5] = nb_vertices | 209 rec[next_indice+5] = nb_vertices |
206 self.last_indices[key] += 6 | 210 self.last_indices[key] += 6 |
207 | 211 |
208 nb_vertices += 4 | 212 nb_vertices += 4 |
209 | 213 |
210 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Elements drawing") | 214 if use_debug_group: |
215 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Elements drawing") | |
216 | |
211 if is_legacy: | 217 if is_legacy: |
212 glVertexPointer(3, GL_SHORT, sizeof(Vertex), &self.vertex_buffer[0].x) | 218 glVertexPointer(3, GL_SHORT, sizeof(Vertex), &self.vertex_buffer[0].x) |
213 glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), &self.vertex_buffer[0].u) | 219 glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), &self.vertex_buffer[0].u) |
214 glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex), &self.vertex_buffer[0].r) | 220 glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex), &self.vertex_buffer[0].r) |
215 else: | 221 else: |
245 | 251 |
246 glBindTexture(GL_TEXTURE_2D, 0) | 252 glBindTexture(GL_TEXTURE_2D, 0) |
247 | 253 |
248 if not is_legacy and use_vao: | 254 if not is_legacy and use_vao: |
249 glBindVertexArray(0) | 255 glBindVertexArray(0) |
250 glPopDebugGroup() | 256 |
257 if use_debug_group: | |
258 glPopDebugGroup() | |
251 | 259 |
252 | 260 |
253 cdef void render_quads(self, rects, colors, GLuint texture): | 261 cdef void render_quads(self, rects, colors, GLuint texture): |
254 # There is nothing that batch more than two quads on the same texture, currently. | 262 # There is nothing that batch more than two quads on the same texture, currently. |
255 cdef Vertex buf[8] | 263 cdef Vertex buf[8] |
265 buf[4*i] = Vertex(r.x, r.y, 0, 0, 0, 0, c1.r, c1.g, c1.b, c1.a) | 273 buf[4*i] = Vertex(r.x, r.y, 0, 0, 0, 0, c1.r, c1.g, c1.b, c1.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) | 274 buf[4*i+1] = Vertex(r.x + r.w, r.y, 0, 0, 1, 0, c2.r, c2.g, c2.b, c2.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) | 275 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) |
268 buf[4*i+3] = Vertex(r.x, r.y + r.h, 0, 0, 0, 1, c4.r, c4.g, c4.b, c4.a) | 276 buf[4*i+3] = Vertex(r.x, r.y + r.h, 0, 0, 0, 1, c4.r, c4.g, c4.b, c4.a) |
269 | 277 |
270 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Quads drawing") | 278 if use_debug_group: |
279 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Quads drawing") | |
280 | |
271 if is_legacy: | 281 if is_legacy: |
272 glVertexPointer(3, GL_SHORT, sizeof(Vertex), &buf[0].x) | 282 glVertexPointer(3, GL_SHORT, sizeof(Vertex), &buf[0].x) |
273 glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), &buf[0].u) | 283 glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), &buf[0].u) |
274 glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex), &buf[0].r) | 284 glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex), &buf[0].r) |
275 else: | 285 else: |
283 self.set_state() | 293 self.set_state() |
284 | 294 |
285 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) | 295 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) |
286 glBindTexture(GL_TEXTURE_2D, texture) | 296 glBindTexture(GL_TEXTURE_2D, texture) |
287 glDrawElements(GL_TRIANGLES, 6 * length, GL_UNSIGNED_SHORT, indices) | 297 glDrawElements(GL_TRIANGLES, 6 * length, GL_UNSIGNED_SHORT, indices) |
288 glPopDebugGroup() | 298 |
299 if use_debug_group: | |
300 glPopDebugGroup() | |
289 | 301 |
290 | 302 |
291 cdef void render_framebuffer(self, Framebuffer fb): | 303 cdef void render_framebuffer(self, Framebuffer fb): |
292 cdef PassthroughVertex[4] buf | 304 cdef PassthroughVertex[4] buf |
293 | 305 |
294 assert not is_legacy | 306 assert not is_legacy |
295 | 307 |
296 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Framebuffer drawing") | 308 if use_debug_group: |
309 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Framebuffer drawing") | |
297 | 310 |
298 glBindFramebuffer(GL_FRAMEBUFFER, 0) | 311 glBindFramebuffer(GL_FRAMEBUFFER, 0) |
299 glViewport(self.x, self.y, self.width, self.height) | 312 glViewport(self.x, self.y, self.width, self.height) |
300 glBlendFunc(GL_ONE, GL_ZERO) | 313 glBlendFunc(GL_ONE, GL_ZERO) |
301 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) | 314 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) |
320 | 333 |
321 if use_vao: | 334 if use_vao: |
322 glBindVertexArray(0) | 335 glBindVertexArray(0) |
323 else: | 336 else: |
324 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0) | 337 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0) |
325 glPopDebugGroup() | 338 |
339 if use_debug_group: | |
340 glPopDebugGroup() | |
326 | 341 |
327 | 342 |
328 cdef class Framebuffer: | 343 cdef class Framebuffer: |
329 def __init__(self, int x, int y, int width, int height): | 344 def __init__(self, int x, int y, int width, int height): |
330 self.x = x | 345 self.x = x |
331 self.y = y | 346 self.y = y |
332 self.width = width | 347 self.width = width |
333 self.height = height | 348 self.height = height |
334 | 349 |
335 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Framebuffer creation") | 350 if use_debug_group: |
351 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Framebuffer creation") | |
336 | 352 |
337 glGenTextures(1, &self.texture) | 353 glGenTextures(1, &self.texture) |
338 glBindTexture(GL_TEXTURE_2D, self.texture) | 354 glBindTexture(GL_TEXTURE_2D, self.texture) |
339 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) | 355 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) |
340 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) | 356 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) |
356 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, self.texture, 0) | 372 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, self.texture, 0) |
357 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, self.rbo) | 373 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, self.rbo) |
358 assert glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE | 374 assert glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE |
359 glBindFramebuffer(GL_FRAMEBUFFER, 0) | 375 glBindFramebuffer(GL_FRAMEBUFFER, 0) |
360 | 376 |
361 glPopDebugGroup() | 377 if use_debug_group: |
378 glPopDebugGroup() | |
362 | 379 |
363 cpdef bind(self): | 380 cpdef bind(self): |
364 glBindFramebuffer(GL_FRAMEBUFFER, self.fbo) | 381 glBindFramebuffer(GL_FRAMEBUFFER, self.fbo) |