Jump to content
  • Advertisement
Sign in to follow this  
My_Mind_Is_Going

MD2 models, glcmds, and 3D API independence

This topic is 4027 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying clean up my usually pretty haphazard programming practices by paying attention the principles of good software engineering, good OO design, etc. I've been reading Stefan Zerbst's book "3D Game Engine Programming" and in the book Mr. Zerbst is always harping on the idea of building an API independent engine and renderer so that you don't have say for instance OpenGL specific code anywhere but in the code for OpenGL renderer class. Also I've been looking at / trying to write a class for MD2 models and part of an MD2 file is information telling you which OpenGL commands to use (such as GL_TRIANGLE_FAN, GL_TRIANGLE_STRIP, etc) to draw the model more efficiently. Now isn't this an example of putting API specific code into what is otherwise a generic model format? Furthermore in the tutorial I've been reading about MD2 the author implements a method in his MD2 class to specifically draw the model using OpenGL commands. What should I be learning from all this? id only intended to support OpenGL in Quake 2 so there was no reason not to build support into the model format just for OpenGL? Quake 2 had a software renderer if I recall so rendering of models couldn't have taken place (like the example from the tutorial) with a Render method that's tied to the API (or lack thereof). Anyway, does anyone have anything insightful about all this? I guess I can summarize my question by asking: is it always important to strive for perfectly designed, modular code or is it a case by case thing where you break these rules sometimes to make stuff easier and faster? -Evan

Share this post


Link to post
Share on other sites
Advertisement
The format works perfectly fine if you ignore that little bit hint about rendering efficiency. It's also a hint that you can use to optimize it's rendering for D3D, or software renderers, as well. The data provided in this particular section is just a hint about what sort of order the data is in, and how this order can contribute to a speed increase if you so choose to take it into consideration. It's still in a platform independant form, just that it's hints are in openGL-speak, even though they can be directly translated into other rendering API's [D3D has triangle strips too, as does pretty much anything else, and if you're using something that doesn't have triangle strips, the data is still in a state that can be rendered by anything that can interpret regular files].

Integrating the rendering of the model into the model-file loader is a bit silly though. Seems pretty strange.

Share this post


Link to post
Share on other sites
It's okay to break the 'rules' of OOP design if it leads to a speed increase or leads to a decreased workload for the programmer.
For instance:
You have a variable 'double x;' now, you could follow OOP design and make the variable private and have a method called 'double getX()' that returned variable 'x', but why? Unless you have a reason to do so, I wouldn't make the method, because it's slower at runtime, and it takes you time to code it.
The same goes for this: if you're only going to use OpenGl, don't bothering trying to design your engine in a way that is also DirectX compatbile.
Hope this helps :)
-wyrmmage

Share this post


Link to post
Share on other sites
Do you think when submitting demo materials for jobs it would be wise to go back and make all those data members private and setup accessor functions or will they understand?

Share this post


Link to post
Share on other sites
The general opinion on this board is to prefer a public member variable to a pair of SetX, GetX type accessors. This is not for efficiency (such methods will almost certainly be inlines) but rather because the methods are unnecessary.

However the presence of such methods is generally an indicator of poor design. If your class is nothing but a bunch of member variables and accessors then you havn't really encapsulated anything even if the member variables are private. You want to think about actions on the class preferring something like a general Move() function to a SetX SetY pair

Share this post


Link to post
Share on other sites
IIRC the GL commands were included in the md2 format due to the relative performance (i.e. none) of 3D hardware at the time, so pre-calculating optimized ways to draw the model was certainly better than calculating it every frame. Modern hardware is obviously fast enough that you can ignore it entirely and write a better renderer than in id's (rather primitive) 10-year-old code.

Share this post


Link to post
Share on other sites
The md2 file also contains raw frame and vertex data in other lumps, so you don't have to use the GL command lump if you don't want to. I don't.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!