OpenGL optimizations

Started by
8 comments, last by RAZORUNREAL 17 years, 7 months ago
Hi! im currently working on a 2d physicsbased engine for a game i and my girfriend are about to make. i have implemented the rigid body physics and optimized it with a quadtree. all and all the physics runns at about 150 fps with pretty damn many objects but when i start to render them it drops drasticly. accually it isnt that wierd since ive not started to optimize the rendering sequence (dont even have a frustum) so, before i start i really would like some tips about getting most out of opengl and rendering. and i am also wondering: 1. is a sdl window better than a windows window (i dont really care about xplatform at the moment) 2. is a quad with texture better than the gldrawpixels alternative 3. is there any opngl window optimizations i could do? now, let the keyboard melt by the force of your fingers.
Advertisement
Quote:so, before i start i really would like some tips about getting most out of opengl and rendering.

There's a number of things. First are non-graphics-related issues like function overhead and inlining, searching, etc. Optimizing your physics update is also key, since you probably want to save most of your CPU power for rendering at a decent rate. Then there's rendering optimizations; scene graphs and spatial sorting, frustum/viewport culling, occlusion culling, dynamic/automatic level of detail, shaders, etc.

Quote:1. is a sdl window better than a windows window (i dont really care about xplatform at the moment)

I'd imagine so. Don't know to tell you the truth.

Quote:2. is a quad with texture better than the gldrawpixels alternative

Probably.

Quote:3. is there any opngl window optimizations i could do?

It all depends on your exact implementation. Technically, there is no concept of a window in OpenGL (only a viewport).
http://blog.protonovus.com/
Quote:Original post by swordfish


Quote:1. is a sdl window better than a windows window (i dont really care about xplatform at the moment)

I'd imagine so. Don't know to tell you the truth.


A SDL window is implemented in the SDL library through a windows window.

Lizard

Quote:Original post by vulh102
2. is a quad with texture better than the gldrawpixels alternative

Yes.
Remember to use textures with power-of-2 dimensions, though.
Quote:Original post by vulh102
and i am also wondering:
1. is a sdl window better than a windows window (i dont really care about xplatform at the moment)

2. is a quad with texture better than the gldrawpixels alternative

3. is there any opngl window optimizations i could do?



1. There is no difference. SDL uses the underlying window manager functionality of the operating system (i.e. CreateWindowEx()) Now if you talked about Linux then there could be some differences in the efficiency of window managers (I suppose), but that's definitely not the point to start optimizing your app.

2. glDrawPixels and glReadPixels are extremely slow usually. The proper way to do 2D rendering in OpenGL is setting up ortho mode and drawing textured quads. Whether you do this with glBegin/glEnd, or by other means, will be your next optimization step.

3. You could test running the app in different bit depths. 16bit might perform very different than 32bit.
Quote:Original post by swordfish

Then there's rendering optimizations; scene graphs and spatial sorting, frustum/viewport culling, occlusion culling, dynamic/automatic level of detail, shaders, etc.




Now thats the stuff i want to hear.

frustom isnt a big deal to create, scince it is 2d

heard of occlusion culling, but never looked into it (will do that now)

for lod i think mipmaps will suffice, since its all just triangle quads with textures


i never heard of scene graphs (gonna google it) so some links would be nice

and ive never tuched shaders so i would like som more information about that too.

by the way, thansk for all the replies

Quote:i never heard of scene graphs (gonna google it) so some links would be nice

A scene graph isn't an optimization (actually it creates additional overhead), but it is a way to organize all objects in your scene.
Basically it is a tree where every node has it's own local transformation matrix and it's global transformation depends on this local matrix multiplied with the global transformation of it's parent.

Quote:and ive never tuched shaders so i would like som more information about that too

It is a way to create pixel and vertex effects faster by rendering them on the GPU insted on the CPU. But I guess you don't have any fancy vertex or pixel effects you are now computing on your CPU...

Cheers,
Constantin
ok, well. some effects will come later when i have a good rendering pipe

im gonna do glow and blur, so i will use the accumulation buffer for that.

i think i will manage now, thanks for the replies
For culling you might want to take a look at this article on flipcode
http://www.flipcode.com/articles/article_frustumculling.shtml

It also discusses quadtrees or maybe octrees
Firstly, as others have said, use textured quads. But from there, you have to work out where your problem lies. The bottleneck may lie in a few places.
1. The CPU. I'm not sure how to tell if the CPU is having a hard time or if it's just waiting for the gpu, so I just try it on a better graphics card. If it doesn't speed up, you need to profile and optimise your code.
2. The vertex pipeline of the GPU. It's fairly easy to check this, just draw loads of quads with all 4 vertices in the same place, so they aren't actually drawn. If it doesn't improve, that's where your problem is.
3. If it did improve in the last test, it must be the pixel pipeline of the GPU. To be sure, just draw your quads really big and see if it slows down more.

Once you've tried all that, you should have a reasonable guess as to what the problem might be. And you can ask more pointed questions.
___________________________________________________David OlsenIf I've helped you, please vote for PigeonGrape!

This topic is closed to new replies.

Advertisement