Skip to content

Commit

Permalink
Android changes (#1194)
Browse files Browse the repository at this point in the history
* Update to latest MacOS image

* Minor android cleanup

Removed no longer required std functionality
  • Loading branch information
SaschaWillems authored Feb 28, 2025
1 parent 495a135 commit 42fc441
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 32 deletions.
3 changes: 1 addition & 2 deletions base/VulkanAndroid.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Android Vulkan function pointer loader
*
* Copyright (C) 2016-2024 by Sascha Willems - www.saschawillems.de
* Copyright (C) 2016-2025 by Sascha Willems - www.saschawillems.de
*
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
*/
Expand Down Expand Up @@ -359,7 +359,6 @@ namespace vks
jni->DeleteLocalRef(jmessage);

androidApp->activity->vm->DetachCurrentThread();
return;
}
}
}
Expand Down
12 changes: 1 addition & 11 deletions base/VulkanAndroid.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Android Vulkan function pointer prototypes
*
* Copyright (C) 2016-2024 by Sascha Willems - www.saschawillems.de
* Copyright (C) 2016-2025 by Sascha Willems - www.saschawillems.de
*
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
*/
Expand Down Expand Up @@ -29,16 +29,6 @@
#include <memory>
#include <string>

// Missing from the NDK
namespace std
{
template<typename T, typename... Args>
std::unique_ptr<T> make_unique(Args&&... args)
{
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}
}

// Global reference to android application object
extern android_app* androidApp;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class VulkanExample : public VulkanExampleBase
VkDeviceMemory memory{ VK_NULL_HANDLE };
};
Image renderImage;
Image depthStencilRenderImage;

VulkanExample() : VulkanExampleBase()
{
Expand All @@ -67,7 +66,7 @@ class VulkanExample : public VulkanExampleBase
deviceCreatepNextChain = &enabledDynamicRenderingFeaturesKHR;
}

