Function Declaration Syntax
Microsoft DirectX 9.0 SDK Update (October 2004)

Function Declaration Syntax


User defined functions are very similar to C functions.

Syntax

Functions are declared with one or more of these components:

[Storage Class Modifiers] [Type Modifiers] 
FunctionType FunctionName ( [ParameterList] ) { [StatementBlock] } ;

Components

Storage Class Modifiers

staticAt global scope, the static keyword prevents a shader variable from being exposed to an application. None of the application programming interface (API) methods (GetVertexShaderConstantx or SetVertexShaderConstantx) and none of the ID3DXConstantTable interface methods can be used to get or set a static variable.
static float fConstant_Hidden_From_the_App = 0.2f;
At local scope, a static variable has a value that persists from one invocation of the function to the next.
inlineEach copy of a function may have its own function body to decrease the overhead of calling the function. All functions are currently inlined. Recursion is not supported.
targetThe target represents an optional identifier specifying the platform for which the function has been authored.

Type Modifiers

Type modifiers are optional keywords placed immediately before the variable type, which give the compiler additional information about the data type.

constThe const modifier indicates a variable whose value cannot be changed by a shader. Declaring a variable with const allows the compiler to put the value in a portion of memory that does not need write access. Because the variable cannot be changed, it must be initialized in the declaration.

FunctionType

Any valid type including: basic types, vector types, matrix types, shader types, sampler type, user defined types.

Function Name

An ASCII string that uniquely identifies the name of the shader function.

Parameter List

One or more parameters separated by commas. See Function Parameter List Syntax.

Statement Block

One or more statements that make up the body of the function. See Statement Block Syntax.

If a function is defined without a body, it is considered to be a prototype. The function must be redefined, with a body, later on in the code.

Remarks

Functions can be overloaded. A function is uniquely identified by its name, the types of its parameters, and the target platform, if provided. For a list of the built in functions, see Intrinsic Functions.



© 2004 Microsoft Corporation. All rights reserved.
Feedback? Please provide us with your comments on this topic.
For more help, visit the DirectX Developer Center.