Jump to content

  • Log In with Google      Sign In   
  • Create Account


jdub

Member Since 01 Aug 2007
Offline Last Active Feb 22 2014 09:35 PM
-----

#5089085 Using padding to make vertex structures align?

Posted by jdub on 25 August 2013 - 11:29 PM

Forgive me if I have things totally wrong here as I'm not too informed on this subject.  I was wondering if it makes a performance difference to add extra padding to my vertex structures to make them align along 32bit boundaries?

 

I'm running a 64bit system so I'm not sure if it would matter (adding enough padding to make my vertex structures align along a 64bit boundary seems like an absurd waste of memory to me).




#4971696 [SlimDX] Triangle not Drawing Correctly

Posted by jdub on 20 August 2012 - 09:09 PM

Trying to render a triangle on the screen. Here's the code which sets up the transform:

Triangle Vertices:
Vector3[] vertices =
			{
				  new Vector3(1.0f, 1.0f, 1.0f),
				  new Vector3(1.0f, 0.0f, 1.0f),
				  new Vector3(0.0f, 0.0f, 1.0f),
			};

private void setShaderParams(Matrix view, Matrix world, Matrix projection)
		{
			BufferDescription bufferDescr = new BufferDescription(
				Marshal.SizeOf(typeof(ConstantBuffer)),
				ResourceUsage.Default,
				BindFlags.ConstantBuffer,
				CpuAccessFlags.None,
				ResourceOptionFlags.None,
				0);
			DXBuffer buffer = new DXBuffer(this.device, bufferDescr);
			DataStream stream = new DataStream(Marshal.SizeOf(typeof(ConstantBuffer)), true, true);
			stream.Write<ConstantBuffer>(new ConstantBuffer() {View = Matrix.Transpose(view), World = Matrix.Transpose(world), Projection = Matrix.Transpose(projection)});
			stream.Position = 0;
			this.context.UpdateSubresource(new DataBox(0, 0, stream), buffer, 0);
		}

this is called at the end of my init function:
Matrix view = Matrix.LookAtLH(Vector3.Zero, -Vector3.UnitZ, Vector3.UnitY);
			Matrix world = Matrix.AffineTransformation(1f, Vector3.Zero, Quaternion.RotationAxis(Vector3.UnitY, 0f), Vector3.Zero);
			Matrix projection = Matrix.PerspectiveFovLH(0.523598776f, 480 / 640, 1.0f, 100.0f);
			this.setShaderParams(view, world, projection);

here's my shader code:
cbuffer ConstantBuffer : register( b0 )
{
	matrix World;
	matrix View;
	matrix Projection;
}


float4 VShader(float4 position : POSITION) : SV_Position
{
float4 output = position;
mul( output, World );
mul( output, View );
mul( output, Projection );
return output;
}

float4 PShader(float4 position : SV_POSITION) : SV_Target
{
	return float4(1.0f, 1.0f, 0.0f, 1.0f);
}

Note that the camera is facing down the negative Z-Axis so the triangle would be out of view right? Wrong. triangle is in view which makes me think that none of the transformations are being applied and DirectX is treating the vertices of the triangle as if they were already transformed. Anybody have any clue where I'm going wrong?


PARTNERS