Skip to content

Commit 3843302

Browse files
committed
[EX_27] New API Changes Applied and Compiles but still doesn't use the AppFramework
1 parent 09d08bd commit 3843302

File tree

1 file changed

+29
-46
lines changed

1 file changed

+29
-46
lines changed

examples_tests/27.PLYSTLDemo/main.cpp

Lines changed: 29 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
using namespace nbl;
1515
using namespace core;
16+
using namespace ui;
1617

1718
/*
1819
Uncomment for more detailed logging
@@ -34,7 +35,11 @@ int main()
3435
constexpr uint32_t FRAMES_IN_FLIGHT = 5u;
3536
static_assert(FRAMES_IN_FLIGHT > SC_IMG_COUNT);
3637

37-
auto initOutput = CommonAPI::Init<WIN_W, WIN_H, SC_IMG_COUNT>(video::EAT_OPENGL, "Ply and Stl demo", nbl::asset::EF_D32_SFLOAT);
38+
CommonAPI::InitOutput initOutput;
39+
const auto swapchainImageUsage = static_cast<asset::IImage::E_USAGE_FLAGS>(asset::IImage::EUF_COLOR_ATTACHMENT_BIT | asset::IImage::EUF_TRANSFER_DST_BIT);
40+
const video::ISurface::SFormat surfaceFormat(asset::EF_B8G8R8A8_SRGB, asset::ECP_COUNT, asset::EOTF_UNKNOWN);
41+
CommonAPI::InitWithDefaultExt(initOutput, video::EAT_OPENGL, "Ply and Stl demo", WIN_W, WIN_H, SC_IMG_COUNT, swapchainImageUsage, surfaceFormat, nbl::asset::EF_D32_SFLOAT);
42+
3843
auto window = std::move(initOutput.window);
3944
auto gl = std::move(initOutput.apiConnection);
4045
auto surface = std::move(initOutput.surface);
@@ -44,13 +49,16 @@ int main()
4449
auto swapchain = std::move(initOutput.swapchain);
4550
auto renderpass = std::move(initOutput.renderpass);
4651
auto fbos = std::move(initOutput.fbo);
47-
auto commandPool = std::move(initOutput.commandPool);
52+
auto commandPools = std::move(initOutput.commandPools);
4853
auto assetManager = std::move(initOutput.assetManager);
4954
auto logger = std::move(initOutput.logger);
5055
auto inputSystem = std::move(initOutput.inputSystem);
5156
auto system = std::move(initOutput.system);
5257
auto windowCallback = std::move(initOutput.windowCb);
5358
auto utilities = std::move(initOutput.utilities);
59+
auto cpu2gpuParams = std::move(initOutput.cpu2gpuParams);
60+
61+
nbl::video::IGPUObjectFromAssetConverter cpu2gpu;
5462

5563
auto createDescriptorPool = [&](const uint32_t count, asset::E_DESCRIPTOR_TYPE type)
5664
{
@@ -63,54 +71,21 @@ int main()
6371
}
6472
};
6573

66-
nbl::video::IGPUObjectFromAssetConverter cpu2gpu;
67-
nbl::video::IGPUObjectFromAssetConverter::SParams cpu2gpuParams;
68-
69-
nbl::core::smart_refctd_ptr<nbl::video::IGPUFence> gpuTransferFence;
70-
nbl::core::smart_refctd_ptr<nbl::video::IGPUSemaphore> gpuTransferSemaphore;
71-
72-
nbl::core::smart_refctd_ptr<nbl::video::IGPUFence> gpuComputeFence;
73-
nbl::core::smart_refctd_ptr<nbl::video::IGPUSemaphore> gpuComputeSemaphore;
74-
74+
auto loadAndGetCpuMesh = [&](std::string path) -> std::pair<core::smart_refctd_ptr<asset::ICPUMesh>, const asset::IAssetMetadata*>
7575
{
76-
gpuTransferFence = logicalDevice->createFence(static_cast<video::IGPUFence::E_CREATE_FLAGS>(0));
77-
gpuTransferSemaphore = logicalDevice->createSemaphore();
78-
79-
gpuComputeFence = logicalDevice->createFence(static_cast<video::IGPUFence::E_CREATE_FLAGS>(0));
80-
gpuComputeSemaphore = logicalDevice->createSemaphore();
81-
82-
cpu2gpuParams.assetManager = assetManager.get();
83-
cpu2gpuParams.device = logicalDevice.get();
84-
cpu2gpuParams.finalQueueFamIx = queues[decltype(initOutput)::EQT_GRAPHICS]->getFamilyIndex();
85-
cpu2gpuParams.limits = gpuPhysicalDevice->getLimits();
86-
cpu2gpuParams.pipelineCache = nullptr;
87-
cpu2gpuParams.sharingMode = nbl::asset::ESM_CONCURRENT;
88-
cpu2gpuParams.utilities = utilities.get();
89-
90-
cpu2gpuParams.perQueue[nbl::video::IGPUObjectFromAssetConverter::EQU_TRANSFER].fence = &gpuTransferFence;
91-
cpu2gpuParams.perQueue[nbl::video::IGPUObjectFromAssetConverter::EQU_TRANSFER].semaphore = &gpuTransferSemaphore;
92-
cpu2gpuParams.perQueue[nbl::video::IGPUObjectFromAssetConverter::EQU_TRANSFER].queue = queues[decltype(initOutput)::EQT_TRANSFER_UP];
93-
94-
cpu2gpuParams.perQueue[nbl::video::IGPUObjectFromAssetConverter::EQU_COMPUTE].fence = &gpuComputeFence;
95-
cpu2gpuParams.perQueue[nbl::video::IGPUObjectFromAssetConverter::EQU_COMPUTE].semaphore = &gpuComputeSemaphore;
96-
cpu2gpuParams.perQueue[nbl::video::IGPUObjectFromAssetConverter::EQU_COMPUTE].queue = queues[decltype(initOutput)::EQT_COMPUTE];
97-
}
98-
99-
auto loadAndGetCpuMesh = [&](std::string path) -> std::pair<core::smart_refctd_ptr<asset::ICPUMesh>, const asset::IAssetMetadata*>
100-
{
10176
auto meshes_bundle = assetManager->getAsset(path, {});
10277
{
10378
bool status = !meshes_bundle.getContents().empty();
10479
assert(status);
10580
}
10681

107-
return std::make_pair(core::smart_refctd_ptr_static_cast<asset::ICPUMesh>(meshes_bundle.getContents().begin()[0]), meshes_bundle.getMetadata());
108-
};
82+
return std::make_pair(core::smart_refctd_ptr_static_cast<asset::ICPUMesh>(meshes_bundle.getContents().begin()[0]), meshes_bundle.getMetadata());
83+
};
10984

11085
auto cpuBundlePLYData = loadAndGetCpuMesh("../../media/ply/Spanner-ply.ply");
11186
auto cpuBundleSTLData = loadAndGetCpuMesh("../../media/extrusionLogo_TEST_fixed.stl");
11287

113-
core::smart_refctd_ptr<asset::ICPUMesh> cpuMeshPly = cpuBundlePLYData.first;
88+
core::smart_refctd_ptr<asset::ICPUMesh> cpuMeshPly = cpuBundlePLYData.first;
11489
auto metadataPly = cpuBundlePLYData.second->selfCast<const asset::CPLYMetadata>();
11590

11691
core::smart_refctd_ptr<asset::ICPUMesh> cpuMeshStl = cpuBundleSTLData.first;
@@ -275,7 +250,7 @@ int main()
275250
dtList[i] = 0.0;
276251

277252
core::smart_refctd_ptr<video::IGPUCommandBuffer> commandBuffers[FRAMES_IN_FLIGHT];
278-
logicalDevice->createCommandBuffers(commandPool.get(), video::IGPUCommandBuffer::EL_PRIMARY, FRAMES_IN_FLIGHT, commandBuffers);
253+
logicalDevice->createCommandBuffers(commandPools[CommonAPI::InitOutput::EQT_GRAPHICS].get(), video::IGPUCommandBuffer::EL_PRIMARY, FRAMES_IN_FLIGHT, commandBuffers);
279254

280255
core::smart_refctd_ptr<video::IGPUFence> frameComplete[FRAMES_IN_FLIGHT] = { nullptr };
281256
core::smart_refctd_ptr<video::IGPUSemaphore> imageAcquire[FRAMES_IN_FLIGHT] = { nullptr };
@@ -429,12 +404,12 @@ int main()
429404
commandBuffer->bindGraphicsPipeline(gpuGraphicsPipeline.get());
430405

431406
const video::IGPUDescriptorSet* gpuds1_ptr = gpuds1.get();
432-
commandBuffer->bindDescriptorSets(asset::EPBP_GRAPHICS, gpuRenderpassIndependentPipeline->getLayout(), 1u, 1u, &gpuds1_ptr, nullptr);
407+
commandBuffer->bindDescriptorSets(asset::EPBP_GRAPHICS, gpuRenderpassIndependentPipeline->getLayout(), 1u, 1u, &gpuds1_ptr);
433408
const video::IGPUDescriptorSet* gpuds3_ptr = gpuMeshBuffer->getAttachedDescriptorSet();
434409

435410
if (gpuds3_ptr)
436-
commandBuffer->bindDescriptorSets(asset::EPBP_GRAPHICS, gpuRenderpassIndependentPipeline->getLayout(), 3u, 1u, &gpuds3_ptr, nullptr);
437-
commandBuffer->pushConstants(gpuRenderpassIndependentPipeline->getLayout(), video::IGPUSpecializedShader::ESS_FRAGMENT, 0u, gpuMeshBuffer->MAX_PUSH_CONSTANT_BYTESIZE, gpuMeshBuffer->getPushConstantsDataPtr());
411+
commandBuffer->bindDescriptorSets(asset::EPBP_GRAPHICS, gpuRenderpassIndependentPipeline->getLayout(), 3u, 1u, &gpuds3_ptr);
412+
commandBuffer->pushConstants(gpuRenderpassIndependentPipeline->getLayout(), asset::IShader::ESS_FRAGMENT, 0u, gpuMeshBuffer->MAX_PUSH_CONSTANT_BYTESIZE, gpuMeshBuffer->getPushConstantsDataPtr());
438413

439414
commandBuffer->drawMeshBuffer(gpuMeshBuffer);
440415
}
@@ -450,14 +425,22 @@ int main()
450425
commandBuffer->endRenderPass();
451426
commandBuffer->end();
452427

453-
CommonAPI::Submit(logicalDevice.get(), swapchain.get(), commandBuffer.get(), queues[decltype(initOutput)::EQT_GRAPHICS], imageAcquire[resourceIx].get(), renderFinished[resourceIx].get(), fence.get());
454-
CommonAPI::Present(logicalDevice.get(), swapchain.get(), queues[decltype(initOutput)::EQT_GRAPHICS], renderFinished[resourceIx].get(), acquiredNextFBO);
428+
CommonAPI::Submit(logicalDevice.get(), swapchain.get(), commandBuffer.get(), queues[CommonAPI::InitOutput::EQT_GRAPHICS], imageAcquire[resourceIx].get(), renderFinished[resourceIx].get(), fence.get());
429+
CommonAPI::Present(logicalDevice.get(), swapchain.get(), queues[CommonAPI::InitOutput::EQT_GRAPHICS], renderFinished[resourceIx].get(), acquiredNextFBO);
455430
}
456431

457432
const auto& fboCreationParams = fbos[acquiredNextFBO]->getCreationParameters();
458433
auto gpuSourceImageView = fboCreationParams.attachments[0];
459434

460-
bool status = ext::ScreenShot::createScreenShot(logicalDevice.get(), queues[decltype(initOutput)::EQT_TRANSFER_UP], renderFinished[resourceIx].get(), gpuSourceImageView.get(), assetManager.get(), "ScreenShot.png");
435+
bool status = ext::ScreenShot::createScreenShot(
436+
logicalDevice.get(),
437+
queues[CommonAPI::InitOutput::EQT_TRANSFER_UP],
438+
renderFinished[resourceIx].get(),
439+
gpuSourceImageView.get(),
440+
assetManager.get(),
441+
"ScreenShot.png",
442+
asset::EIL_PRESENT_SRC,
443+
static_cast<asset::E_ACCESS_FLAGS>(0u));
461444
assert(status);
462445

463446
return 0;

0 commit comments

Comments
 (0)