Hi everybody, this is my first post on these forums. I’m new to cpp, cinder and using xcode as an ide so theres a big possibility that my code is inefficient.
I was following the out of date tutorial posted on this site and got to the end of chapter 2 but noticed my application was running super slow (~10sec/frame) 40% cpu usage on computer. I know game engines can render millions of particles at a decent frame rate so I was wondering if anybody could point out a bottleneck or give me some insight on how to find cpu usage bottle necks in my code.
Below are links to the tutorial I followed and some links to the important parts of my code.
The coder is organized in a weird way right now, I figured Id learn cpp first and then figure out how to appropriately structure the code
Headers (contain Particle and ParticleController classes):
After running time profiler in xcode I’m seeing that the application is spending 88.8% of its time running cinder::gl::drawSolidCircle
Is this function so slow that it takes roughly 9s to execute about 5000 times?? Has anybody found a good way to speed this up? I was hoping to be able and project this image at a much higher resolution while also making it interactive. I’m not sure if that goal seems reasonable at this point if I continue at the performance I’m at.
Edit: Is the answer perhaps that cinder::gl::drawSolidCircle is a convenience method and it would be more efficient to run a batch method instead??
Yes, an instanced batch rendering of a circle would be one of the ways to do it more efficiently.
gl::drawSolidCircle is a convenience method not meant to be fast. In older versions of Cinder (prior to v0.9.0) this method used to be much faster, most notably because the OpenGL driver was able to optimize the code under the hood.
gl::VboMesh from a
geom::Circle and reusing it would already be faster. Alternatively, you could render a quad combined with a shader like this one. This, too, can be done by combining a
gl::VboMesh and a
gl::GlslProg into a
gl::Batch. If you want to render more than a few circles, use instanced rendering. All of this is (slightly) more advanced than beginner-level, so don’t lose hope if it proves a bit difficult.