DisplayLists, VBOs, or neither?

Started by CodeBunny, April 07, 2011, 13:59:02

Previous topic - Next topic

CodeBunny

So, for my 2D engine I have an Image class which basically is a textured quad and convenience methods for drawing and loading it. The standard way of drawing an image is

GL11.glBegin(GL11.GL_QUADS);
		
				float width = (float) (getWidth()/2);
				float height = (float) (getHeight()/2);
		
				GL11.glTexCoord2f(0, 0);
				GL11.glVertex2f(-width, -height);
		
				GL11.glTexCoord2f(texture.getWidth(), 0);
				GL11.glVertex2f(width, -height);
		
				GL11.glTexCoord2f(texture.getWidth(), texture.getHeight());
				GL11.glVertex2f(width, height);
		
				GL11.glTexCoord2f(0, texture.getHeight());
				GL11.glVertex2f(-width, height);
			
			GL11.glEnd();


In the spirit of optimization, I put this into a DisplayList, because 1) this call is static, since I want to draw an entire image and am not mapping it to a complex mesh, and 2) using one call is faster and shorter than 12, 10 of which point to OpenGL.

However, I'm not sure if a VBO would be better. Would it be? I know DisplayLists have a bit of overhead in their creation, but since I load images once and then cache them for future use, that probably doesn't matter when compared to loading in the texture.

Also, the performance gain I'm getting must be miniscule, so: is it even worth it to put this into a display list or VBO at all?

spasi

Generally speaking, you shouldn't use immediate mode rendering these days. Both glBegin/glEnd and display lists have been deprecated and you're supposed to be using VBOs for everything. It won't be slower for sure and if you have to support some other platform one day (say a mobile device with OpenGL ES), your code will work unchanged with VBOs. In practice, both immediate mode and DLs are supported by modern drivers but, like many things in OpenGL, just because it's there doesn't mean you should be using it.

Whether or not VBOs/DLs will be faster depends on several factors, like how many sprites you're rendering, how much overdraw there is in the scene, how easy it is to hit the fill-rate limit of the target hardware, etc. See this thread on JGO for some examples of super-fast sprite rendering. At the very least you should be aiming for a technique (or combinations of techniques) that maximizes the amount of data you can store in static VBOs and minimizes the stuff that need to change per-frame. The less data uploaded from the CPU to the GPU per-frame the better performance will be. It all depends on your target hardware.

CodeBunny

That's good to know about VBOs. I'll convert the code.

I've given up hope of a super-optimized end product - I'm just a freshman in college who's learning this stuff online. Since the engine is going to be open source, my hope is that people will find it useful enough to begin developing in it actively. Even if that fails, I'm getting good enough performance for my own games, so I'll still be happy.

CodeBunny

I'm finding the VBO tutorial a little confusing, especially because I haven't done anything with vertex arrays at all before this.

So, I create the VBO ID via the method in the tutorial. What is it for? Is that an id for the VBO as a whole, or is that an id of one of the component buffers?

And, the example doesn't give enough detail, it just shows pieces of the process. I think I'd get it more if I saw the entire rendering code from start to finish, but it's a little disjointed (I realize that does help the tutorial step-by-step, but it hides the big picture a little bit).

So: does anyone have any code where they create a textured quad in a VBO, and then draw it? It'd be very helpful and I would be very grateful.