次の方法で共有


Effect Constructor (GraphicsDevice, Stream, Int32, CompilerOptions, EffectPool)

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

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

Syntax

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

Parameters

  • graphicsDevice
    The graphics device that will create the effect.
  • effectCodeFileStream
    Stream containing the compiled byte code.
  • numberBytes
    The number of bytes to read from the file.
  • 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.

InvalidOperationException

One of the following conditions is true:

  • effectCodeFileStream does not contain enough data to accommodate the number of bytes requested by the numberBytes parameter.
  • 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.
ObjectDisposedException

Effect was called after pool was disposed.

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