Keith Newton

This is a bit of an odd problem I ran into (seems to be the only ones I find hehe). I have a windows forms application that is using XNA to render to a window. I am using deferred shading so it involves many full screen quads being rendered to and then finaly composed for the final scene. All of these full screen quads are being rendered using DrawUserPrimitive(). When I call DrawUserPrimitive() to render the final scene to the back buffer using the Debug D3D runtime I get an InvalidOperationException. Switching to the retail D3D runtime fixes this problem. Anybody have an idea why this could be or should I submit a bug report on Connect

Full screen quad code:

m_shader.BeginCombinePass();

RenderToTexture(m_device.Viewport.Width, m_device.Viewport.Height);

m_shader.EndCombinePass();

public void RenderToTexture(int width, int height)
{

float xOff = 1.0f / width;

float yOff = 1.0f / height;

m_screenVerts[0].m_pos = new Vector4(-1.0f - xOff, 1.0f + yOff, 0.0f, 1.0f);

m_screenVerts[1].m_pos = new Vector4(1.0f - xOff, 1.0f + yOff, 0.0f, 1.0f);

m_screenVerts[2].m_pos = new Vector4(-1.0f - xOff, -1.0f + yOff, 0.0f, 1.0f);

m_screenVerts[3].m_pos = new Vector4(1.0f - xOff, -1.0f + yOff, 0.0f, 1.0f);

m_device.RenderState.CullMode = CullMode.None;

m_device.VertexDeclaration = m_fullScreenQuadVD;

CullMode currentCulling = m_device.RenderState.CullMode;

m_device.RenderState.CullMode = CullMode.None;

m_device.DrawUserPrimitives<ScreenVert>(PrimitiveType.TriangleStrip, m_screenVerts, 0, 2);

m_device.RenderState.CullMode = currentCulling;
}

P.S. Is there a better way to past code in this forum I couldn't find any documentation on a [code] tag or anything of the like.




Re: XNA Framework Problem with DrawUserPrimitive(), MRT's, while using the D3D debug runtime

Leaf.

Switching to release doesn't fix the issue it probably just hides it. DirectX only reports many errors when using the debug runtimes. You should get hold of something to view the DirectX debug output because it is likely that the debug output contains information telling you why DirectX complained. Use DebugView or similar to view native debug output, unfortunately VC# Express only shows managed debug output.

Cheers,
Leaf.






Re: XNA Framework Problem with DrawUserPrimitive(), MRT's, while using the D3D debug runtime

Keith Newton

It says:

[3628] Direct3D9: Decl Validator: X247: (Element Error) (Decl Element [0]) Declaration can't map to fixed function FVF because position must use D3DDECLTYPE_FLOAT3.
[3628] Direct3D9: Decl Validator: X288: (Global Error) Declaration can't map to fixed function FVF because position field is missing. Usage: D3DDECLUSAGE_POSITION, with usage index 0 is required for fixed function.

If this was something that D3D Retail was simply hiding then why does it render correctly






Re: XNA Framework Problem with DrawUserPrimitive(), MRT's, while using the D3D debug runtime

X-Tatic

Paste what makes up m_fullScreenQuadVD.




Re: XNA Framework Problem with DrawUserPrimitive(), MRT's, while using the D3D debug runtime

Keith Newton

[StructLayout(LayoutKind.Sequential)]

public struct ScreenVert

{

public Vector4 m_pos;

public Vector2 m_texCoords;

public Vector2 m_padding; //pad the structure to 32-bytes to align w/ the vertex cache

public static VertexElement[] VertexElements =

{

new VertexElement(0, 0, VertexElementFormat.Vector4, VertexElementMethod.Default, VertexElementUsage.Position, 0),

new VertexElement(0, 16, VertexElementFormat.Vector2, VertexElementMethod.Default, VertexElementUsage.TextureCoordinate, 0),

new VertexElement(0, 24, VertexElementFormat.Vector2, VertexElementMethod.Default, VertexElementUsage.TextureCoordinate, 1)

};

public static int SizeInBytes

{

get { return Marshal.SizeOf(typeof(ScreenVert)); }

}

}