Domanda

I've been wondering this for a while when loading in your mesh and textures and whatnot in your model class, what do you keep? I figure once the vertices are passed with glBufferData() I don't need them anymore, since the call to glDrawArrays() depends on the last glBindBuffer() This is all my Model class keeps after the loadModel() method is called.

GLuint vboID;//for... something
GLuint vaoID;//for  glBindVertexArray(vaoID);
GLuint textureID;//for glBindTexture(GL_TEXTRUE2D, textureID);
GLuint vboElementCount;//for glDrawArrays(GL_TRIANGLES,0,vboElementCount);

From what I can tell that would be all I need to render a model. Other then that what else should I keep for a simple model?

Edit: Before someone mentions position rotation scale and what have you, I have a ModelInstance class that contains the matrices for those, and I pass it a pointer to the Model object so I can have multiple instances of the same Model.

È stato utile?

Soluzione

I keep

  • VBO ids, so I can delete VBOs when I no longer need them.
  • VAO id, so I can bind before drawing and delete eventually.
  • Number of indices to pass to glDrawElements()
  • ids of all required textures.
  • Material and transformation properties (uniforms in general).

This works fine as long as meshes are static. As soon as you want to manipulate your meshes on the CPU, for example smoothen or split them, you have to keep a copy in main memory. Maybe you also want to keep a low resolution placeholder, for example for more specialized rendering techniques like occlusion culling. But again, this is a special case; your question lists everything needed for basic rendering

Note: you should think about switching to glDrawElements(). It will reduce the amount of vertex data you have to store and transfer.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top