hook Implementation of raymarching.

CodinaColada is my 2d game engine. Its main purpose is to be a sandbox in which I can implement any functionality I’m interested in.

Technologies

OpenGL

Box2D

Tracy

To improve performance of my engine I need to know where the biggest potentials for improvements are. This can be determined using a profiler. Tracy is one such profiler. It is able to measure CPU and GPU performance. This is done by introducing macros inside the functions to be instrumented which then create zones as can be seen in the image showing the performance of a single frame below. hook

From the image we can see that the engine is currently CPU bound as the red zones inside the OpenGL context only make up a tiny portion of frame. This is in contrest to the CPU which is busy the entire frame looping over the gameobjects and preparing rendering data (such as calculating positions). We can also see that there are 8 threads updating the gameobjects but the JsonAnalyser objects requires by far more time than the other >1000 gameobjects together. This however is not an issue of the engine but the application I build using the engine. The JsonAnalyser is responsible for rendering the text over 1000 nodes like these: hook

Therefore I refactored my code to have each individual node be a gameobject. This way much of the processing can happen concurrently in GameObject::Update and only the drawing itself has to take place in the drawing thread (GameObject::Draw). Here is the result: hook

As we can see the giant JsonAnalysis block is gone which in turn reduces the time per frame from ~8ms to ~5ms.

Now the largest block by far is Renderer::Draw, which sets up the data required for the OpenGLShaders (such as position, time…) for each individual GameObject. My next optimization will probably have to be concurrently creating a command buffer for OpenGL calls and then doing all the OpenGL calls from the OpenGL thread right before drawing.

CMAKE