@@ -186,20 +186,25 @@ def __init__(self):
186
186
self .num_plays = 0
187
187
self .skip_animations = False
188
188
189
- self .window = Window ()
190
-
191
189
self .camera = OpenGLCamera ()
192
190
193
- # Initialize context.
194
- self .context = self .window .ctx
191
+ if config ["preview" ]:
192
+ self .window = Window ()
193
+ self .context = self .window .ctx
194
+ self .frame_buffer_object = self .context .detect_framebuffer ()
195
+ else :
196
+ self .window = None
197
+ self .context = moderngl .create_standalone_context ()
198
+ self .frame_buffer_object = self .get_frame_buffer_object (self .context , 0 )
199
+ self .frame_buffer_object .use ()
200
+
195
201
self .context .enable (moderngl .BLEND )
196
202
self .context .blend_func = (
197
203
moderngl .SRC_ALPHA ,
198
204
moderngl .ONE_MINUS_SRC_ALPHA ,
199
205
moderngl .ONE ,
200
206
moderngl .ONE ,
201
207
)
202
- self .frame_buffer_object = self .context .detect_framebuffer ()
203
208
204
209
# Initialize shader map.
205
210
self .id_to_shader_program = {}
@@ -242,7 +247,10 @@ def render_mobjects(self, mobs):
242
247
for mob in mobs :
243
248
shader_wrapper_list = mob .get_shader_wrapper_list ()
244
249
render_group_list = map (
245
- lambda x : self .get_render_group (self .context , x ), shader_wrapper_list
250
+ lambda shader_wrapper : self .get_render_group (
251
+ self .context , shader_wrapper
252
+ ),
253
+ shader_wrapper_list ,
246
254
)
247
255
for render_group in render_group_list :
248
256
self .render_render_group (render_group )
@@ -370,23 +378,40 @@ def update_frame():
370
378
self .frame_buffer_object .clear (* window_background_color )
371
379
self .refresh_perspective_uniforms (scene .camera )
372
380
self .render_mobjects (scene .mobjects )
373
- self .window .swap_buffers ()
374
381
self .animation_elapsed_time = time .time () - self .animation_start_time
375
382
376
383
window_background_color = (0.2 , 0.2 , 0.2 , 1 )
377
384
update_frame ()
378
-
379
385
self .file_writer .write_frame (self )
380
386
381
- while self .animation_elapsed_time < frame_offset :
382
- update_frame ()
387
+ if self .window is not None :
388
+ self .window .swap_buffers ()
389
+ while self .animation_elapsed_time < frame_offset :
390
+ # TODO: Just sleep?
391
+ update_frame ()
392
+ self .window .swap_buffers ()
383
393
384
394
def scene_finished (self , scene ):
385
395
self .file_writer .finish (self .partial_movie_files )
386
396
387
397
def save_static_frame_data (self , scene , static_mobjects ):
388
398
pass
389
399
400
+ def get_frame_buffer_object (self , context , samples = 0 ):
401
+ pixel_width = config ["pixel_width" ]
402
+ pixel_height = config ["pixel_height" ]
403
+ num_channels = 4
404
+ return context .framebuffer (
405
+ color_attachments = context .texture (
406
+ (pixel_width , pixel_height ),
407
+ components = num_channels ,
408
+ samples = samples ,
409
+ ),
410
+ depth_attachment = context .depth_renderbuffer (
411
+ (pixel_width , pixel_height ), samples = samples
412
+ ),
413
+ )
414
+
390
415
def get_raw_frame_buffer_object_data (self , dtype = "f1" ):
391
416
# Copy blocks from the fbo_msaa to the drawn fbo using Blit
392
417
# pw, ph = self.get_pixel_shape()
0 commit comments