在DrawUserPrimitives“不正确的参数”错误调用

问题描述:

我得到一个未处理的异常与消息HRESULT: [0x80070057], Module: [General], ApiCode: [E_INVALIDARG/Invalid Arguments], Message: The parameter is incorrect.在调用DrawUserPrimitives在下面的代码:在DrawUserPrimitives“不正确的参数”错误调用

namespace Game1 

open Microsoft.Xna.Framework 
open Microsoft.Xna.Framework.Graphics 

open System.IO 
open System.Reflection 

type Game1() as this = 
    inherit Game() 
    let graphics = new GraphicsDeviceManager(this) 
    [<DefaultValue>] val mutable effect : Effect 
    [<DefaultValue>] val mutable vertices : VertexPositionColor[] 
    do base.Content.RootDirectory <- "Content" 

    override this.Initialize() = 
     base.Initialize() 
     let device = base.GraphicsDevice 
     let s = Assembly.GetExecutingAssembly().GetManifestResourceStream("effects.mgfxo") 
     let reader = new BinaryReader(s) 
     this.effect <- new Effect(device, reader.ReadBytes((int)reader.BaseStream.Length)) 
     () 

    override this.LoadContent() = 
     this.vertices <- 
      [| 
       VertexPositionColor(Vector3(-0.5f, -0.5f, 0.0f), Color.Red); 
       VertexPositionColor(Vector3(0.0f, 0.5f, 0.0f), Color.Green); 
       VertexPositionColor(Vector3(0.5f, -0.5f, 0.0f), Color.Yellow) 
      |] 

    override this.Draw(gameTime) = 
     let device = base.GraphicsDevice 
     do device.Clear(Color.CornflowerBlue) 
     this.effect.CurrentTechnique <- this.effect.Techniques.["Pretransformed"] 

     this.effect.CurrentTechnique.Passes |> Seq.iter 
      (fun pass -> 
       pass.Apply() 
       device.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.TriangleList, this.vertices, 0, 1) 
      ) 

     do base.Draw(gameTime) 

我的效果代码如下(从优秀的拍摄Riemer's tutorials),并且尽可能简单。它正在转换,如this answer,这似乎工作,因为我可以看到效果名称,如果我在绘制调用之前放置一个断点。

struct VertexToPixel 
{ 
    float4 Position  : POSITION;  
    float4 Color  : COLOR0; 
    float LightingFactor: TEXCOORD0; 
    float2 TextureCoords: TEXCOORD1; 
}; 

struct PixelToFrame 
{ 
    float4 Color : COLOR0; 
}; 

VertexToPixel PretransformedVS(float4 inPos : POSITION, float4 inColor: COLOR) 
{ 
    VertexToPixel Output = (VertexToPixel)0; 

    Output.Position = inPos; 
    Output.Color = inColor; 

    return Output;  
} 

PixelToFrame PretransformedPS(VertexToPixel PSIn) 
{ 
    PixelToFrame Output = (PixelToFrame)0;  

    Output.Color = PSIn.Color; 

    return Output; 
} 

technique Pretransformed 
{ 
    pass Pass0 
    { 
     VertexShader = compile vs_4_0 PretransformedVS(); 
     PixelShader = compile ps_4_0 PretransformedPS(); 
    } 
} 

如果我更换一个BasicEffect按照this example自定义效果,它工作正常。

我使用Monogame 3.2和Visual Studio 2013年

我计算出最终(与帮助下this forum thread),我只需要在特效文件SV_POSITION更换POSITION。这是MonoGame内置DirectX 10/11而不是XNA DirectX 9的结果。