Mountain::Window

struct mountain::Window

Window Wrapper around GLFW

Public Functions

Window(std::string_view title, unsigned width, unsigned height)

Window ctor

Parameters
  • title: Window title

  • width: width of the window

  • height: height of the window

std::vector<const char*> get_instance_extension() const

Return

vector of supported extension by this window

GLFWwindow *get_window() const
inline std::string_view get_title() const
~Window()
Window(std::string_view title, unsigned width, unsigned height)
std::vector<const char*> get_instance_extension() const
SDL_Window *get_window() const
inline std::string_view get_title() const
~Window()

Mountain::Context

struct mountain::Context

Context class will hold the Vulkan context and so will be necessary to all other classes

Public Functions

Context(Window const &window, std::vector<const char*> const &devicesExtension)

Parameters
  • window: The window we want to us

  • devicesExtension: : extensions we need. Example : VK_KHR_SWAPCHAIN_EXTENSION_NAME

inline Window const &get_window() const

Return

Window object

inline vk::Device const &operator*() const

Useful to use vk::Device method through Context object

Return

The vulkan device

inline vk::Device const *operator->() const

Useful to use vk::Device method through Context object

Return

The vulkan device

std::pair<vk::UniqueDeviceMemory, vk::UniqueBuffer> create_buffer_and_memory(vk::DeviceSize const &size, vk::BufferUsageFlags usage, vk::MemoryPropertyFlags properties) const

Helper function which create a buffer and it’s associated memory

Parameters
  • size: Size of the buffer

  • usage: Usage of the buffer. example: eHostCoherent

  • properties: Properties that we want for the memories. example: eTransferDst

void copy_buffer(vk::UniqueBuffer &destination, vk::UniqueBuffer const &source, vk::DeviceSize const &size) const

Copy a fixed size content of source into destination

Parameters
  • destination:

  • source:

  • size: Fixed size data to copied

void copy_buffer_to_image(vk::Buffer buffer, vk::Image image, uint32_t width, uint32_t height) const

Copy the content of buffer inside image

Parameters
  • buffer:

  • image:

  • width: width of the image

  • height: height of the image

vk::UniqueImageView create_2d_image_views(vk::Image image, const vk::Format &format, vk::ImageAspectFlags aspectFlags, uint32_t mipmap_levels) const

Create a 2d Image view from an Image

Return

ImageView with automatic resource managment

Parameters
  • image: The image you’d want to create image view from

  • format: Format of the image view

  • aspectFlags:

  • mipmap_levels: mipmap level of the image

std::pair<vk::UniqueImage, vk::UniqueDeviceMemory> create_image(uint32_t width, uint32_t height, vk::Format format, vk::ImageTiling tiling, const vk::ImageUsageFlags &usage, vk::MemoryPropertyFlagBits, uint32_t mipmap_levels) const

Create an image and it’s associated memory

Return

Image and memory with automatic resources management

Parameters
  • width:

  • height:

  • format:

  • tiling: eOptimal or eLinear. Linear -> you have direct access to texel. Optimal: optimise for speed

  • usage: usage of memory. example eTransferDst

  • mipmap_levels: level of mipmap you’ll be using

vk::SurfaceFormatKHR choose_swap_surface_format() const

Return

adequate swap chain format

struct QueueFamilyIndices
struct SwapChainSupportDetails

Mountain::RenderPass

struct mountain::RenderPass

A render pass specify what will be use when we render something. To be short it define, if we want to use Color, Depth, Stencil

Public Functions

RenderPass(Context const &context, const SubPass &sub_pass)

Create a render pass

Parameters
  • context: Vulkan context

  • sub_pass: Define the subpass we will be using

inline bool has_depth() const

Return

true if renderpass will use depth

RenderPass operator=(RenderPass const&) = delete

Deleted copy operation

RenderPass(RenderPass const&) = delete

Deleted copy constructor

Mountain::SwapChain

struct mountain::SwapChain

Public Functions

SwapChain(Context const &context, RenderPass const &render_pass, int width, int height)

Construct a Vulkan swap chain for graphics purpose

