Skip to content

Commit 8d3d0f1

Browse files
committed
Ported example 3
1 parent 8347c8f commit 8d3d0f1

File tree

1 file changed

+53
-13
lines changed

1 file changed

+53
-13
lines changed

examples_tests/03.GPU_Mesh/main.cpp

Lines changed: 53 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ class GPUMesh : public ApplicationBase
7979
nbl::core::smart_refctd_ptr<nbl::video::IUtilities> utilities;
8080
nbl::core::smart_refctd_ptr<nbl::video::ILogicalDevice> logicalDevice;
8181
nbl::video::IPhysicalDevice* physicalDevice;
82-
std::array<nbl::video::IGPUQueue*, CommonAPI::InitOutput<SC_IMG_COUNT>::EQT_COUNT> queues = { nullptr, nullptr, nullptr, nullptr };
82+
std::array<nbl::video::IGPUQueue*, CommonAPI::InitOutput::MaxQueuesCount> queues = { nullptr, nullptr, nullptr, nullptr };
8383
nbl::core::smart_refctd_ptr<nbl::video::ISwapchain> swapchain;
8484
nbl::core::smart_refctd_ptr<nbl::video::IGPURenderpass> renderpass;
85-
std::array<nbl::core::smart_refctd_ptr<nbl::video::IGPUFramebuffer>, SC_IMG_COUNT> fbos;
86-
nbl::core::smart_refctd_ptr<nbl::video::IGPUCommandPool> commandPool;
85+
std::array<nbl::core::smart_refctd_ptr<nbl::video::IGPUFramebuffer>, CommonAPI::InitOutput::MaxSwapChainImageCount> fbo;
86+
std::array<nbl::core::smart_refctd_ptr<nbl::video::IGPUCommandPool>, CommonAPI::InitOutput::MaxQueuesCount> commandPools;
8787
nbl::core::smart_refctd_ptr<nbl::system::ISystem> system;
8888
nbl::core::smart_refctd_ptr<nbl::asset::IAssetManager> assetManager;
8989
nbl::video::IGPUObjectFromAssetConverter::SParams cpu2gpuParams;
@@ -94,8 +94,8 @@ class GPUMesh : public ApplicationBase
9494
nbl::core::smart_refctd_ptr<video::IGPUFence> gpuComputeFence;
9595
nbl::video::IGPUObjectFromAssetConverter cpu2gpu;
9696

97-
CommonAPI::InputSystem::ChannelReader<IMouseEventChannel> mouse;
98-
CommonAPI::InputSystem::ChannelReader<IKeyboardEventChannel> keyboard;
97+
CommonAPI::InputSystem::ChannelReader<ui::IMouseEventChannel> mouse;
98+
CommonAPI::InputSystem::ChannelReader<ui::IKeyboardEventChannel> keyboard;
9999
Camera camera = Camera(vectorSIMDf(0, 0, 0), vectorSIMDf(0, 0, 0), matrix4SIMD());
100100

101101
int resourceIx = -1;
@@ -123,14 +123,54 @@ class GPUMesh : public ApplicationBase
123123
{
124124
return window.get();
125125
}
126+
video::IAPIConnection* getAPIConnection() override
127+
{
128+
return apiConnection.get();
129+
}
130+
video::ILogicalDevice* getLogicalDevice() override
131+
{
132+
return logicalDevice.get();
133+
}
134+
video::IGPURenderpass* getRenderpass() override
135+
{
136+
return renderpass.get();
137+
}
138+
void setSurface(core::smart_refctd_ptr<video::ISurface>&& s) override
139+
{
140+
surface = std::move(s);
141+
}
142+
void setFBOs(std::vector<core::smart_refctd_ptr<video::IGPUFramebuffer>>& f) override
143+
{
144+
for (int i = 0; i < f.size(); i++)
145+
{
146+
fbo[i] = core::smart_refctd_ptr(f[i]);
147+
}
148+
}
149+
void setSwapchain(core::smart_refctd_ptr<video::ISwapchain>&& s) override
150+
{
151+
swapchain = std::move(s);
152+
}
153+
uint32_t getSwapchainImageCount() override
154+
{
155+
return SC_IMG_COUNT;
156+
}
157+
virtual nbl::asset::E_FORMAT getDepthFormat() override
158+
{
159+
return nbl::asset::EF_D32_SFLOAT;
160+
}
126161

