annotate pytouhou/ui/opengl/renderer.pyx @ 528:7c3c90468996

Inherit music players from a base class.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Wed, 18 Dec 2013 22:36:23 +0100
parents c0b3f8709f74
children dacdcca59b66
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
222
5cac48b328ad Refactor rendering code a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
1 # -*- encoding: utf-8 -*-
5cac48b328ad Refactor rendering code a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
2 ##
5cac48b328ad Refactor rendering code a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
3 ## Copyright (C) 2011 Thibaut Girka <thib@sitedethib.com>
5cac48b328ad Refactor rendering code a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
4 ##
5cac48b328ad Refactor rendering code a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
5 ## This program is free software; you can redistribute it and/or modify
5cac48b328ad Refactor rendering code a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
6 ## it under the terms of the GNU General Public License as published
5cac48b328ad Refactor rendering code a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
7 ## by the Free Software Foundation; version 3 only.
5cac48b328ad Refactor rendering code a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
8 ##
5cac48b328ad Refactor rendering code a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
9 ## This program is distributed in the hope that it will be useful,
5cac48b328ad Refactor rendering code a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
5cac48b328ad Refactor rendering code a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5cac48b328ad Refactor rendering code a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
12 ## GNU General Public License for more details.
5cac48b328ad Refactor rendering code a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
13 ##
5cac48b328ad Refactor rendering code a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
14
423
d8630c086926 Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 412
diff changeset
15 from libc.stdlib cimport malloc, free
449
d56536ef28e8 Improve render_elements’ speed a lot, and fix it in some corner cases. Thanks liori!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 435
diff changeset
16 from libc.string cimport memset
456
cae1ae9de430 Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 449
diff changeset
17 from os.path import join
222
5cac48b328ad Refactor rendering code a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
18
423
d8630c086926 Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 412
diff changeset
19 from pytouhou.lib.opengl cimport \
d8630c086926 Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 412
diff changeset
20 (glVertexPointer, glTexCoordPointer, glColorPointer,
d8630c086926 Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 412
diff changeset
21 glVertexAttribPointer, glEnableVertexAttribArray, glBlendFunc,
d8630c086926 Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 412
diff changeset
22 glBindTexture, glDrawElements, glBindBuffer, glBufferData,
d8630c086926 Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 412
diff changeset
23 GL_ARRAY_BUFFER, GL_DYNAMIC_DRAW, GL_UNSIGNED_BYTE,
518
75ae628522c9 Use shorts instead of ints for vertex position, reducing the size of a vertex to 20 bytes from 24.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 515
diff changeset
24 GL_UNSIGNED_SHORT, GL_SHORT, GL_FLOAT, GL_SRC_ALPHA,
462
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
25 GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO, GL_TEXTURE_2D, GL_TRIANGLES,
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
26 glGenBuffers, glBindFramebuffer, glViewport, glDeleteBuffers,
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
27 glGenTextures, glTexParameteri, glTexImage2D, glGenRenderbuffers,
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
28 glBindRenderbuffer, glRenderbufferStorage, glGenFramebuffers,
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
29 glFramebufferTexture2D, glFramebufferRenderbuffer,
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
30 glCheckFramebufferStatus, GL_FRAMEBUFFER, GL_TEXTURE_MIN_FILTER,
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
31 GL_LINEAR, GL_TEXTURE_MAG_FILTER, GL_RGBA, GL_RENDERBUFFER,
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
32 GL_DEPTH_COMPONENT, GL_COLOR_ATTACHMENT0, GL_DEPTH_ATTACHMENT,
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
33 GL_FRAMEBUFFER_COMPLETE, glClear, GL_COLOR_BUFFER_BIT,
520
c0b3f8709f74 Store the indices of the framebuffer in a static ibo.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 518
diff changeset
34 GL_DEPTH_BUFFER_BIT, GLuint, glDeleteTextures,
c0b3f8709f74 Store the indices of the framebuffer in a static ibo.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 518
diff changeset
35 GL_ELEMENT_ARRAY_BUFFER, GL_STATIC_DRAW)
222
5cac48b328ad Refactor rendering code a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
36
456
cae1ae9de430 Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 449
diff changeset
37 from pytouhou.lib.sdl import SDLError
cae1ae9de430 Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 449
diff changeset
38
449
d56536ef28e8 Improve render_elements’ speed a lot, and fix it in some corner cases. Thanks liori!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 435
diff changeset
39 from pytouhou.game.element cimport Element
222
5cac48b328ad Refactor rendering code a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
40 from .sprite cimport get_sprite_rendering_data
456
cae1ae9de430 Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 449
diff changeset
41
cae1ae9de430 Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 449
diff changeset
42 from pytouhou.utils.helpers import get_logger
cae1ae9de430 Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 449
diff changeset
43
cae1ae9de430 Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 449
diff changeset
44 logger = get_logger(__name__)
222
5cac48b328ad Refactor rendering code a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
45
5cac48b328ad Refactor rendering code a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
46
505
bfea9e9a6845 Manage the texture-specific indices in the Texture, and some more renderer optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 503
diff changeset
47 cdef class Texture:
bfea9e9a6845 Manage the texture-specific indices in the Texture, and some more renderer optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 503
diff changeset
48 def __cinit__(self, GLuint texture, Renderer renderer):
bfea9e9a6845 Manage the texture-specific indices in the Texture, and some more renderer optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 503
diff changeset
49 self.texture = texture
515
b3193b43a86c Add an indirection layer for textures, to cope with drivers assigning them random names.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 513
diff changeset
50
b3193b43a86c Add an indirection layer for textures, to cope with drivers assigning them random names.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 513
diff changeset
51 # Find an unused key in the textures array.
b3193b43a86c Add an indirection layer for textures, to cope with drivers assigning them random names.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 513
diff changeset
52 for key in xrange(MAX_TEXTURES):
b3193b43a86c Add an indirection layer for textures, to cope with drivers assigning them random names.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 513
diff changeset
53 if renderer.textures[key] == 0:
b3193b43a86c Add an indirection layer for textures, to cope with drivers assigning them random names.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 513
diff changeset
54 break
b3193b43a86c Add an indirection layer for textures, to cope with drivers assigning them random names.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 513
diff changeset
55 else:
b3193b43a86c Add an indirection layer for textures, to cope with drivers assigning them random names.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 513
diff changeset
56 raise MemoryError('Too many textures currently loaded, consider increasing MAX_TEXTURES (currently %d).' % MAX_TEXTURES)
b3193b43a86c Add an indirection layer for textures, to cope with drivers assigning them random names.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 513
diff changeset
57
b3193b43a86c Add an indirection layer for textures, to cope with drivers assigning them random names.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 513
diff changeset
58 self.key = key
b3193b43a86c Add an indirection layer for textures, to cope with drivers assigning them random names.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 513
diff changeset
59 self.pointer = &renderer.textures[key]
b3193b43a86c Add an indirection layer for textures, to cope with drivers assigning them random names.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 513
diff changeset
60 self.pointer[0] = texture
505
bfea9e9a6845 Manage the texture-specific indices in the Texture, and some more renderer optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 503
diff changeset
61 for i in xrange(2):
515
b3193b43a86c Add an indirection layer for textures, to cope with drivers assigning them random names.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 513
diff changeset
62 renderer.indices[key][i] = self.indices[i]
505
bfea9e9a6845 Manage the texture-specific indices in the Texture, and some more renderer optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 503
diff changeset
63
bfea9e9a6845 Manage the texture-specific indices in the Texture, and some more renderer optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 503
diff changeset
64 def __dealloc__(self):
515
b3193b43a86c Add an indirection layer for textures, to cope with drivers assigning them random names.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 513
diff changeset
65 if self.texture:
b3193b43a86c Add an indirection layer for textures, to cope with drivers assigning them random names.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 513
diff changeset
66 glDeleteTextures(1, &self.texture)
b3193b43a86c Add an indirection layer for textures, to cope with drivers assigning them random names.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 513
diff changeset
67 if self.pointer != NULL:
b3193b43a86c Add an indirection layer for textures, to cope with drivers assigning them random names.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 513
diff changeset
68 self.pointer[0] = 0
b3193b43a86c Add an indirection layer for textures, to cope with drivers assigning them random names.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 513
diff changeset
69 # The dangling pointers in renderer.indices doesn’t matter, since we
b3193b43a86c Add an indirection layer for textures, to cope with drivers assigning them random names.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 513
diff changeset
70 # won’t use them if no texture is loaded in that slot.
449
d56536ef28e8 Improve render_elements’ speed a lot, and fix it in some corner cases. Thanks liori!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 435
diff changeset
71
d56536ef28e8 Improve render_elements’ speed a lot, and fix it in some corner cases. Thanks liori!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 435
diff changeset
72
468
feecdb4a8928 Add “except *” to cdef void functions, and type some more.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 464
diff changeset
73 cdef long find_objects(Renderer self, object elements) except -1:
449
d56536ef28e8 Improve render_elements’ speed a lot, and fix it in some corner cases. Thanks liori!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 435
diff changeset
74 # Don’t type element as Element, or else the overriding of objects won’t work.
d56536ef28e8 Improve render_elements’ speed a lot, and fix it in some corner cases. Thanks liori!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 435
diff changeset
75 cdef Element obj
d56536ef28e8 Improve render_elements’ speed a lot, and fix it in some corner cases. Thanks liori!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 435
diff changeset
76 cdef long i = 0
d56536ef28e8 Improve render_elements’ speed a lot, and fix it in some corner cases. Thanks liori!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 435
diff changeset
77 for element in elements:
d56536ef28e8 Improve render_elements’ speed a lot, and fix it in some corner cases. Thanks liori!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 435
diff changeset
78 for obj in element.objects:
d56536ef28e8 Improve render_elements’ speed a lot, and fix it in some corner cases. Thanks liori!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 435
diff changeset
79 sprite = obj.sprite
d56536ef28e8 Improve render_elements’ speed a lot, and fix it in some corner cases. Thanks liori!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 435
diff changeset
80 if sprite and sprite.visible:
d56536ef28e8 Improve render_elements’ speed a lot, and fix it in some corner cases. Thanks liori!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 435
diff changeset
81 # warning: no reference is preserved on the object—assuming the object will not die accidentally
d56536ef28e8 Improve render_elements’ speed a lot, and fix it in some corner cases. Thanks liori!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 435
diff changeset
82 self.elements[i] = <PyObject*>obj
d56536ef28e8 Improve render_elements’ speed a lot, and fix it in some corner cases. Thanks liori!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 435
diff changeset
83 i += 1
d56536ef28e8 Improve render_elements’ speed a lot, and fix it in some corner cases. Thanks liori!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 435
diff changeset
84 if i >= 640*3-4:
d56536ef28e8 Improve render_elements’ speed a lot, and fix it in some corner cases. Thanks liori!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 435
diff changeset
85 return i
d56536ef28e8 Improve render_elements’ speed a lot, and fix it in some corner cases. Thanks liori!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 435
diff changeset
86 return i
222
5cac48b328ad Refactor rendering code a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
87
5cac48b328ad Refactor rendering code a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
88
5cac48b328ad Refactor rendering code a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
89 cdef class Renderer:
5cac48b328ad Refactor rendering code a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
90 def __dealloc__(self):
462
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
91 if not self.use_fixed_pipeline:
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
92 glDeleteBuffers(1, &self.framebuffer_vbo)
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
93 glDeleteBuffers(1, &self.vbo)
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
94
222
5cac48b328ad Refactor rendering code a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
95
5cac48b328ad Refactor rendering code a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
96 def __init__(self, resource_loader):
520
c0b3f8709f74 Store the indices of the framebuffer in a static ibo.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 518
diff changeset
97 # Only used in modern GL.
c0b3f8709f74 Store the indices of the framebuffer in a static ibo.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 518
diff changeset
98 cdef unsigned short framebuffer_indices[6]
c0b3f8709f74 Store the indices of the framebuffer in a static ibo.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 518
diff changeset
99
505
bfea9e9a6845 Manage the texture-specific indices in the Texture, and some more renderer optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 503
diff changeset
100 self.texture_manager = TextureManager(resource_loader, self, Texture)
456
cae1ae9de430 Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 449
diff changeset
101 font_name = join(resource_loader.game_dir, 'font.ttf')
cae1ae9de430 Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 449
diff changeset
102 try:
505
bfea9e9a6845 Manage the texture-specific indices in the Texture, and some more renderer optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 503
diff changeset
103 self.font_manager = FontManager(font_name, 16, self, Texture)
456
cae1ae9de430 Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 449
diff changeset
104 except SDLError:
cae1ae9de430 Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 449
diff changeset
105 self.font_manager = None
cae1ae9de430 Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 449
diff changeset
106 logger.error('Font file “%s” not found, disabling text rendering altogether.', font_name)
222
5cac48b328ad Refactor rendering code a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
107
423
d8630c086926 Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 412
diff changeset
108 if not self.use_fixed_pipeline:
520
c0b3f8709f74 Store the indices of the framebuffer in a static ibo.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 518
diff changeset
109 framebuffer_indices[:] = [0, 1, 2, 2, 3, 0]
c0b3f8709f74 Store the indices of the framebuffer in a static ibo.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 518
diff changeset
110
423
d8630c086926 Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 412
diff changeset
111 glGenBuffers(1, &self.vbo)
462
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
112 glGenBuffers(1, &self.framebuffer_vbo)
520
c0b3f8709f74 Store the indices of the framebuffer in a static ibo.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 518
diff changeset
113 glGenBuffers(1, &self.framebuffer_ibo)
c0b3f8709f74 Store the indices of the framebuffer in a static ibo.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 518
diff changeset
114
c0b3f8709f74 Store the indices of the framebuffer in a static ibo.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 518
diff changeset
115 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, self.framebuffer_ibo)
c0b3f8709f74 Store the indices of the framebuffer in a static ibo.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 518
diff changeset
116 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(framebuffer_indices), framebuffer_indices, GL_STATIC_DRAW)
c0b3f8709f74 Store the indices of the framebuffer in a static ibo.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 518
diff changeset
117 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)
423
d8630c086926 Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 412
diff changeset
118
222
5cac48b328ad Refactor rendering code a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
119
468
feecdb4a8928 Add “except *” to cdef void functions, and type some more.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 464
diff changeset
120 cdef void render_elements(self, elements):
449
d56536ef28e8 Improve render_elements’ speed a lot, and fix it in some corner cases. Thanks liori!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 435
diff changeset
121 cdef int key
518
75ae628522c9 Use shorts instead of ints for vertex position, reducing the size of a vertex to 20 bytes from 24.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 515
diff changeset
122 cdef short x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4, ox, oy
449
d56536ef28e8 Improve render_elements’ speed a lot, and fix it in some corner cases. Thanks liori!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 435
diff changeset
123 cdef float left, right, bottom, top
d56536ef28e8 Improve render_elements’ speed a lot, and fix it in some corner cases. Thanks liori!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 435
diff changeset
124 cdef unsigned char r, g, b, a
301
6f1ca1cb5238 Avoid segfaults in the unlikely case a huge number of sprites is rendered.
Thibaut Girka <thib@sitedethib.com>
parents: 245
diff changeset
125
505
bfea9e9a6845 Manage the texture-specific indices in the Texture, and some more renderer optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 503
diff changeset
126 nb_elements = find_objects(self, elements)
bfea9e9a6845 Manage the texture-specific indices in the Texture, and some more renderer optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 503
diff changeset
127 if not nb_elements:
bfea9e9a6845 Manage the texture-specific indices in the Texture, and some more renderer optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 503
diff changeset
128 return
bfea9e9a6845 Manage the texture-specific indices in the Texture, and some more renderer optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 503
diff changeset
129
449
d56536ef28e8 Improve render_elements’ speed a lot, and fix it in some corner cases. Thanks liori!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 435
diff changeset
130 nb_vertices = 0
d56536ef28e8 Improve render_elements’ speed a lot, and fix it in some corner cases. Thanks liori!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 435
diff changeset
131 memset(self.last_indices, 0, sizeof(self.last_indices))
d56536ef28e8 Improve render_elements’ speed a lot, and fix it in some corner cases. Thanks liori!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 435
diff changeset
132
d56536ef28e8 Improve render_elements’ speed a lot, and fix it in some corner cases. Thanks liori!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 435
diff changeset
133 for element_idx in xrange(nb_elements):
d56536ef28e8 Improve render_elements’ speed a lot, and fix it in some corner cases. Thanks liori!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 435
diff changeset
134 element = <object>self.elements[element_idx]
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 301
diff changeset
135 sprite = element.sprite
449
d56536ef28e8 Improve render_elements’ speed a lot, and fix it in some corner cases. Thanks liori!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 435
diff changeset
136 ox, oy = element.x, element.y
d56536ef28e8 Improve render_elements’ speed a lot, and fix it in some corner cases. Thanks liori!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 435
diff changeset
137 key, (vertices, uvs, colors) = get_sprite_rendering_data(sprite)
d56536ef28e8 Improve render_elements’ speed a lot, and fix it in some corner cases. Thanks liori!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 435
diff changeset
138
505
bfea9e9a6845 Manage the texture-specific indices in the Texture, and some more renderer optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 503
diff changeset
139 blendfunc = key & 1
bfea9e9a6845 Manage the texture-specific indices in the Texture, and some more renderer optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 503
diff changeset
140 texture = key >> 1
449
d56536ef28e8 Improve render_elements’ speed a lot, and fix it in some corner cases. Thanks liori!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 435
diff changeset
141
505
bfea9e9a6845 Manage the texture-specific indices in the Texture, and some more renderer optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 503
diff changeset
142 rec = self.indices[texture][blendfunc]
449
d56536ef28e8 Improve render_elements’ speed a lot, and fix it in some corner cases. Thanks liori!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 435
diff changeset
143 next_indice = self.last_indices[key]
222
5cac48b328ad Refactor rendering code a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
144
449
d56536ef28e8 Improve render_elements’ speed a lot, and fix it in some corner cases. Thanks liori!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 435
diff changeset
145 # Pack data in buffer
d56536ef28e8 Improve render_elements’ speed a lot, and fix it in some corner cases. Thanks liori!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 435
diff changeset
146 x1, x2, x3, x4, y1, y2, y3, y4, z1, z2, z3, z4 = vertices
d56536ef28e8 Improve render_elements’ speed a lot, and fix it in some corner cases. Thanks liori!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 435
diff changeset
147 left, right, bottom, top = uvs
d56536ef28e8 Improve render_elements’ speed a lot, and fix it in some corner cases. Thanks liori!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 435
diff changeset
148 r, g, b, a = colors
518
75ae628522c9 Use shorts instead of ints for vertex position, reducing the size of a vertex to 20 bytes from 24.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 515
diff changeset
149 self.vertex_buffer[nb_vertices] = Vertex(x1 + ox, y1 + oy, z1, 0, left, bottom, r, g, b, a)
75ae628522c9 Use shorts instead of ints for vertex position, reducing the size of a vertex to 20 bytes from 24.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 515
diff changeset
150 self.vertex_buffer[nb_vertices+1] = Vertex(x2 + ox, y2 + oy, z2, 0, right, bottom, r, g, b, a)
75ae628522c9 Use shorts instead of ints for vertex position, reducing the size of a vertex to 20 bytes from 24.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 515
diff changeset
151 self.vertex_buffer[nb_vertices+2] = Vertex(x3 + ox, y3 + oy, z3, 0, right, top, r, g, b, a)
75ae628522c9 Use shorts instead of ints for vertex position, reducing the size of a vertex to 20 bytes from 24.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 515
diff changeset
152 self.vertex_buffer[nb_vertices+3] = Vertex(x4 + ox, y4 + oy, z4, 0, left, top, r, g, b, a)
222
5cac48b328ad Refactor rendering code a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
153
449
d56536ef28e8 Improve render_elements’ speed a lot, and fix it in some corner cases. Thanks liori!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 435
diff changeset
154 # Add indices
d56536ef28e8 Improve render_elements’ speed a lot, and fix it in some corner cases. Thanks liori!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 435
diff changeset
155 rec[next_indice] = nb_vertices
d56536ef28e8 Improve render_elements’ speed a lot, and fix it in some corner cases. Thanks liori!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 435
diff changeset
156 rec[next_indice+1] = nb_vertices + 1
d56536ef28e8 Improve render_elements’ speed a lot, and fix it in some corner cases. Thanks liori!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 435
diff changeset
157 rec[next_indice+2] = nb_vertices + 2
d56536ef28e8 Improve render_elements’ speed a lot, and fix it in some corner cases. Thanks liori!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 435
diff changeset
158 rec[next_indice+3] = nb_vertices + 2
d56536ef28e8 Improve render_elements’ speed a lot, and fix it in some corner cases. Thanks liori!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 435
diff changeset
159 rec[next_indice+4] = nb_vertices + 3
d56536ef28e8 Improve render_elements’ speed a lot, and fix it in some corner cases. Thanks liori!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 435
diff changeset
160 rec[next_indice+5] = nb_vertices
d56536ef28e8 Improve render_elements’ speed a lot, and fix it in some corner cases. Thanks liori!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 435
diff changeset
161 self.last_indices[key] += 6
222
5cac48b328ad Refactor rendering code a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
162
449
d56536ef28e8 Improve render_elements’ speed a lot, and fix it in some corner cases. Thanks liori!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 435
diff changeset
163 nb_vertices += 4
222
5cac48b328ad Refactor rendering code a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
164
395
43413d4ff05b Don’t change the vertex attributes for each texture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 394
diff changeset
165 if self.use_fixed_pipeline:
518
75ae628522c9 Use shorts instead of ints for vertex position, reducing the size of a vertex to 20 bytes from 24.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 515
diff changeset
166 glVertexPointer(3, GL_SHORT, sizeof(Vertex), &self.vertex_buffer[0].x)
423
d8630c086926 Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 412
diff changeset
167 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: 412
diff changeset
168 glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex), &self.vertex_buffer[0].r)
395
43413d4ff05b Don’t change the vertex attributes for each texture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 394
diff changeset
169 else:
396
34a91f918e7c Use Buffer Objects instead of host pointers.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 395
diff changeset
170 glBindBuffer(GL_ARRAY_BUFFER, self.vbo)
423
d8630c086926 Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 412
diff changeset
171 glBufferData(GL_ARRAY_BUFFER, nb_vertices * sizeof(Vertex), &self.vertex_buffer[0], GL_DYNAMIC_DRAW)
396
34a91f918e7c Use Buffer Objects instead of host pointers.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 395
diff changeset
172
34a91f918e7c Use Buffer Objects instead of host pointers.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 395
diff changeset
173 #TODO: find a way to use offsetof() instead of those ugly hardcoded values.
518
75ae628522c9 Use shorts instead of ints for vertex position, reducing the size of a vertex to 20 bytes from 24.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 515
diff changeset
174 glVertexAttribPointer(0, 3, GL_SHORT, False, sizeof(Vertex), <void*>0)
395
43413d4ff05b Don’t change the vertex attributes for each texture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 394
diff changeset
175 glEnableVertexAttribArray(0)
518
75ae628522c9 Use shorts instead of ints for vertex position, reducing the size of a vertex to 20 bytes from 24.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 515
diff changeset
176 glVertexAttribPointer(1, 2, GL_FLOAT, False, sizeof(Vertex), <void*>8)
395
43413d4ff05b Don’t change the vertex attributes for each texture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 394
diff changeset
177 glEnableVertexAttribArray(1)
518
75ae628522c9 Use shorts instead of ints for vertex position, reducing the size of a vertex to 20 bytes from 24.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 515
diff changeset
178 glVertexAttribPointer(2, 4, GL_UNSIGNED_BYTE, True, sizeof(Vertex), <void*>16)
395
43413d4ff05b Don’t change the vertex attributes for each texture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 394
diff changeset
179 glEnableVertexAttribArray(2)
43413d4ff05b Don’t change the vertex attributes for each texture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 394
diff changeset
180
505
bfea9e9a6845 Manage the texture-specific indices in the Texture, and some more renderer optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 503
diff changeset
181 # Don’t change the state when it’s not needed.
bfea9e9a6845 Manage the texture-specific indices in the Texture, and some more renderer optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 503
diff changeset
182 previous_blendfunc = -1
bfea9e9a6845 Manage the texture-specific indices in the Texture, and some more renderer optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 503
diff changeset
183 previous_texture = -1
bfea9e9a6845 Manage the texture-specific indices in the Texture, and some more renderer optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 503
diff changeset
184
449
d56536ef28e8 Improve render_elements’ speed a lot, and fix it in some corner cases. Thanks liori!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 435
diff changeset
185 for key in xrange(2 * MAX_TEXTURES):
d56536ef28e8 Improve render_elements’ speed a lot, and fix it in some corner cases. Thanks liori!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 435
diff changeset
186 nb_indices = self.last_indices[key]
d56536ef28e8 Improve render_elements’ speed a lot, and fix it in some corner cases. Thanks liori!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 435
diff changeset
187 if not nb_indices:
d56536ef28e8 Improve render_elements’ speed a lot, and fix it in some corner cases. Thanks liori!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 435
diff changeset
188 continue
423
d8630c086926 Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 412
diff changeset
189
505
bfea9e9a6845 Manage the texture-specific indices in the Texture, and some more renderer optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 503
diff changeset
190 blendfunc = key & 1
bfea9e9a6845 Manage the texture-specific indices in the Texture, and some more renderer optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 503
diff changeset
191 texture = key >> 1
423
d8630c086926 Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 412
diff changeset
192
505
bfea9e9a6845 Manage the texture-specific indices in the Texture, and some more renderer optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 503
diff changeset
193 if blendfunc != previous_blendfunc:
bfea9e9a6845 Manage the texture-specific indices in the Texture, and some more renderer optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 503
diff changeset
194 glBlendFunc(GL_SRC_ALPHA, (GL_ONE_MINUS_SRC_ALPHA, GL_ONE)[blendfunc])
bfea9e9a6845 Manage the texture-specific indices in the Texture, and some more renderer optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 503
diff changeset
195 if texture != previous_texture:
515
b3193b43a86c Add an indirection layer for textures, to cope with drivers assigning them random names.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 513
diff changeset
196 glBindTexture(GL_TEXTURE_2D, self.textures[texture])
505
bfea9e9a6845 Manage the texture-specific indices in the Texture, and some more renderer optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 503
diff changeset
197 glDrawElements(GL_TRIANGLES, nb_indices, GL_UNSIGNED_SHORT, self.indices[texture][blendfunc])
bfea9e9a6845 Manage the texture-specific indices in the Texture, and some more renderer optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 503
diff changeset
198
bfea9e9a6845 Manage the texture-specific indices in the Texture, and some more renderer optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 503
diff changeset
199 previous_blendfunc = blendfunc
bfea9e9a6845 Manage the texture-specific indices in the Texture, and some more renderer optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 503
diff changeset
200 previous_texture = texture
bfea9e9a6845 Manage the texture-specific indices in the Texture, and some more renderer optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 503
diff changeset
201
bfea9e9a6845 Manage the texture-specific indices in the Texture, and some more renderer optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 503
diff changeset
202 glBindTexture(GL_TEXTURE_2D, 0)
222
5cac48b328ad Refactor rendering code a bit.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
203
396
34a91f918e7c Use Buffer Objects instead of host pointers.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 395
diff changeset
204 if not self.use_fixed_pipeline:
34a91f918e7c Use Buffer Objects instead of host pointers.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 395
diff changeset
205 glBindBuffer(GL_ARRAY_BUFFER, 0)
456
cae1ae9de430 Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 449
diff changeset
206
cae1ae9de430 Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 449
diff changeset
207
505
bfea9e9a6845 Manage the texture-specific indices in the Texture, and some more renderer optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 503
diff changeset
208 cdef void render_quads(self, rects, colors, GLuint texture):
456
cae1ae9de430 Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 449
diff changeset
209 # There is nothing that batch more than two quads on the same texture, currently.
cae1ae9de430 Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 449
diff changeset
210 cdef Vertex buf[8]
cae1ae9de430 Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 449
diff changeset
211 cdef unsigned short indices[12]
cae1ae9de430 Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 449
diff changeset
212 indices[:] = [0, 1, 2, 2, 3, 0, 4, 5, 6, 6, 7, 4]
cae1ae9de430 Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 449
diff changeset
213
cae1ae9de430 Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 449
diff changeset
214 length = len(rects)
cae1ae9de430 Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 449
diff changeset
215 assert length == len(colors)
cae1ae9de430 Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 449
diff changeset
216
cae1ae9de430 Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 449
diff changeset
217 for i, r in enumerate(rects):
cae1ae9de430 Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 449
diff changeset
218 c1, c2, c3, c4 = colors[i]
cae1ae9de430 Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 449
diff changeset
219
518
75ae628522c9 Use shorts instead of ints for vertex position, reducing the size of a vertex to 20 bytes from 24.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 515
diff changeset
220 buf[4*i] = Vertex(r.x, r.y, 0, 0, 0, 0, c1.r, c1.g, c1.b, c1.a)
75ae628522c9 Use shorts instead of ints for vertex position, reducing the size of a vertex to 20 bytes from 24.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 515
diff changeset
221 buf[4*i+1] = Vertex(r.x + r.w, r.y, 0, 0, 1, 0, c2.r, c2.g, c2.b, c2.a)
75ae628522c9 Use shorts instead of ints for vertex position, reducing the size of a vertex to 20 bytes from 24.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 515
diff changeset
222 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)
75ae628522c9 Use shorts instead of ints for vertex position, reducing the size of a vertex to 20 bytes from 24.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 515
diff changeset
223 buf[4*i+3] = Vertex(r.x, r.y + r.h, 0, 0, 0, 1, c4.r, c4.g, c4.b, c4.a)
456
cae1ae9de430 Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 449
diff changeset
224
461
6af3854ed826 Make NativeText work with the fixed pipeline.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 456
diff changeset
225 if self.use_fixed_pipeline:
518
75ae628522c9 Use shorts instead of ints for vertex position, reducing the size of a vertex to 20 bytes from 24.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 515
diff changeset
226 glVertexPointer(3, GL_SHORT, sizeof(Vertex), &buf[0].x)
461
6af3854ed826 Make NativeText work with the fixed pipeline.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 456
diff changeset
227 glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), &buf[0].u)
6af3854ed826 Make NativeText work with the fixed pipeline.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 456
diff changeset
228 glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex), &buf[0].r)
6af3854ed826 Make NativeText work with the fixed pipeline.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 456
diff changeset
229 else:
6af3854ed826 Make NativeText work with the fixed pipeline.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 456
diff changeset
230 glBindBuffer(GL_ARRAY_BUFFER, self.vbo)
6af3854ed826 Make NativeText work with the fixed pipeline.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 456
diff changeset
231 glBufferData(GL_ARRAY_BUFFER, 4 * length * sizeof(Vertex), buf, GL_DYNAMIC_DRAW)
6af3854ed826 Make NativeText work with the fixed pipeline.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 456
diff changeset
232
6af3854ed826 Make NativeText work with the fixed pipeline.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 456
diff changeset
233 #TODO: find a way to use offsetof() instead of those ugly hardcoded values.
518
75ae628522c9 Use shorts instead of ints for vertex position, reducing the size of a vertex to 20 bytes from 24.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 515
diff changeset
234 glVertexAttribPointer(0, 3, GL_SHORT, False, sizeof(Vertex), <void*>0)
461
6af3854ed826 Make NativeText work with the fixed pipeline.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 456
diff changeset
235 glEnableVertexAttribArray(0)
518
75ae628522c9 Use shorts instead of ints for vertex position, reducing the size of a vertex to 20 bytes from 24.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 515
diff changeset
236 glVertexAttribPointer(1, 2, GL_FLOAT, False, sizeof(Vertex), <void*>8)
461
6af3854ed826 Make NativeText work with the fixed pipeline.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 456
diff changeset
237 glEnableVertexAttribArray(1)
518
75ae628522c9 Use shorts instead of ints for vertex position, reducing the size of a vertex to 20 bytes from 24.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 515
diff changeset
238 glVertexAttribPointer(2, 4, GL_UNSIGNED_BYTE, True, sizeof(Vertex), <void*>16)
461
6af3854ed826 Make NativeText work with the fixed pipeline.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 456
diff changeset
239 glEnableVertexAttribArray(2)
6af3854ed826 Make NativeText work with the fixed pipeline.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 456
diff changeset
240
456
cae1ae9de430 Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 449
diff changeset
241 glBindTexture(GL_TEXTURE_2D, texture)
cae1ae9de430 Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 449
diff changeset
242 glDrawElements(GL_TRIANGLES, 6 * length, GL_UNSIGNED_SHORT, indices)
461
6af3854ed826 Make NativeText work with the fixed pipeline.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 456
diff changeset
243
6af3854ed826 Make NativeText work with the fixed pipeline.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 456
diff changeset
244 if not self.use_fixed_pipeline:
6af3854ed826 Make NativeText work with the fixed pipeline.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 456
diff changeset
245 glBindBuffer(GL_ARRAY_BUFFER, 0)
462
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
246
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
247
503
c622eaf64428 Optimize GameRunner some more, fix replay, and remove Window dependency in Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 468
diff changeset
248 cdef void render_framebuffer(self, Framebuffer fb):
462
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
249 cdef PassthroughVertex[4] buf
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
250
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
251 assert not self.use_fixed_pipeline
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
252
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
253 glBindFramebuffer(GL_FRAMEBUFFER, 0)
503
c622eaf64428 Optimize GameRunner some more, fix replay, and remove Window dependency in Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 468
diff changeset
254 glViewport(self.x, self.y, self.width, self.height)
462
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
255 glBlendFunc(GL_ONE, GL_ZERO)
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
256 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
257
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
258 glBindBuffer(GL_ARRAY_BUFFER, self.framebuffer_vbo)
520
c0b3f8709f74 Store the indices of the framebuffer in a static ibo.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 518
diff changeset
259 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, self.framebuffer_ibo)
462
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
260
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
261 #TODO: find a way to use offsetof() instead of those ugly hardcoded values.
518
75ae628522c9 Use shorts instead of ints for vertex position, reducing the size of a vertex to 20 bytes from 24.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 515
diff changeset
262 glVertexAttribPointer(0, 2, GL_SHORT, False, sizeof(PassthroughVertex), <void*>0)
462
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
263 glEnableVertexAttribArray(0)
518
75ae628522c9 Use shorts instead of ints for vertex position, reducing the size of a vertex to 20 bytes from 24.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 515
diff changeset
264 glVertexAttribPointer(1, 2, GL_FLOAT, False, sizeof(PassthroughVertex), <void*>4)
462
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
265 glEnableVertexAttribArray(1)
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
266
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
267 buf[0] = PassthroughVertex(fb.x, fb.y, 0, 1)
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
268 buf[1] = PassthroughVertex(fb.x + fb.width, fb.y, 1, 1)
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
269 buf[2] = PassthroughVertex(fb.x + fb.width, fb.y + fb.height, 1, 0)
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
270 buf[3] = PassthroughVertex(fb.x, fb.y + fb.height, 0, 0)
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
271 glBufferData(GL_ARRAY_BUFFER, 4 * sizeof(PassthroughVertex), buf, GL_DYNAMIC_DRAW)
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
272
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
273 glBindTexture(GL_TEXTURE_2D, fb.texture)
520
c0b3f8709f74 Store the indices of the framebuffer in a static ibo.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 518
diff changeset
274 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, NULL)
462
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
275 glBindTexture(GL_TEXTURE_2D, 0)
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
276
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
277 glBindBuffer(GL_ARRAY_BUFFER, 0)
520
c0b3f8709f74 Store the indices of the framebuffer in a static ibo.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 518
diff changeset
278 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)
462
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
279
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
280
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
281 cdef class Framebuffer:
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
282 def __init__(self, int x, int y, int width, int height):
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
283 self.x = x
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
284 self.y = y
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
285 self.width = width
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
286 self.height = height
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
287
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
288 glGenTextures(1, &self.texture)
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
289 glBindTexture(GL_TEXTURE_2D, self.texture)
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
290 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
291 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
292 glTexImage2D(GL_TEXTURE_2D, 0,
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
293 GL_RGBA,
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
294 width, height,
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
295 0,
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
296 GL_RGBA, GL_UNSIGNED_BYTE,
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
297 NULL)
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
298 glBindTexture(GL_TEXTURE_2D, 0)
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
299
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
300 glGenRenderbuffers(1, &self.rbo)
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
301 glBindRenderbuffer(GL_RENDERBUFFER, self.rbo)
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
302 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, width, height)
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
303 glBindRenderbuffer(GL_RENDERBUFFER, 0)
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
304
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
305 glGenFramebuffers(1, &self.fbo)
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
306 glBindFramebuffer(GL_FRAMEBUFFER, self.fbo)
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
307 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, self.texture, 0)
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
308 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, self.rbo)
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
309 assert glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
310 glBindFramebuffer(GL_FRAMEBUFFER, 0)
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
311
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
312 cpdef bind(self):
a71b912b45b7 Render to framebuffers first, and reposition some interface elements in the game area.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 461
diff changeset
313 glBindFramebuffer(GL_FRAMEBUFFER, self.fbo)