Code cleanup
Mostly android related
This commit is contained in:
parent
42fc44114a
commit
1fd45647d7
2 changed files with 20 additions and 26 deletions
|
|
@ -76,7 +76,7 @@ VkResult VulkanExampleBase::createInstance()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Enabled requested instance extensions
|
// Enabled requested instance extensions
|
||||||
if (enabledInstanceExtensions.size() > 0)
|
if (!enabledInstanceExtensions.empty())
|
||||||
{
|
{
|
||||||
for (const char * enabledExtension : enabledInstanceExtensions)
|
for (const char * enabledExtension : enabledInstanceExtensions)
|
||||||
{
|
{
|
||||||
|
|
@ -120,7 +120,7 @@ VkResult VulkanExampleBase::createInstance()
|
||||||
instanceExtensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
|
instanceExtensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (instanceExtensions.size() > 0) {
|
if (!instanceExtensions.empty()) {
|
||||||
instanceCreateInfo.enabledExtensionCount = (uint32_t)instanceExtensions.size();
|
instanceCreateInfo.enabledExtensionCount = (uint32_t)instanceExtensions.size();
|
||||||
instanceCreateInfo.ppEnabledExtensionNames = instanceExtensions.data();
|
instanceCreateInfo.ppEnabledExtensionNames = instanceExtensions.data();
|
||||||
}
|
}
|
||||||
|
|
@ -316,7 +316,7 @@ void VulkanExampleBase::renderLoop()
|
||||||
|
|
||||||
benchmark.run([=] { render(); }, vulkanDevice->properties);
|
benchmark.run([=] { render(); }, vulkanDevice->properties);
|
||||||
vkDeviceWaitIdle(device);
|
vkDeviceWaitIdle(device);
|
||||||
if (benchmark.filename != "") {
|
if (!benchmark.filename.empty()) {
|
||||||
benchmark.saveResults();
|
benchmark.saveResults();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|
@ -344,7 +344,7 @@ void VulkanExampleBase::renderLoop()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#elif defined(VK_USE_PLATFORM_ANDROID_KHR)
|
#elif defined(VK_USE_PLATFORM_ANDROID_KHR)
|
||||||
while (1)
|
while (true)
|
||||||
{
|
{
|
||||||
int ident;
|
int ident;
|
||||||
int events;
|
int events;
|
||||||
|
|
@ -353,9 +353,9 @@ void VulkanExampleBase::renderLoop()
|
||||||
|
|
||||||
focused = true;
|
focused = true;
|
||||||
|
|
||||||
while ((ident = ALooper_pollOnce(focused ? 0 : -1, NULL, &events, (void**)&source)) > ALOOPER_POLL_TIMEOUT)
|
while ((ident = ALooper_pollOnce(focused ? 0 : -1, nullptr, &events, (void**)&source)) > ALOOPER_POLL_TIMEOUT)
|
||||||
{
|
{
|
||||||
if (source != NULL)
|
if (source != nullptr)
|
||||||
{
|
{
|
||||||
source->process(androidApp, source);
|
source->process(androidApp, source);
|
||||||
}
|
}
|
||||||
|
|
@ -404,8 +404,6 @@ void VulkanExampleBase::renderLoop()
|
||||||
|
|
||||||
updateOverlay();
|
updateOverlay();
|
||||||
|
|
||||||
bool updateView = false;
|
|
||||||
|
|
||||||
// Check touch state (for movement)
|
// Check touch state (for movement)
|
||||||
if (touchDown) {
|
if (touchDown) {
|
||||||
touchTimer += frameTimer;
|
touchTimer += frameTimer;
|
||||||
|
|
@ -422,23 +420,20 @@ void VulkanExampleBase::renderLoop()
|
||||||
if (std::abs(gamePadState.axisLeft.x) > deadZone)
|
if (std::abs(gamePadState.axisLeft.x) > deadZone)
|
||||||
{
|
{
|
||||||
camera.rotate(glm::vec3(0.0f, gamePadState.axisLeft.x * 0.5f, 0.0f));
|
camera.rotate(glm::vec3(0.0f, gamePadState.axisLeft.x * 0.5f, 0.0f));
|
||||||
updateView = true;
|
|
||||||
}
|
}
|
||||||
if (std::abs(gamePadState.axisLeft.y) > deadZone)
|
if (std::abs(gamePadState.axisLeft.y) > deadZone)
|
||||||
{
|
{
|
||||||
camera.rotate(glm::vec3(gamePadState.axisLeft.y * 0.5f, 0.0f, 0.0f));
|
camera.rotate(glm::vec3(gamePadState.axisLeft.y * 0.5f, 0.0f, 0.0f));
|
||||||
updateView = true;
|
|
||||||
}
|
}
|
||||||
// Zoom
|
// Zoom
|
||||||
if (std::abs(gamePadState.axisRight.y) > deadZone)
|
if (std::abs(gamePadState.axisRight.y) > deadZone)
|
||||||
{
|
{
|
||||||
camera.translate(glm::vec3(0.0f, 0.0f, gamePadState.axisRight.y * 0.01f));
|
camera.translate(glm::vec3(0.0f, 0.0f, gamePadState.axisRight.y * 0.01f));
|
||||||
updateView = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
updateView = camera.updatePad(gamePadState.axisLeft, gamePadState.axisRight, frameTimer);
|
camera.updatePad(gamePadState.axisLeft, gamePadState.axisRight, frameTimer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -915,9 +910,9 @@ VulkanExampleBase::~VulkanExampleBase()
|
||||||
{
|
{
|
||||||
vkDestroyRenderPass(device, renderPass, nullptr);
|
vkDestroyRenderPass(device, renderPass, nullptr);
|
||||||
}
|
}
|
||||||
for (uint32_t i = 0; i < frameBuffers.size(); i++)
|
for (auto& frameBuffer : frameBuffers)
|
||||||
{
|
{
|
||||||
vkDestroyFramebuffer(device, frameBuffers[i], nullptr);
|
vkDestroyFramebuffer(device, frameBuffer, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& shaderModule : shaderModules)
|
for (auto& shaderModule : shaderModules)
|
||||||
|
|
@ -1509,7 +1504,6 @@ int32_t VulkanExampleBase::handleAppInput(struct android_app* app, AInputEvent*
|
||||||
{
|
{
|
||||||
int32_t keyCode = AKeyEvent_getKeyCode((const AInputEvent*)event);
|
int32_t keyCode = AKeyEvent_getKeyCode((const AInputEvent*)event);
|
||||||
int32_t action = AKeyEvent_getAction((const AInputEvent*)event);
|
int32_t action = AKeyEvent_getAction((const AInputEvent*)event);
|
||||||
int32_t button = 0;
|
|
||||||
|
|
||||||
if (action == AKEY_EVENT_ACTION_UP)
|
if (action == AKEY_EVENT_ACTION_UP)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -1554,7 +1548,7 @@ int32_t VulkanExampleBase::handleAppInput(struct android_app* app, AInputEvent*
|
||||||
|
|
||||||
void VulkanExampleBase::handleAppCommand(android_app * app, int32_t cmd)
|
void VulkanExampleBase::handleAppCommand(android_app * app, int32_t cmd)
|
||||||
{
|
{
|
||||||
assert(app->userData != NULL);
|
assert(app->userData != nullptr);
|
||||||
VulkanExampleBase* vulkanExample = reinterpret_cast<VulkanExampleBase*>(app->userData);
|
VulkanExampleBase* vulkanExample = reinterpret_cast<VulkanExampleBase*>(app->userData);
|
||||||
switch (cmd)
|
switch (cmd)
|
||||||
{
|
{
|
||||||
|
|
@ -1568,7 +1562,7 @@ void VulkanExampleBase::handleAppCommand(android_app * app, int32_t cmd)
|
||||||
break;
|
break;
|
||||||
case APP_CMD_INIT_WINDOW:
|
case APP_CMD_INIT_WINDOW:
|
||||||
LOGD("APP_CMD_INIT_WINDOW");
|
LOGD("APP_CMD_INIT_WINDOW");
|
||||||
if (androidApp->window != NULL)
|
if (androidApp->window != nullptr)
|
||||||
{
|
{
|
||||||
if (vulkanExample->initVulkan()) {
|
if (vulkanExample->initVulkan()) {
|
||||||
vulkanExample->prepare();
|
vulkanExample->prepare();
|
||||||
|
|
@ -3195,8 +3189,8 @@ void VulkanExampleBase::windowResize()
|
||||||
vkDestroyImage(device, depthStencil.image, nullptr);
|
vkDestroyImage(device, depthStencil.image, nullptr);
|
||||||
vkFreeMemory(device, depthStencil.memory, nullptr);
|
vkFreeMemory(device, depthStencil.memory, nullptr);
|
||||||
setupDepthStencil();
|
setupDepthStencil();
|
||||||
for (uint32_t i = 0; i < frameBuffers.size(); i++) {
|
for (auto& frameBuffer : frameBuffers) {
|
||||||
vkDestroyFramebuffer(device, frameBuffers[i], nullptr);
|
vkDestroyFramebuffer(device, frameBuffer, nullptr);
|
||||||
}
|
}
|
||||||
setupFrameBuffer();
|
setupFrameBuffer();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -77,8 +77,8 @@ class VulkanExampleBase
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
std::string getWindowTitle() const;
|
std::string getWindowTitle() const;
|
||||||
uint32_t destWidth;
|
uint32_t destWidth{};
|
||||||
uint32_t destHeight;
|
uint32_t destHeight{};
|
||||||
bool resizing = false;
|
bool resizing = false;
|
||||||
void handleMouseMove(int32_t x, int32_t y);
|
void handleMouseMove(int32_t x, int32_t y);
|
||||||
void nextFrame();
|
void nextFrame();
|
||||||
|
|
@ -122,13 +122,13 @@ protected:
|
||||||
// Handle to the device graphics queue that command buffers are submitted to
|
// Handle to the device graphics queue that command buffers are submitted to
|
||||||
VkQueue queue{ VK_NULL_HANDLE };
|
VkQueue queue{ VK_NULL_HANDLE };
|
||||||
// Depth buffer format (selected during Vulkan initialization)
|
// Depth buffer format (selected during Vulkan initialization)
|
||||||
VkFormat depthFormat;
|
VkFormat depthFormat{VK_FORMAT_UNDEFINED};
|
||||||
// Command buffer pool
|
// Command buffer pool
|
||||||
VkCommandPool cmdPool{ VK_NULL_HANDLE };
|
VkCommandPool cmdPool{ VK_NULL_HANDLE };
|
||||||
/** @brief Pipeline stages used to wait at for graphics queue submissions */
|
/** @brief Pipeline stages used to wait at for graphics queue submissions */
|
||||||
VkPipelineStageFlags submitPipelineStages = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
VkPipelineStageFlags submitPipelineStages = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
||||||
// Contains command buffers and semaphores to be presented to the queue
|
// Contains command buffers and semaphores to be presented to the queue
|
||||||
VkSubmitInfo submitInfo;
|
VkSubmitInfo submitInfo{};
|
||||||
// Command buffers used for rendering
|
// Command buffers used for rendering
|
||||||
std::vector<VkCommandBuffer> drawCmdBuffers;
|
std::vector<VkCommandBuffer> drawCmdBuffers;
|
||||||
// Global render pass for frame buffer writes
|
// Global render pass for frame buffer writes
|
||||||
|
|
@ -151,7 +151,7 @@ protected:
|
||||||
VkSemaphore presentComplete;
|
VkSemaphore presentComplete;
|
||||||
// Command buffer submission and execution
|
// Command buffer submission and execution
|
||||||
VkSemaphore renderComplete;
|
VkSemaphore renderComplete;
|
||||||
} semaphores;
|
} semaphores{};
|
||||||
std::vector<VkFence> waitFences;
|
std::vector<VkFence> waitFences;
|
||||||
bool requiresStencil{ false };
|
bool requiresStencil{ false };
|
||||||
public:
|
public:
|
||||||
|
|
@ -170,7 +170,7 @@ public:
|
||||||
vks::Benchmark benchmark;
|
vks::Benchmark benchmark;
|
||||||
|
|
||||||
/** @brief Encapsulated physical and logical vulkan device */
|
/** @brief Encapsulated physical and logical vulkan device */
|
||||||
vks::VulkanDevice *vulkanDevice;
|
vks::VulkanDevice *vulkanDevice{};
|
||||||
|
|
||||||
/** @brief Example settings that can be changed e.g. by command line arguments */
|
/** @brief Example settings that can be changed e.g. by command line arguments */
|
||||||
struct Settings {
|
struct Settings {
|
||||||
|
|
@ -234,7 +234,7 @@ public:
|
||||||
struct TouchPos {
|
struct TouchPos {
|
||||||
int32_t x;
|
int32_t x;
|
||||||
int32_t y;
|
int32_t y;
|
||||||
} touchPos;
|
} touchPos{};
|
||||||
bool touchDown = false;
|
bool touchDown = false;
|
||||||
double touchTimer = 0.0;
|
double touchTimer = 0.0;
|
||||||
int64_t lastTapTime = 0;
|
int64_t lastTapTime = 0;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue