Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

Currently, my Effect class contains CGprogram, CGprofile and an array of CGparameter variables which get populated on loading the Effect similar to this:

m_vertexProfile = cgGLGetLatesProfile(CG_GL_VERTEX);
cgGLSetOptimalOptions(m_vertexProfile);
m_vertexProgram = cgCreateProgramFromFile(g_cgContext, CG_SOURCE, fileName, m_vertexProfile, entryPointName, NULL);
cgGLLoadProgram(m_vertexProgram);[/color]

CGparameter param = cgGetFirstParameter(m_vertexProgram, CG_PROGRAM);
while (param)
{
    const char* paramName = cgGetParameterName(param);
    m_vertexParameters[m_vertexParamNum++] = param;
    param = cgGetNextParameter(param);
}

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.

void Effect::Enable()
{
    cgGLBindProgram(m_vertexProgram);
    cgGLEnableProfile(m_vertexProfile);
}


void Effect::Disable()
{
    cgGLUnbindProgram(m_vertexProfile);
    cgGLDisableProfile(m_vertexProfile);
}

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?

Any advice would be much appreciated.

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.