Jump to content

One function, mutiple types of parameters?


Recommended Posts

Hi!

I want to create dso for custom VEX function, say for the addition of two numbers of various types

Add(number1, number2)

I can create a callback like that

static void
Add(int, void *argv[], void *)
{
  // Some code
}

And I think what I can register this function two or more times with different signatures like

new VEX_VexOp("Add@&III", Add); // for integer numbers
new VEX_VexOp("Add@&FFF", Add); // for float numbers
...

How I can know, what type the input parameters?

Link to comment
Share on other sites

Just call appropriate evaluation function

static void
vsocker_Evaluate(int, void *argv[], void *)
{
   UT_Vector3  *result	= (UT_Vector3 *)argv[0];
   float	*u  = (float *)argv[1];
   float	*v  = (float *)argv[2];
   UT_Vector3  *col1  = (UT_Vector3 *)argv[3];
   UT_Vector3  *col2  = (UT_Vector3 *)argv[4];
   float	*flt  = (float *)argv[5];
....
....
....
}

static void
fsocker_Evaluate(int, void *argv[], void *)
{
   float  *result	= (float *)argv[0];
   float	*u  = (float *)argv[1];
   float	*v  = (float *)argv[2];
   float  *width  = (float *)argv[3];
   float  *depth  = (float *)argv[4];
....
....
....
}

static void
vpsocker_Evaluate(int, void *argv[], void *)
{
   UT_Vector3  *result	= (UT_Vector3 *)argv[0];
   UT_Vector3  *pos  = (UT_Vector3 *)argv[1];
   UT_Vector3  *col1  = (UT_Vector3 *)argv[2];
   UT_Vector3  *col2  = (UT_Vector3 *)argv[3];
   float	*flt  = (float *)argv[4];
....
....
....
}

static void
fpsocker_Evaluate(int, void *argv[], void *)
{
   float  *result	= (float *)argv[0];
   UT_Vector3  *pos  = (UT_Vector3 *)argv[1];
   float  *width  = (float *)argv[2];
   float  *depth  = (float *)argv[3];
....
....
....
}

void
newVEXOp(void *)
{
	new VEX_VexOp("socker@&VFFVVF",
 	 vsocker_Evaluate,
 	 (VEX_OP_CONTEXT|VEX_SHADING_CONTEXT),
 	 0,
 	 0);
	new VEX_VexOp("socker@&FFFFF",
 	 fsocker_Evaluate,
 	 (VEX_OP_CONTEXT|VEX_SHADING_CONTEXT),
 	 0,
 	 0);
	new VEX_VexOp("socker@&VVVVF",
 	 vpsocker_Evaluate,
 	 (VEX_OP_CONTEXT|VEX_SHADING_CONTEXT),
 	 0,
 	 0);
	new VEX_VexOp("socker@&FVFF",
 	 fpsocker_Evaluate,
 	 (VEX_OP_CONTEXT|VEX_SHADING_CONTEXT),
 	 0,
 	 0);

}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...