Sign in to follow this  
Tesserex

OpenGL The more efficient way to do primitives?

Recommended Posts

Before I get too deep in my program and end up doing an overhaul, I think I'd rather get it right the first time. I'm writing some classes and methods to draw various opengl primitives like the 2d faces, and then the next level up, drawing whole cubes and pyramids and such. I don't know which is better for the 3d objects: storing the data on the points, or data on the faces. Here's my pro/con breakdown: Note: for "points" I have written a struct containing x,y,z,red,green,blue. "Faces" are a struct of three or four points. Storing points: PRO - Smaller total data storage, no redundant information - Transformations performed once per point to save processing time CON - Functions that draw objects will have to be more literal, taking four points for a pyramid and explicitly drawing each face. The alternative is constructing four triangles on the fly and then drawing those. This takes more processing time per frame. - Cannot store differing color information for each face without some other method I haven't thought of yet. Storing as faces: PRO - Since faces are already constructed, only the face-drawing function needs to be called each frame. They don't need to be rebuilt out of points. - Each face can store it's own color and texture information. CON - Faces that share points store redundant data on them, waste of memory. - Redundant points are transformed repeatedly by rotations, waste of processing. Is there some happy medium here? Or is one just better than the other and I haven't realized it yet? Does it matter / depend on the type of program I'm creating? What do you usually do?

Share this post


Link to post
Share on other sites
Look into drawing meshes as indexed primitives. You can store your vertices as arrays, and draw whole strips of triangles in a single call if your data is organized correctly. Storing a mesh as individual triangles is probably not the best way to go. Any vertices that are identical (same position, normal, color and tex coords, other attributes) should be merged into a single vertex and the whole assembly drawn as a triangle strip if possible. Streamlining your data like this makes it easier to cache and can greatly boost performance.

Share this post


Link to post
Share on other sites
Where do you suggest I store data pertaining to vertices that have one color for one face and another for an adjacent face? Should I just make those objects as composites of faces then as a special case? Like a "cube" is one color or corner blended colors, but a "open box with a different colored top" is something else, made of four quads?

Share this post


Link to post
Share on other sites
If a vertex has 2 different colors then it needs to be treated as 2 vertices. If all your polygons are flat-shaded, then they'll need to be treated as collections of faces, and triangle-strips go out the window. Vertices are identical only if all attributes are identical.

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