Skip to content

Commit 3c0a01f

Browse files
committed
Ported Example 27
1 parent c98276d commit 3c0a01f

File tree

1 file changed

+61
-22
lines changed

1 file changed

+61
-22
lines changed

examples_tests/27.PLYSTLDemo/main.cpp

Lines changed: 61 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ class PLYSTLDemo : public ApplicationBase
4949
nbl::core::smart_refctd_ptr<nbl::video::IUtilities> utilities;
5050
nbl::core::smart_refctd_ptr<nbl::video::ILogicalDevice> logicalDevice;
5151
nbl::video::IPhysicalDevice* gpuPhysicalDevice;
52-
std::array<nbl::video::IGPUQueue*, CommonAPI::InitOutput<SC_IMG_COUNT>::EQT_COUNT> queues = { nullptr, nullptr, nullptr, nullptr };
52+
std::array<nbl::video::IGPUQueue*, CommonAPI::InitOutput::MaxQueuesCount> queues = { nullptr, nullptr, nullptr, nullptr };
5353
nbl::core::smart_refctd_ptr<nbl::video::ISwapchain> swapchain;
5454
nbl::core::smart_refctd_ptr<nbl::video::IGPURenderpass> renderpass;
55-
std::array<nbl::core::smart_refctd_ptr<nbl::video::IGPUFramebuffer>, SC_IMG_COUNT> fbos;
56-
nbl::core::smart_refctd_ptr<nbl::video::IGPUCommandPool> commandPool;
55+
std::array<nbl::core::smart_refctd_ptr<nbl::video::IGPUFramebuffer>, CommonAPI::InitOutput::MaxSwapChainImageCount> fbos;
56+
std::array<nbl::core::smart_refctd_ptr<nbl::video::IGPUCommandPool>, CommonAPI::InitOutput::MaxQueuesCount> commandPools;
5757
nbl::core::smart_refctd_ptr<nbl::system::ISystem> system;
5858
nbl::core::smart_refctd_ptr<nbl::asset::IAssetManager> assetManager;
5959
nbl::video::IGPUObjectFromAssetConverter::SParams cpu2gpuParams;
@@ -79,8 +79,8 @@ class PLYSTLDemo : public ApplicationBase
7979
double time_sum = 0;
8080
double dtList[NBL_FRAMES_TO_AVERAGE] = {};
8181

82-
CommonAPI::InputSystem::ChannelReader<IMouseEventChannel> mouse;
83-
CommonAPI::InputSystem::ChannelReader<IKeyboardEventChannel> keyboard;
82+
CommonAPI::InputSystem::ChannelReader<ui::IMouseEventChannel> mouse;
83+
CommonAPI::InputSystem::ChannelReader<ui::IKeyboardEventChannel> keyboard;
8484

8585
Camera camera = Camera(core::vectorSIMDf(0, 0, 0), core::vectorSIMDf(0, 0, 0), core::matrix4SIMD());
8686

@@ -94,22 +94,62 @@ class PLYSTLDemo : public ApplicationBase
9494
{
9595
window = std::move(wnd);
9696
}
97+
nbl::ui::IWindow* getWindow() override
98+
{
99+
return window.get();
100+
}
97101
void setSystem(core::smart_refctd_ptr<nbl::system::ISystem>&& s) override
98102
{
99103
system = std::move(s);
100104
}
101-
nbl::ui::IWindow* getWindow() override
105+
video::IAPIConnection* getAPIConnection() override
102106
{
103-
return window.get();
107+
return gl.get();
108+
}
109+
video::ILogicalDevice* getLogicalDevice() override
110+
{
111+
return logicalDevice.get();
112+
}
113+
video::IGPURenderpass* getRenderpass() override
114+
{
115+
return renderpass.get();
116+
}
117+
void setSurface(core::smart_refctd_ptr<video::ISurface>&& s) override
118+
{
119+
surface = std::move(s);
120+
}
121+
void setFBOs(std::vector<core::smart_refctd_ptr<video::IGPUFramebuffer>>& f) override
122+
{
123+
for (int i = 0; i < f.size(); i++)
124+
{
125+
fbos[i] = core::smart_refctd_ptr(f[i]);
126+
}
127+
}
128+
void setSwapchain(core::smart_refctd_ptr<video::ISwapchain>&& s) override
129+
{
130+
swapchain = std::move(s);
131+
}
132+
uint32_t getSwapchainImageCount() override
133+
{
134+
return SC_IMG_COUNT;
135+
}
136+
virtual nbl::asset::E_FORMAT getDepthFormat() override
137+
{
138+
return nbl::asset::EF_D32_SFLOAT;
104139
}
105140

106141
APP_CONSTRUCTOR(PLYSTLDemo)
107142

