【问题标题】:"Incorrect parameter" error in DrawUserPrimitives callDrawUserPrimitives 调用中的“参数不正确”错误
【发布时间】:2014-10-03 03:20:54
【问题描述】:

在下面的代码中调用DrawUserPrimitives 时,我收到消息HRESULT: [0x80070057], Module: [General], ApiCode: [E_INVALIDARG/Invalid Arguments], Message: The parameter is incorrect. 的未处理异常:

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 exampleBasicEffect 替换自定义效果,效果很好。

我正在使用 Monogame 3.2 和 Visual Studio 2013。

【问题讨论】:

    标签: f# monogame


    【解决方案1】:

    我最终发现(在this forum thread 的帮助下)我只需要在效果文件中将POSITION 替换为SV_POSITION。这是在 DirectX 10/11 而不是 XNA 的 DirectX 9 中构建 MonoGame 的结果。

    【讨论】:

      猜你喜欢
      • 2021-04-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-25
      相关资源
      最近更新 更多