1

I'm getting an unhandled exception with the message HRESULT: [0x80070057], Module: [General], ApiCode: [E_INVALIDARG/Invalid Arguments], Message: The parameter is incorrect. at the call to DrawUserPrimitives in the code below:

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)

My effect code is as follows (taken from the excellent Riemer's tutorials) and is as simple as can be. It's being converted as in this answer, and that seems to be working because I can see the effect name if I put a breakpoint in before the draw call.

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();
    }
}

It works fine if I replace the custom effect with a BasicEffect as per this example.

I'm using Monogame 3.2 and Visual Studio 2013.

Community
  • 1
  • 1
Mark Pattison
  • 2,964
  • 1
  • 22
  • 42

1 Answers1

3

I worked out eventually (with help from this forum thread) that I just needed to replace POSITION with SV_POSITION in the effect file. This is a consequence of MonoGame being built in DirectX 10/11 rather then XNA's DirectX 9.

Mark Pattison
  • 2,964
  • 1
  • 22
  • 42