Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualjmakitalo

Posted 20 January 2013 - 02:34 PM

"Should I put all vertex data to a single VBO?"

Whereever possible, yes. It means the whole vertex will be pulled into a cache at the same time. By having multiple VBOs, you're using multiple memory units which means multiple caches need to be loaded. Each will contain the vertex data for more vertices, but that's not necessarily useful; if you use the coords for a vertex, you'll use the normal data and probably quite soon, so the memory effort in loading it is useful.

If you have multiple memory units loading many verts into their cache, their effort may well be wasted -- touching vertex V implies nothing about when or even whether you will need the data for vertex V+1.

"If a group has, say 4000 polygons (which could happen for the player models), is it advisable to call glDrawElements once for the whole chunk, or should I cut it into pieces?"

Do the whole thing. Reason; let the driver do the optimisation work. It knows what shape the hardware is, and you don't. Don't try and second guess it unless you have a known crap driver you're trying to work round. Some drivers, for example, may take the min/max vert index and transform everything in that range and then bin the unused values. If you unchunk the data, they'll obviously waste more time on unused nodes. For the same sorts of reasons, try and make sure all the verts in a chunk are adjacent in your VBO.

You're also likely to transform verticies on the split boundaries more than once, whereas as one draw, they'll likely only be done once.
Ok, thanks for your insight. And I guess that interleaving is useful, if all attributes are used, but maybe not so if only e.g. position data is used (like for shadowmaps).

I'm thinking of writing a VBO manager that is passed to mesh classes and such to unify vertex data management. I was thinking of writing two classes: CVertexArrayObject to store one vbo for attributes, a vertex array object and one index buffer, and CVertexArrayManager, which would create new vertex arrays whenever a buffer size exceeds some threshold. Something like
class CVertexArrayObject
{
private:
  GLuint vaoID;
  GLuint vboID;
  GLuint indexID;
// ...
};

class CVertexArrayManager
{
private:
  std::vector<CVertexArrayObject*> objects;

  // ...

public:
  CVertexArrayManager();
  ~CVertexArrayManager();

  // Maximum buffer sizes.
  void setVertexBufferSize(int _vbSize);
  void setIndexBufferSize(int _ibSize);

  // Request new buffer, which is identified by index to object
  // and offset within the buffer of the object.
  bool allocateVertexBuffer(int size, int &objectIndex, int &offset);
  bool allocateIndexBuffer(int size, int &objectIndex, int &offset);

  // Bind object for rendering (vertex attribute buffers and index buffer).
  void bindObject(int objectIndex);

  // Write index data to allocated buffer.
  void fillIndexBuffer(int objectIndex, int offset, GLushort *indices, int nindices);

  // Write vertex data to allocated buffer.
  // Data is a struct array containing interleaved data.
  template <class T>
  void fillVertexBuffer(int objectIndex, int offset, const T *data, int size);
};

An instance of the manager would then be passed to a mesh class, which would fill the buffers with its data. What do you think?

#2jmakitalo

Posted 20 January 2013 - 02:34 PM

"Should I put all vertex data to a single VBO?"

Whereever possible, yes. It means the whole vertex will be pulled into a cache at the same time. By having multiple VBOs, you're using multiple memory units which means multiple caches need to be loaded. Each will contain the vertex data for more vertices, but that's not necessarily useful; if you use the coords for a vertex, you'll use the normal data and probably quite soon, so the memory effort in loading it is useful.

If you have multiple memory units loading many verts into their cache, their effort may well be wasted -- touching vertex V implies nothing about when or even whether you will need the data for vertex V+1.

"If a group has, say 4000 polygons (which could happen for the player models), is it advisable to call glDrawElements once for the whole chunk, or should I cut it into pieces?"

Do the whole thing. Reason; let the driver do the optimisation work. It knows what shape the hardware is, and you don't. Don't try and second guess it unless you have a known crap driver you're trying to work round. Some drivers, for example, may take the min/max vert index and transform everything in that range and then bin the unused values. If you unchunk the data, they'll obviously waste more time on unused nodes. For the same sorts of reasons, try and make sure all the verts in a chunk are adjacent in your VBO.

You're also likely to transform verticies on the split boundaries more than once, whereas as one draw, they'll likely only be done once.
Ok, thanks for your insight. And I guess that interleaving is useful, if all attributes are used, but maybe not so if only e.g. position data is used (like for shadowmaps).

