我在下面的代码中调用HRESULT: [0x80070057], Module: [General], ApiCode: [E_INVALIDARG/Invalid Arguments], Message: The parameter is incorrect.
时收到消息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();
}
}
如果我根据this example将自定义效果替换为BasicEffect
,则效果正常。
我使用的是Monogame 3.2和Visual Studio 2013。
答案 0 :(得分:3)
我最终得到了(this forum thread的帮助),我只需要在效果文件中将POSITION
替换为SV_POSITION
。这是MonoGame在DirectX 10/11而不是XNA的DirectX 9中构建的结果。