Mercurial > touhou
annotate pytouhou/ui/opengl/background.pyx @ 660:31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sat, 10 Aug 2019 14:41:30 +0200 |
parents | a6af3ff86612 |
children |
rev | line source |
---|---|
423
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
1 # -*- encoding: utf-8 -*- |
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
2 ## |
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
3 ## Copyright (C) 2013 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
4 ## |
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
5 ## This program is free software; you can redistribute it and/or modify |
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
6 ## it under the terms of the GNU General Public License as published |
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
7 ## by the Free Software Foundation; version 3 only. |
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
8 ## |
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
9 ## This program is distributed in the hope that it will be useful, |
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
12 ## GNU General Public License for more details. |
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
13 ## |
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
14 |
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
15 from libc.stdlib cimport malloc, free, realloc |
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
16 |
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
17 from pytouhou.lib.opengl cimport \ |
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
18 (glVertexPointer, glTexCoordPointer, glColorPointer, |
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
19 glVertexAttribPointer, glEnableVertexAttribArray, glBlendFunc, |
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
20 glBindTexture, glBindBuffer, glBufferData, GL_ARRAY_BUFFER, |
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
21 GL_STATIC_DRAW, GL_UNSIGNED_BYTE, GL_FLOAT, GL_SRC_ALPHA, |
519
b18f0bd30ad0
Optimise background rendering.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
515
diff
changeset
|
22 GL_ONE_MINUS_SRC_ALPHA, GL_TEXTURE_2D, glGenBuffers, glEnable, |
593
974decb8df4f
Only selects between GL_TRIANGLE_STRIP and GL_TRIANGLES once, in the backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
23 glDisable, GL_DEPTH_TEST, glDrawElements, GL_UNSIGNED_SHORT, |
974decb8df4f
Only selects between GL_TRIANGLE_STRIP and GL_TRIANGLES once, in the backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
24 GL_ELEMENT_ARRAY_BUFFER, glDeleteBuffers, glGenVertexArrays, |
974decb8df4f
Only selects between GL_TRIANGLE_STRIP and GL_TRIANGLES once, in the backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
25 glDeleteVertexArrays, glBindVertexArray, glPushDebugGroup, |
611
a6a191e371c7
Add back a GL_QUADS path for legacy applications.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
606
diff
changeset
|
26 GL_DEBUG_SOURCE_APPLICATION, glPopDebugGroup, glDrawArrays) |
423
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
27 |
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
28 from .sprite cimport get_sprite_rendering_data |
593
974decb8df4f
Only selects between GL_TRIANGLE_STRIP and GL_TRIANGLES once, in the backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
586
diff
changeset
|
29 from .backend cimport primitive_mode, is_legacy, use_debug_group, use_vao, use_primitive_restart |
423
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
30 |
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
31 |
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
32 cdef class BackgroundRenderer: |
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
33 def __dealloc__(self): |
560
c759b97f4f81
Remove all reference to the old fixed pipeline option in the OpenGL backend, use the newer is_legacy one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
558
diff
changeset
|
34 if is_legacy: |
558
94725968dabb
Use vertex array objects, to be compatible with OpenGL 3.1+ core profile.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
532
diff
changeset
|
35 if self.vertex_buffer != NULL: |
94725968dabb
Use vertex array objects, to be compatible with OpenGL 3.1+ core profile.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
532
diff
changeset
|
36 free(self.vertex_buffer) |
94725968dabb
Use vertex array objects, to be compatible with OpenGL 3.1+ core profile.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
532
diff
changeset
|
37 else: |
94725968dabb
Use vertex array objects, to be compatible with OpenGL 3.1+ core profile.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
532
diff
changeset
|
38 glDeleteBuffers(1, &self.vbo) |
94725968dabb
Use vertex array objects, to be compatible with OpenGL 3.1+ core profile.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
532
diff
changeset
|
39 glDeleteBuffers(1, &self.ibo) |
94725968dabb
Use vertex array objects, to be compatible with OpenGL 3.1+ core profile.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
532
diff
changeset
|
40 |
94725968dabb
Use vertex array objects, to be compatible with OpenGL 3.1+ core profile.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
532
diff
changeset
|
41 if use_vao: |
94725968dabb
Use vertex array objects, to be compatible with OpenGL 3.1+ core profile.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
532
diff
changeset
|
42 glDeleteVertexArrays(1, &self.vao) |
423
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
43 |
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
44 |
560
c759b97f4f81
Remove all reference to the old fixed pipeline option in the OpenGL backend, use the newer is_legacy one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
558
diff
changeset
|
45 def __init__(self): |
c759b97f4f81
Remove all reference to the old fixed pipeline option in the OpenGL backend, use the newer is_legacy one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
558
diff
changeset
|
46 if not is_legacy: |
582
6e79756b7f42
Don’t call gl*DebugGroup if it isn’t exposed by the driver.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
47 if use_debug_group: |
6e79756b7f42
Don’t call gl*DebugGroup if it isn’t exposed by the driver.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
48 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Background creation") |
6e79756b7f42
Don’t call gl*DebugGroup if it isn’t exposed by the driver.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
49 |
423
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
50 glGenBuffers(1, &self.vbo) |
519
b18f0bd30ad0
Optimise background rendering.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
515
diff
changeset
|
51 glGenBuffers(1, &self.ibo) |
423
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
52 |
558
94725968dabb
Use vertex array objects, to be compatible with OpenGL 3.1+ core profile.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
532
diff
changeset
|
53 if use_vao: |
94725968dabb
Use vertex array objects, to be compatible with OpenGL 3.1+ core profile.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
532
diff
changeset
|
54 glGenVertexArrays(1, &self.vao) |
94725968dabb
Use vertex array objects, to be compatible with OpenGL 3.1+ core profile.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
532
diff
changeset
|
55 glBindVertexArray(self.vao) |
94725968dabb
Use vertex array objects, to be compatible with OpenGL 3.1+ core profile.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
532
diff
changeset
|
56 self.set_state() |
94725968dabb
Use vertex array objects, to be compatible with OpenGL 3.1+ core profile.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
532
diff
changeset
|
57 glBindVertexArray(0) |
582
6e79756b7f42
Don’t call gl*DebugGroup if it isn’t exposed by the driver.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
58 |
6e79756b7f42
Don’t call gl*DebugGroup if it isn’t exposed by the driver.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
59 if use_debug_group: |
6e79756b7f42
Don’t call gl*DebugGroup if it isn’t exposed by the driver.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
60 glPopDebugGroup() |
558
94725968dabb
Use vertex array objects, to be compatible with OpenGL 3.1+ core profile.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
532
diff
changeset
|
61 |
94725968dabb
Use vertex array objects, to be compatible with OpenGL 3.1+ core profile.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
532
diff
changeset
|
62 |
94725968dabb
Use vertex array objects, to be compatible with OpenGL 3.1+ core profile.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
532
diff
changeset
|
63 cdef void set_state(self) nogil: |
94725968dabb
Use vertex array objects, to be compatible with OpenGL 3.1+ core profile.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
532
diff
changeset
|
64 glBindBuffer(GL_ARRAY_BUFFER, self.vbo) |
94725968dabb
Use vertex array objects, to be compatible with OpenGL 3.1+ core profile.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
532
diff
changeset
|
65 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, self.ibo) |
94725968dabb
Use vertex array objects, to be compatible with OpenGL 3.1+ core profile.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
532
diff
changeset
|
66 |
94725968dabb
Use vertex array objects, to be compatible with OpenGL 3.1+ core profile.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
532
diff
changeset
|
67 #TODO: find a way to use offsetof() instead of those ugly hardcoded values. |
94725968dabb
Use vertex array objects, to be compatible with OpenGL 3.1+ core profile.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
532
diff
changeset
|
68 glVertexAttribPointer(0, 3, GL_FLOAT, False, sizeof(Vertex), <void*>0) |
94725968dabb
Use vertex array objects, to be compatible with OpenGL 3.1+ core profile.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
532
diff
changeset
|
69 glEnableVertexAttribArray(0) |
94725968dabb
Use vertex array objects, to be compatible with OpenGL 3.1+ core profile.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
532
diff
changeset
|
70 glVertexAttribPointer(1, 2, GL_FLOAT, False, sizeof(Vertex), <void*>12) |
94725968dabb
Use vertex array objects, to be compatible with OpenGL 3.1+ core profile.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
532
diff
changeset
|
71 glEnableVertexAttribArray(1) |
94725968dabb
Use vertex array objects, to be compatible with OpenGL 3.1+ core profile.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
532
diff
changeset
|
72 glVertexAttribPointer(2, 4, GL_UNSIGNED_BYTE, True, sizeof(Vertex), <void*>20) |
94725968dabb
Use vertex array objects, to be compatible with OpenGL 3.1+ core profile.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
532
diff
changeset
|
73 glEnableVertexAttribArray(2) |
94725968dabb
Use vertex array objects, to be compatible with OpenGL 3.1+ core profile.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
532
diff
changeset
|
74 |
423
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
75 |
606
3c2f96f1d715
Fix compilation under Cython 0.22, by making the pyx and the pxd declarations’ except clause similar.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
593
diff
changeset
|
76 cdef void render_background(self) nogil: |
582
6e79756b7f42
Don’t call gl*DebugGroup if it isn’t exposed by the driver.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
77 if use_debug_group: |
6e79756b7f42
Don’t call gl*DebugGroup if it isn’t exposed by the driver.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
78 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Background drawing") |
6e79756b7f42
Don’t call gl*DebugGroup if it isn’t exposed by the driver.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
79 |
560
c759b97f4f81
Remove all reference to the old fixed pipeline option in the OpenGL backend, use the newer is_legacy one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
558
diff
changeset
|
80 if is_legacy: |
423
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
81 glVertexPointer(3, GL_FLOAT, sizeof(Vertex), &self.vertex_buffer[0].x) |
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
82 glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), &self.vertex_buffer[0].u) |
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
83 glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex), &self.vertex_buffer[0].r) |
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
84 else: |
558
94725968dabb
Use vertex array objects, to be compatible with OpenGL 3.1+ core profile.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
532
diff
changeset
|
85 if use_vao: |
94725968dabb
Use vertex array objects, to be compatible with OpenGL 3.1+ core profile.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
532
diff
changeset
|
86 glBindVertexArray(self.vao) |
94725968dabb
Use vertex array objects, to be compatible with OpenGL 3.1+ core profile.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
532
diff
changeset
|
87 else: |
94725968dabb
Use vertex array objects, to be compatible with OpenGL 3.1+ core profile.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
532
diff
changeset
|
88 self.set_state() |
423
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
89 |
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
90 glEnable(GL_DEPTH_TEST) |
519
b18f0bd30ad0
Optimise background rendering.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
515
diff
changeset
|
91 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) |
426
5d7bb2fd74f7
Never keep texture on the host when it has been uploaded, and prevent them from being decoded again.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
423
diff
changeset
|
92 glBindTexture(GL_TEXTURE_2D, self.texture) |
611
a6a191e371c7
Add back a GL_QUADS path for legacy applications.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
606
diff
changeset
|
93 if is_legacy: |
a6a191e371c7
Add back a GL_QUADS path for legacy applications.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
606
diff
changeset
|
94 glDrawArrays(primitive_mode, 0, self.nb_vertices) |
a6a191e371c7
Add back a GL_QUADS path for legacy applications.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
606
diff
changeset
|
95 else: |
a6a191e371c7
Add back a GL_QUADS path for legacy applications.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
606
diff
changeset
|
96 glDrawElements(primitive_mode, self.nb_indices, GL_UNSIGNED_SHORT, NULL) |
423
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
97 glDisable(GL_DEPTH_TEST) |
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
98 |
560
c759b97f4f81
Remove all reference to the old fixed pipeline option in the OpenGL backend, use the newer is_legacy one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
558
diff
changeset
|
99 if not is_legacy: |
558
94725968dabb
Use vertex array objects, to be compatible with OpenGL 3.1+ core profile.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
532
diff
changeset
|
100 if use_vao: |
94725968dabb
Use vertex array objects, to be compatible with OpenGL 3.1+ core profile.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
532
diff
changeset
|
101 glBindVertexArray(0) |
94725968dabb
Use vertex array objects, to be compatible with OpenGL 3.1+ core profile.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
532
diff
changeset
|
102 else: |
94725968dabb
Use vertex array objects, to be compatible with OpenGL 3.1+ core profile.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
532
diff
changeset
|
103 glBindBuffer(GL_ARRAY_BUFFER, 0) |
94725968dabb
Use vertex array objects, to be compatible with OpenGL 3.1+ core profile.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
532
diff
changeset
|
104 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0) |
582
6e79756b7f42
Don’t call gl*DebugGroup if it isn’t exposed by the driver.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
105 |
6e79756b7f42
Don’t call gl*DebugGroup if it isn’t exposed by the driver.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
106 if use_debug_group: |
6e79756b7f42
Don’t call gl*DebugGroup if it isn’t exposed by the driver.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
107 glPopDebugGroup() |
423
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
108 |
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
109 |
617
a6af3ff86612
Change all “void except *” function into “bint except True”, to prevent PyErr_Occurred() from being called at each call.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
611
diff
changeset
|
110 cdef bint load(self, background, GLuint[MAX_TEXTURES] textures) except True: |
423
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
111 cdef float ox, oy, oz, ox2, oy2, oz2 |
519
b18f0bd30ad0
Optimise background rendering.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
515
diff
changeset
|
112 cdef GLsizei nb_vertices = 0, nb_indices = 0 |
423
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
113 |
519
b18f0bd30ad0
Optimise background rendering.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
515
diff
changeset
|
114 vertex_buffer = <Vertex*> malloc(65536 * sizeof(Vertex)) |
611
a6a191e371c7
Add back a GL_QUADS path for legacy applications.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
606
diff
changeset
|
115 |
a6a191e371c7
Add back a GL_QUADS path for legacy applications.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
606
diff
changeset
|
116 if not is_legacy: |
a6a191e371c7
Add back a GL_QUADS path for legacy applications.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
606
diff
changeset
|
117 indices = <GLushort*> malloc(65536 * sizeof(GLushort)) |
423
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
118 |
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
119 for ox, oy, oz, model_id, model in background.object_instances: |
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
120 for ox2, oy2, oz2, width_override, height_override, sprite in model: |
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
121 #TODO: view frustum culling |
532
dacdcca59b66
Don’t put back the rendering data into a tuple, use a specialised struct inside Sprite to pass it to the renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
519
diff
changeset
|
122 data = get_sprite_rendering_data(sprite) |
dacdcca59b66
Don’t put back the rendering data into a tuple, use a specialised struct inside Sprite to pass it to the renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
519
diff
changeset
|
123 key = data.key |
dacdcca59b66
Don’t put back the rendering data into a tuple, use a specialised struct inside Sprite to pass it to the renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
519
diff
changeset
|
124 |
dacdcca59b66
Don’t put back the rendering data into a tuple, use a specialised struct inside Sprite to pass it to the renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
519
diff
changeset
|
125 x1, x2, x3, x4, y1, y2, y3, y4, z1, z2, z3, z4 = data.pos[0], data.pos[1], data.pos[2], data.pos[3], data.pos[4], data.pos[5], data.pos[6], data.pos[7], data.pos[8], data.pos[9], data.pos[10], data.pos[11] |
dacdcca59b66
Don’t put back the rendering data into a tuple, use a specialised struct inside Sprite to pass it to the renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
519
diff
changeset
|
126 r, g, b, a = data.color[0], data.color[1], data.color[2], data.color[3] |
423
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
127 |
519
b18f0bd30ad0
Optimise background rendering.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
515
diff
changeset
|
128 # Pack data |
532
dacdcca59b66
Don’t put back the rendering data into a tuple, use a specialised struct inside Sprite to pass it to the renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
519
diff
changeset
|
129 vertex_buffer[nb_vertices] = Vertex(x1 + ox + ox2, y1 + oy + oy2, z1 + oz + oz2, data.left, data.bottom, r, g, b, a) |
dacdcca59b66
Don’t put back the rendering data into a tuple, use a specialised struct inside Sprite to pass it to the renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
519
diff
changeset
|
130 vertex_buffer[nb_vertices+1] = Vertex(x2 + ox + ox2, y2 + oy + oy2, z2 + oz + oz2, data.right, data.bottom, r, g, b, a) |
611
a6a191e371c7
Add back a GL_QUADS path for legacy applications.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
606
diff
changeset
|
131 vertex_buffer[nb_vertices+2] = Vertex(x3 + ox + ox2, y3 + oy + oy2, z3 + oz + oz2, data.right, data.top, r, g, b, a) |
a6a191e371c7
Add back a GL_QUADS path for legacy applications.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
606
diff
changeset
|
132 vertex_buffer[nb_vertices+3] = Vertex(x4 + ox + ox2, y4 + oy + oy2, z4 + oz + oz2, data.left, data.top, r, g, b, a) |
423
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
133 |
611
a6a191e371c7
Add back a GL_QUADS path for legacy applications.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
606
diff
changeset
|
134 if not is_legacy: |
a6a191e371c7
Add back a GL_QUADS path for legacy applications.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
606
diff
changeset
|
135 # Add indices |
a6a191e371c7
Add back a GL_QUADS path for legacy applications.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
606
diff
changeset
|
136 if use_primitive_restart: |
a6a191e371c7
Add back a GL_QUADS path for legacy applications.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
606
diff
changeset
|
137 indices[nb_indices] = nb_vertices |
a6a191e371c7
Add back a GL_QUADS path for legacy applications.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
606
diff
changeset
|
138 indices[nb_indices+1] = nb_vertices + 1 |
a6a191e371c7
Add back a GL_QUADS path for legacy applications.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
606
diff
changeset
|
139 indices[nb_indices+2] = nb_vertices + 3 |
a6a191e371c7
Add back a GL_QUADS path for legacy applications.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
606
diff
changeset
|
140 indices[nb_indices+3] = nb_vertices + 2 |
a6a191e371c7
Add back a GL_QUADS path for legacy applications.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
606
diff
changeset
|
141 indices[nb_indices+4] = 0xFFFF |
a6a191e371c7
Add back a GL_QUADS path for legacy applications.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
606
diff
changeset
|
142 else: |
a6a191e371c7
Add back a GL_QUADS path for legacy applications.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
606
diff
changeset
|
143 indices[nb_indices] = nb_vertices |
a6a191e371c7
Add back a GL_QUADS path for legacy applications.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
606
diff
changeset
|
144 indices[nb_indices+1] = nb_vertices + 1 |
a6a191e371c7
Add back a GL_QUADS path for legacy applications.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
606
diff
changeset
|
145 indices[nb_indices+2] = nb_vertices + 3 |
a6a191e371c7
Add back a GL_QUADS path for legacy applications.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
606
diff
changeset
|
146 indices[nb_indices+3] = nb_vertices + 1 |
a6a191e371c7
Add back a GL_QUADS path for legacy applications.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
606
diff
changeset
|
147 indices[nb_indices+4] = nb_vertices + 2 |
a6a191e371c7
Add back a GL_QUADS path for legacy applications.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
606
diff
changeset
|
148 indices[nb_indices+5] = nb_vertices + 3 |
a6a191e371c7
Add back a GL_QUADS path for legacy applications.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
606
diff
changeset
|
149 |
a6a191e371c7
Add back a GL_QUADS path for legacy applications.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
606
diff
changeset
|
150 nb_indices += 5 if use_primitive_restart else 6 |
519
b18f0bd30ad0
Optimise background rendering.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
515
diff
changeset
|
151 |
423
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
152 nb_vertices += 4 |
611
a6a191e371c7
Add back a GL_QUADS path for legacy applications.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
606
diff
changeset
|
153 |
a6a191e371c7
Add back a GL_QUADS path for legacy applications.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
606
diff
changeset
|
154 self.texture = textures[key >> 1] |
519
b18f0bd30ad0
Optimise background rendering.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
515
diff
changeset
|
155 |
b18f0bd30ad0
Optimise background rendering.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
515
diff
changeset
|
156 # We only need to keep the rendered vertices and indices in memory, |
b18f0bd30ad0
Optimise background rendering.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
515
diff
changeset
|
157 # either in RAM or in VRAM, they will never change until we implement |
b18f0bd30ad0
Optimise background rendering.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
515
diff
changeset
|
158 # background animation. |
423
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
159 |
560
c759b97f4f81
Remove all reference to the old fixed pipeline option in the OpenGL backend, use the newer is_legacy one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
558
diff
changeset
|
160 if is_legacy: |
519
b18f0bd30ad0
Optimise background rendering.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
515
diff
changeset
|
161 self.vertex_buffer = <Vertex*> realloc(vertex_buffer, nb_vertices * sizeof(Vertex)) |
611
a6a191e371c7
Add back a GL_QUADS path for legacy applications.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
606
diff
changeset
|
162 self.nb_vertices = nb_vertices |
519
b18f0bd30ad0
Optimise background rendering.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
515
diff
changeset
|
163 else: |
582
6e79756b7f42
Don’t call gl*DebugGroup if it isn’t exposed by the driver.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
164 if use_debug_group: |
6e79756b7f42
Don’t call gl*DebugGroup if it isn’t exposed by the driver.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
165 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Background uploading") |
6e79756b7f42
Don’t call gl*DebugGroup if it isn’t exposed by the driver.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
166 |
423
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
167 glBindBuffer(GL_ARRAY_BUFFER, self.vbo) |
519
b18f0bd30ad0
Optimise background rendering.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
515
diff
changeset
|
168 glBufferData(GL_ARRAY_BUFFER, nb_vertices * sizeof(Vertex), vertex_buffer, GL_STATIC_DRAW) |
423
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
169 glBindBuffer(GL_ARRAY_BUFFER, 0) |
519
b18f0bd30ad0
Optimise background rendering.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
515
diff
changeset
|
170 |
b18f0bd30ad0
Optimise background rendering.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
515
diff
changeset
|
171 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, self.ibo) |
b18f0bd30ad0
Optimise background rendering.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
515
diff
changeset
|
172 glBufferData(GL_ELEMENT_ARRAY_BUFFER, nb_indices * sizeof(GLushort), indices, GL_STATIC_DRAW) |
b18f0bd30ad0
Optimise background rendering.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
515
diff
changeset
|
173 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0) |
582
6e79756b7f42
Don’t call gl*DebugGroup if it isn’t exposed by the driver.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
174 |
611
a6a191e371c7
Add back a GL_QUADS path for legacy applications.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
606
diff
changeset
|
175 self.nb_indices = nb_indices |
a6a191e371c7
Add back a GL_QUADS path for legacy applications.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
606
diff
changeset
|
176 |
582
6e79756b7f42
Don’t call gl*DebugGroup if it isn’t exposed by the driver.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
177 if use_debug_group: |
6e79756b7f42
Don’t call gl*DebugGroup if it isn’t exposed by the driver.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
178 glPopDebugGroup() |