This overloaded function allows easily create or resize canvas and is a short replacement for the following code.
if (!canvas || !canvas->isValid())
{
if (canvas)
canvas->setSize(width, height);
else
canvas = renderer->CreateTexture(width, height, 1, TextureFormat::RGBA, 1);
if (canvas)
{
...
// Render on the canvas everything you need
}
}
Which can be replaced using this function with
if (RepareCanvas(renderer, &canvas, width, height))
{
...
// Render on the canvas everything you need
}
You can find more information in comments below.
bool PrepareCanvas(IRenderer *renderer, ITexture **canvas, const int width, const int height); // Return true if rendering is required
bool PrepareCanvas(IRenderer *renderer, ITexture **canvas, const float width, const float height); // Return true if rendering is required. Canvas size will be rounded
bool PrepareCanvas(IRenderer *renderer, ITexture **canvas, const PointF &size); // Return true if rendering is required. Canvas size will be rounded
bool PrepareCanvas(IRenderer *renderer, ITexture **canvas, const RectF &rect); // Return true if rendering is required. Canvas size, which is the size of the rect, will be rounded
Namespace: | nitisa |
Include: | Nitisa/Render/Utils.h |