Parameters
  • context: Vulkan context

  • render_pass:

  • width: width of the output image

  • height: height of the output image

SwapChain(SwapChain const&) = delete
SwapChain &operator=(SwapChain const&) = delete
const std::vector<vk::UniqueImageView> &get_swap_chain_image_views() const
std::vector<vk::Framebuffer> get_framebuffers() const
vk::Format get_swap_chain_image_format() const
const vk::Extent2D &get_swap_chain_extent() const
vk::SwapchainKHR get_swap_chain() const
~SwapChain()

Mountain::GraphicsPipeline

template<PushConstantType>
struct mountain::PushConstant

Template Parameters
  • PushConstantType: type of the value we want to be a push constant

Public Members

vk::ShaderStageFlagBits shader_stage

the stage in which the push constant will be use

struct mountain::shader

Public Members

std::filesystem::path path

path to spir-v file

vk::ShaderStageFlagBits type

Type of shader we pass

struct mountain::GraphicsPipeline

Public Functions

template<size_t n, class ...Ts>
GraphicsPipeline(Context const &context, SwapChain const &swap_chain, RenderPass const &render_pass, std::array<shader, n> const &shaders, const std::vector<buffer::vertex> &buffers, std::vector<vk::DescriptorSetLayout> const &descriptor_layout = {}, PushConstant<Ts> const&... push_constant)

Create a vulkan pipeline

Template Parameters
  • n: number of shaders

  • Ts: types of values hold by push constant

Parameters
  • context: Vulkan context

  • swap_chain:

  • render_pass:

  • shaders: array of compiled shaders

  • buffers: arrays of vertex buffers

  • descriptor_layout: array of descriptor layout for handling uniform

  • push_constant: PushConstant for each shaders use

inline vk::Pipeline const &get_pipeline() const
inline vk::PipelineLayout const &get_pipeline_layout() const
inline std::vector<vk::PushConstantRange> const &get_push_constant_ranges() const
~GraphicsPipeline()

Mountain::CommandBuffer

struct mountain::CommandBuffer

Public Functions

CommandBuffer(const Context &context, const SwapChain &swap_chain, RenderPass const &renderpass, int nb_uniform = 0)

Create CommandBuffer object

Parameters
  • context: Vulkan context

  • swap_chain:

  • renderpass:

  • nb_uniform: number of uniform we want to use (image sample count as uniform)

template<class PushConstantType>
void init(PipelineData<PushConstantType> const &pipeline_data)

Create vulkan command buffer

Template Parameters
  • PushConstantType: type of push constant to use in shader

Parameters
  • pipeline_data: contains data for rendering a vertex buffer

void allocate_descriptor_set(std::vector<vk::DescriptorSetLayout> &&descriptor_set_layouts)

Allocate the number of descriptor set layout we need, the size of vector parameter X the number of image in swap chain

Parameters
  • descriptor_set_layouts:

template<class T>
void update_descriptor_set(int first_descriptor_set_index, int binding, const buffer::uniform<T> &uniform_buffer)

Update uniform descriptor set

Template Parameters
  • T: type of value for the uniform

Parameters
  • first_descriptor_set_index: set value for this descriptor

  • binding: binding value

  • uniform_buffer: uniform buffer to associate with this descriptor

void update_descriptor_set(int first_descriptor_set_index, int binding, buffer::image2d const &image, image::sampler const &sampler)

Update image descriptor set

Parameters
  • first_descriptor_set_index: set value for this descriptor

  • binding: binding value

  • image: image to associate with this descriptor

  • sampler: sample to associate with this image

void drawFrame(std::vector<buffer::uniform_updater> &&updaters)

Draw frame with the record command buffers and update uniform values

Parameters
  • updaters: vector of uniform_updater. uniform_updater are created by calling get_uniform_updater on a mountain::buffer::uniform object

Mountain::buffer::uniform

template<class T>
struct mountain::buffer::uniform

The uniform class in Mountain-API packed two vulkan things:

  • vk::Buffer

  • vk::MemoryDevice It’s purpose is to encapsulate the creation of this two things.

    Template Parameters
    • T: type of the value we want in our uniform

