Bagikan melalui


Effect Constructor (GraphicsDevice, Stream, CompilerOptions, EffectPool)

Initializes a new instance of this class from a compiled effect, specifying the compiled effect as a stream.

Namespace: Microsoft.Xna.Framework.Graphics
Assembly: Microsoft.Xna.Framework (in microsoft.xna.framework.dll)

Syntax

public Effect (
         GraphicsDevice graphicsDevice,
         Stream effectCodeFileStream,
         CompilerOptions options,
         EffectPool pool
)

Parameters

  • graphicsDevice
    The graphics device that will create the effect.
  • effectCodeFileStream
    Stream containing the compiled byte code.
  • options
    Compilation optimization options.
  • pool
    Specifies a pool of resources to share between effects.

Exceptions

Exception type Condition
ArgumentNullException

graphicsDevice is null. The graphics device must not be null when creating new resources.

ObjectDisposedException

Effect was called after pool was disposed.

InvalidOperationException
  • The code contained in effectCodeFileStream is not compiled. Creating an effect requires that the shader code has been compiled.
  • The code contained in effectCodeFileStream does not have a size that is a multiple of four bytes. Effect and shader code must have a size that is a multiple of four bytes.
  • Unable to create the effect resource on the graphics device.

Remarks

Tip

In most cases, it is preferrable to initialize a new instance of an effect using the ContentManager.Load<Effect> method rather than using the Effect constructors. For an example of initializing an effect with this method, see How to: Create and Apply Custom Effects.

Obtaining the compiled byte code for effectCodeFileStream is a two-part process. First, you must compile the effect by using the static method Effect.CompileEffectFromFile or Effect.CompileEffectFromSource, either of which returns an instance of CompiledEffect. CompiledEffect.GetEffectCode returns the compiled byte code from the compiled effect.

See Also

Tasks

How to: Create and Apply Custom Effects

Reference

Effect.CompileEffectFromFile Method
Effect.CompileEffectFromSource Method
Effect Class
Effect Members
Microsoft.Xna.Framework.Graphics Namespace

Platforms

Xbox 360, Windows XP SP2, Windows Vista