comparison pytouhou/ui/gamerunner.py @ 396:34a91f918e7c

Use Buffer Objects instead of host pointers.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Wed, 06 Feb 2013 21:19:20 +0100
parents 346614f788f1
children 1c773544eaeb
comparison
equal deleted inserted replaced
395:43413d4ff05b 396:34a91f918e7c
15 import pyglet 15 import pyglet
16 import traceback 16 import traceback
17 17
18 from pyglet.gl import (glMatrixMode, glLoadIdentity, glEnable, glDisable, 18 from pyglet.gl import (glMatrixMode, glLoadIdentity, glEnable, glDisable,
19 glHint, glEnableClientState, glViewport, glScissor, 19 glHint, glEnableClientState, glViewport, glScissor,
20 glLoadMatrixf, 20 glLoadMatrixf, glGenBuffers, glDeleteBuffers,
21 GL_MODELVIEW, GL_PROJECTION, 21 GL_MODELVIEW, GL_PROJECTION,
22 GL_TEXTURE_2D, GL_BLEND, GL_FOG, 22 GL_TEXTURE_2D, GL_BLEND, GL_FOG,
23 GL_PERSPECTIVE_CORRECTION_HINT, GL_FOG_HINT, GL_NICEST, 23 GL_PERSPECTIVE_CORRECTION_HINT, GL_FOG_HINT, GL_NICEST,
24 GL_COLOR_ARRAY, GL_VERTEX_ARRAY, GL_TEXTURE_COORD_ARRAY, 24 GL_COLOR_ARRAY, GL_VERTEX_ARRAY, GL_TEXTURE_COORD_ARRAY,
25 GL_SCISSOR_TEST) 25 GL_SCISSOR_TEST)
29 29
30 from .gamerenderer import GameRenderer 30 from .gamerenderer import GameRenderer
31 from .music import MusicPlayer, SFXPlayer, NullPlayer 31 from .music import MusicPlayer, SFXPlayer, NullPlayer
32 from .shaders.eosd import GameShader, BackgroundShader 32 from .shaders.eosd import GameShader, BackgroundShader
33 33
34 from ctypes import c_uint, byref
35
34 36
35 logger = get_logger(__name__) 37 logger = get_logger(__name__)
36 38
37 39
38 class GameRunner(pyglet.window.Window, GameRenderer): 40 class GameRunner(pyglet.window.Window, GameRenderer):
52 54
53 if not self.use_fixed_pipeline: 55 if not self.use_fixed_pipeline:
54 self.game_shader = GameShader() 56 self.game_shader = GameShader()
55 self.background_shader = BackgroundShader() 57 self.background_shader = BackgroundShader()
56 self.interface_shader = self.game_shader 58 self.interface_shader = self.game_shader
59
60 self.vbo = c_uint(0)
57 61
58 if game: 62 if game:
59 self.load_game(game, background, replay) 63 self.load_game(game, background, replay)
60 64
61 self.clock = pyglet.clock.get_default() 65 self.clock = pyglet.clock.get_default()
100 glHint(GL_FOG_HINT, GL_NICEST) 104 glHint(GL_FOG_HINT, GL_NICEST)
101 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST) 105 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
102 glEnableClientState(GL_COLOR_ARRAY) 106 glEnableClientState(GL_COLOR_ARRAY)
103 glEnableClientState(GL_VERTEX_ARRAY) 107 glEnableClientState(GL_VERTEX_ARRAY)
104 glEnableClientState(GL_TEXTURE_COORD_ARRAY) 108 glEnableClientState(GL_TEXTURE_COORD_ARRAY)
109 else:
110 glGenBuffers(1, byref(self.vbo))
105 111
106 self.proj = self.perspective(30, float(self.game.width) / float(self.game.height), 112 self.proj = self.perspective(30, float(self.game.width) / float(self.game.height),
107 101010101./2010101., 101010101./10101.) 113 101010101./2010101., 101010101./10101.)
108 game_view = self.setup_camera(0, 0, 1) 114 game_view = self.setup_camera(0, 0, 1)
109 self.game_mvp = game_view * self.proj 115 self.game_mvp = game_view * self.proj
119 self.render_game() 125 self.render_game()
120 self.render_interface() 126 self.render_interface()
121 self.flip() 127 self.flip()
122 else: 128 else:
123 self.update() 129 self.update()
130
131 if not self.use_fixed_pipeline:
132 glDeleteBuffers(1, byref(self.vbo))
124 133
125 134
126 def _event_text_symbol(self, ev): 135 def _event_text_symbol(self, ev):
127 # XXX: Ugly workaround to a pyglet bug on X11 136 # XXX: Ugly workaround to a pyglet bug on X11
128 #TODO: fix that bug in pyglet 137 #TODO: fix that bug in pyglet