How to create a texture out of part of a canvas

13 views
Skip to first unread message

Klaas van Schelven

unread,
Jan 23, 2017, 6:35:21 AM1/23/17
to Kivy users support
I am in the process of creating a custom Kivy Widget and am running in some questions surrounding the relationship between texture & canvas in the process.

The scenario is as such: I am doing a lot of 2d drawing (to the point of it being "too slow"). My data structures (the stuff that needs to be represented on screen) define a space partitioning. The kind of changes that can be expected in the state of the data are almost always limited to small parts of that tree. This suggests the following optimization: cache the results of drawing parts of the data structure, recalculate only the parts that are new and glue it all together.

My idea for the cache would be: use pre-rendered textures. Since all my current drawing logic is expressed as series of Canvas instructions, I was thinking of creating a texture out of a particular part of the Canvas.

1. Is it possible in OpenGL / Kivy to create a texture out of an existing canvas, draw on a texture or have some intermediate form that can be turned into a texture?
2. If not, what would be the recommended approach to the above problem?

Ideally, I'm looking for an approach that makes it so that it doesn't matter what I'm drawing on (canvas, texture or something that will be turned into a texture). Such an approach would decouple decisions about what to cache from having to rewrite everything to another "language for drawing".

Klaas van Schelven

unread,
Jan 24, 2017, 6:57:17 AM1/24/17
to Kivy users support
Answering myself here:

The answer appears to be to use an FBO / Framebuffer

"""You can activate the fbo for rendering into a texture and use your fbo as a texture for other drawing.

The Fbo acts as a kivy.graphics.instructions.Canvas."""
Reply all
Reply to author
Forward
0 new messages