Jump to content

  • Log In with Google      Sign In   
  • Create Account

Using 2 input slots and 2 vertex buffers


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 noatom   Members   -  Reputation: 782

Like
0Likes
Like

Posted 23 June 2012 - 09:31 AM

I wanna send the position trough one input slot,and the color trough another input slot.Then i wanna create a vertex buffer for position,one for color,and use them.The problem is that I that the color doesn't get processed! The position gets there,but the color not,so everything remains black!

[source lang="cpp"] // Create the vertex input layout. D3D10_INPUT_ELEMENT_DESC vertexDesc[] = { {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0}, {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, 0, D3D10_INPUT_PER_VERTEX_DATA, 0} }; // Create the input layout D3D10_PASS_DESC PassDesc; mTech->GetPassByIndex(0)->GetDesc(&PassDesc); HR(md3dDevice->CreateInputLayout(vertexDesc, 2, PassDesc.pIAInputSignature, PassDesc.IAInputSignatureSize, &mVertexLayout)); mNumVertices = 8; mNumFaces = 7; // 2 per quad // Create vertex buffer Vertex vertices[] = { {D3DXVECTOR3(+1.0f, 0.0f, -1.0f), WHITE}, {D3DXVECTOR3(-1.0f, 0.0f, -1.0f), BLACK}, {D3DXVECTOR3(+1.0f, 0.0f, +1.0f), RED}, {D3DXVECTOR3(-1.0f, 0.0f, +1.0f), GREEN}, {D3DXVECTOR3(0.0f, 2.0f, 0.0f), BLUE}, //varf {D3DXVECTOR3(+4.0f, 0.0f, -1.0f), WHITE}, {D3DXVECTOR3(+6.0f, 0.0f, -1.0f), BLACK}, {D3DXVECTOR3(+5.0f, 0.0f, +1.0f), RED}, }; // Scale the box. for(DWORD i = 0; i < mNumVertices; ++i) vertices[i].pos *= scale; D3D10_BUFFER_DESC vbd; vbd.Usage = D3D10_USAGE_IMMUTABLE; vbd.ByteWidth = sizeof(Vertex) * mNumVertices; vbd.BindFlags = D3D10_BIND_VERTEX_BUFFER; vbd.CPUAccessFlags = 0; vbd.MiscFlags = 0; D3D10_SUBRESOURCE_DATA vinitData; vinitData.pSysMem = vertices; HR(md3dDevice->CreateBuffer(&vbd, &vinitData, &mVB)); D3D10_BUFFER_DESC vbd2; vbd2.Usage = D3D10_USAGE_IMMUTABLE; vbd2.ByteWidth = sizeof(Vertex) * mNumVertices; vbd2.BindFlags = D3D10_BIND_VERTEX_BUFFER; vbd2.CPUAccessFlags = 0; vbd2.MiscFlags = 0; D3D10_SUBRESOURCE_DATA vinitData2; vinitData2.pSysMem = vertices; HR(md3dDevice->CreateBuffer(&vbd2, &vinitData2, &mVB2)); // Create the index buffer DWORD indices[] = { 1,0,2, 1,3,2, 0,4,1, 0,4,2, 4,2,3, 4,3,1, 5,6,7 }; D3D10_BUFFER_DESC ibd; ibd.Usage = D3D10_USAGE_IMMUTABLE; ibd.ByteWidth = sizeof(DWORD) * mNumFaces*3; ibd.BindFlags = D3D10_BIND_INDEX_BUFFER; ibd.CPUAccessFlags = 0; ibd.MiscFlags = 0; D3D10_SUBRESOURCE_DATA iinitData; iinitData.pSysMem = indices; HR(md3dDevice->CreateBuffer(&ibd, &iinitData, &mIB)); ID3D10Buffer* g[] = {mVB,mVB2}; UINT stride = sizeof(Vertex); UINT offset = 0; md3dDevice->IASetVertexBuffers(0, 2, g, &stride, &offset); md3dDevice->IASetIndexBuffer(mIB, DXGI_FORMAT_R32_UINT, 0); md3dDevice->DrawIndexed(mNumFaces*3 - 3, 0, 0); md3dDevice->DrawIndexed(3,mNumFaces * 3 - 3, 0);[/source]

Sponsor:

#2 TiagoCosta   Crossbones+   -  Reputation: 2190

Like
4Likes
Like

Posted 23 June 2012 - 11:55 AM

You have some errors in your code.

1-If you want data separated in two vertex buffers store it in different structures, in this case no need to use structures since each buffer only contains one type of data.
So separate position from color like this:

