I’m using vtkContext2D to draw an entire scene made of lines, polygons, texts.
Works great.
I’m starting to work with larger scenes, and I’m issuing very bad performance drops when the number of primitives grows :
several 10th of primitives => 60+fps
several 1000th of primitives => 10-30fps
over 100000 primitives => <5fps (unusable)
Through these drops were expected, my point is how can I improve it ?
As far as I can tell, vtkContext2D (OpenGL counterpart) is a direct rendering proxy.
For each primitive, and for each frame :
it creates a VBO
it fills the VBO with primitive’s data (vertex, colors, …)
it calls the shader to actually draw
it releases the VBO
This “naive” approach is ok when scene is small, or when primitives change very often.
But when scene is very “static”, with very few primitive changing between each frame, this approach is less than perfect …
Old times OpenGL was giving some tools to optimize things, such as DisplayLists, that are obsolete in modern OpenGL implementations.
One way to improve things would be to cache VBOs for each primitive, and just “recall it” before calling shader.
As far as I understand, vtkOpenGLContextDeviceBufferObjectBuilder::BuildVBO has such a mecanism thanks to parameter cacheIdentifier.
But when coming from vtkOpenGLContextDevice2D::BuildVBO it is always “0”, actually disabling cache.
Without taking a look at your code I think the bottleneck is here: “for each primitive…”. I think you are better off not creating a VBO for each point, line or triangle. You usually put lots of data in it and draw parts of it (via offsets). Please, take a look at this explained example of VBO usage: OpenGL Vertex Buffer Object (VBO)
As stated in my post, I place my question within the scope of vtkContext2D.
So, I was just wondering if there was some things I missed, that could speed vtkContext2D up, without having to make deep tweaks in the code, or use another OpenGL wrapping method.
Well, if you’re creating one VBO for each primitive, you must expect performance penalties in your program. If you don’t change that, there wont be much hope in improving its performance.
Yes I understand, but the VBO creation is not a choice of mine, but rather the way vtkContext2D works.
vtkContext2D acts as a high level wrapper that allows display of 2d primitives, by encapsulating some basic stuff (VBO creation, data transfert, shader management, etc …) inside a single call.
As far as I can tell, the current implementation of vtkContext2D is not intended to display huge number of objects, but rather a small bunch of “HUD things” above a 3D scene.
Despite that, it seams vtkContext2D is able to manage some sort of caching mechanism inside the VBO.
Hence my question.