cgCreateObj(3)

NAME
cgCreateObj - create a cg object type from a shader string

SYNOPSIS
  #include <Cg/cg.h>

  CGobj cgCreateObj( CGcontext context,
                     CGenum program_type,
                     const char * source,
                     CGprofile profile,
                     const char ** args );

PARAMETERS

context
    The context to which the new object will be added.

program_type
    An enumerant describing the contents of the source string. The following enumerants are allowed:

    CG_SOURCE
        source contains Cg source code.

    CG_OBJECT
        source contains object code that resulted from the precompilation of some Cg source code.

source
    A string containing either the programs source or object code. See program_type for more information.

profile
    The profile enumerant for the program.

args
    If args is not NULL it is assumed to be an array of NULL-terminated strings that will be passed directly to the compiler as arguments. The last value of the array must be a NULL.

RETURN VALUES
Returns a CGobj handle on success.

Returns NULL if an error occurs.

DESCRIPTION
cgCreateObj creates a new CGobj which is a source code object similar to a .obj or .o in C/C++ programming where various forms of data can be extracted. This can be used, for example, to create user defined data types from a Cg source string.

EXAMPLES
 // Imagine a Cg source string that contains:

 const char src[] =
  "typedef struct { \n"
  " float3 param1;  \n"
  " half4  param2;  \n"
  "} MyType;";

 // To create a Cg obj:

 CGcontext ctx = cgCreateContext();
 CGobj structObj = cgCreateObj(ctx, CG_SOURCE, src, CG_PROFILE_ARBVP1, NULL);

 // Now we can get the CGtype:

 CGtype userDefinedMyType = cgGetNamedUserType(structObj, "MyType");

 // We could also iterate through all the types in the CGobj printing their
 // names like this:

 int numTypes = cgGetNumUserTypes(structObj);
 for (int i=0; i<numTypes; i++) {
    cout << cgGetTypeString(cgGetUserType(structObj, i)) << endl;
 }

ERRORS
CG_INVALID_CONTEXT_HANDLE_ERROR is generated if context is not a valid context.

CG_INVALID_ENUMERANT_ERROR is generated if program_type is not CG_SOURCE or CG_OBJECT.

CG_UNKNOWN_PROFILE_ERROR is generated if profile is not a supported profile.

CG_COMPILER_ERROR is generated if compilation fails.

HISTORY
cgCreateObj was introduced in Cg 2.0.

SEE ALSO
cgCreateObjFromFile, cgDestroyObj