- A few Vulkan wrapper structs
- Framework for Vulkan context - Fixed a bug with dynarray where if `resize()` shrinks the array, destructors are not called. - Fixed grammar issues with the containers library and added property tables to existing data structures.
This commit is contained in:
210
include/fennec/renderers/vulkan/lib/app_info.h
Normal file
210
include/fennec/renderers/vulkan/lib/app_info.h
Normal file
@@ -0,0 +1,210 @@
|
||||
// =====================================================================================================================
|
||||
// fennec, a free and open source game engine
|
||||
// Copyright © 2025 Medusa Slockbower
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
// =====================================================================================================================
|
||||
|
||||
///
|
||||
/// \file instance.h
|
||||
/// \brief
|
||||
///
|
||||
///
|
||||
/// \details
|
||||
/// \author Medusa Slockbower
|
||||
///
|
||||
/// \copyright Copyright © 2025 Medusa Slockbower ([GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html))
|
||||
///
|
||||
///
|
||||
|
||||
|
||||
#ifndef FENNEC_RENDERERS_VULKAN_LIB_APP_INFO_H
|
||||
#define FENNEC_RENDERERS_VULKAN_LIB_APP_INFO_H
|
||||
|
||||
#include <volk.h>
|
||||
|
||||
#include <fennec/core/version.h>
|
||||
#include <fennec/string/cstring.h>
|
||||
|
||||
namespace fennec::vk
|
||||
{
|
||||
|
||||
struct app_info : private VkApplicationInfo {
|
||||
|
||||
// Constructors & Destructor ===========================================================================================
|
||||
public:
|
||||
///
|
||||
/// \brief Create a Vulkan application information structure
|
||||
/// \param app_name the name of the application, this cstring must exist for the lifetime of this object
|
||||
/// until a structure of type fennec::vk::instance is constructed
|
||||
/// \param app_version the internal version of the application
|
||||
/// \param engine_name the name of the engine, this cstring must exist for the lifetime of this object
|
||||
/// until a structure of type fennec::vk::instance is constructed
|
||||
/// \param engine_version the internal version of the engine
|
||||
/// \param api_version the Vulkan API version to use, version::patch and version::str are ignored
|
||||
/// \param ext a pointer to an extension structure, the object next points to must exist for the lifetime of this
|
||||
/// object until a structure of type fennec::vk::instance is constructed
|
||||
/// TODO: DEFINE EXTENSION STRUCTURE WRAPPERS
|
||||
app_info(
|
||||
const cstring& app_name = {}, const version& app_version = {},
|
||||
const cstring& engine_name = {}, const version& engine_version = {},
|
||||
const version& api_version = {},
|
||||
void* ext = nullptr
|
||||
) noexcept : VkApplicationInfo {
|
||||
.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
|
||||
.pNext = ext,
|
||||
.pApplicationName = app_name,
|
||||
.applicationVersion = VK_MAKE_VERSION(app_version.major, app_version.minor, app_version.patch),
|
||||
.pEngineName = engine_name,
|
||||
.engineVersion = VK_MAKE_VERSION(engine_version.major, engine_version.minor, engine_version.patch),
|
||||
.apiVersion = VK_MAKE_API_VERSION(0, api_version.major, api_version.minor, 0),
|
||||
} {
|
||||
}
|
||||
|
||||
///
|
||||
/// \brief Copy Constructor
|
||||
app_info(const app_info&) noexcept = default;
|
||||
|
||||
///
|
||||
/// \brief Move Constructor
|
||||
app_info(app_info&&) noexcept = default;
|
||||
|
||||
///
|
||||
/// \brief Destructor
|
||||
~app_info() noexcept = default;
|
||||
|
||||
|
||||
// Assignment Operators ================================================================================================
|
||||
public:
|
||||
|
||||
///
|
||||
/// \brief Copy Assignment
|
||||
app_info& operator=(const app_info&) noexcept = default;
|
||||
|
||||
///
|
||||
/// \brief Move Assignment
|
||||
app_info& operator=(app_info&&) noexcept = default;
|
||||
|
||||
|
||||
// Implicit Conversions ================================================================================================
|
||||
public:
|
||||
|
||||
///
|
||||
operator VkApplicationInfo*() noexcept {
|
||||
return this;
|
||||
}
|
||||
|
||||
///
|
||||
/// \brief Implicit Pointer Conversion
|
||||
operator const VkApplicationInfo*() const noexcept {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
// Properties ==========================================================================================================
|
||||
public:
|
||||
|
||||
///
|
||||
/// \returns A cstring containing the application name
|
||||
cstring get_app_name() const {
|
||||
return cstring(pApplicationName, strlen(pApplicationName));
|
||||
}
|
||||
|
||||
///
|
||||
/// \brief Set the application name
|
||||
/// \param str A cstring containing the new name
|
||||
void set_app_name(const cstring& str) {
|
||||
pApplicationName = str;
|
||||
}
|
||||
|
||||
///
|
||||
/// \returns A version struct containing the application version
|
||||
version get_app_version() const {
|
||||
return version {
|
||||
.major = VK_VERSION_MAJOR(applicationVersion),
|
||||
.minor = VK_VERSION_MINOR(applicationVersion),
|
||||
.patch = VK_VERSION_PATCH(applicationVersion)
|
||||
};
|
||||
}
|
||||
|
||||
///
|
||||
/// \brief Set the engine version
|
||||
/// \param ver A version struct containing the new version
|
||||
void set_engine_version(const version& ver) {
|
||||
engineVersion = VK_MAKE_VERSION(ver.major, ver.minor, ver.patch);
|
||||
}
|
||||
|
||||
///
|
||||
/// \returns A cstring containing the engine name
|
||||
cstring get_engine_name() const { return cstring(pEngineName, strlen(pEngineName)); }
|
||||
|
||||
///
|
||||
/// \brief Set the engine name
|
||||
/// \param str A cstring containing the new name
|
||||
void set_engine_name(const cstring& str) { pEngineName = str; }
|
||||
|
||||
///
|
||||
/// \returns A version struct containing the engine version
|
||||
version get_engine_version() const {
|
||||
return version {
|
||||
.major = VK_VERSION_MAJOR(engineVersion),
|
||||
.minor = VK_VERSION_MINOR(engineVersion),
|
||||
.patch = VK_VERSION_PATCH(engineVersion)
|
||||
};
|
||||
}
|
||||
|
||||
///
|
||||
/// \brief Set the engine version
|
||||
/// \param ver A version struct containing the new version
|
||||
void set_engine_version(const version& ver) {
|
||||
engineVersion = VK_MAKE_VERSION(ver.major, ver.minor, ver.patch);
|
||||
}
|
||||
|
||||
///
|
||||
/// \returns A version struct containing the Vulkan API version
|
||||
version get_api_version() const {
|
||||
return version {
|
||||
.major = VK_API_VERSION_MAJOR(apiVersion),
|
||||
.minor = VK_API_VERSION_MINOR(apiVersion)
|
||||
};
|
||||
}
|
||||
|
||||
///
|
||||
/// \brief Set the Vulkan API version
|
||||
/// \param ver A version struct containing the new version
|
||||
void set_api_version(const version& ver) {
|
||||
apiVersion = VK_MAKE_API_VERSION(0, ver.major, ver.minor, 0);
|
||||
}
|
||||
|
||||
///
|
||||
/// \brief Set the extension structure
|
||||
/// \param ext A pointer to the new extension object
|
||||
void set_extension(void* ext) {
|
||||
pNext = ext;
|
||||
}
|
||||
|
||||
///
|
||||
/// \brief Clear the extension structure with \f$nullptr\f$
|
||||
void set_extension(nullptr_t) {
|
||||
pNext = nullptr;
|
||||
}
|
||||
|
||||
|
||||
// Private Members =====================================================================================================
|
||||
private:
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // FENNEC_RENDERERS_VULKAN_LIB_APP_INFO_H
|
||||
89
include/fennec/renderers/vulkan/lib/instance.h
Normal file
89
include/fennec/renderers/vulkan/lib/instance.h
Normal file
@@ -0,0 +1,89 @@
|
||||
// =====================================================================================================================
|
||||
// fennec, a free and open source game engine
|
||||
// Copyright © 2025 Medusa Slockbower
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
// =====================================================================================================================
|
||||
|
||||
///
|
||||
/// \file instance.h
|
||||
/// \brief
|
||||
///
|
||||
///
|
||||
/// \details
|
||||
/// \author Medusa Slockbower
|
||||
///
|
||||
/// \copyright Copyright © 2025 Medusa Slockbower ([GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html))
|
||||
///
|
||||
///
|
||||
|
||||
|
||||
#ifndef FENNEC_RENDERERS_VULKAN_LIB_INSTANCE_H
|
||||
#define FENNEC_RENDERERS_VULKAN_LIB_INSTANCE_H
|
||||
|
||||
#include <volk.h>
|
||||
#include <fennec/containers/dynarray.h>
|
||||
|
||||
#include <fennec/renderers/vulkan/lib/app_info.h>
|
||||
|
||||
namespace fennec::vk
|
||||
{
|
||||
|
||||
struct instance {
|
||||
public:
|
||||
using create_flags = VkInstanceCreateFlags;
|
||||
|
||||
struct create_info : private VkInstanceCreateInfo {
|
||||
public:
|
||||
template<size_t LayersN, size_t ExtensionsN>
|
||||
create_info(
|
||||
create_flags flags, const app_info& info,
|
||||
const cstring (&layers)[LayersN], const cstring (&extensions)[ExtensionsN],
|
||||
void* ext
|
||||
) : VkInstanceCreateInfo {
|
||||
.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
|
||||
.pNext = ext,
|
||||
.flags = flags,
|
||||
.pApplicationInfo = info,
|
||||
.enabledLayerCount = LayersN,
|
||||
.ppEnabledLayerNames = nullptr,
|
||||
.enabledExtensionCount = ExtensionsN,
|
||||
.ppEnabledExtensionNames = nullptr,
|
||||
} {
|
||||
_layers.reserve(LayersN);
|
||||
for (const auto& layer : layers) { _layers.push_back(layer); }
|
||||
|
||||
_extensions.reserve(ExtensionsN);
|
||||
for (const auto& extension : extensions) { _extensions.push_back(extension); }
|
||||
|
||||
ppEnabledLayerNames = _layers.data();
|
||||
ppEnabledExtensionNames = _extensions.data();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private:
|
||||
dynarray<const char*> _layers;
|
||||
dynarray<const char*> _extensions;
|
||||
};
|
||||
|
||||
instance();
|
||||
|
||||
private:
|
||||
VkInstance _handle;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // FENNEC_RENDERERS_VULKAN_LIB_INSTANCE_H
|
||||
@@ -23,7 +23,6 @@ namespace fennec {
|
||||
|
||||
vkcontext::vkcontext(display_server* display)
|
||||
: gfxcontext(display) {
|
||||
|
||||
}
|
||||
|
||||
vkcontext::~vkcontext() {
|
||||
|
||||
@@ -40,15 +40,14 @@
|
||||
namespace fennec
|
||||
{
|
||||
|
||||
class vkcontext : gfxcontext {
|
||||
class vkcontext : public gfxcontext {
|
||||
public:
|
||||
vkcontext(display_server* display);
|
||||
~vkcontext();
|
||||
|
||||
bool is_valid() override;
|
||||
|
||||
private:
|
||||
|
||||
protected:
|
||||
};
|
||||
|
||||
} // fennec
|
||||
|
||||
Reference in New Issue
Block a user