Jump to content
  • Advertisement
Sign in to follow this  
vidalsasoon

VertexDeclaration and FVF

This topic is 4744 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

CODE THAT WORKS WITH FVF:

Render()...

dev.SetRenderTarget(0,_backBuffer); 

dev.SetTexture(0,_renderTexture);
dev.SetStreamSource(0, vertBuffer, 0);
dev.VertexFormat = CustomVertex.TransformedTextured.Format;
dev.Indices = ib;		    dev.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 4, 0, 2);


CODE THAT I WOULD LIKE TO WORK WITH VERTEXDECLARATION!:

Constructor()...

VertexElement[] elements = new VertexElement[]
{	
	new VertexElement(0, 0, DeclarationType.Float4,
	DeclarationMethod.Default,
	DeclarationUsage.Position, 0),
			                            
	new VertexElement(0, 16, DeclarationType.Float2,
	DeclarationMethod.Default,
	DeclarationUsage.TextureCoordinate, 0),		                    
            
	VertexElement.VertexDeclarationEnd 
};
decl = new VertexDeclaration(dev, elements);

Render()...

dev.SetRenderTarget(0,_backBuffer); 
dev.SetTexture(0,_renderTexture);
dev.SetStreamSource(0, vertBuffer, 0);
//dev.VertexFormat = CustomVertex.TransformedTextured.Format;
dev.VertexDeclaration = decl;
dev.Indices = ib;		    dev.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 4, 0, 2);



Vertex Buffer
vertBuffer = new VertexBuffer(typeof(PositionTexVertex), 4, dev, Usage.None, PositionTexVertex.FVF, Pool.Managed);

			PositionTexVertex[] vbData = (PositionTexVertex[]) vertBuffer.Lock(0, typeof(PositionTexVertex), LockFlags.None, 4);

			vbData[0].Position = new Vector4(0, dev.Viewport.Height, 0.0f, 1);  
			vbData[0].UV = new Vector2(0,1);

			vbData[1].Position = new Vector4(0, 0, 0.0f, 1);  
			vbData[1].UV = new Vector2(0,0);

			vbData[2].Position = new Vector4(dev.Viewport.Width, 0, 0.0f, 1);  
			vbData[2].UV = new Vector2(1,0);

			vbData[3].Position = new Vector4(dev.Viewport.Width, dev.Viewport.Height, 0.0f, 1);  
			vbData[3].UV = new Vector2(1,1);


			//Unlock the vb before you can use it elsewhere
			vertBuffer.Unlock();


PositionTexVertex struct
	public struct PositionTexVertex
	{
		public Vector4 Position;
		public Vector2 UV;
		//public static readonly VertexFormats FVF = VertexFormats.Position | VertexFormats.Texture0;
		public static readonly VertexFormats FVF = CustomVertex.TransformedTextured.Format;
	}


Basically, CustomVertex.TransformedTextured.Format works but when trying to switch over to a vertexdeclaration, information is no longer synchronized? Should both VertexDeclaration and FVF be used at the same time? Thanks, V.

Share this post


Link to post
Share on other sites
Advertisement
Hi there VidalSasoon,
How are you doing?

The Problem
Your own custom vertex format... not working like it should.

The Solution
Buddy, this tutorial by DrunkenHyena is fantastic.

1) You have to give direct3d a format to work with. It has to know how your
vertex buffer is formatted to be able to render from it
2) The vertex format would be
e.g.
public static readonly D3D.VertexFormats Format =
Microsoft.DirectX.Direct3D.VertexFormats.Position | Microsoft.DirectX.Direct3D.VertexFormats.Diffuse;

I hope this helps buddy.
Take care.

Share this post


Link to post
Share on other sites
Quote:
Original post by vidalsasoon
Should both VertexDeclaration and FVF be used at the same time?

You shouldn't need both of them.

Is the debug runtime telling you anything? I find that it's pretty good at complaining about FVF/VertDecl mis-matches [smile]

I can't see anything else that's obviously wrong with your code... Make sure you run with a software device and the debug runtimes cranked up!

hth
Jack

Share this post


Link to post
Share on other sites
Typically you would only change the vertex declaration if you are using a programmable shader. Is this what you meant to do? If you change it, then you must set your FVF so that the pipeline knows which elements you are using, so yes you must uncomment your dev.VertexFormat = CustomVertex.TransformedTextured.Format; line. I think this is correct anyway...haven't messed with decls in a while.

Share this post


Link to post
Share on other sites

thanks for replies but i'm still confused.


is the following equivalent?

CustomVertex.TransformedTexture.Format == VertexFormats.Transformed | VertexFormats.Texture1

I think they are so i'll assume yes.

Setting my vertex declaration always crashes app when trying at DrawPrimitive()..


dev.VertexDeclaration = decl;

Now from what I can tell TransformedTexture is a Vector4 followed by a Verctor2?

I don't know what's wrong :(

...

VertexElement[] elements = new VertexElement[]
{
new VertexElement(0, 0, DeclarationType.Float4,
DeclarationMethod.Default,
DeclarationUsage.Position, 0),

new VertexElement(0, 16, DeclarationType.Float2,
DeclarationMethod.Default,
DeclarationUsage.TextureCoordinate, 0),

VertexElement.VertexDeclarationEnd
};

decl = new VertexDeclaration(dev, elements);

Share this post


Link to post
Share on other sites
Hi there. Your problem is with your declaration.

VertexElement[] elements = new VertexElement[]
{
new VertexElement(0, 0, DeclarationType.Float4,
DeclarationMethod.Default,
DeclarationUsage.PositionTransformed, 0),

new VertexElement(0, 16, DeclarationType.Float2,
DeclarationMethod.Default,
DeclarationUsage.TextureCoordinate, 0),

VertexElement.VertexDeclarationEnd
};


DeclarationUsage.Position should be changed to DeclarationUsage.PositionTransformed

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!