comparison pytouhou/ui/gamerenderer.pyx @ 370:74471afbac37

Add a programmable pipeline renderer, and a --fixed-pipeline switch to use the old one.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Fri, 27 Jul 2012 18:43:48 +0200
parents 2c4589370cc6
children 0537af9125a7
comparison
equal deleted inserted replaced
369:f305cdd6f6c5 370:74471afbac37
14 14
15 15
16 from itertools import chain 16 from itertools import chain
17 17
18 from pyglet.gl import * 18 from pyglet.gl import *
19
20 from pytouhou.utils.matrix import Matrix
19 21
20 from .renderer cimport Renderer 22 from .renderer cimport Renderer
21 from .background cimport get_background_rendering_data 23 from .background cimport get_background_rendering_data
22 24
23 25
47 49
48 back = self.background 50 back = self.background
49 game = self.game 51 game = self.game
50 texture_manager = self.texture_manager 52 texture_manager = self.texture_manager
51 53
54 if self.use_fixed_pipeline:
55 glMatrixMode(GL_PROJECTION)
56 glLoadIdentity()
57
52 if game is not None and game.spellcard_effect is not None: 58 if game is not None and game.spellcard_effect is not None:
53 self.setup_camera(0, 0, 1) 59 if self.use_fixed_pipeline:
60 glMatrixMode(GL_MODELVIEW)
61 glLoadMatrixf(self.game_mvp.get_c_data())
62 glDisable(GL_FOG)
63 else:
64 self.game_shader.bind()
65 self.game_shader.uniform_matrixf('mvp', self.game_mvp.get_c_data())
54 66
55 glDisable(GL_FOG)
56 self.render_elements([game.spellcard_effect]) 67 self.render_elements([game.spellcard_effect])
57 glEnable(GL_FOG)
58 elif back is not None: 68 elif back is not None:
69 if self.use_fixed_pipeline:
70 glEnable(GL_FOG)
71 else:
72 self.background_shader.bind()
59 fog_b, fog_g, fog_r, fog_start, fog_end = back.fog_interpolator.values 73 fog_b, fog_g, fog_r, fog_start, fog_end = back.fog_interpolator.values
60 x, y, z = back.position_interpolator.values 74 x, y, z = back.position_interpolator.values
61 dx, dy, dz = back.position2_interpolator.values 75 dx, dy, dz = back.position2_interpolator.values
62 76
63 glFogi(GL_FOG_MODE, GL_LINEAR) 77 glFogi(GL_FOG_MODE, GL_LINEAR)
64 glFogf(GL_FOG_START, fog_start) 78 glFogf(GL_FOG_START, fog_start)
65 glFogf(GL_FOG_END, fog_end) 79 glFogf(GL_FOG_END, fog_end)
66 glFogfv(GL_FOG_COLOR, (GLfloat * 4)(fog_r / 255., fog_g / 255., fog_b / 255., 1.)) 80 glFogfv(GL_FOG_COLOR, (GLfloat * 4)(fog_r / 255., fog_g / 255., fog_b / 255., 1.))
67 81
68 self.setup_camera(dx, dy, dz) 82 model = Matrix()
69 glTranslatef(-x, -y, -z) 83 model.data[3] = [-x, -y, -z, 1]
84 view = self.setup_camera(dx, dy, dz)
85 model_view = model * view
86 model_view_projection = model * view * self.proj
87
88 if self.use_fixed_pipeline:
89 glMatrixMode(GL_MODELVIEW)
90 glLoadMatrixf(model_view_projection.get_c_data())
91 else:
92 self.background_shader.uniform_matrixf('model_view', model_view.get_c_data())
93 self.background_shader.uniform_matrixf('projection', self.proj.get_c_data())
70 94
71 glEnable(GL_DEPTH_TEST) 95 glEnable(GL_DEPTH_TEST)
72 for (texture_key, blendfunc), (nb_vertices, vertices, uvs, colors) in get_background_rendering_data(back): 96 for (texture_key, blendfunc), (nb_vertices, vertices, uvs, colors) in get_background_rendering_data(back):
73 glBlendFunc(GL_SRC_ALPHA, (GL_ONE_MINUS_SRC_ALPHA, GL_ONE)[blendfunc]) 97 glBlendFunc(GL_SRC_ALPHA, (GL_ONE_MINUS_SRC_ALPHA, GL_ONE)[blendfunc])
74 glBindTexture(GL_TEXTURE_2D, texture_manager[texture_key].id) 98 glBindTexture(GL_TEXTURE_2D, texture_manager[texture_key].id)
79 glDisable(GL_DEPTH_TEST) 103 glDisable(GL_DEPTH_TEST)
80 else: 104 else:
81 glClear(GL_COLOR_BUFFER_BIT) 105 glClear(GL_COLOR_BUFFER_BIT)
82 106
83 if game is not None: 107 if game is not None:
84 self.setup_camera(0, 0, 1) 108 if self.use_fixed_pipeline:
109 glMatrixMode(GL_MODELVIEW)
110 glLoadMatrixf(self.game_mvp.get_c_data())
111 glDisable(GL_FOG)
112 else:
113 self.game_shader.bind()
114 self.game_shader.uniform_matrixf('mvp', self.game_mvp.get_c_data())
85 115
86 glDisable(GL_FOG)
87 self.render_elements(chain(*(enemy.objects() for enemy in game.enemies if enemy.visible))) 116 self.render_elements(chain(*(enemy.objects() for enemy in game.enemies if enemy.visible)))
88 self.render_elements(enemy for enemy in game.enemies if enemy.visible) 117 self.render_elements(enemy for enemy in game.enemies if enemy.visible)
89 self.render_elements(game.effects) 118 self.render_elements(game.effects)
90 self.render_elements(chain(game.players_bullets, 119 self.render_elements(chain(game.players_bullets,
91 game.lasers_sprites(), 120 game.lasers_sprites(),
94 *(player.objects() for player in game.players))) 123 *(player.objects() for player in game.players)))
95 self.render_elements(chain(game.bullets, game.lasers, 124 self.render_elements(chain(game.bullets, game.lasers,
96 game.cancelled_bullets, game.items, 125 game.cancelled_bullets, game.items,
97 (item.indicator for item in game.items if item.indicator), 126 (item.indicator for item in game.items if item.indicator),
98 *(label.objects() for label in game.labels))) 127 *(label.objects() for label in game.labels)))
99 glEnable(GL_FOG)
100 128