Frame Rate is painfully slow

I recently decided to start using OpenGL to make myself a game engine and it was going pretty good until I started to attempt performance optimizations.
At first I was using immediate mode but I quit using it right away and went straight to VBOs. Even after switching to VBOs i still experienced tons of lag,
about 4-10 FPS. I am using C# with SharpGL as my access to OpenGL.
My test game is just set up to render chunks of cubes so that I could test performance.
Here are some factors that might help.

Triangles being rendered: 76800
VBO count: 1 (Static)
Times VBO is updated: 1
Draw Calls: 1 (glDrawArrays)
FBOs: Yes
Shaders: None
Textures: None
Finish/Flush calls: None
Culling: Enabled, CCW, Back

I’m not sure what is causing the frame rate to be so slow, I’ve been researching performance optimizations for weeks but I have found nothing that fixed my problems.
I am also aware that the low framerate could 100% be the fault of C# and/or SharpGL, and that C++ is much faster than C#.

If you need me to post any code I can do that too.

Is this once per “run” or once per “frame”?

Your perf makes it sound like you’ve flipped down into a software rendering path.

If you need my to post any code I can do that too.

That would help. Please distinguish between: 1) What’s called once on startup, versus 2) what’s called every frame (including SwapBuffers). With #1, you might include your context creation including the output of GL_RENDERER and GL_VERSION.

Thanks for the quick response!

I technically update the VBO when the float array I use to store vertex positions changes.

I do this (as well as drawing) on a timer that ticks every 1 ms (the time I set the tick to has not positively affected performance). I’m still pretty new to OpenGL so I’m not completely familiar with what SwapBuffers actually does, but I still call it.

*Note: GL11 is just a class I made because I used to use LWJGL a bit

The following code is run once every frame

First I get the models that will be rendered and add their data to the float array

            //Set the current models that should be rendered
            pinnedModals = data;
            //Add vertex data to float array inside of a object called vertexBuffer

Next I set buffer data if I have to and I make a draw call

//                                                         This variable stores the vertex data used last frame and checks if the buffer should update                                                                   
if (!compareArrays(vertexBuffer.buffer(), GL11.CURRENT_BUFFER_DATA))
                        //Set Buffer Data
                        SetData(0, vertexBuffer, false, 3, GL11.GL_STATIC_DRAW);
                        Debug.WriteLine("Updating buffer with " + vertexBuffer.getSize() + " vertices");
                    gl.DrawArrays(GL11.GL_TRIANGLES, 0, 36 * pinnedModals.Length);

Next I make a call to Blit (a function in sharpgl) which does this

if (deviceContextHandle != IntPtr.Zero)
                //  Set the read buffer.

			    //	Read the pixels into the DIB section.
			    gl.ReadPixels(0, 0, Width, Height, OpenGL.GL_BGRA, 
                    OpenGL.GL_UNSIGNED_BYTE, dibSection.Bits);

			    //	Blit the DC (containing the DIB section) to the target DC.
			    Win32.BitBlt(hdc, 0, 0, Width, Height,
                    dibSectionDeviceContext, 0, 0, Win32.SRCCOPY);

Then I make a call to Win32.SwapBuffers and im done with that frame.

Here are the calls made once when the program starts:, RenderContextType.FBO, 1, 1, 32, null);
  , 0F, 0F, 0F);
  , 4354U);

Thank you!


Edit: Here’s the link to the SharpGL source on github: sharpgl/source/SharpGL/Core/SharpGL at master · dwmkerr/sharpgl · GitHub

I did a bit of looking around my code and I realized that my problem had nothing to do with the performance of my vbo or OpenGL, the problem was the amount of looping I did to gather vertex data, after removing some unneeded loops and doing optimizations on when to update the buffer, I was able to get my frame rate back up to 500 FPS.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.