Jump to content
  • Advertisement
Sign in to follow this  
bluntman

Cg and OpenGL

This topic is 4877 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Sorry couldn't really figure out where to post this (is Cg not popular enough to have its own forums?) I am having a problem getting my shaders to compile. At first I couldn't get Cg to recognise that my fx5600 had any shader capabilities at all. Then I eventually found out that if the Pixelformat is not set correctly for the OpenGL render context then the software implementation will be fallen back on. I found out that I have to use a 32bit zbuffer in order to get cgGLIsProfileSupported to return anything except false. So after fixing the zbuffer to 32bit it returns true for CG_PROFILE_ARBFP1. But now my cgCreateProgramFromFile call returns CG_PROFILE_NOT_SUPPORTED, even though I am passing the profile I just verified as supported: if (cgGLIsProfileSupported(CG_PROFILE_ARBFP1)) m_cgpBestFragmentProfile = CG_PROFILE_ARBFP1; // this gets executed else { // try FP30 if (cgGLIsProfileSupported(CG_PROFILE_FP30)) m_cgpBestFragmentProfile = CG_PROFILE_FP30; else { return(false); } } prog = cgCreateProgramFromFile(m_cgcContext, CG_SOURCE, name.c_str(), m_cgpBestFragmentProfile, funcname.c_str(), NULL); Any ideas? I am using a few other gl rendering contexts in my program, running in other threads, and one running in the same thread, but these calls are all made within one function. Thanks. billw

Share this post


Link to post
Share on other sites
Advertisement
Since you're picking ARBFP1 first, is it at all possible that what you're trying to compile isn't supported by ARBFP1?

Share this post


Link to post
Share on other sites
Sorry it is CG_INVALID_PROFILE_ERROR that is being returned. Surely if the Cg code is at fault it will return CG_COMPILE_ERROR? I tried swapping the order of checks and now it succeeds in finding CG_PROFILE_FP30, but still the same problem when I try to load and compile the shader from file.

The reference documentation for Cg is pretty awfull, from what I have seen of it so far (everything related to what I am trying to do I have been over a few times). Its got spelling mistakes, grammer mistakes and the absolute minumum of useful information.
What shading language do most people use?

Share this post


Link to post
Share on other sites
unfortunately, this doesn't answer your question but i was curious. if you are using OGL then why use the GLSL shading language? is it not equivalent to Cg? doesn't GLSL integrate better to OGL than Cg does?

Share this post


Link to post
Share on other sites
Just because I have heard more about Cg. Also I thought that GLSL was only in OpenGL 2.0, which you don't get on Windows XP.
I am tempted to switch. But I have invested time and money in Cg and don't want to drop it quite yet (I have already written the shaders, and am pretty sure they will work just fine, never thought the problem would just be getting them to load!).

Share this post


Link to post
Share on other sites
Curiouser and curiouser! After alot of fiddling about I have managed to get get the required program to load and compile, but only if I call cgCreateProgramFromFile from within the init function, and not if I call my own Load function which then calls cgCreateProgramFromFile.

i.e.
This works:

bool WWCgImageProcessor::Init()
{
m_cgcContext = cgCreateContext();

if(m_cgcContext == NULL)
return(false);

m_cgpBestFragmentProfile = cgGLGetLatestProfile(CG_GL_FRAGMENT);
cgGLSetOptimalOptions(m_cgpBestFragmentProfile);

m_cgpHorizConvolution1_8 = cgCreateProgramFromFile(m_cgcContext,
CG_SOURCE,
"F:/Programming/Geometrix/Cg Shaders/horiz_convolve_sigma_1_8.cg",
m_cgpBestFragmentProfile,
"FragmentProgram",
NULL);

// ....
}

This does not work:
bool WWCgImageProcessor::Init()
{
m_cgcContext = cgCreateContext();

if(m_cgcContext == NULL)
return(false);

m_cgpBestFragmentProfile = cgGLGetLatestProfile(CG_GL_FRAGMENT);
cgGLSetOptimalOptions(m_cgpBestFragmentProfile);

if(!LoadProgram(&m_cgpHorizConvolution1_8, "FragmentProgram",
"F:/Programming/Geometrix/Cg Shaders/horiz_convolve_sigma_1_8.cg"))
return(false);

// ....
}

bool WWCgImageProcessor::LoadProgram(CGprogram *prog, const char *funcname, const char *name)
{
*prog = cgCreateProgramFromFile(m_cgcContext,
CG_SOURCE,
name,
m_cgpBestFragmentProfile,
funcname,
NULL);

// ....
}

What the hell is going on?

[Edited by - bluntman on June 8, 2005 8:49:27 AM]

Share this post


Link to post
Share on other sites
The version that does not work creates a new context which does not have a profile set. Maybe you should create a context only once.

Share this post


Link to post
Share on other sites
Yeah sorry that was debug code I had left in by accident, I have fixed the code above. I was just checking that the context is indeed new and valid. I get the same result regardless of that line of code.

Share this post


Link to post
Share on other sites
Quote:
Original post by bluntman
Just because I have heard more about Cg. Also I thought that GLSL was only in OpenGL 2.0, which you don't get on Windows XP.
I am tempted to switch. But I have invested time and money in Cg and don't want to drop it quite yet (I have already written the shaders, and am pretty sure they will work just fine, never thought the problem would just be getting them to load!).


IIRC, the OpenGL 1.4 API spec introduced the GLSL properly.

It IS supported on any platform that runs OpenGL 1.4 (yes, even XP..*wink*), you just need to make sure you've got an updated set of video drivers from your board manufacturer.

I could be wrong, but I'm under the impression that on non-nvidia hardware (ie. ATI), Cg calls are using the GLSL "under the hood". At least that's the impression I get on the documentation I've seen.

hth,

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!