Original Post
[color=#000000]I've started writing an Effect class which uses Cg shaders in OpenGL and I'm a bit confused about the order of operations when creating and rendering using Cg.
[color=#000000]Currently, my Effect class contains CGprogram, CGprofile and an array of CGparameter variables which get populated on loading the Effect similar to this:
[color=#000000]
[color=#000000]It's not exactly like this and this is only using a vertex shader but it contains the important code. Anyway, that's how I create the Effect and then when I want to use it during a render I use Enable() and Disable() functions before and after I draw the verts etc.
[color=#000000]
[color=#000000]I'm not sure if this is the correct way to do it, though. Is it correct to enable and disable the profile for each shader? More to the point, do I actually want a profile per shader? I'm using the same profile for each shader so surely I could just have a global one and use that?
[color=#000000]Any advice would be much appreciated.
[color=#000000]Currently, my Effect class contains CGprogram, CGprofile and an array of CGparameter variables which get populated on loading the Effect similar to this:
[color=#000000]
m_vertexProfile = cgGLGetLatesProfile(CG_GL_VERTEX);
cgGLSetOptimalOptions(m_vertexProfile);
m_vertexProgram = cgCreateProgramFromFile(g_cgContext, CG_SOURCE, fileName, m_vertexProfile, entryPointName, NULL);
cgGLLoadProgram(m_vertexProgram);
CGparameter param = cgGetFirstParameter(m_vertexProgram, CG_PROGRAM);
while (param)
{
const char* paramName = cgGetParameterName(param);
m_vertexParameters[m_vertexParamNum++] = param;
param = cgGetNextParameter(param);
}
[color=#000000]It's not exactly like this and this is only using a vertex shader but it contains the important code. Anyway, that's how I create the Effect and then when I want to use it during a render I use Enable() and Disable() functions before and after I draw the verts etc.
[color=#000000]
void Effect::Enable()
{
cgGLBindProgram(m_vertexProgram);
cgGLEnableProfile(m_vertexProfile);
}
void Effect::Disable()
{
cgGLUnbindProgram(m_vertexProfile);
cgGLDisableProfile(m_vertexProfile);
}
[color=#000000]I'm not sure if this is the correct way to do it, though. Is it correct to enable and disable the profile for each shader? More to the point, do I actually want a profile per shader? I'm using the same profile for each shader so surely I could just have a global one and use that?
[color=#000000]Any advice would be much appreciated.