Monday, February 10, 2014

My Model Class

Next thing to clean up is the code for managing models.  What it needs to accomplish:
  • Load all necessary information from OBJ files
  • Remember the buffer objects to store the data needed for rendering
  • Track the changes to the model data and only update buffers when changes happen
  • Perform all the work needed to render the model
Once again this class will likely be kept in a large array, one element for each model I have a need of drawing.  Eventually this class will need extended to be able to manipulate the object, or at least track transformations that it'll need when rendered.  I haven't dealt much with movements yet, but that's going to have to happen soon.
This class should hit all of the requirements I have for it right now.  It'll need a bunch of updates as I progress with OpenGL stuff.  Here's the current list of public properties and methods:
1:  class GLModel {  
2:      public GLModel();  
3:    
4:      public Vector4 BaseColor;  
5:      public int UniformBuffer;  
6:      public int UniformID;  
7:      public int VertexAttributeID;  
8:      public string ErrorDescription;  
9:    
10:      public bool SetBaseColor(float fRed, float fGreen, float fBlue, float fAlpha);  
11:      public bool LoadOBJFile(string strFile);  
12:      public bool RenderObject();  
13:  }  

Properties:
  • BaseColor the color the object should appear.
  • UniformBuffer the buffer object ID where the uniform data should be stored.
  • UniformID the ID of the uniform variable to bind to the uniform buffer.
  • VertexAttributeID the ID of the attribute variable to bind the vertex information to.
  • ErrorDescription if an error occurred during a function a description will be provided here.

Methods:
  • GLModel() the constructor, it will create buffer objects to hold the vertex data.
  • SetBaseColor() assigns the base color using float values.
  • LoadOBJFile() loads the model's information from the specified OBJ file.
  • RenderObject() attempts to render the model.
The functions all will return true on success, and false if any sort of error occurs.

Like all pieces of code I've worked on this one has a list of things I think need fixed, as well as areas for improvement.
  1. Once again I had the functions press on through errors and report bad results in a string property.  This really should be reworked into a set of exceptions.
  2. So far as I can tell there's no limit to the number of buffer objects you can have, so having all models share a uniform buffer seems unnecessary.  Having the class create and maintain its own buffer object should be fine.
  3. The class really does need to track the position of the model and be able to position it during rendering.  I have some ideas on this, but nothing that I've tried out just yet.
To get the full source, go here.

No comments:

Post a Comment