~VulkanExample()
~VulkanExample() override
{
if (device) {
vkDestroyPipeline(device, pipeline, nullptr);
Expand Down Expand Up @@ -160,7 +159,7 @@ class VulkanExample : public VulkanExampleBase
}

// Enable physical device features required for this example
virtual void getEnabledFeatures()
void getEnabledFeatures() override
{
// Enable anisotropic filtering if supported
if (deviceFeatures.samplerAnisotropy) {
Expand All @@ -174,7 +173,7 @@ class VulkanExample : public VulkanExampleBase
model.loadFromFile(getAssetPath() + "models/voyager.gltf", vulkanDevice, queue, glTFLoadingFlags);
}

void buildCommandBuffers()
void buildCommandBuffers() override
{
VkCommandBufferBeginInfo cmdBufInfo = vks::initializers::commandBufferBeginInfo();

Expand Down Expand Up @@ -365,7 +364,7 @@ class VulkanExample : public VulkanExampleBase
memcpy(uniformBuffer.mapped, &uniformData, sizeof(uniformData));
}

void prepare()
void prepare() override
{
VulkanExampleBase::prepare();

Expand All @@ -390,7 +389,7 @@ class VulkanExample : public VulkanExampleBase
VulkanExampleBase::submitFrame();
}

virtual void render()
void render() override
{
if (!prepared)
return;
Expand Down
16 changes: 8 additions & 8 deletions examples/triangle/triangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Contrary to the other examples, this one won't make use of helper functions or initializers
* Except in a few cases (swap chain setup e.g.)
*
* Copyright (C) 2016-2024 by Sascha Willems - www.saschawillems.de
* Copyright (C) 2016-2025 by Sascha Willems - www.saschawillems.de
*
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
*/
Expand Down Expand Up @@ -126,7 +126,7 @@ class VulkanExample : public VulkanExampleBase
// Values not set here are initialized in the base class constructor
}

~VulkanExample()
~VulkanExample() override
{
// Clean up used Vulkan resources
// Note: Inherited destructor cleans up resources stored in base class
Expand Down Expand Up @@ -452,7 +452,7 @@ class VulkanExample : public VulkanExampleBase

// Create the depth (and stencil) buffer attachments used by our framebuffers
// Note: Override of virtual function in the base class and called from within VulkanExampleBase::prepare
void setupDepthStencil()
void setupDepthStencil() override
{
// Create an optimal image used as the depth stencil attachment
VkImageCreateInfo imageCI{};
Expand Down Expand Up @@ -502,7 +502,7 @@ class VulkanExample : public VulkanExampleBase

// Create a frame buffer for each swap chain image
// Note: Override of virtual function in the base class and called from within VulkanExampleBase::prepare
void setupFrameBuffer()
void setupFrameBuffer() override
{
// Create a frame buffer for every image in the swapchain
frameBuffers.resize(swapChain.images.size());
Expand Down Expand Up @@ -533,7 +533,7 @@ class VulkanExample : public VulkanExampleBase
// This allows the driver to know up-front what the rendering will look like and is a good opportunity to optimize especially on tile-based renderers (with multiple subpasses)
// Using sub pass dependencies also adds implicit layout transitions for the attachment used, so we don't need to add explicit image memory barriers to transform them
// Note: Override of virtual function in the base class and called from within VulkanExampleBase::prepare
void setupRenderPass()
void setupRenderPass() override
{
// This example will use a single render pass with one subpass

Expand Down Expand Up @@ -622,7 +622,7 @@ class VulkanExample : public VulkanExampleBase
// Vulkan loads its shaders from an immediate binary representation called SPIR-V
// Shaders are compiled offline from e.g. GLSL using the reference glslang compiler
// This function loads such a shader from a binary file and returns a shader module structure
VkShaderModule loadSPIRVShader(std::string filename)
VkShaderModule loadSPIRVShader(const std::string& filename)
{
size_t shaderSize;
char* shaderCode{ nullptr };
Expand Down Expand Up @@ -886,7 +886,7 @@ class VulkanExample : public VulkanExampleBase

}

void prepare()
void prepare() override
{
VulkanExampleBase::prepare();
createSynchronizationPrimitives();
Expand All @@ -900,7 +900,7 @@ class VulkanExample : public VulkanExampleBase
prepared = true;
}

virtual void render()
void render() override
{
if (!prepared)
return;
Expand Down
10 changes: 5 additions & 5 deletions examples/trianglevulkan13/trianglevulkan13.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class VulkanExample : public VulkanExampleBase
deviceCreatepNextChain = &enabledFeatures;
}

~VulkanExample()
~VulkanExample() override
{
// Clean up used Vulkan resources
// Note: Inherited destructor cleans up resources stored in base class
Expand Down Expand Up @@ -381,7 +381,7 @@ class VulkanExample : public VulkanExampleBase

// Create the depth (and stencil) buffer attachments
// While we don't do any depth testing in this sample, having depth testing is very common so it's a good idea to learn it from the very start
void setupDepthStencil()
void setupDepthStencil() override
{
// Create an optimal tiled image used as the depth stencil attachment
VkImageCreateInfo imageCI{ VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO };
Expand Down Expand Up @@ -428,7 +428,7 @@ class VulkanExample : public VulkanExampleBase
// Vulkan loads its shaders from an immediate binary representation called SPIR-V
// Shaders are compiled offline from e.g. GLSL using the reference glslang compiler
// This function loads such a shader from a binary file and returns a shader module structure
VkShaderModule loadSPIRVShader(std::string filename)
VkShaderModule loadSPIRVShader(const std::string& filename)
{
size_t shaderSize;
char* shaderCode{ nullptr };
Expand Down Expand Up @@ -661,7 +661,7 @@ class VulkanExample : public VulkanExampleBase

}

void prepare()
void prepare() override
{
VulkanExampleBase::prepare();
createSynchronizationPrimitives();
Expand All @@ -673,7 +673,7 @@ class VulkanExample : public VulkanExampleBase
prepared = true;
}

virtual void render() override
void render() override
{
// Use a fence to wait until the command buffer has finished execution before using it again
vkWaitForFences(device, 1, &waitFences[currentFrame], VK_TRUE, UINT64_MAX);
Expand Down

0 comments on commit 42fc441

Please sign in to comment.