108143
void onAppInitialized_impl() override
109144
{
110-
CommonAPI::InitOutput<SC_IMG_COUNT> initOutput;
145+
CommonAPI::InitOutput initOutput;
111146
initOutput.window = core::smart_refctd_ptr(window);
112-
CommonAPI::Init<WIN_W, WIN_H, SC_IMG_COUNT>(initOutput, video::EAT_OPENGL, "plystldemo", nbl::asset::EF_D32_SFLOAT);
147+
initOutput.system = core::smart_refctd_ptr(system);
148+
149+
const auto swapchainImageUsage = static_cast<asset::IImage::E_USAGE_FLAGS>(asset::IImage::EUF_COLOR_ATTACHMENT_BIT);
150+
const video::ISurface::SFormat surfaceFormat(asset::EF_R8G8B8A8_SRGB, asset::ECP_COUNT, asset::EOTF_UNKNOWN);
151+
152+
CommonAPI::InitWithDefaultExt(initOutput, video::EAT_OPENGL_ES, "plystldemo", WIN_W, WIN_H, SC_IMG_COUNT, swapchainImageUsage, surfaceFormat, nbl::asset::EF_D32_SFLOAT);
113153
window = std::move(initOutput.window);
114154
gl = std::move(initOutput.apiConnection);
115155
surface = std::move(initOutput.surface);
@@ -119,7 +159,7 @@ APP_CONSTRUCTOR(PLYSTLDemo)
119159
swapchain = std::move(initOutput.swapchain);
120160
renderpass = std::move(initOutput.renderpass);
121161
fbos = std::move(initOutput.fbo);
122-
commandPool = std::move(initOutput.commandPool);
162+
commandPools = std::move(initOutput.commandPools);
123163
assetManager = std::move(initOutput.assetManager);
124164
logger = std::move(initOutput.logger);
125165
inputSystem = std::move(initOutput.inputSystem);
@@ -162,11 +202,9 @@ APP_CONSTRUCTOR(PLYSTLDemo)
162202
cpu2gpuParams.sharingMode = nbl::asset::ESM_CONCURRENT;
163203
cpu2gpuParams.utilities = utilities.get();
164204

165-
cpu2gpuParams.perQueue[nbl::video::IGPUObjectFromAssetConverter::EQU_TRANSFER].fence = &gpuTransferFence;
166205
cpu2gpuParams.perQueue[nbl::video::IGPUObjectFromAssetConverter::EQU_TRANSFER].semaphore = &gpuTransferSemaphore;
167206
cpu2gpuParams.perQueue[nbl::video::IGPUObjectFromAssetConverter::EQU_TRANSFER].queue = queues[decltype(initOutput)::EQT_TRANSFER_UP];
168207

169-
cpu2gpuParams.perQueue[nbl::video::IGPUObjectFromAssetConverter::EQU_COMPUTE].fence = &gpuComputeFence;
170208
cpu2gpuParams.perQueue[nbl::video::IGPUObjectFromAssetConverter::EQU_COMPUTE].semaphore = &gpuComputeSemaphore;
171209
cpu2gpuParams.perQueue[nbl::video::IGPUObjectFromAssetConverter::EQU_COMPUTE].queue = queues[decltype(initOutput)::EQT_COMPUTE];
172210
}
@@ -338,7 +376,7 @@ APP_CONSTRUCTOR(PLYSTLDemo)
338376
for (size_t i = 0ull; i < NBL_FRAMES_TO_AVERAGE; ++i)
339377
dtList[i] = 0.0;
340378

341-
logicalDevice->createCommandBuffers(commandPool.get(), video::IGPUCommandBuffer::EL_PRIMARY, FRAMES_IN_FLIGHT, commandBuffers);
379+
logicalDevice->createCommandBuffers(commandPools[CommonAPI::InitOutput::EQT_GRAPHICS].get(), video::IGPUCommandBuffer::EL_PRIMARY, FRAMES_IN_FLIGHT, commandBuffers);
342380

343381
for (uint32_t i = 0u; i < FRAMES_IN_FLIGHT; i++)
344382
{
@@ -352,8 +390,9 @@ APP_CONSTRUCTOR(PLYSTLDemo)
352390
const auto& fboCreationParams = fbos[acquiredNextFBO]->getCreationParameters();
353391
auto gpuSourceImageView = fboCreationParams.attachments[0];
354392

355-
bool status = ext::ScreenShot::createScreenShot(logicalDevice.get(), queues[CommonAPI::InitOutput<1u>::EQT_TRANSFER_UP], renderFinished[resourceIx].get(), gpuSourceImageView.get(), assetManager.get(), "ScreenShot.png");
356-
assert(status);
393+
//TODO:
394+
//bool status = ext::ScreenShot::createScreenShot(logicalDevice.get(), queues[CommonAPI::InitOutput<1u>::EQT_TRANSFER_UP], renderFinished[resourceIx].get(), gpuSourceImageView.get(), assetManager.get(), "ScreenShot.png");
395+
//assert(status);
357396
}
358397

