• Advertisement
Sign in to follow this  

OGL FBOs recommendation

This topic is 565 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello guys, yesterday I started to work on FBOs to make some render targets using cameras like Unity does, today I finished a stable code to test it but I realized it's a bit laggy depending on the entities or times I call glDrawArrays. I don't really know if it's normal or I should do it better but I'll post some code to explain myself, I need some recommendations about how to properly use this because I'm pretty sure I don't need to call glDrawArrays 2 times (1 for the FBO and another one for the real rendering).

 

This is exactly where I do the rendering:

 

glBindFramebuffer(GL_FRAMEBUFFER, 1);
glViewport(0, 0, 256, 256);
static glm::mat4 mView2 = glm::lookAt(glm::vec3(0, 70.f, 70.f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f));
Renderer->MainProgram.setUniform("EngineMatrices.ProjectionMatrix", Television.CalculateProjectionMatrix(60.f, 0.5f, 201.f));
Renderer->MainProgram.setUniform("EngineMatrices.ViewMatrix", mView2);
glDrawArrays(GL_TRIANGLES, 0, VertexSize);


glBindFramebuffer(GL_FRAMEBUFFER, 0); //cleaning buffers to render 3D models
glViewport(0, 0, Renderer->ScreenSX, Renderer->ScreenSY);


Renderer->MainProgram.setUniform("EngineMatrices.ProjectionMatrix", Renderer->GetProjectionMatrix());
Renderer->MainProgram.setUniform("EngineMatrices.ViewMatrix", Renderer->GetViewMatrix());
glDrawArrays(GL_TRIANGLES, 0, VertexSize);

After this code I update the viewport to come back to the normal rendering and I render the texture of the FBO in a plane (a plane, not a cube so I only render 1 face). Here's a picture of the frame buffer: c9186ccf4f67ac9647ccd4ec2df4be5a.jpg

 

in this case I have 1000 cubes with a total of 12 faces each one (triangulated obviously) causing a FPS drop of ~7 FPS.

 

In the next image I'll show the same but with only 600 cubes:

20f27bbc20cd5f4510643b8043893e4e.jpg

 

In this case the FPS are constant and it's stable at 59-60 FPS. I hope someone could tell me some tricks or tips about how I should render a model in both buffers with the less FPS drop possible. I also thought about occlusion but first I want to make sure this is well done. Thanks in advance.

 

Edit: Using a 8192x8192 buffer I get like 27 FPS drop.

Edited by Tonyx97

Share this post


Link to post
Share on other sites
Advertisement

I do not wonder about your 27 FPS! You should know every pixel in the buffer needs to be processed so larger buffers mean more processing on the GPU when displaying the contents and when post processing things there is even more work to do by the GPU. If you still want such buffer sizes think of going multi threaded rendering where e.g. each thread manages one render target or something like this.

 

And to answer your question, yes you need to call DrawArrays for each FBO you want to render to because swapping them by calling glBindFramebuffer means switching to a different location in memory and there isnt anything stored or obsolete in here so you need to do it again. I would also try to call glFlush command before each buffer swap so GPU may now that the buffer is finished

Share this post


Link to post
Share on other sites

As far as I know what you are doing looks fine, rendering to a framebuffer the objects from camera one, then rendering from a different camera to make the image used on the plane in the sky?.

 

If you have two objects, a cube and a plane, in different VBO's that you are going to render there will be two draw calls unless you combined them into one VBO, although having two separate makes more sense here.

 

As you are drawing a lot of cubes you might want to look into Instancing, this might give you some extra performance (depending on the number your drawing). To do this replace glDrawArrays with glDrawElementsInstanced, more information here: https://www.opengl.org/sdk/docs/man/html/glDrawElementsInstanced.xhtml

 

Generally, if you are going to draw multiple objects, you're going to have multiple draw calls.

Share this post


Link to post
Share on other sites

As you are drawing a lot of cubes you might want to look into Instancing, this might give you some extra performance (depending on the number your drawing). To do this replace glDrawArrays with glDrawElementsInstanced, more information here: https://www.opengl.org/sdk/docs/man/html/glDrawElementsInstanced.xhtml Generally, if you are going to draw multiple objects, you're going to have multiple draw calls.

 

If you are in a game engine things are preprocessed during deploy so that static meshes are backed together to safe draw calls by putting vertices into one single VBO/ VAO. Instead of calling 20 times the same mesh there vertices/normals/texcoords are 20 times copied together with other meshes depending on the hardware (setting the VBO index limit to either 16bit on portable devices and 32bit on PC/Mac)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement