Mercurial > touhou
comparison pytouhou/ui/opengl/background.pyx @ 560:c759b97f4f81
Remove all reference to the old fixed pipeline option in the OpenGL backend, use the newer is_legacy one.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Fri, 30 May 2014 16:51:38 +0200 |
parents | 94725968dabb |
children | b8df946d394d |
comparison
equal
deleted
inserted
replaced
559:1be60813f7cb | 560:c759b97f4f81 |
---|---|
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 | 26 |
27 from .sprite cimport get_sprite_rendering_data | 27 from .sprite cimport get_sprite_rendering_data |
28 from .backend cimport use_vao | 28 from .backend cimport is_legacy, use_vao |
29 | 29 |
30 | 30 |
31 cdef class BackgroundRenderer: | 31 cdef class BackgroundRenderer: |
32 def __dealloc__(self): | 32 def __dealloc__(self): |
33 if self.use_fixed_pipeline: | 33 if is_legacy: |
34 if self.vertex_buffer != NULL: | 34 if self.vertex_buffer != NULL: |
35 free(self.vertex_buffer) | 35 free(self.vertex_buffer) |
36 if self.indices != NULL: | 36 if self.indices != NULL: |
37 free(self.indices) | 37 free(self.indices) |
38 else: | 38 else: |
41 | 41 |
42 if use_vao: | 42 if use_vao: |
43 glDeleteVertexArrays(1, &self.vao) | 43 glDeleteVertexArrays(1, &self.vao) |
44 | 44 |
45 | 45 |
46 def __init__(self, use_fixed_pipeline): | 46 def __init__(self): |
47 self.use_fixed_pipeline = use_fixed_pipeline | 47 if not is_legacy: |
48 | |
49 if not use_fixed_pipeline: | |
50 glGenBuffers(1, &self.vbo) | 48 glGenBuffers(1, &self.vbo) |
51 glGenBuffers(1, &self.ibo) | 49 glGenBuffers(1, &self.ibo) |
52 | 50 |
53 if use_vao: | 51 if use_vao: |
54 glGenVertexArrays(1, &self.vao) | 52 glGenVertexArrays(1, &self.vao) |
70 glVertexAttribPointer(2, 4, GL_UNSIGNED_BYTE, True, sizeof(Vertex), <void*>20) | 68 glVertexAttribPointer(2, 4, GL_UNSIGNED_BYTE, True, sizeof(Vertex), <void*>20) |
71 glEnableVertexAttribArray(2) | 69 glEnableVertexAttribArray(2) |
72 | 70 |
73 | 71 |
74 cdef void render_background(self): | 72 cdef void render_background(self): |
75 if self.use_fixed_pipeline: | 73 if is_legacy: |
76 indices = self.indices | 74 indices = self.indices |
77 glVertexPointer(3, GL_FLOAT, sizeof(Vertex), &self.vertex_buffer[0].x) | 75 glVertexPointer(3, GL_FLOAT, sizeof(Vertex), &self.vertex_buffer[0].x) |
78 glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), &self.vertex_buffer[0].u) | 76 glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), &self.vertex_buffer[0].u) |
79 glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex), &self.vertex_buffer[0].r) | 77 glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex), &self.vertex_buffer[0].r) |
80 else: | 78 else: |
88 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) | 86 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) |
89 glBindTexture(GL_TEXTURE_2D, self.texture) | 87 glBindTexture(GL_TEXTURE_2D, self.texture) |
90 glDrawElements(GL_TRIANGLES, self.nb_indices, GL_UNSIGNED_SHORT, indices) | 88 glDrawElements(GL_TRIANGLES, self.nb_indices, GL_UNSIGNED_SHORT, indices) |
91 glDisable(GL_DEPTH_TEST) | 89 glDisable(GL_DEPTH_TEST) |
92 | 90 |
93 if not self.use_fixed_pipeline: | 91 if not is_legacy: |
94 if use_vao: | 92 if use_vao: |
95 glBindVertexArray(0) | 93 glBindVertexArray(0) |
96 else: | 94 else: |
97 glBindBuffer(GL_ARRAY_BUFFER, 0) | 95 glBindBuffer(GL_ARRAY_BUFFER, 0) |
98 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0) | 96 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0) |
136 # background animation. | 134 # background animation. |
137 | 135 |
138 self.texture = renderer.textures[key >> 1] | 136 self.texture = renderer.textures[key >> 1] |
139 self.nb_indices = nb_indices | 137 self.nb_indices = nb_indices |
140 | 138 |
141 if self.use_fixed_pipeline: | 139 if is_legacy: |
142 self.vertex_buffer = <Vertex*> realloc(vertex_buffer, nb_vertices * sizeof(Vertex)) | 140 self.vertex_buffer = <Vertex*> realloc(vertex_buffer, nb_vertices * sizeof(Vertex)) |
143 self.indices = <GLushort*> realloc(indices, nb_indices * sizeof(GLushort)) | 141 self.indices = <GLushort*> realloc(indices, nb_indices * sizeof(GLushort)) |
144 else: | 142 else: |
145 glBindBuffer(GL_ARRAY_BUFFER, self.vbo) | 143 glBindBuffer(GL_ARRAY_BUFFER, self.vbo) |
146 glBufferData(GL_ARRAY_BUFFER, nb_vertices * sizeof(Vertex), vertex_buffer, GL_STATIC_DRAW) | 144 glBufferData(GL_ARRAY_BUFFER, nb_vertices * sizeof(Vertex), vertex_buffer, GL_STATIC_DRAW) |