comparison pytouhou/ui/opengl/background.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
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 27
28 from .sprite cimport get_sprite_rendering_data 28 from .sprite cimport get_sprite_rendering_data
29 from .backend cimport is_legacy, use_vao 29 from .backend cimport is_legacy, use_debug_group, use_vao
30 30
31 31
32 cdef class BackgroundRenderer: 32 cdef class BackgroundRenderer:
33 def __dealloc__(self): 33 def __dealloc__(self):
34 if is_legacy: 34 if is_legacy:
44 glDeleteVertexArrays(1, &self.vao) 44 glDeleteVertexArrays(1, &self.vao)
45 45
46 46
47 def __init__(self): 47 def __init__(self):
48 if not is_legacy: 48 if not is_legacy:
49 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Background creation") 49 if use_debug_group:
50 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Background creation")
51
50 glGenBuffers(1, &self.vbo) 52 glGenBuffers(1, &self.vbo)
51 glGenBuffers(1, &self.ibo) 53 glGenBuffers(1, &self.ibo)
52 54
53 if use_vao: 55 if use_vao:
54 glGenVertexArrays(1, &self.vao) 56 glGenVertexArrays(1, &self.vao)
55 glBindVertexArray(self.vao) 57 glBindVertexArray(self.vao)
56 self.set_state() 58 self.set_state()
57 glBindVertexArray(0) 59 glBindVertexArray(0)
58 glPopDebugGroup() 60
61 if use_debug_group:
62 glPopDebugGroup()
59 63
60 64
61 cdef void set_state(self) nogil: 65 cdef void set_state(self) nogil:
62 glBindBuffer(GL_ARRAY_BUFFER, self.vbo) 66 glBindBuffer(GL_ARRAY_BUFFER, self.vbo)
63 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, self.ibo) 67 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, self.ibo)
70 glVertexAttribPointer(2, 4, GL_UNSIGNED_BYTE, True, sizeof(Vertex), <void*>20) 74 glVertexAttribPointer(2, 4, GL_UNSIGNED_BYTE, True, sizeof(Vertex), <void*>20)
71 glEnableVertexAttribArray(2) 75 glEnableVertexAttribArray(2)
72 76
73 77
74 cdef void render_background(self): 78 cdef void render_background(self):
75 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Background drawing") 79 if use_debug_group:
80 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Background drawing")
81
76 if is_legacy: 82 if is_legacy:
77 indices = self.indices 83 indices = self.indices
78 glVertexPointer(3, GL_FLOAT, sizeof(Vertex), &self.vertex_buffer[0].x) 84 glVertexPointer(3, GL_FLOAT, sizeof(Vertex), &self.vertex_buffer[0].x)
79 glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), &self.vertex_buffer[0].u) 85 glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), &self.vertex_buffer[0].u)
80 glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex), &self.vertex_buffer[0].r) 86 glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex), &self.vertex_buffer[0].r)
95 if use_vao: 101 if use_vao:
96 glBindVertexArray(0) 102 glBindVertexArray(0)
97 else: 103 else:
98 glBindBuffer(GL_ARRAY_BUFFER, 0) 104 glBindBuffer(GL_ARRAY_BUFFER, 0)
99 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0) 105 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)
100 glPopDebugGroup() 106
107 if use_debug_group:
108 glPopDebugGroup()
101 109
102 110
103 cdef void load(self, background, Renderer renderer): 111 cdef void load(self, background, Renderer renderer):
104 cdef float ox, oy, oz, ox2, oy2, oz2 112 cdef float ox, oy, oz, ox2, oy2, oz2
105 cdef GLsizei nb_vertices = 0, nb_indices = 0 113 cdef GLsizei nb_vertices = 0, nb_indices = 0
142 150
143 if is_legacy: 151 if is_legacy:
144 self.vertex_buffer = <Vertex*> realloc(vertex_buffer, nb_vertices * sizeof(Vertex)) 152 self.vertex_buffer = <Vertex*> realloc(vertex_buffer, nb_vertices * sizeof(Vertex))
145 self.indices = <GLushort*> realloc(indices, nb_indices * sizeof(GLushort)) 153 self.indices = <GLushort*> realloc(indices, nb_indices * sizeof(GLushort))
146 else: 154 else:
147 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Background uploading") 155 if use_debug_group:
156 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Background uploading")
157
148 glBindBuffer(GL_ARRAY_BUFFER, self.vbo) 158 glBindBuffer(GL_ARRAY_BUFFER, self.vbo)
149 glBufferData(GL_ARRAY_BUFFER, nb_vertices * sizeof(Vertex), vertex_buffer, GL_STATIC_DRAW) 159 glBufferData(GL_ARRAY_BUFFER, nb_vertices * sizeof(Vertex), vertex_buffer, GL_STATIC_DRAW)
150 glBindBuffer(GL_ARRAY_BUFFER, 0) 160 glBindBuffer(GL_ARRAY_BUFFER, 0)
151 161
152 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, self.ibo) 162 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, self.ibo)
153 glBufferData(GL_ELEMENT_ARRAY_BUFFER, nb_indices * sizeof(GLushort), indices, GL_STATIC_DRAW) 163 glBufferData(GL_ELEMENT_ARRAY_BUFFER, nb_indices * sizeof(GLushort), indices, GL_STATIC_DRAW)
154 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0) 164 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)
155 glPopDebugGroup() 165
166 if use_debug_group:
167 glPopDebugGroup()