Skip to content

Commit 006d001

Browse files
committed
[EX_12] New API Changes Applied to GLTF Example
1 parent 90dba5f commit 006d001

File tree

1 file changed

+22
-41
lines changed

1 file changed

+22
-41
lines changed

examples_tests/12.glTF/main.cpp

Lines changed: 22 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ using namespace nbl;
2222
using namespace asset;
2323
using namespace video;
2424
using namespace core;
25+
using namespace ui;
2526

2627
class GLTFApp : public ApplicationBase
2728
{
@@ -84,8 +85,10 @@ class GLTFApp : public ApplicationBase
8485
void onAppInitialized_impl() override
8586
{
8687
initOutput.window = core::smart_refctd_ptr(window);
87-
88-
CommonAPI::Init<WIN_W, WIN_H, SC_IMG_COUNT>(initOutput, video::EAT_OPENGL, "glTF", asset::EF_D32_SFLOAT);
88+
89+
const auto swapchainImageUsage = static_cast<asset::IImage::E_USAGE_FLAGS>(asset::IImage::EUF_COLOR_ATTACHMENT_BIT);
90+
const video::ISurface::SFormat surfaceFormat(asset::EF_B8G8R8A8_SRGB, asset::ECP_COUNT, asset::EOTF_UNKNOWN);
91+
CommonAPI::InitWithDefaultExt(initOutput, video::EAT_OPENGL, "glTF", WIN_W, WIN_H, SC_IMG_COUNT, swapchainImageUsage, surfaceFormat, asset::EF_D32_SFLOAT);
8992
window = std::move(initOutput.window);
9093
gl = std::move(initOutput.apiConnection);
9194
surface = std::move(initOutput.surface);
@@ -95,7 +98,7 @@ class GLTFApp : public ApplicationBase
9598
swapchain = std::move(initOutput.swapchain);
9699
renderpass = std::move(initOutput.renderpass);
97100
fbos = std::move(initOutput.fbo);
98-
commandPool = std::move(initOutput.commandPool);
101+
commandPools = std::move(initOutput.commandPools);
99102
assetManager = std::move(initOutput.assetManager);
100103
logger = std::move(initOutput.logger);
101104
inputSystem = std::move(initOutput.inputSystem);
@@ -104,7 +107,7 @@ class GLTFApp : public ApplicationBase
104107
cpu2gpuParams = std::move(initOutput.cpu2gpuParams);
105108
utilities = std::move(initOutput.utilities);
106109

107-
transferUpQueue = queues[decltype(initOutput)::EQT_TRANSFER_UP];
110+
transferUpQueue = queues[CommonAPI::InitOutput::EQT_TRANSFER_UP];
108111

109112
transformTreeManager = scene::ITransformTreeManager::create(utilities.get(),transferUpQueue);
110113
ttDebugDrawPipeline = transformTreeManager->createDebugPipeline<scene::ITransformTreeWithNormalMatrices>(core::smart_refctd_ptr(renderpass));
@@ -114,37 +117,7 @@ class GLTFApp : public ApplicationBase
114117
sicDebugDrawPipeline = sicManager->createDebugPipeline(core::smart_refctd_ptr(renderpass));
115118
sicDescriptorSets = sicManager->createAllDescriptorSets(logicalDevice.get());
116119

117-
auto gpuTransferFence = logicalDevice->createFence(static_cast<video::IGPUFence::E_CREATE_FLAGS>(0));
118-
auto gpuComputeFence = logicalDevice->createFence(static_cast<video::IGPUFence::E_CREATE_FLAGS>(0));
119-
120120
nbl::video::IGPUObjectFromAssetConverter cpu2gpu;
121-
{
122-
cpu2gpuParams.perQueue[nbl::video::IGPUObjectFromAssetConverter::EQU_TRANSFER].fence = &gpuTransferFence;
123-
cpu2gpuParams.perQueue[nbl::video::IGPUObjectFromAssetConverter::EQU_COMPUTE].fence = &gpuComputeFence;
124-
}
125-
126-
auto cpu2gpuWaitForFences = [&]() -> void
127-
{
128-
video::IGPUFence::E_STATUS waitStatus = video::IGPUFence::ES_NOT_READY;
129-
while (waitStatus != video::IGPUFence::ES_SUCCESS)
130-
{
131-
waitStatus = logicalDevice->waitForFences(1u, &gpuTransferFence.get(), false, 99999999ull);
132-
if (waitStatus == video::IGPUFence::ES_ERROR)
133-
assert(false);
134-
else if (waitStatus == video::IGPUFence::ES_TIMEOUT)
135-
break;
136-
}
137-
138-
waitStatus = video::IGPUFence::ES_NOT_READY;
139-
while (waitStatus != video::IGPUFence::ES_SUCCESS)
140-
{
141-
waitStatus = logicalDevice->waitForFences(1u, &gpuComputeFence.get(), false, 99999999ull);
142-
if (waitStatus == video::IGPUFence::ES_ERROR)
143-
assert(false);
144-
else if (waitStatus == video::IGPUFence::ES_TIMEOUT)
145-
break;
146-
}
147-
};
148121

149122
auto createDescriptorPool = [&](const uint32_t amount, const E_DESCRIPTOR_TYPE type) // TODO: review
150123
{
@@ -230,7 +203,7 @@ class GLTFApp : public ApplicationBase
230203
nbl::core::smart_refctd_ptr<nbl::video::IGPUCommandBuffer> xferCmdbuf;
231204
{
232205
xferFence = logicalDevice->createFence(static_cast<nbl::video::IGPUFence::E_CREATE_FLAGS>(0));
233-
logicalDevice->createCommandBuffers(commandPool.get(),nbl::video::IGPUCommandBuffer::EL_PRIMARY,1u,&xferCmdbuf);
206+
logicalDevice->createCommandBuffers(commandPools[CommonAPI::InitOutput::EQT_TRANSFER_UP].get(),nbl::video::IGPUCommandBuffer::EL_PRIMARY,1u,&xferCmdbuf);
234207
xferCmdbuf->begin(0);
235208
}
236209
auto xferQueue = logicalDevice->getQueue(xferCmdbuf->getQueueFamilyIndex(),0u);
@@ -779,7 +752,7 @@ class GLTFApp : public ApplicationBase
779752
camera = Camera(cameraPosition, core::vectorSIMDf(0, 0, 0), projectionMatrix, 0.4f, 1.f);
780753
auto lastTime = std::chrono::system_clock::now();
781754

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

784757
//
785758
oracle.reportBeginFrameRecord();
@@ -795,7 +768,15 @@ class GLTFApp : public ApplicationBase
795768
const auto& fboCreationParams = fbos[acquiredNextFBO]->getCreationParameters();
796769
auto gpuSourceImageView = fboCreationParams.attachments[0];
797770

798-
bool status = ext::ScreenShot::createScreenShot(logicalDevice.get(), queues[decltype(initOutput)::EQT_TRANSFER_UP], renderFinished[resourceIx].get(), gpuSourceImageView.get(), assetManager.get(), "ScreenShot.png");
771+
bool status = ext::ScreenShot::createScreenShot(
772+
logicalDevice.get(),
773+
queues[CommonAPI::InitOutput::EQT_TRANSFER_UP],
774+
renderFinished[resourceIx].get(),
775+
gpuSourceImageView.get(),
776+
assetManager.get(),
777+
"ScreenShot.png",
778+
asset::EIL_PRESENT_SRC,
779+
static_cast<asset::E_ACCESS_FLAGS>(0u));
799780
assert(status);
800781
}
801782

@@ -1016,17 +997,17 @@ class GLTFApp : public ApplicationBase
1016997
}
1017998

1018999
private:
1019-
CommonAPI::InitOutput<SC_IMG_COUNT> initOutput;
1000+
CommonAPI::InitOutput initOutput;
10201001
nbl::core::smart_refctd_ptr<nbl::ui::IWindow> window;
10211002
nbl::core::smart_refctd_ptr<nbl::video::IAPIConnection> gl;
10221003
nbl::core::smart_refctd_ptr<nbl::video::ISurface> surface;
10231004
nbl::video::IPhysicalDevice* gpuPhysicalDevice;
10241005
nbl::core::smart_refctd_ptr<nbl::video::ILogicalDevice> logicalDevice;
1025-
std::array<nbl::video::IGPUQueue*, CommonAPI::InitOutput<SC_IMG_COUNT>::EQT_COUNT> queues = { nullptr, nullptr, nullptr, nullptr };
1006+
std::array<nbl::video::IGPUQueue*, CommonAPI::InitOutput::MaxQueuesCount> queues;
10261007
nbl::core::smart_refctd_ptr<nbl::video::ISwapchain> swapchain;
10271008
nbl::core::smart_refctd_ptr<nbl::video::IGPURenderpass> renderpass;
1028-
std::array<nbl::core::smart_refctd_ptr<nbl::video::IGPUFramebuffer>, SC_IMG_COUNT> fbos;
1029-
nbl::core::smart_refctd_ptr<nbl::video::IGPUCommandPool> commandPool;
1009+
std::array<nbl::core::smart_refctd_ptr<nbl::video::IGPUFramebuffer>, CommonAPI::InitOutput::MaxSwapChainImageCount> fbos;
1010+
std::array<nbl::core::smart_refctd_ptr<nbl::video::IGPUCommandPool>, CommonAPI::InitOutput::MaxQueuesCount> commandPools;
10301011
nbl::core::smart_refctd_ptr<nbl::asset::IAssetManager> assetManager;
10311012
nbl::core::smart_refctd_ptr<nbl::system::ILogger> logger;
10321013
nbl::core::smart_refctd_ptr<CommonAPI::InputSystem> inputSystem;

0 commit comments

Comments
 (0)