reven's picture

OpenTK and Cg Parameters

Hi, I'm currently using OpenTK and Tao.Cg to include shader support in the project.

There is, however a problem I cannot find a sane solution to, without adding methods doing more work than necessary. The problem is as follows:

I can get some a parameter from a cg effect file with like this:

Vector3 position = Vector3( );
IntPtr pos = Cg.cgGetEffectParameterBySemantic(CgEffect, "Position");
CgGl.cgGLSetParameter3fv(color, new float[] {position.X,position.Y,position.Z});

I'd like not to create that copy. I am aware that I can use cgGLSetParameter3f and then avoid the new array, but I really don't think that it should be necessary to use the property for each of the variables if they could just be returned as a float[].

Why does the class not provide that?

On a sidenote, anyone knows how I would provide my Cg effect file with a matrix that is not currently in the OpenGL state, but managed by myself? I.e. set a matrix parameter from something else than the state manager.


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

A copy would still be needed even if the Vector class could be cast to float[]. Only If CgGl.cgGLSetParameter3fv provides a "ref float" overload will you be able to avoid the copy:

CgGl.cgGLSetParameter3fv(color, ref position.X);