Effect.BeginPass(Int32) Method (Microsoft.DirectX.Direct3D)

How Do I...?

  • Using an Effect

Applies the state settings for the specified pass of a technique.

Definition

Visual Basic Public Sub BeginPass( _
    ByVal passNumber As Integer _
)
C# public void BeginPass(
    int passNumber
);
C++ public:
void BeginPass(
    int passNumber
);
JScript public function BeginPass(
    passNumber : int
);

Parameters

passNumber System.Int32
An integer that identifies the pass to apply. This value is returned by Effect.Begin, which must be called before rendering an effect.

Remarks

Before entering the rendering loop for the effect, Effect.Begin must be called to obtain the number of effect passes.

After calling Effect.BeginPass, the application must draw the geometry to the device to which the effect is set and then call Effect.EndPass.

After all passes are rendered, Effect.End must be called.

Exceptions

InvalidCallException

The method call is invalid. For example, a method's parameter might contain an invalid value.

InvalidDataException

The data is invalid.

OutOfMemoryExceptionLeave Site

Microsoft Direct3D could not allocate sufficient memory to complete the call.

How Do I...?

Using an Effect

This example demonstrates how to use an effect technique that was loaded from a file.

Add effects code to your rendering method, such as OnRender(), in-between calls to Device.BeginScene and Device.EndScene.

  1. Create or obtain access to a high-level shader language (HLSL) file (.fx).
  2. Load the HLSL file using Effect.FromFile.
  3. Set Effect.Technique with the effect's technique.
  4. Use Effect.Begin to obtain the number of passes for the effect.
  5. Create a loop to iterate through all of the effect's passes. Rendering an effect occurs within a loop between calls to Effect.BeginPass and Effect.EndPass. The loop itself is nested between calls to Effect.Begin and Effect.End.
  6. Render each pass within the loop with calls to Effect.BeginPass, Device.DrawPrimitives, and Effect.EndPass.

In the following C# code example, device is assumed to be the rendering Device.

              [C#]
              

public void OnRender ()
{
    .
    .
    .

    // Load the effect from file.
    Effect effect = Effect.FromFile(device, "shadercode.fx", null,
                                    ShaderFlags.None, null);
    // Set the technique.
    effect.Technique = "ShaderTechnique";

    // Note: Effect.Begin returns the number of
    // passes required to render the effect.
    int passes = effect.Begin(0);
    
    // Loop through all of the effect's passes.
    for (int i = 0; i < passes; i++)
    {
        // Set a shader constant
        effect.SetValue("WorldMatrix", worldMatrix);

        // Set state for the current effect pass.
        effect.BeginPass(i);
        
        // Render some primitives.
        device.DrawPrimitives(PrimitiveType.TriangleList, 0, 1);
        
        // End the effect pass
        effect.EndPass();
    }

    // Must call Effect.End to signal the end of the technique.
    effect.End();

    .
    .
    .
}

See Also