Jump to content
  • Advertisement
Sign in to follow this  
chuchu_leon

how to use Cg profiles

This topic is 4839 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

I'm using a graphics card that should support all Cg language profiles (nvidia 6800GT), but when I run my C++ code an error appears saying that the profile chosen is not supported. I've tried all of them, VP40, VP30, VP20, and ARBV1. All give me the same error. Am I missing something? I downloaded the Cg toolkit very recently and copied all the .lib and .h files into the lib and include directories, respectively. Any help or comments would be appreciated.

Share this post


Link to post
Share on other sites
Advertisement
ok, well the code is pretty long, but i'll post what's relevant. I'm using OpenGL as the API. I will omit the fragment shader as it just passes the color on (I should just get rid of it). I hope it's understandable and not too messy, and I know it's long. Here's the vertex shader, then the Cg runtime environment calls:

//---------------------------
//BEGIN VERTEX CODE (
struct v_dotVectors_Output
{
float4 oPosition : POSITION;
float4 oColor : COLOR;
};

v_dotVectors_Output main(float3 position : POSITION,
float3 color : COLOR,

uniform samplerRECT transfer, //1024*numVertices
uniform samplerRECT lightIn, //768*128
uniform float vertexID,
uniform float width, //192
uniform float height, //32
uniform float supersampling) //4 (per direction)
{

v_dotVectors_Output OUT;
float i, j;
float2 texel,transferIndex;
int k;

OUT.oPosition = float4(position, 1);
OUT.oColor = float4(color, 1);
for (i = 0; i < width; i++)//goal: 32
{
for (j = 0; j < height; j++)//goal: 32
{
texel = float2(j,i);
transferIndex = float2(vertexID, j*width + i);
for (k = 0; k < supersampling; k++)
{
OUT.oColor += texRECT(lightIn, (texel + ((k/(int)supersampling)).xx)*supersampling.xx + fmod(k, supersampling).xx) * texRECT(transfer, transferIndex);
}
}
}
return OUT;
}
//END VERTEX CODE
//-----------------------------------------------------------------

//-----------------------------------------------------------------
//BEGIN CGGLINIT()

