   How To Wrap Cg Functionality
  I'm new to Cg and while still learning about this library, I find that there is very little code out there that shows you a good way to wrap the library. Basically, I'm trying to wrap it in Classes. What I cannot wrap my head around is where setup and teardown happens.Where would I put cgCreateContext()? In my renderer class (assuming there is only one context which holds all the programs) or should I create a new context each time a Shader is created (one per vertex and fragment shader pair)?Is Cg a state machine? When I create programs with variables with the same name, which one will I access when I do a cgSetParameter()?Lastly, has anyone wrapped the Cg library in a set of classes?Thanks in advance.EDIT: One more Question. Can you do the same things (ie. get access to variables etc) with Cg as you can do with CgFX? (I vaguely remember that with HLSL you could not get access to Sampler information, due to annotations, but with the Effects framework you could).[Edited by - RealMarkP on May 15, 2009 10:53:14 PM]
  You only need one context for the rendering system. All effects/shaders should be loaded with that context. I simply create the context in the Renderer and then pass it to my Material/Effect system.I have wrapped the Cg functionality into an Effect class. The effect class holds the available technique, the passes, and the parameters. The system resembles the case study proposed by Wolfgang Engel in Shader X4: Case Study: Designing a Shader Subsystem for a Next-Gen Graphics EngineTo handle parameters, I cycle through the parameters using cgGetFirstEffectParameter()/cgGetNextParameter()/cgGetParameterName().  This way each effect knows which parameters are required and different shaders can have the parameters with the same name with no confusion.Finally, each visual object to be rendered maintains a name for the material it uses. The material is simply an xml style file with the name of the effect it uses and the values of each parameter.- me   ;  Ok, great! Thanks for the books suggestion.Another question, should I bother with handling Programs myself or should I dive into the CgFX framework? I tried looking for Pros and Cons of both, but I cannot find anything of value.   ;  I think it depends on the scale of the project you are working on. I found that the CgFX framework work nice because I wanted to allow lots of different effects. My framework loads all effects in a folder and stores the information. Then any effect can be used simply by knowing its name.But if you are only planning on using a couple programs, it might be overkill to invest time in a full Material/Effect system.- me   