D3DXVECTOR3 verticesPos[] = { positions here };
D3DXCOLOR verticesColor[] = {colors here};


2-The code you're using to create the buffers is creating 2 buffers each containing both positions and colors. So replace to this:
D3D10_BUFFER_DESC vbd;

	vbd.Usage = D3D10_USAGE_IMMUTABLE;
	vbd.ByteWidth = sizeof([b]D3DXVECTOR3[/b]) * mNumVertices;
	vbd.BindFlags = D3D10_BIND_VERTEX_BUFFER;
	vbd.CPUAccessFlags = 0;
	vbd.MiscFlags = 0;
	D3D10_SUBRESOURCE_DATA vinitData;
	vinitData.pSysMem = [b]verticesPos[/b];
	HR(md3dDevice->CreateBuffer(&vbd, &vinitData, &mVB));

	D3D10_BUFFER_DESC vbd2;
	vbd2.Usage = D3D10_USAGE_IMMUTABLE;
	vbd2.ByteWidth = sizeof([b]D3DXCOLOR[/b]) * mNumVertices;
	vbd2.BindFlags = D3D10_BIND_VERTEX_BUFFER;
	vbd2.CPUAccessFlags = 0;
	vbd2.MiscFlags = 0;
	D3D10_SUBRESOURCE_DATA vinitData2;
	vinitData2.pSysMem = [b]verticesColor[/b];
	HR(md3dDevice->CreateBuffer(&vbd2, &vinitData2, &mVB2));


3-If you're using multiple vertex buffers you have to pass an array of strides/offsets:

UINT strides[] = { sizeof(D3DXVECTOR3), sizeof(D3DXCOLOR) };

	UINT offsets[] = {0,0};
		md3dDevice->IASetVertexBuffers(0, 2, g, strides, offsets);



#3 Nik02   Crossbones+   -  Reputation: 2824

Like
0Likes
Like

Posted 23 June 2012 - 12:03 PM

You fill both of the buffers with the same interleaved data (that contains both positions and colors). Since the vertex stride (byte width) is still correct in both buffers, the input assembler treats the first 16 bytes of each vertex found in the second vertex buffer as color (which is presumably not what you want).

Also, enable the debug output to see if you get warnings for invalid states. An invalid pixel shader can cause black results.

Niko Suni


#4 noatom   Members   -  Reputation: 782

Like
0Likes
Like

Posted 23 June 2012 - 09:40 PM

Tiago,can you also tell me how to use structures like you said above?

How would this work with structures if I would have 2 vertex buffers and the following elements:



position


normal


color


texcoord



So I would send position and normal trough 1 buffer,and color and texcoord in another buffer.



Please show me how I would use the structures in this.



#5 TiagoCosta   Crossbones+   -  Reputation: 2190

Like
1Likes
Like

Posted 24 June 2012 - 02:52 AM

Create 2 structures and fill them:
struct PosNormal
{
	 D3DXVECTOR3 position;
	 D3DXVECTOR3 normal;
};


struct ColorTexC
{
	 D3DXCOLOR color;
	 D3DXVECTOR2 texC;
};

PosNormal positionNormals[] = { data here };
ColorTexC colorTexCoords[] = { data here };

Replace the size of the buffers and the strides
D3D10_BUFFER_DESC vbd;
vbd.Usage = D3D10_USAGE_IMMUTABLE;
vbd.ByteWidth = sizeof([b]PosNormal[/b]) * mNumVertices;
vbd.BindFlags = D3D10_BIND_VERTEX_BUFFER;
vbd.CPUAccessFlags = 0;
vbd.MiscFlags = 0;
D3D10_SUBRESOURCE_DATA vinitData;
vinitData.pSysMem = [b]positionNormals[/b];
HR(md3dDevice->CreateBuffer(&vbd, &vinitData, &mVB));

D3D10_BUFFER_DESC vbd2;
vbd2.Usage = D3D10_USAGE_IMMUTABLE;
vbd2.ByteWidth = sizeof([b]ColorTexC[/b]) * mNumVertices;
vbd2.BindFlags = D3D10_BIND_VERTEX_BUFFER;
vbd2.CPUAccessFlags = 0;
vbd2.MiscFlags = 0;
D3D10_SUBRESOURCE_DATA vinitData2;
vinitData2.pSysMem = [b]colorTexCoords[/b];
HR(md3dDevice->CreateBuffer(&vbd2, &vinitData2, &mVB2));


UINT strides[] = { sizeof(PosNormal), sizeof(ColorTexC) };
UINT offsets[] = {0,0};
md3dDevice->IASetVertexBuffers(0, 2, buffers, strides, offsets);





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS