Skip to content

Commit ddf41b6

Browse files
committed
Example 06 Fix for Android (almost working)
1 parent 130ac15 commit ddf41b6

File tree

1 file changed

+37
-34
lines changed

1 file changed

+37
-34
lines changed

examples_tests/06.MeshLoaders/main.cpp

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ class MeshLoadersApp : public ApplicationBase
3939
nbl::core::smart_refctd_ptr<nbl::video::IUtilities> utilities;
4040
nbl::core::smart_refctd_ptr<nbl::video::ILogicalDevice> logicalDevice;
4141
nbl::video::IPhysicalDevice* physicalDevice;
42-
std::array<video::IGPUQueue*, CommonAPI::InitOutput::MaxQueuesCount> queues;
42+
std::array<video::IGPUQueue*, CommonAPI::InitOutput::MaxQueuesCount> queues;
4343
nbl::core::smart_refctd_ptr<nbl::video::ISwapchain> swapchain;
4444
nbl::core::smart_refctd_ptr<nbl::video::IGPURenderpass> renderpass;
45-
std::array<nbl::core::smart_refctd_ptr<nbl::video::IGPUFramebuffer>, CommonAPI::InitOutput::MaxSwapChainImageCount> fbo;
46-
std::array<nbl::core::smart_refctd_ptr<nbl::video::IGPUCommandPool>, CommonAPI::InitOutput::MaxQueuesCount> commandPools;
45+
std::array<nbl::core::smart_refctd_ptr<nbl::video::IGPUFramebuffer>, CommonAPI::InitOutput::MaxSwapChainImageCount> fbo;
46+
std::array<nbl::core::smart_refctd_ptr<nbl::video::IGPUCommandPool>, CommonAPI::InitOutput::MaxQueuesCount> commandPools;
4747
nbl::core::smart_refctd_ptr<nbl::system::ISystem> system;
4848
nbl::core::smart_refctd_ptr<nbl::asset::IAssetManager> assetManager;
4949
nbl::video::IGPUObjectFromAssetConverter::SParams cpu2gpuParams;
@@ -152,8 +152,8 @@ class MeshLoadersApp : public ApplicationBase
152152
initOutput.window = core::smart_refctd_ptr(window);
153153
initOutput.system = core::smart_refctd_ptr(system);
154154

155-
const auto swapchainImageUsage = static_cast<asset::IImage::E_USAGE_FLAGS>(asset::IImage::EUF_COLOR_ATTACHMENT_BIT);
156-
const video::ISurface::SFormat surfaceFormat(asset::EF_R8G8B8A8_SRGB, asset::ECP_COUNT, asset::EOTF_UNKNOWN);
155+
const auto swapchainImageUsage = static_cast<asset::IImage::E_USAGE_FLAGS>(asset::IImage::EUF_COLOR_ATTACHMENT_BIT);
156+
const video::ISurface::SFormat surfaceFormat(asset::EF_R8G8B8A8_SRGB, asset::ECP_SRGB, asset::EOTF_sRGB);
157157

158158
CommonAPI::InitWithDefaultExt(initOutput, video::EAT_OPENGL_ES, "MeshLoaders", WIN_W, WIN_H, SC_IMG_COUNT, swapchainImageUsage, surfaceFormat, nbl::asset::EF_D32_SFLOAT);
159159
window = std::move(initOutput.window);
@@ -232,8 +232,8 @@ class MeshLoadersApp : public ApplicationBase
232232
ubomemreq.vulkanReqs.size = neededDS1UBOsz;
233233
video::IGPUBuffer::SCreationParams gpuuboCreationParams;
234234
gpuuboCreationParams.canUpdateSubRange = true;
235-
gpuuboCreationParams.usage = asset::IBuffer::EUF_UNIFORM_BUFFER_BIT;
236-
gpuuboCreationParams.sharingMode = asset::E_SHARING_MODE::ESM_CONCURRENT;
235+
gpuuboCreationParams.usage = core::bitflag<asset::IBuffer::E_USAGE_FLAGS>(asset::IBuffer::EUF_UNIFORM_BUFFER_BIT) | asset::IBuffer::EUF_TRANSFER_DST_BIT;
236+
gpuuboCreationParams.sharingMode = asset::E_SHARING_MODE::ESM_EXCLUSIVE;
237237
gpuuboCreationParams.queueFamilyIndexCount = 0u;
238238
gpuuboCreationParams.queueFamilyIndices = nullptr;
239239

@@ -344,36 +344,18 @@ class MeshLoadersApp : public ApplicationBase
344344
viewport.width = WIN_W;
345345
viewport.height = WIN_H;
346346
commandBuffer->setViewport(0u, 1u, &viewport);
347-
348-
swapchain->acquireNextImage(MAX_TIMEOUT, imageAcquire[resourceIx].get(), nullptr, &acquiredNextFBO);
349-
350-
nbl::video::IGPUCommandBuffer::SRenderpassBeginInfo beginInfo;
351-
{
352-
VkRect2D area;
353-
area.offset = { 0,0 };
354-
area.extent = { WIN_W, WIN_H };
355-
asset::SClearValue clear[2] = {};
356-
clear[0].color.float32[0] = 1.f;
357-
clear[0].color.float32[1] = 1.f;
358-
clear[0].color.float32[2] = 1.f;
359-
clear[0].color.float32[3] = 1.f;
360-
clear[1].depthStencil.depth = 0.f;
361-
362-
beginInfo.clearValueCount = 2u;
363-
beginInfo.framebuffer = fbo[acquiredNextFBO];
364-
beginInfo.renderpass = renderpass;
365-
beginInfo.renderArea = area;
366-
beginInfo.clearValues = clear;
367-
}
368-
369-
commandBuffer->beginRenderPass(&beginInfo, nbl::asset::ESC_INLINE);
347+
348+
VkRect2D scissor = {};
349+
scissor.offset = { 0, 0 };
350+
scissor.extent = { WIN_W, WIN_H };
351+
commandBuffer->setScissor(0u, 1u, &scissor);
370352

371353
core::matrix3x4SIMD modelMatrix;
372354
modelMatrix.setTranslation(nbl::core::vectorSIMDf(0, 0, 0, 0));
373-
374355
core::matrix4SIMD mvp = core::concatenateBFollowedByA(viewProjectionMatrix, modelMatrix);
375356

376-
core::vector<uint8_t> uboData(gpuubo->getSize());
357+
const size_t uboSize = gpuubo->getCachedCreationParams().declaredSize;
358+
core::vector<uint8_t> uboData(uboSize);
377359
for (const auto& shdrIn : pipelineMetadata->m_inputSemantics)
378360
{
379361
if (shdrIn.descriptorSection.type == asset::IRenderpassIndependentPipelineMetadata::ShaderInput::ET_UNIFORM_BUFFER && shdrIn.descriptorSection.uniformBufferObject.set == 1u && shdrIn.descriptorSection.uniformBufferObject.binding == ds1UboBinding)
@@ -397,8 +379,28 @@ class MeshLoadersApp : public ApplicationBase
397379
}
398380
}
399381
}
382+
commandBuffer->updateBuffer(gpuubo.get(), 0ull, uboSize, uboData.data());
383+
384+
nbl::video::IGPUCommandBuffer::SRenderpassBeginInfo beginInfo;
385+
{
386+
VkRect2D area;
387+
area.offset = { 0,0 };
388+
area.extent = { WIN_W, WIN_H };
389+
asset::SClearValue clear[2] = {};
390+
clear[0].color.float32[0] = 1.f;
391+
clear[0].color.float32[1] = 1.f;
392+
clear[0].color.float32[2] = 1.f;
393+
clear[0].color.float32[3] = 1.f;
394+
clear[1].depthStencil.depth = 0.f;
395+
396+
beginInfo.clearValueCount = 2u;
397+
beginInfo.framebuffer = fbo[acquiredNextFBO];
398+
beginInfo.renderpass = renderpass;
399+
beginInfo.renderArea = area;
400+
beginInfo.clearValues = clear;
401+
}
400402

401-
commandBuffer->updateBuffer(gpuubo.get(), 0ull, gpuubo->getSize(), uboData.data());
403+
commandBuffer->beginRenderPass(&beginInfo, nbl::asset::ESC_INLINE);
402404

403405
for (size_t i = 0; i < gpumesh->getMeshBuffers().size(); ++i)
404406
{
@@ -422,7 +424,8 @@ class MeshLoadersApp : public ApplicationBase
422424

423425
commandBuffer->endRenderPass();
424426
commandBuffer->end();
425-
427+
428+
logicalDevice->resetFences(1, &fence.get());
426429
CommonAPI::Submit(logicalDevice.get(),
427430
swapchain.get(),
428431
commandBuffer.get(),

0 commit comments

Comments
 (0)