Aspyr Media's GameAgent NonBlog recently added a new developer diary focusing on the effort to bring Civilization IV to Macintosh computers. The article includes discussion of some of the unique challenges the developers encountered and lessons learned which will aid in the porting of future game titles.

The most challenging aspect of porting Civ IV was its reliance on the Direct3D Effects framework for managing shaders and pipeline states and choosing rendering techniques at runtime. Rendering techniques are all specified in a high level language in “FX” files, which are compiled by the D3DX effects compiler. Techniques encapsulate global variables, pipeline state, texture/sampler state, and shaders. Multiple techniques are specified for a given rendering task so that the game can select the most appropriate method at runtime for the current graphics hardware. For example, HLSL shaders may be used on the more advanced GPUs while earlier GPUs fall back to a fixed-function shader method. On the Mac we would be using OpenGL, which has no real equivalent to the effects framework.

Although we had experience translating Direct3D shaders written in shader model assembly code to a form that we could use with OpenGL, we had no compiler for turning FX files into something usable. We were able to solve this problem by taking the compiled (binary) form of the FX files and interpreting and translating them at runtime. The embedded shaders are translated to “ARB” vertex and fragment program assembly language. We interpreted the other information about techniques, passes, and state and implemented our own versions of the D3DX functions for applying and managing them.