Hi all - I have changed my code to use a new canvas for each 'sprite' (actually a Rive object). They all target the same buffer. I loop through all the canvases and draw/sync them in order. However, only the last canvas is drawn, and all around it is black. It is like outside the shape is not transparent but instead it is solid black. What could I be doing wrong?
This is what I am doing:
// Each rive sprite has it's own canvas
_canvas = tvg::SwCanvas::gen();
_canvas->target((uint32_t*)context->buffer(), context->width(), context->width(), context->height(), tvg::SwCanvas::ARGB8888);
// If I do this, sprite 0 is drawn with black all around it, despite the buffer being red
context->buffer()->clear( COLOR_RED );
sprites[0]->canvas()->draw(); sprites[0]->canvas()->sync();
// If I do this, only sprite 1 is visible (with black all around it)
context->buffer()->clear( COLOR_RED );
sprites[0]->canvas()->draw(); sprites[0]->canvas()->sync();
sprites[1]->canvas()->draw(); sprites[1]->canvas()->sync();
// And so on. (only sprite 2 is visible)
context->buffer()->clear( COLOR_RED );
sprites[0]->canvas()->draw(); sprites[0]->canvas()->sync();
sprites[1]->canvas()->draw(); sprites[1]->canvas()->sync();
sprites[2]->canvas()->draw(); sprites[2]->canvas()->sync();
It doesn't matter if the sprite is a Rive file or a Picture, or a combination. Result is all the same.
Any ideas?
@hermet I have changed my code now to use a single canvas. Each 'sprite' maintains a Scene
and owns the pointer to it. The canvas is cleared every frame, and the scenes are added back to the canvas in the correct order every frame. This means that I do not have to rebuild the scene every frame, just push it back onto the canvas. To do this I had to add an overloaded method for Canvas::push that takes a Paint*
instead of a unique_ptr<Paint>
so that my sprites can maintain ownership of the Scene.
The rendering is fixed, but I have a slow memory leak somewhere. This was happening even before I added the Paint*
overload (see rive-app/rive-tizen#70).
Result push(Paint* paint)
instead of Result push(std::unique_ptr<Paint> paint)
)