0
\$\begingroup\$

Hello i would like to present my problem here. At the moment i have a scene with about 250 trees , 100 ferns , a player model and a custom generated terrain (from height map). For the past few days i was searching about batch rendering in OpenGL which gave me some ideas about how i can render some objects (similar to batch rendering , but in my own fashion). Bellow are simple examples of my render functions which are executed each frame. I came to the conclusion that glDrawArrays takes up most ms/frame to execute(for the terrain render this line takes up about 8 ms/frame). Uploading to shaders or switching buffer bindings does affect slightly (~0.3 ms)

In Main creating Example Models can look something like (&TreeData is a reference to a object that contains model's data already bound to a certain vbo - i use 1 vbo to store all vertex data(normals,position,texcoords). So TreeData will occupy vboID 1 , FernData will occupy vboID 2 and so on. Later in the render i just rebind to the correct vbo ID and directly render.

vector<Model*>Trees
for(number of trees)
Trees.push_back(new Entity(&TreeData, ShdrBasic));
Trees.back()->Translate(vec3(randomX, Terrain1->getTerrainData()->getHeightOfTerrain((float)randomX, (float)randomY), randomY));

And the render function below which takes vector list of models and renders them all.

void EntityRenderer::RenderArray(vector<Model*> Models)
{
GLuint model_vertex_number = Models[0]->getModelData()->getVerticesSize() / sizeof(vec3);
if (Models[0]->getModelData()->getTransparency()) Models[0]->disableCulling();
glBindBuffer(GL_ARRAY_BUFFER, Models[0]->getModelData()->getVboID());
Models[0]->getActiveShader()->StartShader();
Models[0]->getActiveShader()->EnableVertexAttribArray();
Models[0]->ShaderStaticLoad();
for (int i = 0; i < Models.size(); i++)
{
    Models[i]->ShaderDynamicLoad();
    glDrawArrays(GL_TRIANGLES, 0, model_vertex_number);
}
Models[0]->getActiveShader()->DisableVertexAttribArray();
Models[0]->getActiveShader()->StopShader();
glBindBuffer(GL_ARRAY_BUFFER, 0);
Models[0]->enableCulling();
}

This simple array render function renders objects (from the same type and same data , from vector list) Shader Dynamic Load -> contains only transformation matrices: translate scale and rotate. As for the Static Shader Load -> contains vertex data, some uniform variables .. etc. As far as logic and sanity tells me this function should be relatively good in terms of performance since most of the operations are executed per frame rather than per object. The problems come when i try to render about 500+/- objects (trees + ferns) , i have a millisecond per frame function which tells me that it takes about 10 ms for the scene to render, if i add terrain to the picture the ms/frame goes up to 20 ms/frame. (And for a fact i know that 33~ ms/frame is about 30 fps)

Terrain Renderer Function. Terrain generated from height map. This terrain render functions takes up about 7-9 ms/frame to render

void TerrainRenderer::Render(Terrain* TerrainToRender)
{
glBindBuffer(GL_ARRAY_BUFFER, TerrainToRender->getTerrainData()->getVboID());
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, TerrainToRender->getTerrainData()->getIboID());
TerrainToRender->getActiveShader()->StartShader();
TerrainToRender->getActiveShader()->EnableVertexAttribArray();
TerrainToRender->LoadToShader();
glDrawElements(GL_TRIANGLES, TerrainToRender->getTerrainData()->getIndicesSize()/sizeof(GLuint), GL_UNSIGNED_INT, NULL); 
TerrainToRender->getActiveShader()->DisableVertexAttribArray();
TerrainToRender->getActiveShader()->StopShader();
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}

My Question is: Am i doing the rendering correctly , is it a problem on my side , or my PC's. I have some suspicions that my Graphics Card or/and my CPU are probably not good enough.I need to test that on other configurations. The program currently uses steady 30-33 MB of RAM during run Time. Supported OpenGL version 4.4. Drivers up to date PC Specs: CPU: AMD A8-5600K APU with GPU: AMD HD Graphics 7560D + 6500 Dual Graphics. (OFF TOPIC: some days ago i downloaded a simple 2d engine from youtube which handles batch rendering with 56k Sprites, according to the video that person is rendering those 56k sprites with ~4000 FPS, i render them with ~20-25 FPS, thats when i started to suspect my configuration)

\$\endgroup\$
  • \$\begingroup\$ What happens on another system? If you suspect this to be because of your computer then try another one. \$\endgroup\$ – Eejin Apr 10 '15 at 12:39
  • \$\begingroup\$ I will try that ASAP , i am not able to do so at the moment. But that aside i wanted to know if my approach is good , performance wise. I know its not Batch Rendering but still.... \$\endgroup\$ – user2742982 Apr 10 '15 at 12:54
  • \$\begingroup\$ UPDATE: Ruled out the PC specs. Yesterday i tested the models with some simple 1-2 line vertex and fragment shaders. With my original shaders the FPS is low ~60 Frames , but if i use the new shaders the FPS goes up to over 1650 (notice that my terrain has about ~65500 vertices) \$\endgroup\$ – user2742982 Apr 11 '15 at 6:52
1
\$\begingroup\$

If anyone is interested or stumbles upon such problem. I implemented complete batch rendering. Meaning that now i can batch render objects from the same type with one draw Call. Further more i am working on implementing a LOD algorithm for the terrain and also implementing Frutrum Culling to limit maximum objects rendered per frame. This results in huge performance boost.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.