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)