Jump to content
  • Advertisement
Sign in to follow this  

cg get vertex shader parameters

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

hi there, I've got a question about getting parameter values from a vertex shader in nvidia CG (as i have just started programming in cg). I know it is possible to set parameter values in the vertex shader thru cgGLSetParameterPointer() or cgGLSetParameter4f() functions among others. However, I wonder if there is a procedure to get variable values from the cg program during execution time. I'm using a simple program with cgGetParameterValuefr() and the code snippet is the following (from NeHe tutorials) BOOL Initialize (GL_Window* window, Keys* keys) { ... //Im skipping the Error checking functions for sake of clarity cgContext = cgCreateContext(); cgVertexProfile = cgGLGetLatestProfile(CG_GL_VERTEX); cgGLSetOptimalOptions(cgVertexProfile); cgProgram = cgCreateProgramFromFile(cgContext, CG_SOURCE, "CG/Wave.cg", cgVertexProfile, "main", 0); cgGLLoadProgram(cgProgram); position = cgGetNamedParameter(cgProgram, "IN.position"); res = cgGetNamedParameter(cgProgram, "result"); modelViewMatrix = cgGetNamedParameter(cgProgram, "ModelViewProj"); } void Draw (void) { ... glLoadIdentity (); ... cgGLSetStateMatrixParameter(modelViewMatrix, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY); int p = -1; float* fTest; if (cg_enable) { cgGLEnableClientState(position); cgGLSetParameter4f(position, 0.5f, 1.0f, 0.5f, 1.0f); cgGLEnableProfile(cgVertexProfile); cgGLBindProgram(cgProgram); p = cgGetParameterValuefr(res, 4, fTest); cgGLDisableClientState(position); } And the vertex program is: struct appdata { float4 position : POSITION; }; struct vfconn { float4 HPos : POSITION; }; vfconn main(appdata IN, uniform float4x4 ModelViewProj, inout float4 result) { vfconn OUT; //not using it for the moment,but just left it for future purposes result = mul(ModelViewProj, IN.position); OUT.HPos = mul(ModelViewProj, IN.position); return OUT; } The problem is that when I perform the calculation in the vertex program I cannot get the updated variable 'result' (I always get the initial position value fTest = {0.5f, 1.0f, 0.5f, 1.0f}). I wonder if there is a proper way to get a parameter value from the vertex program using a diferent cg function or if I am screwing the whole thing up. Thanks a lot in advance for any ideas, gdoglz [Edited by - gdoglz on June 13, 2008 6:11:53 AM]

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!