create 2 index buffer

Started by
3 comments, last by Le Van 10 years, 11 months ago

hi there, ive just read the following tutorial http://www.braynzarsoft.net/index.php?p=D3D11INDICES
A
nd i started do the exercise 1. Make 2 index buffer.


	Vertex v[] =
	{
		Vertex( -0.5f, -0.5f, 0.5f, 1.0f, 0.0f, 0.0f, 1.0f ),
		Vertex( -0.5f,  0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 1.0f ),
		Vertex(  0.5f,  0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 1.0f ),
		Vertex(  0.5f, -0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 1.0f ),
		Vertex(  0.0f,  1.0f, 0.5f, 0.0f, 1.0f, 0.0f, 1.0f ),
	};

	DWORD indices1[] = {
		0, 1, 2,
		0, 2, 3,
	};

	DWORD indices2[] = {
		1, 2, 4
	};

	D3D11_BUFFER_DESC indexBufferDesc;
	ZeroMemory( &indexBufferDesc, sizeof(indexBufferDesc) );

	indexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
	indexBufferDesc.ByteWidth = sizeof(DWORD) * 2 * 3;
	indexBufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
	indexBufferDesc.CPUAccessFlags = 0;
	indexBufferDesc.MiscFlags = 0;

	D3D11_SUBRESOURCE_DATA iinitData;
	//D3D11_SUBRESOURCE_DATA iinitData2;


	iinitData.pSysMem = indices1;
	d3d11Device->CreateBuffer(&indexBufferDesc, &iinitData, &squareIndexBuffer1);

	indexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
	indexBufferDesc.ByteWidth = sizeof(DWORD) * 1 * 3;
	indexBufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
	indexBufferDesc.CPUAccessFlags = 0;
	indexBufferDesc.MiscFlags = 0;

	iinitData.pSysMem = indices2;
	d3d11Device->CreateBuffer(&indexBufferDesc, &iinitData, &squareIndexBuffer2);

	d3d11DevCon->IASetIndexBuffer( squareIndexBuffer1, DXGI_FORMAT_R32_UINT, 0);
	d3d11DevCon->IASetIndexBuffer( squareIndexBuffer2, DXGI_FORMAT_R32_UINT, 0);

And the questions are:

1.i use the same D3D11_BUFFER_DESC and D3D11_SUBRESOURCE_DATA to create 2 Index buffer ( adjust the fied of D3D11_BUFFER_DESC )
Is it possible?
2. the function d3d11DevCon->IASetIndexBuffer(). i so confuse about the third parametter, how can we know the offset? Thankyou

Advertisement

1. Yes it is.

2. the offset param defines the start of the buffer. Mostly this is zero (so the first index used is the first inside the buffer). You could however have 1 big buffer made of multiple smaller onces, that is where the offset comes into place.

thankyou smile.png.


d3d11DevCon->IASetIndexBuffer( squareIndexBuffer1, DXGI_FORMAT_R32_UINT, 0);
d3d11DevCon->IASetIndexBuffer( squareIndexBuffer2, DXGI_FORMAT_R32_UINT, 0);

the second index buffer set to the IA stage require the offset, how can we get the size of the first buffer ?

Sounds like you're trying to set 2 index buffers at once, you can have set only 1 index buffer at a time.

the article say "Make 2 buffers", can u post the code, i can't imagine it smile.png. If there is 1 buffer set. Thankyou so much, i have tried but its all blank screen.

This topic is closed to new replies.

Advertisement