Let me start off by saying that I am not overly concerned with optimization right now (maybe I should be?), it’s more important that I get something that just works. I have spent a lot of time with 2D programming and am trying to make the leap into 3D. I am concentrating on OpenGL 3. While I’ve enjoyed making floating triangles and cubes, I think it’s time for something a little more substantial. I am right now trying to develop a 3D entity class and I am not totally sure what goes where. In a 2D setting, I am very comfortable with something like the following:
public class Entity2D {
private float x, y;
Sprite sprite;
... // other instance variables and methods
public void drawMe(Graphics g) {
sprite.draw(g, x, y); // maybe you also translate by some world coordinates, whatever!
... // draw other things that have to do with this entity, HP bars, armor, etc.
}
... // more stuff , update(float delta), etc...
}
and this kind of structure makes sense to me. But now in OpenGL there is a lot more information, and I am having a difficult time deciding who (which object) owns that data. Is a Mesh object just a collection of 3d points, a VAO, a VAO and a texture, a VAO a texture and what shader program to use, etc… It doesn’t seem unreasonable to me that different entities would use the same vertex data, but a different texture for instance. Or that sometimes you would want to render a mesh with one shader program, and other times another…
So my question is, is there some sort of convention for this type of thing? My fear is that I will get the reply “it depends” and this is my biggest fear. So I’ll preemptively reply to this answer with “depends on what?” :-\
As always, I appreciate all replies. Sorry if this post sounded a little exasperated, I promise I am usually a jolly fellow. ;D