本文整理汇总了C++中SubMesh::SetMeshShader方法的典型用法代码示例。如果您正苦于以下问题:C++ SubMesh::SetMeshShader方法的具体用法?C++ SubMesh::SetMeshShader怎么用?C++ SubMesh::SetMeshShader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SubMesh
的用法示例。
在下文中一共展示了SubMesh::SetMeshShader方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _genMesh
void MeshGroup::_genMesh(const Array<Mesh *> & arr, int first, int last, bool hasLightingColor)
{
MeshSourcePtr source = arr[0]->GetSource();
Mesh * mesh = new Mesh;
for (int i = 0; i < source->GetMeshBufferCount(); ++i)
{
SubMesh * submesh = mesh->NewSubMesh();
VertexBufferPtr srcVB = source->GetMeshBuffer(i)->GetRenderOp()->vertexBuffers[0];
IndexBufferPtr srcIB = source->GetMeshBuffer(i)->GetRenderOp()->indexBuffer;
int p_offset = source->GetMeshBuffer(i)->GetRenderOp()->vertexDeclarations[0].GetElementOffset(eVertexSemantic::POSITION);
int n_offset = source->GetMeshBuffer(i)->GetRenderOp()->vertexDeclarations[0].GetElementOffset(eVertexSemantic::NORMAL);
int stride = srcVB->GetStride();
VertexBufferPtr vb = HWBufferManager::Instance()->NewVertexBuffer(stride, srcVB->GetCount() * (last - first));
const char * v_src = (const char *)srcVB->Lock(eLockFlag::READ);
char * v_dest = (char *)vb->Lock(eLockFlag::WRITE);
for (int j = first; j < last; ++j)
{
const Mat4 & worldTM = arr[j]->GetWorldTM();
bool hasScale = arr[j]->GetWorldScale() != Float3(1, 1, 1);
for (int k = 0; k < srcVB->GetCount(); ++k)
{
memcpy(v_dest, v_src, stride);
Float3 * position = (Float3 *)(v_dest + p_offset);
position->TransformA(worldTM);
if (n_offset != -1)
{
Float3 * normal = (Float3 *)(v_dest + n_offset);
normal->TransformN(worldTM);
if (hasScale)
{
normal->Normalize();
}
}
v_dest += stride;
v_src += stride;
}
}
vb->Unlock();
srcVB->Unlock();
IndexBufferPtr ib = HWBufferManager::Instance()->NewIndexBuffer(srcIB->GetCount() * (last - first));
int startVertex = 0;
const short * i_src = (const short *)srcIB->Lock(eLockFlag::READ);
char * i_dest = (char *)ib->Lock(eLockFlag::WRITE);
for (int j = first; j < last; ++j)
{
for (int k = 0; k < srcIB->GetCount(); ++k)
{
*i_dest++ = (*i_src++) + startVertex;
}
startVertex += srcVB->GetCount();
}
ib->Unlock();
srcIB->Unlock();
submesh->GetRenderOp()->vertexDeclarations[0] = source->GetMeshBuffer(i)->GetRenderOp()->vertexDeclarations[0];
submesh->GetRenderOp()->vertexBuffers[0] = vb;
submesh->GetRenderOp()->indexBuffer = ib;
submesh->GetRenderOp()->primCount = ib->GetCount() / 3;
submesh->GetRenderOp()->primType = ePrimType::TRIANGLE_LIST;
if (hasLightingColor)
{
int count = submesh->GetRenderOp()->vertexBuffers[0]->GetCount();
submesh->GetRenderOp()->vertexDeclarations[LIGHTING_COLOR_STREAM].AddElement(eVertexSemantic::LIGHTING_COLOR, eVertexType::UBYTE4);
submesh->GetRenderOp()->vertexBuffers[LIGHTING_COLOR_STREAM] = HWBufferManager::Instance()->NewVertexBuffer(4, count);
Array<Rgba32> lightColors;
Rgba32 * data = (Rgba32 *)submesh->GetRenderOp()->vertexBuffers[LIGHTING_COLOR_STREAM]->Lock(eLockFlag::WRITE);
for (int j = first; j < last; ++j)
{
arr[j]->GetLightingColor(lightColors);
d_assert (lightColors.Size() > 0);
memcpy(data, &lightColors[0], 4 * count);
startVertex += count;
lightColors.Clear();
}
submesh->GetRenderOp()->vertexBuffers[LIGHTING_COLOR_STREAM]->Unlock();
}
*submesh->GetMaterial() = *source->GetMeshBuffer(i)->GetMaterial();
submesh->SetMeshShader(source->GetMeshBuffer(i)->GetShader());
}
mesh->SetSLMode(hasLightingColor ? eStaticLightingMode::LIGHTING_COLOR : eStaticLightingMode::NONE);
mMeshes.PushBack(mesh);
//.........这里部分代码省略.........