Sign in to follow this  
MoonDemon

OpenGL Some help with optimization

Recommended Posts

MoonDemon    100
I am currently writing a little engine based on OpenGL. It will allow somebody to create a 2.5d game ( a 3d looking game based on 2d logic ) by dropping object onto a 2d map. Given the simplicity of this, I am a little concerned by the speed at which this runs on my machine. The scene comprises of backdrops (objects that will not move) and actives (objects that will move at some point). I thought that the best idea would be to draw all of the backdrop objects into a display list. Is this a good idea? The majority of the scene is drawn into a display list. I don't know if this would cause problems given the size of the scene? I have been trying to work out where the bottleneck in the system is and I think it comes from a vertex limitation. My scenes are very simple in the sense that there's no fancy lighting, no texture filtering: it's all very primitive in the grand scheme of things, and almost looks like a raycast engine, so I would expect a higher framerate than what I am getting on my machine. I am surprised that shrinking the farplane value doesn't yield a performance increase. Any insights on this would be very helpful :)

Share this post


Link to post
Share on other sites
swiftcoder    18437
A screenshot of what you are currently rendering would be helpful, as would letting us know just how bad the performance is, and on what hardware.

Keep in mind that performance rarely scales in a linear fashion, and frames-per-second isn't a linear measure of performance either.
Quote:
I thought that the best idea would be to draw all of the backdrop objects into a display list. Is this a good idea?
It is certainly a good first step. However, display lists can only optimise if you hand them very specific configurations of vertex data (i.e. all components present for all vertices), so you may not be getting much benefit at the moment.

I would recommend switching to VBO, but this may be a fair amount of work to implement if your current code is not designed with vertex-arrays/VBO in mind.
Quote:
I am surprised that shrinking the farplane value doesn't yield a performance increase.
This would only affect the number of fragments processed (and often minimally at that), since all vertices still have to be transformed and clipped. If you are indeed vertex bound, reducing the far plane distance will not help.

Share this post


Link to post
Share on other sites
coordz    130
If you are vertex bound you probably want to get some culling on the go before you pass the vertices to the GL. It sounds like you're dropping pre-baked objects in a repeating way? If (as swiftcoder suggests) you use VBOs and create these for each object you could then use instancing and some sort of geometry shader culling of the instances. At the very least simple bounding spheres on the CPU side should be used to cut down on the amount of geometry to be processed.

Share this post


Link to post
Share on other sites
MoonDemon    100
Unfortunately I can't produce an image of the said scene (captain's orders), but I can describe it... The user drops squares/cubes onto a 2d grid which represent textured cubes/cuboids in a 3d space. The position of the square in 2d specifies the cube/cuboids x and z position and dimensions, and the object has additional variables for specifying the cube's height and y position. The user is able to specify a texture for each of the 6 faces, and not specifying a texture at all results in that quad not being rendered. In this case there are a lot of redundant quads as the user has specified textures on cube faces that are touching, but I figured it's not exactly the cause of the problem.

I have had numerous thoughts about how to optimise this. At the moment my approach is a little clumsy. For each object in the scene, the "draw cube" function is called. This function draws a maximum of 6 quads, binds their texures and specifies the texture coordinates. In any one scene I can call this function about 200 times. I figured it would be nice and easy to do this just the once and compile those commands into a display list. This makes it very easy for me to redraw the scene with just one call. However I am pretty sure this isn't the most efficient approach.

My first thought was that binding the texture each time is pretty inefficient. I could group quads by texture and draw them in a sorted order. I don't suppose OpenGL can optimise this for me (but it would be awfully nice if it did).

Secondly I could cull a lot of those cubes myself. Clearly not possible with my current displaylist approach. I imagine I could half the number of vertices being used to render the scene.

I do render everything with backface culling turned on, there's no lighting, the texturing mode is GL_DECAL instead of the default GL_MODULATE. The machine I am testing this with has an AMD Turion X2 processor @1.60GHz, 2GB ram and comes with a rather low end integrated ATI graphics card (Xpress 1150 I think). I installed the drivers for my card (ATI's legacy Xpress graphics driver) and the previous owner seemed to play Guildwars on it fine (though with medium/low graphic settings). I would expect the app I am running to do a little better on this spec as I would consider it lightweight (and I would consider this machine more than capable of rendering this in software). At the moment it runs at about 30fps, where my target is 50. Unfortunately I am unable to disconnect the logic speed from the rendering speed with the tools I am using. Obviously this is quite hideous in concept but I have to live with that. I don't think this is too ambitious, but may stand corrected?