127162
APP_CONSTRUCTOR(GPUMesh)
128163

129164
void onAppInitialized_impl() override
130165
{
131-
CommonAPI::InitOutput<SC_IMG_COUNT> initOutput;
166+
CommonAPI::InitOutput initOutput;
132167
initOutput.window = core::smart_refctd_ptr(window);
133-
CommonAPI::Init<WIN_W, WIN_H, SC_IMG_COUNT>(initOutput, video::EAT_OPENGL, "GPUMesh", nbl::asset::EF_D32_SFLOAT);
168+
initOutput.system = core::smart_refctd_ptr(system);
169+
170+
const auto swapchainImageUsage = static_cast<asset::IImage::E_USAGE_FLAGS>(asset::IImage::EUF_COLOR_ATTACHMENT_BIT);
171+
const video::ISurface::SFormat surfaceFormat(asset::EF_R8G8B8A8_SRGB, asset::ECP_COUNT, asset::EOTF_UNKNOWN);
172+
173+
CommonAPI::InitWithDefaultExt(initOutput, video::EAT_OPENGL_ES, "GPUMesh", WIN_W, WIN_H, SC_IMG_COUNT, swapchainImageUsage, surfaceFormat, nbl::asset::EF_D32_SFLOAT);
134174
window = std::move(initOutput.window);
135175
windowCb = std::move(initOutput.windowCb);
136176
apiConnection = std::move(initOutput.apiConnection);
@@ -141,8 +181,8 @@ class GPUMesh : public ApplicationBase
141181
queues = std::move(initOutput.queues);
142182
swapchain = std::move(initOutput.swapchain);
143183
renderpass = std::move(initOutput.renderpass);
144-
fbos = std::move(initOutput.fbo);
145-
commandPool = std::move(initOutput.commandPool);
184+
fbo = std::move(initOutput.fbo);
185+
commandPools = std::move(initOutput.commandPools);
146186
system = std::move(initOutput.system);
147187
assetManager = std::move(initOutput.assetManager);
148188
cpu2gpuParams = std::move(initOutput.cpu2gpuParams);
@@ -155,7 +195,7 @@ class GPUMesh : public ApplicationBase
155195
matrix4SIMD projectionMatrix = matrix4SIMD::buildProjectionMatrixPerspectiveFovLH(core::radians(60.0f), float(WIN_W) / WIN_H, 0.1, 1000);
156196
camera = Camera(core::vectorSIMDf(-4, 0, 0), core::vectorSIMDf(0, 0, 0), projectionMatrix);
157197

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

160200
for (uint32_t i = 0u; i < FRAMES_IN_FLIGHT; i++)
161201
{
@@ -213,8 +253,8 @@ class GPUMesh : public ApplicationBase
213253
inputSystem->getDefaultKeyboard(&keyboard);
214254

215255
camera.beginInputProcessing(nextPresentationTimeStamp);
216-
mouse.consumeEvents([&](const IMouseEventChannel::range_t& events) -> void { camera.mouseProcess(events); }, logger.get());
217-
keyboard.consumeEvents([&](const IKeyboardEventChannel::range_t& events) -> void { camera.keyboardProcess(events); }, logger.get());
256+
mouse.consumeEvents([&](const ui::IMouseEventChannel::range_t& events) -> void { camera.mouseProcess(events); }, logger.get());
257+
keyboard.consumeEvents([&](const ui::IKeyboardEventChannel::range_t& events) -> void { camera.keyboardProcess(events); }, logger.get());
218258
camera.endInputProcessing(nextPresentationTimeStamp);
219259

220260
const auto& mvp = camera.getConcatenatedMatrix();
@@ -246,7 +286,7 @@ class GPUMesh : public ApplicationBase
246286
clear[1].depthStencil.depth = 0.f;
247287

248288
beginInfo.clearValueCount = 2u;
249-
beginInfo.framebuffer = fbos[acquiredNextFBO];
289+
beginInfo.framebuffer = fbo[acquiredNextFBO];
250290
beginInfo.renderpass = renderpass;
251291
beginInfo.renderArea = area;
252292
beginInfo.clearValues = clear;

0 commit comments

Comments
 (0)