Optimizing Draw Calls
Performance is important, and a good developer always has this in mind. There is no secret formula to optimize any type of environment, and we have to deal with the limitations in the most efficient way according to the circumstances.
In this tutorial we show you in a simple way how to optimize the graphic load of our video game.
1.0 – Joint Friction
Before we talk about performance, let’s briefly review the friction joint. This is the last option we offer by default in the physics library.
So we will do the same by creating two objects that we will join with the FRICTION JOINT board. In its options we are allowed to configure the driving force values, in such a way that a force is exerted contrary to the assigned gravity.
It will give us the feeling that our instance floats in the air, receiving a frictional force from the point that we indicate from the interface.
magine we settle on a cloud, or even on a stream of water shot from a source … With this type of configuration and the appropriate assets we can simulate these effects.
1.1 – Optimizing the graphics pipeline
Once here, let’s talk about performance and how to optimize each of our levels …
To do this, we will do a test that will test our hardware.
In the case presented in this tutorial we decided to duplicate an entire family, this family is composed of 2 terrains, 8 particle systems that project 2 particles each, 8 animations and 6 texture patterns.
Our goal is to duplicate this family to reach 1000 objects on the screen, take performance data in both editor mode and test mode.
1.2 – Cómo funciona nuestra GPU
With open panels and 11 active text boxes our panel reaches 254 texture breaks. Now you will wonder … What is a texture jump or Texture Swap? I will try to be brief and concise, every time GameMaker draws your content, you have to choose an image that is in a texture and draw the area that defines it.
The graphic to show can occupy the size of our texture. Since in a scenario it is a set of drawings stored in images, every time an asset is drawn that contains an image / texture different from the previous one, our graphics card needs to jump into memory to choose the appropriate texture.
In this way you can continue drawing our assets and this is called texture jump. The more powerful our graphics, the more texture breaks you can produce without lowering performance.
Now we are going to explain what Vertex Batches are …
Our GPU has assigned values of how it should represent what it draws on the screen, and we are allowed to modify the matrix of how the world is visualized. We can manipulate our images so that they look of a certain color, brightness, in addition to being able to create effects by manipulating each pixel of our textures.
We can create models manipulated with an independent matrix, which is responsible for manipulating their transformations.
In short, each of these actions adds a new cycle. A new call to change values from our graphics card.
This is called a VERTEX BATCH. The more “drawing interruptions” our GPU needs to “reset” its drawing mode, the greater the power needed to move our level.
In the image below you can see the results of our test in edit mode and without optimizing our level …
And these are the results in the Test mode, where our editor is destroyed at 99%, dedicating all the performance of our GPU in playing the game.
1.3 – Executing Improvements
At this point you begin to ask yourself … So, what should I do to improve the performance of my level? Well, it’s very simple, thanks to a Script (function / piece of code) that is executed by pressing the F1 key of our keyboard, DarkSpine is responsible for automatically optimizing our level.
As we can see in the image below, in the editing mode we have improved almost 50% the efficiency of how and what our Gpu should draw with the least amount of texture breaks possible.
In Test mode our graphics card dispenses with 48 jumps to reproduce all the content. It is a considerable improvement that allows us to create large worlds with HD textures.
On our YouTube channel, you can watch videos where the content of our assets is high definition.
We strongly recommend that you view the video located at the beginning of this article to get a clear idea of this section.
The video tutorials provided on the YouTube channel support subtitle contributions from users. This means that any user can contribute to add subtitles with the editor and the new contribution program of YouTube subscribers.
We will talk about other methods to optimize our level in following articles. But for now we do not want you to worry about building thinking if you are doing things properly.
With what is explained in this article and our image manager, you have more than enough to start creating real works of art.
We send you our best regards and see you in the next tutorial!