Bagikan melalui


Effect Constructor (GraphicsDevice, Byte , CompilerOptions, EffectPool)

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

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

Syntax

public Effect (
         GraphicsDevice graphicsDevice,
         byte[] effectCode,
         CompilerOptions options,
         EffectPool pool
)

Parameters

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

Exceptions

Exception type Condition
ArgumentNullException

effectCode or graphicsDevice is null.

InvalidOperationException

One of the following conditions is true:

  • The code contained in effectCode is not compiled. Creating an effect requires that the shader code has been compiled.
  • The code contained in effectCode 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 effectCode 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