I'm thinking of writing a VBO manager that is passed to mesh classes and such to unify vertex data management. I was thinking of writing two classes: CVertexArrayObject to store one vbo for attributes, a vertex array object and one index buffer, and CVertexArrayManager, which would create new vertex arrays whenever a buffer size exceeds some threshold. Something like
class CVertexArrayObject
{
private:
  GLuint vaoID;
  GLuint vboID;
  GLuint indexID;
// ...
};

class CVertexArrayManager
{
private:
  std::vector<CVertexArrayObject*> objects;

  // ...

public:
  CVertexArrayManager();
  ~CVertexArrayManager();

  // Maximum buffer sizes.
  void setVertexBufferSize(int _vbSize);
  void setIndexBufferSize(int _ibSize);

  // Request new buffer, which is identified by index to object
  // and offset within the buffer of the object.
  bool allocateVertexBuffer(int size, int &objectIndex, int &offset);
  bool allocateIndexBuffer(int size, int &objectIndex, int &offset);

  // Bind object for rendering (vertex attribute buffers and index buffer).
  void bindObject(int objectIndex);

  // Write index data to allocated buffer.
  void fillIndexBuffer(int objectIndex, int offset, GLushort *indices, int nindices);

  // Write vertex data to allocated buffer.
  // Data is a struct array containing interleaved data.
  template <class T>
  void fillVertexBuffer(int objectIndex, int offset, const T *data, int size);
};

An instance of the manager would then be passed to a mesh class, which would fill the buffers with its data. What do you think?

#1jmakitalo

Posted 20 January 2013 - 01:34 PM

"Should I put all vertex data to a single VBO?"

 

Whereever possible, yes. It means the whole vertex will be pulled into a cache at the same time. By having multiple VBOs, you're using multiple memory units which means multiple caches need to be loaded. Each will contain the vertex data for more vertices, but that's not necessarily useful; if you use the coords for a vertex, you'll use the normal data and probably quite soon, so the memory effort in loading it is useful.

 

If you have multiple memory units loading many verts into their cache, their effort may well be wasted -- touching vertex V implies nothing about when or even whether you will need the data for vertex V+1.

 

"If a group has, say 4000 polygons (which could happen for the player models), is it advisable to call glDrawElements once for the whole chunk, or should I cut it into pieces?"

 

Do the whole thing. Reason; let the driver do the optimisation work. It knows what shape the hardware is, and you don't. Don't try and second guess it unless you have a known crap driver you're trying to work round. Some drivers, for example, may take the min/max vert index and transform everything in that range and then bin the unused values. If you unchunk the data, they'll obviously waste more time on unused nodes. For the same sorts of reasons, try and make sure all the verts in a chunk are adjacent in your VBO.

 

You're also likely to transform verticies on the split boundaries more than once, whereas as one draw, they'll likely only be done once.

Ok, thanks for your insight. And I guess that interleaving is useful, if all attributes are used, but maybe not so if only e.g. position data is used (like for shadowmaps).

 

I'm thinking of writing a VBO manager that is passed to mesh classes and such to unify vertex data management. I was thinking of writing two classes: CVertexArrayObject to store one vbo for attributes, a vertex array object and one index buffer, and CVertexArrayManager, which would create new vertex arrays whenever a buffer size exceeds some threshold. Something like

 


class CVertexArrayObject
{
private:
  GLuint vaoID;
  GLuint vboID;
  GLuint indexID;
// ...

}; class CVertexArrayManager { private: std::vector<CVertexArrayObject*> objects; // ... public: CVertexArrayManager(); ~CVertexArrayManager(); // Maximum buffer sizes. void setVertexBufferSize(int _vbSize); void setIndexBufferSize(int _ibSize); // Request new buffer, which is identified by index to object // and offset within the buffer of the object. bool allocateVertexBuffer(int size, int &objectIndex, int &offset); bool allocateIndexBuffer(int size, int &objectIndex, int &offset); // Bind object for rendering (vertex attribute buffers and index buffer). void bindObject(int objectIndex); // Write index data to allocated buffer. void fillIndexBuffer(int objectIndex, int offset, GLushort *indices, int nindices); // Write vertex data to allocated buffer. // Data is a struct array containing interleaved data. template <class T> void fillVertexBuffer(int objectIndex, int offset, const T *data, int size); };

 

An instance of the manager would then be passed to a mesh class, which would fill the buffers with its data. What do you think?


PARTNERS