The first problem is how dynamic your rendering is. Do you need to render a few circles? Or do you need complex vector art that changes all the time?
If it's the latter, you're screwed. Unless you develop a very advanced vector rendering solution like
Slug, you would have to rely on a CPU vector rasterization library, then copy the results to a texture and draw that as a quad.
If it's the former, you can render:
- Render everything as chained triangles. The vertex count could get humongous. Not recommended.
- Render everything as a quad, displaying either a texture or a special shader. It may waste fill rate due to the empty spaces (eg. a circle inside a rectangle)
- Render everything as a simplified geometry, with a texture or a special texture. This is the same as the above, but e.g. instead of rendering a circle as a quad, you render a circle as an hexagon, thus less waste. If you use many triangles, you get the small triangle problem, if you use too few you waste a lot of empty space.
Regarding "texture" vs "special shader", you can rely on a texture (which may need a lot of resolution, consumes memory) or you can use a simple shader.
For example a circle can be rendered with:
Code: Select all
//Non-smooth
float4 circle(float2 p, float2 center, float radius)
{
return length(p) - r;
}
//Smooth
float4 circle(float2 p, float2 center, float radius)
{
return lerp(float4(1,1,1,0), float4(1,0,0,1), smoothstep(radius + 0.005, radius - 0.005, length(p - center)));
}
Example 1 in Shadertoy,
Example 2. Iñigo has a useful reference on
2D drawing functions for basic shapes.
The advantage of using a shader is that it adapts to all resolution without consuming memory, and should be very fast, but it requires more knowledge and getting familiar with more advanced features. You would have to either use v1 low level materials to setup your shaders (more user friendly and easier to start with, but may get difficult to manage if you have many basic shapes and settings), or get familiar with writing a custom Hlms implementation.
As to how to change the vertices of the VAO on the fly, see DynamicGeometry and CustomRenderable samples.