Hello Guest

Recent Posts

Pages: 1 [2] 3 4 ... 10
11
OpenGL / Re: Improving Performance of Rendering 2D Tiled Terrain
« Last post by Setlock on November 06, 2018, 15:57:09 »
Can you link your code?

Code: [Select]
public void render(Map<TexturedModel,List<Entity>> entities)
{
for(TexturedModel model : entities.keySet())
{
if(model!= null)
{
prepareTexturedModel(model);
pointer = 0;
List<Entity> batch = entities.get(model);
float[] vboData = new float[batch.size() * INSTANCE_DATA_LENGTH];
for(Entity entity : batch)
{
updateTransform(entity,vboData);
}
Artist.loader.updateVbo(vbo, vboData, buffer);

GL31.glDrawArraysInstanced(GL11.GL_TRIANGLE_STRIP, 0, quad.getVertexCount(), batch.size());

unbindTexturedModel();
}
}
}

updateTransform simply creates a new transformation matrix and stores it in the vbo, I havent correctly implemented storing the color and lighting values but obviously that would be implemented later, in the same way as the transformation matrix.
12
OpenGL / Re: Improving Performance of Rendering 2D Tiled Terrain
« Last post by mudlee on November 06, 2018, 13:22:12 »
Can you link your code?
13
OpenGL / Re: Improving Performance of Rendering 2D Tiled Terrain
« Last post by Setlock on November 06, 2018, 12:57:27 »
Let's first make an obvious observation based on the performance figures:
"You called glDrawElements - and now glDrawElementsInstanced - 2800 times per frame, each call rendering a single quad." Right?
And a single quad is what you called an "Entity" and your for loop ranged over 2800 "entities" (i.e. quads). Right?

Instead of calling glDrawElements 2800 times and each call rendering a single quad (or two triangles), you should call glDrawElements exactly once (per material/texture) per frame.

The problem is that you are making _assumptions_ about where performance is going to hurt. And one of your assumptions was that rendering a visible quad takes more time than rendering an invisible quad. That's why you collected all visible quads in a list and then looped over each quad/entity and render it with a single draw call.
The truth/reality is that issuing a single draw call is veeeeery costly. Doing a single call to glDrawElements which renders a million _invisible_ quads is far faster than doing 3000 calls of glDrawElements each rendering 1 _visible_ quad. So the goal is not to reduce the amount of visible vs. invisible quads but rather reducing the amount of _draw calls_ you are doing.

So first actually I lied sorry, there was an FPS increase of about 10 frames after implementing instanced rendering but it wasnt the performance change I had hoped for. I only call glDrawElementsInstanced once per texture, and currently there are no more than 6 textures that are changing(once I implement texture atlases I will of course switch to those). Secondly isnt that what glDrawElementsInstanced is supposed to do? So I store all the information about a quad like position, color, texture coords, etc. and update the relevant information once per object, so really I loop through all the objects changing the information about its world position, color, lighting etc, and store that back in the VAO. Then after doing that it renders all of them with glDrawElementsInstanced. Thats how I currently do it, but it has only provided a small FPS increase but it really may come down to the hardware im testing this on, im running this on the worse laptop possible in order to heavily optimize it so it will run fine on any average computer, so it may just be hardware limitations but if you have any other thoughts im really happy to hear them, thanks for all the help!
14
OpenGL / Re: Improving Performance of Rendering 2D Tiled Terrain
« Last post by Cornix on November 06, 2018, 12:13:09 »
What KaiHH says is generally correct but also keep in mind that multiple draw calls are not that bad as long as there are no state changes in between. Drivers can oftentimes optimize these calls quite well.
As I tried to allude to in my first post: Before you try to "optimize" the performance of your code you need to actually understand where the time is lost. Do some profiling, find out the big time costs and then experiment. Without proper measuring you will run around in circles chasing invisible targets.
15
OpenGL / Re: Improving Performance of Rendering 2D Tiled Terrain
« Last post by KaiHH on November 06, 2018, 09:21:01 »
Let's first make an obvious observation based on the performance figures:
"You called glDrawElements - and now glDrawElementsInstanced - 2800 times per frame, each call rendering a single quad." Right?
And a single quad is what you called an "Entity" and your for loop ranged over 2800 "entities" (i.e. quads). Right?

Instead of calling glDrawElements 2800 times and each call rendering a single quad (or two triangles), you should call glDrawElements exactly once (per material/texture) per frame.

The problem is that you are making _assumptions_ about where performance is going to hurt. And one of your assumptions was that rendering a visible quad takes more time than rendering an invisible quad. That's why you collected all visible quads in a list and then looped over each quad/entity and render it with a single draw call.
The truth/reality is that issuing a single draw call is veeeeery costly. Doing a single call to glDrawElements which renders a million _invisible_ quads is far faster than doing 3000 calls of glDrawElements each rendering 1 _visible_ quad. So the goal is not to reduce the amount of visible vs. invisible quads but rather reducing the amount of _draw calls_ you are doing.
16
OpenGL / Re: Improving Performance of Rendering 2D Tiled Terrain
« Last post by mudlee on November 06, 2018, 04:34:54 »
Have you measured you render time? Measure how much time the glfwSwapBuffers takes, also the glDrawElementsInstanced.
Those should be around 0ms-10ms. If so, you performance problem is somewhere in the Java code.
17
OpenGL / Re: Improving Performance of Rendering 2D Tiled Terrain
« Last post by Setlock on November 06, 2018, 02:31:27 »
First step would be to render the tiles instanced. That will help, but of course, cornix asked the right question too.
Instanced rendering: https://ahbejarano.gitbook.io/lwjglgamedev/chapter21

So ive applied instance rendering and it hasnt helped performance at all, I would like to get it running at 60 fps on the extremely low end machine(its currently running at 30-50 depending on how many tiles are on screen) but maybe that just isnt possible, Im not sure what else I can do to increase FPS, im really only drawing 2800 squares at max currently, but maybe this is just to much for such a low end machine.
18
OpenGL / Re: Improving Performance of Rendering 2D Tiled Terrain
« Last post by Setlock on November 04, 2018, 20:39:17 »
First step would be to render the tiles instanced. That will help, but of course, cornix asked the right question too.
Instanced rendering: https://ahbejarano.gitbook.io/lwjglgamedev/chapter21

I think instance rendering is what I’ll be going for, since I’m only ever drawing squares I think that’s the best way to do that, then for other things I’ll just stick with my usual batch rendering, thanks
19
OpenGL / Re: Improving Performance of Rendering 2D Tiled Terrain
« Last post by Setlock on November 04, 2018, 18:45:25 »
What have you measured? What is your bottleneck?

If you want to "optimize" something you better know how good it is right now and how good it needs to be.

I assume its the number of vertices that I need to process, I make sure to only render the things that are directly on screen, and of course I try to do my work on a pretty bad system so I can make it highly optimized so I know that it will run well on any average machine, the laptop I use right now has an Intel Celeron N2840 CPU and simply Intel HD graphics for the GPU so obviously it isnt great for games in the first place, but I dont feel that rendering a bunch of squares should be extremely difficulty, but it runs at 40-50FPS. So really I think I need to decrease the amount of entity processing calls I make.
20
OpenGL / Re: Improving Performance of Rendering 2D Tiled Terrain
« Last post by mudlee on November 04, 2018, 17:57:26 »
First step would be to render the tiles instanced. That will help, but of course, cornix asked the right question too.
Instanced rendering: https://ahbejarano.gitbook.io/lwjglgamedev/chapter21
Pages: 1 [2] 3 4 ... 10