Results 1 to 9 of 9

Thread: Having trouble with glDrawElements and triangles

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #6
    PGD Staff / News Reporter phibermon's Avatar
    Join Date
    Sep 2009
    Location
    England
    Posts
    524
    you'll find that most model formats intended to be rendered on a GPU will be stored as plain old triangles. (sometimes strips but fans only make sence with certain patches of geometry)

    It was the case many years ago that some game engines stored models as a combination of tris/strips/fans so you were passing less data to the GPU, but :

    A) Today in almost all practical 3D model cases, it's slower to make multiple calls to glDrawElements (splitting a model into tris/strips/fans) than it is to pass more data than is technically needed (just GL_TRIANGLES)

    B) For various reasons such as using multiple textures/materials on a single model, you'll need to clone any verticies that are shared but have different normals/UVs. Strips/Fans share verticies by definintion so when using an index buffer, you can't have different UVs/Normals per face, for the same vertex.

    --

    So you'll often find you'll need to 'unwrap' shared verticies/uvs/normals. For example a vertex may be shared between two faces but those faces may have different materials or require lighting in unique ways (so different normals for a vertex, per face. think smoothing groups in the wavefront .obj format)

    That's not to say there won't be shared vert/norm/uv sets. Basic rule of thumb is to identify any unique sets of vert/norm/uv and ensure that each unique combination has it's own index.

    My engine (JenJin) has several model plugins that load into a generic data structure, depending on how a particular model format is stored I can either unwrap shared verts/uvs/normals as I load or do another pass after the data is loaded. (only for importing model formats of course, you don't want to be hogging the CPU in a game release, store your objects in a binary format with a layout that lets you get the data to the GPU with the bare minimum of pre-processing)

    After unwrapping it's off to the GPU. It's normal to generate index buffers per material (I've not come across a method of drawing sub-sets of a shared index buffer with glDrawElements but if I'm being blind someone please enlighten me)

    Be sure to replicate any per vertex data in this process, for example if you're loading bone weights they'll need to cloned along with the vertex.

    --

    Long story short : use GL_TRIANGLES for almost everything, it's your only practical choice for models using multiple materials.

    Only use fans/strips for special geometry cases that use a single, continually mapped texture (a sky dome for example) but you'd have to be drawing a lot of this special case geometry to make it worth optimizing.
    Last edited by phibermon; 23-07-2012 at 10:45 PM.
    When the moon hits your eye like a big pizza pie - that's an extinction level impact event.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •