Effect.CommitChanges() Method (Microsoft.DirectX.Direct3D)
How Do I...?
- Using an Effect
Propagates the state change that occurs inside of an active pass to the device before rendering.
Definition
Visual Basic Public Sub CommitChanges() C# public void CommitChanges(); C++ public:
void CommitChanges();JScript public function CommitChanges();
Remarks
If the application changes any effect state using the Effect class members that modify state, such as Effect.StateManager, inside of an Effect.BeginPass/Effect.EndPass matching pair, the application must call Effect.CommitChanges before any of the various Device.DrawPrimitives methods are called to propagate state changes to the device before rendering. If no state changes occur within an Effect.BeginPass/Effect.EndPass matching pair, it is not necessary to call Effect.CommitChanges.
Exceptions
The method call is invalid. For example, a method's parameter might contain an invalid value.
The data is invalid.
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.
- Create or obtain access to a high-level shader language (HLSL) file (.fx).
- Load the HLSL file using Effect.FromFile.
- Set Effect.Technique with the effect's technique.
- Use Effect.Begin to obtain the number of passes for the effect.
- 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.
- 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(); . . . }