MCPcopy Create free account
hub / github.com/NVIDIAGameWorks/Falcor / createMeshVao

Method createMeshVao

Source/Falcor/Scene/Scene.cpp:434–497  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

432 }
433
434 void Scene::createMeshVao(uint32_t drawCount, const std::vector<SkinningVertexData>& skinningData)
435 {
436 if (drawCount == 0) return;
437 if (mMeshIndexData.getBufferCount() > 1 || mMeshStaticData.getBufferCount() > 1)
438 {
439 logWarning("MeshVao cannot be created, rasterization will not be available.");
440 return;
441 }
442
443 ref<Buffer> pIB;
444 if (!mMeshIndexData.empty())
445 pIB = mMeshIndexData.getGpuBuffer(0);
446
447 ref<Buffer> pStaticBuffer = mMeshStaticData.getGpuBuffer(0);
448
449 Vao::BufferVec pVBs(kVertexBufferCount);
450 pVBs[kStaticDataBufferIndex] = pStaticBuffer;
451
452 // Create the draw ID buffer.
453 // This is only needed when rasterizing meshes in the scene.
454 ResourceFormat drawIDFormat = drawCount <= (1 << 16) ? ResourceFormat::R16Uint : ResourceFormat::R32Uint;
455
456 ref<Buffer> pDrawIDBuffer;
457 if (drawIDFormat == ResourceFormat::R16Uint)
458 {
459 FALCOR_ASSERT(drawCount <= (1 << 16));
460 std::vector<uint16_t> drawIDs(drawCount);
461 for (uint32_t i = 0; i < drawCount; i++) drawIDs[i] = i;
462 pDrawIDBuffer = mpDevice->createBuffer(drawCount * sizeof(uint16_t), ResourceBindFlags::Vertex, MemoryType::DeviceLocal, drawIDs.data());
463 }
464 else if (drawIDFormat == ResourceFormat::R32Uint)
465 {
466 std::vector<uint32_t> drawIDs(drawCount);
467 for (uint32_t i = 0; i < drawCount; i++) drawIDs[i] = i;
468 pDrawIDBuffer = mpDevice->createBuffer(drawCount * sizeof(uint32_t), ResourceBindFlags::Vertex, MemoryType::DeviceLocal, drawIDs.data());
469 }
470 else FALCOR_UNREACHABLE();
471
472 FALCOR_ASSERT(pDrawIDBuffer);
473 pVBs[kDrawIdBufferIndex] = pDrawIDBuffer;
474
475 // Create vertex layout.
476 // The layout only initializes the vertex data and draw ID layout. The skinning data doesn't get passed into the vertex shader.
477 ref<VertexLayout> pLayout = VertexLayout::create();
478
479 // Add the packed static vertex data layout.
480 ref<VertexBufferLayout> pStaticLayout = VertexBufferLayout::create();
481 pStaticLayout->addElement(VERTEX_POSITION_NAME, offsetof(PackedStaticVertexData, position), ResourceFormat::RGB32Float, 1, VERTEX_POSITION_LOC);
482 pStaticLayout->addElement(VERTEX_PACKED_NORMAL_TANGENT_CURVE_RADIUS_NAME, offsetof(PackedStaticVertexData, packedNormalTangentCurveRadius), ResourceFormat::RGB32Float, 1, VERTEX_PACKED_NORMAL_TANGENT_CURVE_RADIUS_LOC);
483 pStaticLayout->addElement(VERTEX_TEXCOORD_NAME, offsetof(PackedStaticVertexData, texCrd), ResourceFormat::RG32Float, 1, VERTEX_TEXCOORD_LOC);
484 pLayout->addBufferLayout(kStaticDataBufferIndex, pStaticLayout);
485
486 // Add the draw ID layout.
487 ref<VertexBufferLayout> pInstLayout = VertexBufferLayout::create();
488 pInstLayout->addElement(INSTANCE_DRAW_ID_NAME, 0, drawIDFormat, 1, INSTANCE_DRAW_ID_LOC);
489 pInstLayout->setInputClass(VertexBufferLayout::InputClass::PerInstanceData, 1);
490 pLayout->addBufferLayout(kDrawIdBufferIndex, pInstLayout);
491

Callers

nothing calls this directly

Calls 8

getGpuBufferMethod · 0.80
createBufferMethod · 0.80
addBufferLayoutMethod · 0.80
logWarningFunction · 0.50
createFunction · 0.50
getBufferCountMethod · 0.45
emptyMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected