mirror of
https://github.com/opus-tango/IntroductionToVulkan.git
synced 2026-03-20 03:55:26 +00:00
Added license.txt file.
Added Project folder with source code examples Part 1, Part 2, Part 3 and Part 4.
This commit is contained in:
134
Project/Common/VulkanCommon.h
Normal file
134
Project/Common/VulkanCommon.h
Normal file
@@ -0,0 +1,134 @@
|
||||
// Copyright 2016 Intel Corporation All Rights Reserved
|
||||
//
|
||||
// Intel makes no representations about the suitability of this software for any purpose.
|
||||
// THIS SOFTWARE IS PROVIDED ""AS IS."" INTEL SPECIFICALLY DISCLAIMS ALL WARRANTIES,
|
||||
// EXPRESS OR IMPLIED, AND ALL LIABILITY, INCLUDING CONSEQUENTIAL AND OTHER INDIRECT DAMAGES,
|
||||
// FOR THE USE OF THIS SOFTWARE, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PROPRIETARY
|
||||
// RIGHTS, AND INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
// Intel does not assume any responsibility for any errors which may appear in this software
|
||||
// nor any responsibility to update it.
|
||||
|
||||
#if !defined(VULKAN_COMMON_HEADER)
|
||||
#define VULKAN_COMMON_HEADER
|
||||
|
||||
#include <vector>
|
||||
#include "vulkan.h"
|
||||
#include "OperatingSystem.h"
|
||||
|
||||
namespace Tutorial {
|
||||
|
||||
// ************************************************************ //
|
||||
// QueueParameters //
|
||||
// //
|
||||
// Vulkan Queue's parameters container class //
|
||||
// ************************************************************ //
|
||||
struct QueueParameters {
|
||||
VkQueue Handle;
|
||||
uint32_t FamilyIndex;
|
||||
|
||||
QueueParameters() :
|
||||
Handle( VK_NULL_HANDLE ),
|
||||
FamilyIndex( 0 ) {
|
||||
}
|
||||
};
|
||||
|
||||
// ************************************************************ //
|
||||
// SwapChainParameters //
|
||||
// //
|
||||
// Vulkan SwapChain's parameters container class //
|
||||
// ************************************************************ //
|
||||
struct SwapChainParameters {
|
||||
VkSwapchainKHR Handle;
|
||||
VkFormat Format;
|
||||
std::vector<VkImage> Images;
|
||||
|
||||
SwapChainParameters() :
|
||||
Handle( VK_NULL_HANDLE ),
|
||||
Format( VK_FORMAT_UNDEFINED ),
|
||||
Images() {
|
||||
}
|
||||
};
|
||||
|
||||
// ************************************************************ //
|
||||
// VulkanCommonParameters //
|
||||
// //
|
||||
// General Vulkan parameters' container class //
|
||||
// ************************************************************ //
|
||||
struct VulkanCommonParameters {
|
||||
VkInstance Instance;
|
||||
VkPhysicalDevice PhysicalDevice;
|
||||
VkDevice Device;
|
||||
QueueParameters GraphicsQueue;
|
||||
QueueParameters PresentQueue;
|
||||
VkSurfaceKHR PresentationSurface;
|
||||
SwapChainParameters SwapChain;
|
||||
VkSemaphore ImageAvailableSemaphore;
|
||||
VkSemaphore RenderingFinishedSemaphore;
|
||||
|
||||
VulkanCommonParameters() :
|
||||
Instance( VK_NULL_HANDLE ),
|
||||
PhysicalDevice( VK_NULL_HANDLE ),
|
||||
Device( VK_NULL_HANDLE ),
|
||||
GraphicsQueue(),
|
||||
PresentQueue(),
|
||||
PresentationSurface( VK_NULL_HANDLE ),
|
||||
SwapChain() {
|
||||
}
|
||||
};
|
||||
|
||||
// ************************************************************ //
|
||||
// VulkanCommon //
|
||||
// //
|
||||
// Base class for Vulkan more advanced tutorial classes //
|
||||
// ************************************************************ //
|
||||
class VulkanCommon : public OS::TutorialBase {
|
||||
public:
|
||||
VulkanCommon();
|
||||
virtual ~VulkanCommon();
|
||||
|
||||
bool PrepareVulkan( OS::WindowParameters parameters );
|
||||
virtual bool OnWindowSizeChanged() final override;
|
||||
|
||||
protected:
|
||||
VkPhysicalDevice GetPhysicalDevice() const;
|
||||
VkDevice GetDevice() const;
|
||||
|
||||
const QueueParameters GetGraphicsQueue() const;
|
||||
const QueueParameters GetPresentQueue() const;
|
||||
|
||||
const SwapChainParameters GetSwapChain() const;
|
||||
const VkSemaphore GetImageAvailableSemaphore() const;
|
||||
const VkSemaphore GetRenderingFinishedSemaphore() const;
|
||||
|
||||
private:
|
||||
OS::LibraryHandle VulkanLibrary;
|
||||
OS::WindowParameters Window;
|
||||
VulkanCommonParameters Vulkan;
|
||||
|
||||
bool LoadVulkanLibrary();
|
||||
bool LoadExportedEntryPoints();
|
||||
bool LoadGlobalLevelEntryPoints();
|
||||
bool CreateInstance();
|
||||
bool LoadInstanceLevelEntryPoints();
|
||||
bool CreatePresentationSurface();
|
||||
bool CreateDevice();
|
||||
bool CheckPhysicalDeviceProperties( VkPhysicalDevice physical_device, uint32_t &graphics_queue_family_index, uint32_t &present_queue_family_index );
|
||||
bool LoadDeviceLevelEntryPoints();
|
||||
bool GetDeviceQueue();
|
||||
bool CreateSwapChain();
|
||||
bool CreateSemaphores();
|
||||
virtual bool ChildOnWindowSizeChanged() = 0;
|
||||
virtual void ChildClear() = 0;
|
||||
|
||||
bool CheckExtensionAvailability( const char *extension_name, const std::vector<VkExtensionProperties> &available_extensions );
|
||||
uint32_t GetSwapChainNumImages( VkSurfaceCapabilitiesKHR &surface_capabilities );
|
||||
VkSurfaceFormatKHR GetSwapChainFormat( std::vector<VkSurfaceFormatKHR> &surface_formats );
|
||||
VkExtent2D GetSwapChainExtent( VkSurfaceCapabilitiesKHR &surface_capabilities );
|
||||
VkImageUsageFlags GetSwapChainUsageFlags( VkSurfaceCapabilitiesKHR &surface_capabilities );
|
||||
VkSurfaceTransformFlagBitsKHR GetSwapChainTransform( VkSurfaceCapabilitiesKHR &surface_capabilities );
|
||||
VkPresentModeKHR GetSwapChainPresentMode( std::vector<VkPresentModeKHR> &present_modes );
|
||||
};
|
||||
|
||||
} // namespace Tutorial
|
||||
|
||||
#endif // VULKAN_COMMON_HEADER
|
||||
Reference in New Issue
Block a user