359398
void workLoopBody() override
@@ -399,8 +438,8 @@ APP_CONSTRUCTOR(PLYSTLDemo)
399438
inputSystem->getDefaultKeyboard(&keyboard);
400439

401440
camera.beginInputProcessing(nextPresentationTimeStamp);
402-
mouse.consumeEvents([&](const IMouseEventChannel::range_t& events) -> void { camera.mouseProcess(events); }, logger.get());
403-
keyboard.consumeEvents([&](const IKeyboardEventChannel::range_t& events) -> void { camera.keyboardProcess(events); }, logger.get());
441+
mouse.consumeEvents([&](const ui::IMouseEventChannel::range_t& events) -> void { camera.mouseProcess(events); }, logger.get());
442+
keyboard.consumeEvents([&](const ui::IKeyboardEventChannel::range_t& events) -> void { camera.keyboardProcess(events); }, logger.get());
404443
camera.endInputProcessing(nextPresentationTimeStamp);
405444

406445
const auto& viewMatrix = camera.getViewMatrix();
@@ -494,12 +533,12 @@ APP_CONSTRUCTOR(PLYSTLDemo)
494533
commandBuffer->bindGraphicsPipeline(gpuGraphicsPipeline.get());
495534

496535
const video::IGPUDescriptorSet* gpuds1_ptr = gpuds1.get();
497-
commandBuffer->bindDescriptorSets(asset::EPBP_GRAPHICS, gpuRenderpassIndependentPipeline->getLayout(), 1u, 1u, &gpuds1_ptr, nullptr);
536+
commandBuffer->bindDescriptorSets(asset::EPBP_GRAPHICS, gpuRenderpassIndependentPipeline->getLayout(), 1u, 1u, &gpuds1_ptr, 0u);
498537
const video::IGPUDescriptorSet* gpuds3_ptr = gpuMeshBuffer->getAttachedDescriptorSet();
499538

500539
if (gpuds3_ptr)
501-
commandBuffer->bindDescriptorSets(asset::EPBP_GRAPHICS, gpuRenderpassIndependentPipeline->getLayout(), 3u, 1u, &gpuds3_ptr, nullptr);
502-
commandBuffer->pushConstants(gpuRenderpassIndependentPipeline->getLayout(), video::IGPUSpecializedShader::ESS_FRAGMENT, 0u, gpuMeshBuffer->MAX_PUSH_CONSTANT_BYTESIZE, gpuMeshBuffer->getPushConstantsDataPtr());
540+
commandBuffer->bindDescriptorSets(asset::EPBP_GRAPHICS, gpuRenderpassIndependentPipeline->getLayout(), 3u, 1u, &gpuds3_ptr, 0u);
541+
commandBuffer->pushConstants(gpuRenderpassIndependentPipeline->getLayout(), video::IGPUShader::ESS_FRAGMENT, 0u, gpuMeshBuffer->MAX_PUSH_CONSTANT_BYTESIZE, gpuMeshBuffer->getPushConstantsDataPtr());
503542

504543
commandBuffer->drawMeshBuffer(gpuMeshBuffer);
505544
}
@@ -515,8 +554,8 @@ APP_CONSTRUCTOR(PLYSTLDemo)
515554
commandBuffer->endRenderPass();
516555
commandBuffer->end();
517556

518-
CommonAPI::Submit(logicalDevice.get(), swapchain.get(), commandBuffer.get(), queues[CommonAPI::InitOutput<1u>::EQT_GRAPHICS], imageAcquire[resourceIx].get(), renderFinished[resourceIx].get(), fence.get());
519-
CommonAPI::Present(logicalDevice.get(), swapchain.get(), queues[CommonAPI::InitOutput<1u>::EQT_GRAPHICS], renderFinished[resourceIx].get(), acquiredNextFBO);
557+
CommonAPI::Submit(logicalDevice.get(), swapchain.get(), commandBuffer.get(), queues[CommonAPI::InitOutput::EQT_GRAPHICS], imageAcquire[resourceIx].get(), renderFinished[resourceIx].get(), fence.get());
558+
CommonAPI::Present(logicalDevice.get(), swapchain.get(), queues[CommonAPI::InitOutput::EQT_GRAPHICS], renderFinished[resourceIx].get(), acquiredNextFBO);
520559
}
521560

522561
bool keepRunning() override

0 commit comments

Comments
 (0)