def add_widget(self, widget): # noqa # Add the widget to our Fbo instead of the normal canvas c = self.canvas self.canvas = self.fbo with widget.canvas: self._callbacks[widget.canvas] = Callback(self._propagate_updates) super(EffectWidget, self).add_widget(widget) self.canvas = c
def __init__(self, zs, ps, **kwargs): super(Renderer, self).__init__(**kwargs) self.canvas = RenderContext(compute_normal_mat=True) self.canvas.shader.source = resource_find('simple.glsl') #self._keyboard = Window.request_keyboard(self._keyboard_closed, self) self.zs = zs self.ps = ps #self._keyboard.bind(on_key_down=self._on_keyboard_down) #self._keyboard.bind(on_key_up=self._on_keyboard_up) self.shiftDown = False #self.scene = ObjFile(resource_find("monkey.obj")) with self.canvas: self.cb = Callback(self.setup_gl_context) PushMatrix() self.setup_scene() PopMatrix() self.cb = Callback(self.reset_gl_context) Clock.schedule_interval(self.update_glsl, 1 / 60.)
def __init__(self, mc: "MpfMc", name: str, config: dict) -> None: """Initialise DMD.""" self.mc = mc self.name = name self.mc.log.info('Initializing DMD') self.config = self._get_validated_config(config) self.source = self.mc.displays[self.config['source_display']] self.prev_data = None self._dirty = True # put the widget canvas on a Fbo texture = Texture.create(size=self.source.size, colorfmt='rgb') self.fbo = Fbo(size=self.source.size, texture=texture) self.effect_widget = EffectWidget() effect_list = list() effect_list.append(FlipVerticalEffect()) if self.config['brightness'] != 1.0: if not 0.0 <= self.config['brightness'] <= 1.0: raise ValueError("DMD brightness value should be between 0.0 " "and 1.0. Yours is {}".format( self.config['brightness'])) effect_list.append(GainEffect(gain=self.config['brightness'])) if self.config['gamma'] != 1.0: effect_list.append(GammaEffect(gamma=self.config['gamma'])) self.effect_widget.effects = effect_list self.effect_widget.size = self.source.size self.fbo.add(self.effect_widget.canvas) with self.source.canvas: self.callback = Callback(self._trigger_rendering) self._set_dmd_fps()
def _setup_fbo(self, element, settings, context): """Setup FBO for a display.""" if element not in self.machine.displays: raise AssertionError("Display {} not found. Please create it to use display_light_player.".format(element)) source = self.machine.displays[element] # put the widget canvas on a Fbo texture = Texture.create(size=source.size, colorfmt='rgba') fbo = Fbo(size=source.size, texture=texture) effect_widget = RelativeLayout() effect_widget.size = source.size fbo.add(effect_widget.canvas) with source.canvas: callback = Callback(partial(self._trigger_render, context, element)) return [fbo, effect_widget, source, settings, True, True, True, callback]