Thanks for your help guys.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Similar Content

    • By pseudomarvin
      I assumed that if a shader is computationally expensive then the execution is just slower. But running the following GLSL FS instead just crashes
      void main() { float x = 0; float y = 0; int sum = 0; for (float x = 0; x < 10; x += 0.00005) { for (float y = 0; y < 10; y += 0.00005) { sum++; } } fragColor = vec4(1, 1, 1 , 1.0); } with unhandled exception in nvoglv32.dll. Are there any hard limits on the number of steps/time that a shader can take before it is shut down? I was thinking about implementing some time intensive computation in shaders where it would take on the order of seconds to compute a frame, is that possible? Thanks.
    • By Arulbabu Donbosco
      There are studios selling applications which is just copying any 3Dgraphic content and regenerating into another new window. especially for CAVE Virtual reality experience. so that the user opens REvite or CAD or any other 3D applications and opens a model. then when the user selects the rendered window the VR application copies the 3D model information from the OpenGL window. 
      I got the clue that the VR application replaces the windows opengl32.dll file. how this is possible ... how can we copy the 3d content from the current OpenGL window.
      anyone, please help me .. how to go further... to create an application like VR CAVE. 
       
      Thanks
    • By cebugdev
      hi all,

      i am trying to build an OpenGL 2D GUI system, (yeah yeah, i know i should not be re inventing the wheel, but this is for educational and some other purpose only),
      i have built GUI system before using 2D systems such as that of HTML/JS canvas, but in 2D system, i can directly match a mouse coordinates to the actual graphic coordinates with additional computation for screen size/ratio/scale ofcourse.
      now i want to port it to OpenGL, i know that to render a 2D object in OpenGL we specify coordiantes in Clip space or use the orthographic projection, now heres what i need help about.
      1. what is the right way of rendering the GUI? is it thru drawing in clip space or switching to ortho projection?
      2. from screen coordinates (top left is 0,0 nd bottom right is width height), how can i map the mouse coordinates to OpenGL 2D so that mouse events such as button click works? In consideration ofcourse to the current screen/size dimension.
      3. when let say if the screen size/dimension is different, how to handle this? in my previous javascript 2D engine using canvas, i just have my working coordinates and then just perform the bitblk or copying my working canvas to screen canvas and scale the mouse coordinates from there, in OpenGL how to work on a multiple screen sizes (more like an OpenGL ES question).
      lastly, if you guys know any books, resources, links or tutorials that handle or discuss this, i found one with marekknows opengl game engine website but its not free,
      Just let me know. Did not have any luck finding resource in google for writing our own OpenGL GUI framework.
      IF there are no any available online, just let me know, what things do i need to look into for OpenGL and i will study them one by one to make it work.
      thank you, and looking forward to positive replies.
    • By fllwr0491
      I have a few beginner questions about tesselation that I really have no clue.
      The opengl wiki doesn't seem to talk anything about the details.
       
      What is the relationship between TCS layout out and TES layout in?
      How does the tesselator know how control points are organized?
          e.g. If TES input requests triangles, but TCS can output N vertices.
             What happens in this case?
      In this article,
      http://www.informit.com/articles/article.aspx?p=2120983
      the isoline example TCS out=4, but TES in=isoline.
      And gl_TessCoord is only a single one.
      So which ones are the control points?
      How are tesselator building primitives?
    • By Orella
      I've been developing a 2D Engine using SFML + ImGui.
      Here you can see an image
      The editor is rendered using ImGui and the scene window is a sf::RenderTexture where I draw the GameObjects and then is converted to ImGui::Image to render it in the editor.
      Now I need to create a 3D Engine during this year in my Bachelor Degree but using SDL2 + ImGui and I want to recreate what I did with the 2D Engine. 
      I've managed to render the editor like I did in the 2D Engine using this example that comes with ImGui. 
      3D Editor preview
      But I don't know how to create an equivalent of sf::RenderTexture in SDL2, so I can draw the 3D scene there and convert it to ImGui::Image to show it in the editor.
      If you can provide code will be better. And if you want me to provide any specific code tell me.
      Thanks!
  • Popular Now