Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Correct order of operations when enabling/disabling Cg shaders in OpenGL


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
No replies to this topic

#1 redneon   Members   -  Reputation: 134

Like
0Likes
Like

Posted 28 April 2012 - 02:28 AM

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.

Sponsor:



Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS