本文整理汇总了C++中VertexElement::getOffset方法的典型用法代码示例。如果您正苦于以下问题:C++ VertexElement::getOffset方法的具体用法?C++ VertexElement::getOffset怎么用?C++ VertexElement::getOffset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VertexElement
的用法示例。
在下文中一共展示了VertexElement::getOffset方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: mLoad
//.........这里部分代码省略.........
Vertex v;
v.setPosition(positions[vi.p]);
if (hasUv) {
v.setUv(uvs[vi.uv]);
}
if (hasFlat) {
v.setFlatNormal(flatNormals[vi.fn]);
}
if (hasSmooth) {
v.setSmoothNormal(smoothNormals[vi.sn]);
}
vertices.push_back(v);
} else {
indices.push_back(indexMap[vi]);
}
}
U32 vertexSize = 0;
U32 vertexCount = (U32) vertices.size();
//Positions
VertexElement positionElement(VertexElement::Semantic::POSITION, 3, GL_FLOAT, vertexSize);
vertexSize += positionElement.getSizeInByte();
mesh->addVertexElement(positionElement);
//Normals
if (hasFlat) {
VertexElement flatNormalElement(VertexElement::Semantic::FLAT_NORMAL, 3, GL_FLOAT, vertexSize);
vertexSize += flatNormalElement.getSizeInByte();
mesh->addVertexElement(flatNormalElement);
}
if (hasSmooth) {
VertexElement smoothNormalElement(VertexElement::Semantic::SMOOTH_NORMAL, 3, GL_FLOAT, vertexSize);
vertexSize += smoothNormalElement.getSizeInByte();
mesh->addVertexElement(smoothNormalElement);
}
// UVs
if (hasUv) {
VertexElement uvElement(VertexElement::Semantic::UV, 2, GL_FLOAT, vertexSize);
vertexSize += uvElement.getSizeInByte();
mesh->addVertexElement(uvElement);
}
mesh->mVertexSize = vertexSize;
mesh->mVertexCount = vertexCount;
//Log::debug(TAG, "vertexSize=%d vertexCount=%d", vertexSize, vertexCount);
//Log::debug(TAG, "indices=%d", indices.size());
BYTE* data = new BYTE[vertexSize * vertexCount];
/////////////////////////////////////////////////////////////////////////
// Generate vertex buffer
//delete mesh->mVertexBuffer;
if (mesh->mVertexBuffer != nullptr) {
mesh->mVertexBuffer->wipe();
}
mesh->mVertexBuffer = std::make_shared<VertexBuffer>(vertexSize, (U32) (vertexSize * vertexCount));
/////////////////////////////////////////////////////////////////////////
// Fills data
for (U32 v = 0; v < vertexCount; ++v) {
if (mesh->hasVertexElement(VertexElement::Semantic::POSITION)) {
VertexElement ve = mesh->getVertexElement(VertexElement::Semantic::POSITION);
memcpy(&data[v * vertexSize + ve.getOffset()], &(vertices[v].getPosition()), ve.getSizeInByte());
}
if (mesh->hasVertexElement(VertexElement::Semantic::FLAT_NORMAL)) {
VertexElement ve = mesh->getVertexElement(VertexElement::Semantic::FLAT_NORMAL);
memcpy(&data[v * vertexSize + ve.getOffset()], &(vertices[v].getFlatNormal()), ve.getSizeInByte());
}
if (mesh->hasVertexElement(VertexElement::Semantic::SMOOTH_NORMAL)) {
VertexElement ve = mesh->getVertexElement(VertexElement::Semantic::SMOOTH_NORMAL);
memcpy(&data[v * vertexSize + ve.getOffset()], &(vertices[v].getSmoothNormal()), ve.getSizeInByte());
}
if (mesh->hasVertexElement(VertexElement::Semantic::UV)) {
VertexElement ve = mesh->getVertexElement(VertexElement::Semantic::UV);
memcpy(&data[v * vertexSize + ve.getOffset()], &(vertices[v].getUv()), ve.getSizeInByte());
}
}
/////////////////////////////////////////////////////////////////////////
// Uploads data to GPU
mesh->mVertexBuffer->writeData(0, vertexSize * vertexCount, data);
delete[] data;
//delete mesh->mIndexBuffer;
if (mesh->mIndexBuffer != nullptr) {
mesh->mIndexBuffer->wipe();
}
mesh->mIndexBuffer = std::make_shared<IndexBuffer>((U32) indices.size());
mesh->mIndexBuffer->writeData(indices.data());
mesh->mBoundingSphere = generateBoundingSphere(positions);
Log::trace(TAG, "Mesh %s loaded", sid.c_str());
return STATUS_OK;
}