当前位置: 首页>>代码示例>>C++>>正文


C++ VertexElement::size方法代码示例

本文整理汇总了C++中VertexElement::size方法的典型用法代码示例。如果您正苦于以下问题:C++ VertexElement::size方法的具体用法?C++ VertexElement::size怎么用?C++ VertexElement::size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在VertexElement的用法示例。


在下文中一共展示了VertexElement::size方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: rebuild

void VertexDeclaration::rebuild()
{
	mHash = 0;
	int nTexCoord = 0;

	int nElem = 0;
	int nVB = mParent->vertexBufferCount();
	for (int v = 0; v<nVB; ++v) {
		VertexBuffer* vb = mParent->vertexBuffer(v);
		if (vb) {
			nElem += vb->vertexElementCount();
		}
	}

	delete[] mElements;
	mElements = TD_NEW D3D11_INPUT_ELEMENT_DESC[nElem];

	int eIdx = 0;
	for (int v = 0; v<nVB; ++v) {
		VertexBuffer* vb = mParent->vertexBuffer(v);

		if (vb) {
			int offset = 0;

			int nVbElem = vb->vertexElementCount();
			for (int e = 0; e<nVbElem; ++e)
			{
				VertexElement* ve = vb->vertexElement(e);
				D3D11_INPUT_ELEMENT_DESC& elem = mElements[eIdx];

				elem.SemanticName = s_SemanticNameLUT[ve->mUsage];
				elem.SemanticIndex = (BYTE)ve->mIndex;
				elem.Format = makeD3D11Type(ve->mType, ve->mCount);
				elem.AlignedByteOffset = (WORD)offset;
				elem.InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
				elem.InputSlot = v;
				elem.InstanceDataStepRate = 0;

				offset += ve->size();
				++eIdx;

				// while we at this, create the hash (bitmask) that identifies this vertex structure
				if (ve->mUsage == VEU_TEXCOORD)
					nTexCoord++;

				int mask = 0;
				if (ve->mUsage != VEU_UNKNOWN) {
					mask = 1 << ve->mUsage;
				}

				mHash |= mask;
			}
		}
	}

	// add the number of texcoords (if any) to the hash
	mHash |= (nTexCoord << 16);

	// release any existing declaration object
	mLayout.Reset();

	// it seems pretty ugly from a dependency perspective, but D3D11 forces us to have an 
	// existing vertex shader in order to make a vertex declaration (input format), so we 
	// need to fetch one that matches the submesh (or face the warnings that the D3D runtime
	// will spew at us)
	VertexShader* vs = static_cast<VertexShader*>(ShaderManager::instance().createOrFindInstanceOf(mParent));

	// create the vertex declaration
	HRESULT hr = mDevice->CreateInputLayout(
		mElements,
		nElem,
		vs->bytecode(),
		vs->bytecodeLength(),
		&mLayout
		);

	if (FAILED(hr)) {
		throw Exception("Failed to (re)build vertex input layout in VertexDeclaration::rebuild");
	}
}
开发者ID:nbtdev,项目名称:teardrop,代码行数:80,代码来源:VertexDeclarationD3D11.cpp


注:本文中的VertexElement::size方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。