Jump to content

  • Log In with Google      Sign In   
  • Create Account


Having trouble with my Vertex Element Class


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
2 replies to this topic

#1 Enerjak   Members   -  Reputation: 230

Like
0Likes
Like

Posted 03 May 2014 - 12:43 AM

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.)



Sponsor:

#2 eppo   Crossbones+   -  Reputation: 2337

Like
1Likes
Like

Posted 03 May 2014 - 02:54 AM

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.



#3 kubera   Members   -  Reputation: 888

Like
1Likes
Like

Posted 03 May 2014 - 02:31 PM

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, 03 May 2014 - 04:44 PM.





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