Public Functions

uniform(Context const &context, size_t swap_chain_nb_images)

Construct a uniform object

Parameters
  • context: Vulkan context

  • swap_chain_nb_images: nb of uniform to create, one for each swap chain image

uniform_updater get_uniform_updater(const T &value)

Return

an uniform_updater object, it has to be passed to the draw function of CommandBuffer to be effective

Parameters
  • value: value for this uniform

Mountain::buffer::vertex

struct mountain::buffer::vertex_description

Public Functions

template<class T, auto N>
inline vertex_description(uint32_t binding, uint32_t location_start_from, std::array<format_offset<T>, N> &&format_offsets)

Template Parameters
  • T: Type of the structure use to create vertex buffer

  • N: number of attributes in the structure

Parameters
  • binding: must be unique by pipeline

  • location_start_from: location refer to location in shaders. The first attribute will have location=location_start_from and then we increment by 1 for every others attribute.

  • format_offsets: contains information about attributes, theirs offset inside the structure. This is not create by hand and you should use the CLASS_DESCRIPTION macro.

template<class T, class ...Ts>
auto mountain::get_format_offsets(Ts T::*... args)

Return

an array of offset by attribute. Use to create a buffer::vertex

Template Parameters
  • T: type of the structure

  • Ts: type of the attributes

Parameters
  • args: member pointer to attributes

struct mountain::buffer::vertex

Public Functions

template<Container container, Container_uint32_t indices_container>
vertex(Context const &context, vertex_description &&description, container &&vertices, indices_container &&indices)

Construct a vertex bufer

Template Parameters
  • container: a container

  • indices_container: a container of uint32_t

Parameters
  • context: vulkan context

  • description: the vertex_description

  • vertices: the vertices to include inside the buffer

  • indices: the corresponding indices

Mountain::buffer::image2d

struct mountain::buffer::image2d

A image2d in Mountain-API correspond to three vulkan things:

  • vk::Image

  • vk::MemoryDevice

  • vk::ImageView This three things are packed in this only structure. image2d will be required when you want to add texture in your shaders

Public Functions

image2d(Context const &context, fs::path const &image_path, uint32_t mipmap_level)

Construct an image and it’s associated Memory and imageview. After the image2d has been construct, it can be use directly

Parameters
  • context: Vulkan context

  • image_path: Path to the texture image

  • mipmap_level: : mipmap level wanted (automatically compute)

Mountain::image::sampler

struct mountain::image::sampler

Public Functions

sampler(Context const &context, uint32_t mipmap_levels)

Create a basic sampler with mipmap

Parameters
  • context: Vulkan context

  • mipmap_levels: mipmap level you want

Free Functions

std::pair<std::vector<Vertex>, std::vector<uint32_t>> mountain::model::load_obj(fs::path const &model_path)

Return

a vector of vertices and a vector of the corresponding indices

Parameters
  • model_path: path to the obj to load

vk::DescriptorSetLayoutBinding mountain::descriptorset_layout::create_descriptor_uniform(int binding, vk::ShaderStageFlags const &shader)

Create descriptor layout to be use as a uniform

Return

Corresponding descriptor set layout binding

Parameters
  • binding: number inside shader

  • shader: The stage of the shader this descriptor will be use

vk::DescriptorSetLayoutBinding mountain::descriptorset_layout::create_descriptor_image_sampler(int binding, vk::ShaderStageFlags const &shader)

Create descriptor layout to be use for image sampler

Return

Corresponding descriptor set layout binding

Parameters
  • binding: number inside shader

  • shader: The stage of the shader this descriptor will be use

vk::DescriptorSetLayout mountain::descriptorset_layout::create_descriptorset_layout(Context const &context, std::vector<vk::DescriptorSetLayoutBinding> &&set_layout_bindings)

Create a descriptor set layout from descriptor set layout binding pass as parameters

Return

Corresponding descriptor set layout

Parameters
  • context: Vulkan context

  • set_layout_bindings: vector of descriptor set layout binding