Usually, when I do OpenGL programming, I have a Mesh class:
public class Mesh {
List<Vector3f> vertices = new ArrayList<>();
List<Vector3f> normals = new ArrayList<>();
List<Vector2f> texCoords = new ArrayList<>();
protected int vertices;
protected boolean dirty;
protected int vertexArrayID = -1;
protected int vertexBufferID = -1;
...
}
However, the application I'm currently working on is much more general, and I want individual OpenGL elements to be separated from regular 3D materials. For example, someone might want to save the Mesh as an STL file and print it in 3D or send it to Raytrace to make it look beautiful. In this case, the data specific to OpenGL is useless.
In other words, this implementation of the Mesh class violates the principle of shared responsibility.
Now one solution I can think of is the following:
public class Mesh {
List<Vector3f> vertices = new ArrayList<>();
List<Vector3f> normals = new ArrayList<>();
List<Vector2f> texCoords = new ArrayList<>();
}
public class GlMesh extends Mesh implements GlDrawable {
protected int vertices;
protected boolean dirty;
protected int vertexArrayID = -1;
protected int vertexBufferID = -1;
}
, OpenGL, , . Mesh , GlMesh, Mesh, , , OpenGL, .
- :
public class Mesh {
List<Vector3f> vertices = new ArrayList<>();
List<Vector3f> normals = new ArrayList<>();
List<Vector2f> texCoords = new ArrayList<>();
}
public class GlMesh {
protected int vertices;
protected boolean dirty;
protected int vertexArrayID = -1;
protected int vertexBufferID = -1;
}
Map<Mesh, GlMesh> meshToGlMesh = (whatever)
Mesh GlMesh, .
, ?