p5py / p5

p5 is a Python package based on the core ideas of Processing.
https://p5.readthedocs.io
GNU General Public License v3.0
728 stars 120 forks source link

Creating new SkiaRenderer module in p5py #293

Open arihantparsoya opened 3 years ago

arihantparsoya commented 3 years ago

We need to add two new classes SkiaSketch and SkiaRenderer for adding skia into p5py.

SkiaSketch

The first step is to create a base class SkiaSketch (similar to VispySketch https://github.com/p5py/p5/blob/master/p5/sketch/Vispy2DRenderer/base.py#L39) which we can call to initiate the sketch window.

This class will run a timer function to call the draw() function set by the timer.

Reference: https://kyamagu.github.io/skia-python/tutorial/canvas.html

SkiaRenderer

SkiaRenderer will contain the rendering code for the shapes. For now we can write the code for rectangle only. Skia uses path API, its simple to implement than the Vispy pipeline we currently have.

Reference: https://kyamagu.github.io/skia-python/tutorial/path.html#

tushar5526 commented 3 years ago

Skia does not have its own event handling, it is only a rendering library but we can use glfw to support events. Also glfw provides us with a window to show the canvas. https://kyamagu.github.io/skia-python/tutorial/canvas.html#opengl-window

Is there any other way I am missing out to handle events?

arihantparsoya commented 3 years ago

You are right. We should use glfw to handle events.

tushar5526 commented 3 years ago

What do you mean by this ?

For now we can write the code for rectangle only

arihantparsoya commented 3 years ago

I meant that we can only implement the rect() API in SkiaRenderer

tushar5526 commented 3 years ago

@parsoyaarihant Any reason why events are first queued and then called after the end of each timer loop. https://github.com/p5py/p5/blob/master/p5/sketch/Vispy2DRenderer/base.py#L117 Why are we not calling the events instantly when vispy detects it?