• Advertisement
Sign in to follow this  

Having trouble with my Vertex Element Class

This topic is 1361 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

OK, I'm trying to make it so all you have to do to add a new vertex element is this:

void Shape::setVertexElement(string semanticName, unsigned int semanticIndex, unsigned int format, unsigned int inputSlot, unsigned int inputSlotClass, unsigned int alignedByteOffset, unsigned int instanceDataStepRate)
{
	VertexElement* vertElem = new VertexElement(semanticName, semanticIndex, format, inputSlot, inputSlotClass, alignedByteOffset, instanceDataStepRate);
	
	m_vertexElements.push_back(*vertElem);
}

than, updating them like this:

void Shape::createInputlayout()
{
	D3D11_INPUT_ELEMENT_DESC* elemDesc = new D3D11_INPUT_ELEMENT_DESC[this->m_vertexElements.size() - 1];

	VertexElements::iterator i;
	unsigned int x;
	for (x = 0, i = m_vertexElements.begin(); i != m_vertexElements.end(); ++i, ++x)
	{
		elemDesc[x].SemanticName = static_cast<LPCSTR>(i->getSemanticName().c_str());
		elemDesc[x].SemanticIndex = i->getSemanticIndex();
		elemDesc[x].Format = static_cast<DXGI_FORMAT>(i->getFormat());
		elemDesc[x].InputSlot = i->getInputslot();
		elemDesc[x].InputSlotClass = static_cast<D3D11_INPUT_CLASSIFICATION>(i->getInputSlotClass());
		elemDesc[x].InstanceDataStepRate = i->getInstanceDataStepRate();
		elemDesc[x].AlignedByteOffset = i->getAlignedByteOffset();
		
	
	}
	if (m_hardwareMaterial != NULL)
	{
		HRESULT hr = m_device->CreateInputLayout(elemDesc, (unsigned int)m_vertexElements.size(), m_hardwareMaterial->getVertexShaderBlob()->GetBufferPointer(), m_hardwareMaterial->getVertexShaderBlob()->GetBufferSize(), &m_inputlayout);

		if (FAILED(hr))
		{
			const char* err = DXGetErrorDescriptionA(hr);

			MessageBoxA(NULL, err, NULL, MB_OK);
			return;
		}
		m_devContext->IASetInputLayout(m_inputlayout);
	}

	
}

How ever, for some reason, Direct3D says this:

D3D11 ERROR: ID3D11Device::CreateInputLayout: Element[1] and Element[0] have the same Semantic ( 0).  All Semantics in the Input Layout must be unique.  This error is only printed on the first occurence detected. [ STATE_CREATION ERROR #160: CREATEINPUTLAYOUT_DUPLICATESEMANTIC]

It seems like the string from the class isn't updating right. I wonder if I'm doing it wrong or you can't do it this way. (I was trying to do it like Ogre's vertex declaration, but they do it with Direct3D9. I thought it would be the same concept, since all you'd have to do is iterator through the vector and set the elements[x] to what ever the iterator holds.)

Share this post


Link to post
Share on other sites
Advertisement

What are the VertexElements you feed it with? Do elements that share the same semantic-name have individually unique indices? A name + index pair defines a unique semantic.

 

It would be less error sensitive if you don't have to specify a semanticIndex, but calculate it based on the number of previous occurrences of the same name.

Share this post


Link to post
Share on other sites

Yes, there would be an error in the loop block. Something would be filled twice.

P. S.
Consider such versions of your function smile.png

void Shape::setVertexElement(string semanticName, unsigned int semanticIndex, unsigned int format, unsigned int inputSlot, unsigned int inputSlotClass, unsigned int alignedByteOffset, unsigned int instanceDataStepRate)
{
	m_vertexElements.emplace_back(semanticName, semanticIndex, format, inputSlot, inputSlotClass, alignedByteOffset, instanceDataStepRate);
}

void Shape::setVertexElement(string semanticName, unsigned int semanticIndex, unsigned int format, unsigned int inputSlot, unsigned int inputSlotClass, unsigned int alignedByteOffset, unsigned int instanceDataStepRate)
{
	m_vertexElements.push_back(VertexElement(semanticName, semanticIndex, format, inputSlot, inputSlotClass, alignedByteOffset, instanceDataStepRate));
}
Edited by kubera

Share this post


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

  • Advertisement