本文整理汇总了C++中ogre::VertexDeclaration::findElementsBySource方法的典型用法代码示例。如果您正苦于以下问题:C++ VertexDeclaration::findElementsBySource方法的具体用法?C++ VertexDeclaration::findElementsBySource怎么用?C++ VertexDeclaration::findElementsBySource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ogre::VertexDeclaration
的用法示例。
在下文中一共展示了VertexDeclaration::findElementsBySource方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createVertexDataForVertexAndGeometryShaders
void GPUBillboardSet::createVertexDataForVertexAndGeometryShaders(const std::vector<PhotoSynth::Vertex>& vertices)
{
// Setup render operation
mRenderOp.operationType = Ogre::RenderOperation::OT_POINT_LIST;
mRenderOp.vertexData = OGRE_NEW Ogre::VertexData();
mRenderOp.vertexData->vertexCount = vertices.size();
mRenderOp.vertexData->vertexStart = 0;
mRenderOp.useIndexes = false;
mRenderOp.indexData = 0;
// Vertex format declaration
unsigned short sourceBufferIdx = 0;
Ogre::VertexDeclaration* decl = mRenderOp.vertexData->vertexDeclaration;
size_t currOffset = 0;
decl->addElement(sourceBufferIdx, currOffset, Ogre::VET_FLOAT3, Ogre::VES_POSITION);
currOffset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);
decl->addElement(sourceBufferIdx, currOffset, Ogre::VET_COLOUR, Ogre::VES_DIFFUSE);
currOffset += Ogre::VertexElement::getTypeSize(Ogre::VET_COLOUR);
// Create vertex buffer
Ogre::HardwareVertexBufferSharedPtr vbuf = Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(
decl->getVertexSize(sourceBufferIdx),
mRenderOp.vertexData->vertexCount,
Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY);
// Bind vertex buffer
Ogre::VertexBufferBinding* bind = mRenderOp.vertexData->vertexBufferBinding;
bind->setBinding(sourceBufferIdx, vbuf);
// Fill vertex buffer (see http://www.ogre3d.org/docs/manual/manual_59.html#SEC287)
Ogre::RenderSystem* renderSystem = Ogre::Root::getSingletonPtr()->getRenderSystem();
unsigned char* pVert = static_cast<unsigned char*>(vbuf->lock(Ogre::HardwareBuffer::HBL_DISCARD));
Ogre::Real* pReal;
Ogre::RGBA* pRGBA;
Ogre::VertexDeclaration::VertexElementList elems = decl->findElementsBySource(sourceBufferIdx);
Ogre::VertexDeclaration::VertexElementList::iterator itr;
for (unsigned int i=0; i<vertices.size(); ++i )
{
const PhotoSynth::Vertex& vertex = vertices[i];
for (itr=elems.begin(); itr!=elems.end(); ++itr)
{
Ogre::VertexElement& elem = *itr;
if (elem.getSemantic() == Ogre::VES_POSITION)
{
elem.baseVertexPointerToElement(pVert, &pReal);
*pReal = vertex.position.x; *pReal++;
*pReal = vertex.position.y; *pReal++;
*pReal = vertex.position.z; *pReal++;
}
else if (elem.getSemantic() == Ogre::VES_DIFFUSE)
{
elem.baseVertexPointerToElement(pVert, &pRGBA);
renderSystem->convertColourValue(vertex.color, pRGBA);
}
}
// Go to next vertex
pVert += vbuf->getVertexSize();
}
vbuf->unlock();
// Set material
this->setMaterial("GPUBillboardWithGS");
}
示例2: createVertexDataForVertexShaderOnly
void GPUBillboardSet::createVertexDataForVertexShaderOnly(const std::vector<PhotoSynth::Vertex>& vertices)
{
// Setup render operation
mRenderOp.operationType = Ogre::RenderOperation::OT_TRIANGLE_LIST;
mRenderOp.vertexData = OGRE_NEW Ogre::VertexData();
mRenderOp.vertexData->vertexCount = vertices.size() * 4;
mRenderOp.vertexData->vertexStart = 0;
mRenderOp.useIndexes = true;
mRenderOp.indexData = OGRE_NEW Ogre::IndexData();
mRenderOp.indexData->indexCount = vertices.size() * 6;
mRenderOp.indexData->indexStart = 0;
// Vertex format declaration
unsigned short sourceBufferIdx = 0;
Ogre::VertexDeclaration* decl = mRenderOp.vertexData->vertexDeclaration;
size_t currOffset = 0;
decl->addElement(sourceBufferIdx, currOffset, Ogre::VET_FLOAT3, Ogre::VES_POSITION);
currOffset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);
decl->addElement(sourceBufferIdx, currOffset, Ogre::VET_COLOUR, Ogre::VES_DIFFUSE);
currOffset += Ogre::VertexElement::getTypeSize(Ogre::VET_COLOUR);
decl->addElement(sourceBufferIdx, currOffset, Ogre::VET_FLOAT2, Ogre::VES_TEXTURE_COORDINATES, 0);
currOffset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT2);
// Create vertex buffer
Ogre::HardwareVertexBufferSharedPtr vbuf = Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(
decl->getVertexSize(sourceBufferIdx),
mRenderOp.vertexData->vertexCount,
Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY);
// Bind vertex buffer
Ogre::VertexBufferBinding* bind = mRenderOp.vertexData->vertexBufferBinding;
bind->setBinding(sourceBufferIdx, vbuf);
// Fill vertex buffer (see http://www.ogre3d.org/docs/manual/manual_59.html#SEC287)
Ogre::RenderSystem* renderSystem = Ogre::Root::getSingletonPtr()->getRenderSystem();
unsigned char* pVert = static_cast<unsigned char*>(vbuf->lock(Ogre::HardwareBuffer::HBL_DISCARD));
Ogre::Real* pReal;
Ogre::RGBA* pRGBA;
Ogre::VertexDeclaration::VertexElementList elems = decl->findElementsBySource(sourceBufferIdx);
Ogre::VertexDeclaration::VertexElementList::iterator itr;
const Ogre::Vector2 uvs[4] = { Ogre::Vector2( -1.f, 1.f ),
Ogre::Vector2( -1.f, -1.f ),
Ogre::Vector2( 1.f, -1.f ),
Ogre::Vector2( 1.f, 1.f ) };
for (unsigned int i=0; i<vertices.size(); ++i )
{
const PhotoSynth::Vertex& vertex = vertices[i];
for ( unsigned int j=0; j<4; j++ )
{
for (itr=elems.begin(); itr!=elems.end(); ++itr)
{
Ogre::VertexElement& elem = *itr;
if (elem.getSemantic() == Ogre::VES_POSITION)
{
elem.baseVertexPointerToElement(pVert, &pReal);
*pReal = vertex.position.x; *pReal++;
*pReal = vertex.position.y; *pReal++;
*pReal = vertex.position.z; *pReal++;
}
else if (elem.getSemantic() == Ogre::VES_DIFFUSE)
{
elem.baseVertexPointerToElement(pVert, &pRGBA);
renderSystem->convertColourValue(vertex.color, pRGBA);
}
else if (elem.getSemantic() == Ogre::VES_TEXTURE_COORDINATES && elem.getIndex() == 0)
{
elem.baseVertexPointerToElement(pVert, &pReal);
*pReal = uvs[j].x; *pReal++;
*pReal = uvs[j].y; *pReal++;
}
}
// Go to next vertex
pVert += vbuf->getVertexSize();
}
}
vbuf->unlock();
// Create index buffer
if (mRenderOp.indexData->indexCount>=65536)
{
Ogre::HardwareIndexBufferSharedPtr ibuf = Ogre::HardwareBufferManager::getSingleton().createIndexBuffer(
Ogre::HardwareIndexBuffer::IT_32BIT,
mRenderOp.indexData->indexCount,
Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY, false);
mRenderOp.indexData->indexBuffer = ibuf;
Ogre::uint32* indices = static_cast<Ogre::uint32*>(ibuf->lock( Ogre::HardwareBuffer::HBL_DISCARD));
Ogre::uint32 indexFirstVertex = 0;
const Ogre::uint32 inds[6] = { 0, 1, 2, 3, 0, 2 };
for (unsigned int i=0; i<vertices.size(); ++i)
{
for (unsigned int j=0; j<6; ++j)
{
*indices = indexFirstVertex + inds[j];
indices++;
}
indexFirstVertex +=4;
}
//.........这里部分代码省略.........