12

How to quickly draw a curved shape?

  • by "quickly" I presume one should use hardware facilities as much as possible

  • by "curved" I mean boundaries defined by either quadratic or cubic Bezier curves

  • by "shape" I mean either a "fat" stroke (i.e. more than 1px wide) or even-odd/non-zero filled "2D curved polygon", possibly with holes (i.e. letter "O")

I'm asking because the options I know of have several drawbacks:

  • triangulating the shape and sending it to OpenGL - does the most difficult work on CPU and might use too many/few triangles (i.e. wasteful/coarse)

  • texture atlas - has to recompute/upload the texture on every change (shape, scale, rotation, ...)

  • Signed distance field - on large scales the details don't look pretty or has to recompute/upload the texture

  • NV_path_rendering - could be it, if it was not working only on Nvidia's cards

  • OpenVG - could be it, if it was not working only on mobile

  • ?


* It seems to me that OpenVG is not exactly moving forward, to put it mildly. Does anyone know anything about its future prospects? Is it worth at all to keep an eye on in the present day?

** OpenGL 4+ provides means of on-fly tessellation of polygons. Could it be somehow used to refine the the mesh from the "triangulating" option so that the shape boundary at least wont look "angled"?

Ecir Hana
  • 1,459
  • 11
  • 20

2 Answers2

2

You can use OpenGl 4.x tessellation shaders to convert Bezier control points into polygons.

A google search for "tessellation shader bezier" found this outline describing the tessellation of Bezier surfaces and curves:

http://web.engr.oregonstate.edu/~mjb/cs519/Handouts/tessellation.1pp.pdf

This offloads the Bezier evaluation from the CPU to the GPU and reduces the data flow across the bus.

atb
  • 121
  • 4
0

One can do curved drawing with hardware. There is a method described in GPU Gems 3 that describes how to do this. User @yuriks actually comments this. I have actually made a quick a dirty demo for you to take a look at.

curve

Image 1: HW accelerated curve shapen (drawn usung a triangle) and webgl source

joojaa
  • 8,437
  • 1
  • 24
  • 47