![]() ![]() ![]() This way, you can accumulate a “batch” of draws as they come in, and only send them to the GPU for rendering when you get a new request which switches the texture. If you draw two textures in a row that share the same texture atlas however, since you don’t need to change the GPU state (the currently bound texture, in this case), you can batch them both into one draw. Before, each game sprite was in a separate texture, so we had to bind the correct texture for each sprite before drawing. In the end, the system I implemented involves pre-loading all the assets in the game into a series of large atlas textures. Especially in older apis like opengl and Directx 11 and under, there is a large cost associated with issuing a new draw call, so if you can batch up items that use the same state configuration and issue fewer, but larger draw calls, that is a major performance win. For those of you who are not familiar with graphics APIs, fundamentally what you do is a: push vertex data onto GPU, and then b: issue commands to draw the vertices with a specific configuration (shader, blending, etc). ![]() Then, you hand it over to your main graphics thread to submit it for execution on the GPU.įor now, the implementation of CommandQueueOpenGL just runs the corresponding GL commands immediately, but having the interface in place should help if and when we want to add a vulkan renderer.Īs for optimisations, the big one was batching, thanks to for getting that started. In vulkan you create a command queue object, and then push commands into it on whatever thread you want. For example, the RenderInstance is not in charge of dispatching draw calls, that is done by a CommandQueue. ![]() RenderInstance is subclassed into RenderInstanceOpenGL, but the application only uses the base interface from RenderInstance.ĭown the line, there’s a decent chance that we will want to add a vulkan renderer, so there is some inspiration taken from that API here. The system I went for is pretty simple, you have a RenderInstance class that is in charge of creating the GL context, as well as resources like buffers and textures. The first step was to abstract the rendering code into something cleaner, which also lets us swap out opengl down the line as well. Prior to this refactoring, freeablo’s rendering was a nasty sprawl of ad-hoc opengl and SDL related code in a huge file called sdl2backend.cpp. If you're a programmer, click here for more details about freeablo's rendering code Next steps for graphics are scaling the GUI, and there are still a lot more possible optimisations on the table, but for now I will probably move on to more gameplay-related changes (specifically ranged combat). ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
March 2023
Categories |