Graphics Reference
In-Depth Information
When using functions, it is important to keep in mind that shader programs do not use
a traditional stack as in C++. Consequently, it is not possible to recursively call functions.
Instead dynamic loop constructs must be used to implement recursive algorithms.
6.3.6 Interfaces
Interfaces in HLSL are similar to abstract virtual classes in C++, and are primarily used
to enable dynamic shader linkage. Interfaces can only contain member functions, and not
member variables. Listing 6.9 contains a declaration of a simple interface type.
interface Mylnterface
{
float3 Hethodl( );
float2 Method2( float2 param );
};
Listing 6.9. Interface declaration syntax.
The methods declared in an interface are always considered to be pure virtual func-
tions, and thus no virtual keyword is necessary. See the "Dynamic Shader Linkage" section
for more information on using interfaces in HLSL.
6.3.7 Classes
HLSL classes, like classes in C++, can contain member variables, as well as member func-
tions. They can also inherit from a single base class, and can inherit from multiple interfaces.
However if a class inherits from an interface, it must fully implement all methods declared in
that interface. Listing 6.10 contains a simple class declaration that implements an interface.
interface Mylnterface
{
float3 Methodl( );
float2 Method2( float2 param );
};
class MyClass : Mylnterface
{
float3 Member1;
Search WWH ::




Custom Search