void CgGLInit()
{
// Create context
context = cgCreateContext();
CheckCgError();

// Initialize profiles and compiler options
v_profile = cgGLGetLatestProfile(CG_GL_VERTEX);
cgGLSetOptimalOptions(v_profile);
f_profile = cgGLGetLatestProfile(CG_GL_FRAGMENT);
cgGLSetOptimalOptions(f_profile);

/* Test adding source text to context */
v_dotVectors_prog = cgCreateProgramFromFile(context,
CG_SOURCE, CWD "v_dotVectors.cg",
v_profile,
"main", NULL);
CheckCgError();

fprintf(stderr, "LAST LISTING----%s----\n", cgGetLastListing(context));

fprintf(stderr, "---- PROGRAM BEGIN ----\n%s---- PROGRAM END ----\n",
cgGetProgramString(v_dotVectors_prog, CG_COMPILED_PROGRAM));

f_dotVectors_prog = cgCreateProgramFromFile(context,
CG_SOURCE, CWD "f_dotVectors.cg",
f_profile,
"main", NULL);
CheckCgError();

cgCompileProgram(v_dotVectors_prog);
cgCompileProgram(f_dotVectors_prog);

fprintf(stderr, "---- PROGRAM BEGIN ----\n%s---- PROGRAM END ----\n",
cgGetProgramString(f_dotVectors_prog, CG_COMPILED_PROGRAM));

if(v_dotVectors_prog != NULL)
{
cgGLLoadProgram(v_dotVectors_prog);
CheckCgError();

position_param = cgGetNamedParameter(v_dotVectors_prog, "position");
CheckCgError();

v_color_param = cgGetNamedParameter(v_dotVectors_prog, "color");
CheckCgError();

vertexID_param = cgGetNamedParameter(v_dotVectors_prog, "vertexID");
CheckCgError();

width_param = cgGetNamedParameter(v_dotVectors_prog, "width");
CheckCgError();

height_param = cgGetNamedParameter(v_dotVectors_prog, "height");
CheckCgError();

supersampling_param = cgGetNamedParameter(v_dotVectors_prog, "supersampling");
CheckCgError();

transfer_param = cgGetNamedParameter(v_dotVectors_prog, "transfer");
CheckCgError();

lightIn_param = cgGetNamedParameter(v_dotVectors_prog, "lightIn");
CheckCgError();
}

if(f_dotVectors_prog != NULL)
{
cgGLLoadProgram(f_dotVectors_prog);
CheckCgError();

f_color_param = cgGetNamedParameter(f_dotVectors_prog, "color");
CheckCgError();
}

makeTexture1(lightIn, LIGHTIN, 128, 768, 3);
if(lightIn_param != NULL)
{
cgGLSetTextureParameter(lightIn_param, LIGHTIN);
cgGLEnableTextureParameter(lightIn_param);
}

if(width_param != NULL)
cgGLSetParameter1f(width_param, 192.0);
if(height_param != NULL)
cgGLSetParameter1f(width_param, 32.0);

float * vertID;
for (objectID = 0; objectID < numObjects; objectID++)
{
vertID = (float*) malloc (numVerticesPerObject[objectID]*sizeof(float));
for (i = 0; i < numVerticesPerObject[objectID]; i++) vertID = i;
makeTexture2(transfer[objectID], TRANSFER, 1024, numVerticesPerObject[objectID], 3, numVerticesPerObject[objectID], transferSize);
cgGLSetTextureParameter(transfer_param, texture[TRANSFER]);
cgGLEnableTextureParameter(transfer_param);

// Set the varying parameters
cgGLEnableClientState(position_param);
cgGLSetParameterPointer(position_param, 3, GL_FLOAT, 0, vertexPos[objectID]);

cgGLEnableClientState(v_color_param);
cgGLSetParameterPointer(v_color_param, 3, GL_FLOAT, 0, black);

cgGLEnableClientState(f_color_param);
cgGLSetParameterPointer(f_color_param, 3, GL_FLOAT, 0, v_color_param);
cgConnectParameter(v_color_param, f_color_param);

cgGLEnableClientState(f_color_param);
cgGLSetParameterPointer(f_color_param, 3, GL_FLOAT, 0, v_color_param);

cgGLEnableClientState(vertexID_param);
cgGLSetParameterPointer(vertexID_param, 1, GL_FLOAT, 0, vertID);
}

for (objectID = 0; objectID < numObjects; objectID++)
{
cgGLBindProgram(v_dotVectors_prog);
cgGLBindProgram(f_dotVectors_prog);
CheckCgError();

cgGLEnableProfile(f_profile);
cgGLEnableProfile(v_profile);

for (j = 0; j < (totalNumFaces); j++)
{
glBegin(GL_POLYGON);
for (i = 0; i < polySize; i++)
{
glVertex3f( vertexPos[objectID][face[objectID][j]].x,
vertexPos[objectID][face[objectID][j]].y,
vertexPos[objectID][face[objectID][j]].z);
}
glEnd();
}
}
glutSwapBuffers();

// Disable texture
cgGLDisableTextureParameter(lightIn_param);
cgGLDisableTextureParameter(transfer_param);

cgGLDisableProfile(f_profile);
cgGLDisableProfile(v_profile);

// Set the varying parameters
cgGLDisableClientState(position_param);
cgGLDisableClientState(vertexID_param);
cgGLDisableClientState(f_color_param);
cgGLDisableClientState(v_color_param);
}
//END OF CGGLINIT()

//---------------------------------------------------------------------------

Share this post


Link to post
Share on other sites
Just glancing at it, your for loops in the actual shader may well be the problem. You seem to be looping 192*32*4 times per vertex you are passing into the shader. Maybe thats why its throwing a fit?

Have you tried writting a plain (empty) shader to see if that will run. Atleast narrow it down to a cg interface or a shader problem.

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!